Skip to content

Commit

Permalink
Merge pull request #147 from essentialkaos/develop
Browse files Browse the repository at this point in the history
Version 7.3.0
  • Loading branch information
andyone authored Jul 18, 2023
2 parents ed1e59e + 4c7831b commit 9b79dff
Show file tree
Hide file tree
Showing 12 changed files with 125 additions and 13 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ jobs:
uses: actions/checkout@v3

- name: Check spelling
continue-on-error: true
uses: crate-ci/typos@master

DockerBuild:
Expand Down
23 changes: 23 additions & 0 deletions COOKBOOK.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
* [`service-present`](#service-present)
* [`service-enabled`](#service-enabled)
* [`service-works`](#service-works)
* [`wait-service`](#wait-service)
* [HTTP](#http)
* [`http-status`](#http-status)
* [`http-header`](#http-header)
Expand Down Expand Up @@ -1636,6 +1637,28 @@ command "-" "Check environment"

<a href="#"><img src="https://gh.kaos.st/separator.svg"/></a>

##### `wait-service`

Waits for service start.

**Syntax:** `wait-service <service-name> <timeout>`

**Arguments:**

* `service-name` - Service name (_String_)
* `timeout` - Timeout in seconds (_Float_) [Optional | 15 seconds]

**Negative form:** Yes

**Example:**

```yang
command "systemctl start nginx" "Start Nginx service"
wait-service nginx 5
```

<a href="#"><img src="https://gh.kaos.st/separator.svg"/></a>

#### HTTP

##### `http-status`
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<br/>

`bibop` is a utility for testing command-line tools and daemons. Initially, this utility was created for testing packages from [ESSENTIAL KAOS Public Yum Repository](https://yum.kaos.st).
`bibop` is a utility for testing command-line tools and daemons. Initially, this utility was created for testing packages from [ESSENTIAL KAOS Public Repository](https://pkgs.kaos.st).

Information about bibop recipe syntax you can find in our [cookbook](COOKBOOK.md).

Expand Down
57 changes: 57 additions & 0 deletions action/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ package action

import (
"fmt"
"time"

"github.com/essentialkaos/ek/v12/initsystem"
"github.com/essentialkaos/ek/v12/mathutil"
"github.com/essentialkaos/ek/v12/timeutil"

"github.com/essentialkaos/bibop/recipe"
)
Expand Down Expand Up @@ -84,3 +87,57 @@ func ServiceWorks(action *recipe.Action) error {

return nil
}

// WaitService is action processor for "wait-service"
func WaitService(action *recipe.Action) error {
var timeout float64

service, err := action.GetS(0)

if err != nil {
return err
}

if action.Has(1) {
timeout, err = action.GetF(1)

if err != nil {
return err
}
} else {
timeout = 15.0
}

start := time.Now()
timeout = mathutil.BetweenF64(timeout, 0.01, 3600.0)
timeoutDur := timeutil.SecondsToDuration(timeout)

for range time.NewTicker(time.Second / 2).C {
isWorks, err := initsystem.IsWorks(service)

if err == nil {
switch {
case !action.Negative && isWorks,
action.Negative && !isWorks:
return nil
}
}

if time.Since(start) >= timeoutDur {
break
}
}

switch action.Negative {
case false:
return fmt.Errorf(
"Timeout (%g sec) reached, and service %s not started",
timeout, service,
)
default:
return fmt.Errorf(
"Timeout (%g sec) reached, and service %s still works",
timeout, service,
)
}
}
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
// Application info
const (
APP = "bibop"
VER = "7.2.3"
VER = "7.3.0"
DESC = "Utility for testing command-line tools"
)

Expand Down
1 change: 1 addition & 0 deletions cli/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ var handlers = map[string]action.Handler{
recipe.ACTION_SERVICE_PRESENT: action.ServicePresent,
recipe.ACTION_SERVICE_ENABLED: action.ServiceEnabled,
recipe.ACTION_SERVICE_WORKS: action.ServiceWorks,
recipe.ACTION_WAIT_SERVICE: action.WaitService,
recipe.ACTION_HTTP_STATUS: action.HTTPStatus,
recipe.ACTION_HTTP_HEADER: action.HTTPHeader,
recipe.ACTION_HTTP_CONTAINS: action.HTTPContains,
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ require (
github.com/buger/jsonparser v1.1.1
github.com/essentialkaos/check v1.4.0
github.com/essentialkaos/depsy v1.1.0
github.com/essentialkaos/ek/v12 v12.69.0
github.com/essentialkaos/ek/v12 v12.71.0
github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ github.com/essentialkaos/check v1.4.0 h1:kWdFxu9odCxUqo1NNFNJmguGrDHgwi3A8daXX1n
github.com/essentialkaos/check v1.4.0/go.mod h1:LMKPZ2H+9PXe7Y2gEoKyVAwUqXVgx7KtgibfsHJPus0=
github.com/essentialkaos/depsy v1.1.0 h1:U6dp687UkQwXlZU17Hg2KMxbp3nfZAoZ8duaeUFYvJI=
github.com/essentialkaos/depsy v1.1.0/go.mod h1:kpiTAV17dyByVnrbNaMcZt2jRwvuXClUYOzpyJQwtG8=
github.com/essentialkaos/ek/v12 v12.69.0 h1:UxDZdFLgA15BVelpR3IpkY3RPc/EdY7sXJHbT4T7J90=
github.com/essentialkaos/ek/v12 v12.69.0/go.mod h1:juDcZWOWaj1QmYShZkT9RzdqJ3n0tmeP/iq4sw5fQF0=
github.com/essentialkaos/ek/v12 v12.71.0 h1:r5rz4C+wVhsjiXV/vwnaeojrRAOx/Q8aufyRGKLUuRI=
github.com/essentialkaos/ek/v12 v12.71.0/go.mod h1:juDcZWOWaj1QmYShZkT9RzdqJ3n0tmeP/iq4sw5fQF0=
github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2 h1:CVuJwN34x4xM2aT4sIKhmeib40NeBPhRihNjQmpJsA4=
github.com/google/goterm v0.0.0-20200907032337-555d40f16ae2/go.mod h1:nOFQdrUlIlx6M6ODdSpBj1NVA+VgLC6kmw60mkw34H4=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
Expand Down
19 changes: 15 additions & 4 deletions recipe/recipe.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ var varExtRegex = regexp.MustCompile(`\{([a-zA-Z0-9]{1}[a-zA-Z0-9_\-]+\:[^\}]+)\
// userRegex is regexp for parsing user in command
var userRegex = regexp.MustCompile(`^([a-zA-Z_0-9\{\}]+):`)

// varNameRegex is regexp for variable name validation
var varNameRegex = regexp.MustCompile(`^([a-zA-Z0-9]{1}[a-zA-Z0-9_\-]+)$`)

// ////////////////////////////////////////////////////////////////////////////////// //

// NewRecipe create new recipe struct
Expand Down Expand Up @@ -168,6 +171,10 @@ func (r *Recipe) AddVariable(name, value string) error {
return fmt.Errorf("Can't define variable %q: variable contains itself as a part of value", name)
}

if !varNameRegex.MatchString(name) {
return fmt.Errorf("Can't define variable %q: variable name is not valid", name)
}

r.variables.data = append(r.variables.data, name)
r.variables.index[name] = &Variable{value, true}

Expand Down Expand Up @@ -530,11 +537,13 @@ func renderVars(r *Recipe, data string) string {
continue
}

data = strings.ReplaceAll(data, found[0], varValue)
rendered := strings.ReplaceAll(data, found[0], varValue)

if len(data) > MAX_VARIABLE_SIZE {
if len(rendered) > MAX_VARIABLE_SIZE {
return data
}

data = rendered
}

for _, found := range varExtRegex.FindAllStringSubmatch(data, -1) {
Expand All @@ -544,11 +553,13 @@ func renderVars(r *Recipe, data string) string {
continue
}

data = strings.ReplaceAll(data, found[0], varValue)
rendered := strings.ReplaceAll(data, found[0], varValue)

if len(data) > MAX_VARIABLE_SIZE {
if len(rendered) > MAX_VARIABLE_SIZE {
return data
}

data = rendered
}
}

Expand Down
13 changes: 12 additions & 1 deletion recipe/recipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ package recipe
import (
"errors"
"os"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -361,7 +362,11 @@ func (s *RecipeSuite) TestVariables(c *C) {

c.Assert(r.GetVariable("unknown", false), Equals, "")

r.AddVariable("test1", "abc1")
err := r.AddVariable("test1$", "abc1")
c.Assert(err, NotNil)

err = r.AddVariable("test1", "abc1")
c.Assert(err, IsNil)
c.Assert(r.GetVariable("test1", false), Equals, "abc1")

r.variables = &Variables{index: map[string]*Variable{}}
Expand All @@ -383,6 +388,12 @@ func (s *RecipeSuite) TestVariables(c *C) {
c.Assert(r.GetVariable("unknown", false), Equals, "")

c.Assert(r.GetVariables(), DeepEquals, []string{"test2", "test1", "test3"})

r.variables.index["longvar"] = &Variable{strings.Repeat("A", 300), false}
r.variables.index["longvar:test"] = &Variable{strings.Repeat("A", 300), false}

c.Assert(renderVars(r, "{longvar}{longvar}"), Equals, "{longvar}{longvar}")
c.Assert(renderVars(r, "{longvar:test}{longvar:test}"), Equals, "{longvar:test}{longvar:test}")
}

func (s *RecipeSuite) TestAux(c *C) {
Expand Down
2 changes: 2 additions & 0 deletions recipe/tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ const (
ACTION_SERVICE_PRESENT = "service-present"
ACTION_SERVICE_ENABLED = "service-enabled"
ACTION_SERVICE_WORKS = "service-works"
ACTION_WAIT_SERVICE = "wait-service"

ACTION_HTTP_STATUS = "http-status"
ACTION_HTTP_HEADER = "http-header"
Expand Down Expand Up @@ -194,6 +195,7 @@ var Tokens = []TokenInfo{
{ACTION_SERVICE_PRESENT, 1, 1, false, true},
{ACTION_SERVICE_ENABLED, 1, 1, false, true},
{ACTION_SERVICE_WORKS, 1, 1, false, true},
{ACTION_WAIT_SERVICE, 1, 2, false, true},

{ACTION_HTTP_STATUS, 3, 4, false, true},
{ACTION_HTTP_HEADER, 4, 5, false, true},
Expand Down
12 changes: 9 additions & 3 deletions scripts/bibop-dep
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
################################################################################

APP="bibop-dep"
VER="1.3.0"
VER="1.3.1"

################################################################################

Expand Down Expand Up @@ -68,6 +68,7 @@ MERGEABLE_OPTS="enablerepo disablerepo"
################################################################################

transactions_dir="/var/tmp/bibop-dep-transactions"
repolist_cache="/var/tmp/repolist.cache"

################################################################################

Expand Down Expand Up @@ -138,15 +139,20 @@ prepare() {
checkOptions() {
local repo

if [[ -z $(find "/var/tmp" -name '*.cache' -newermt '1 hour ago') ]] ; then
show "\nCaching repolist info…\n" $DARK
yum -q repolist all | cut -f1 -d' ' > "$repolist_cache"
fi

for repo in "${enablerepo[@]}" ; do
if ! yum repolist all | cut -f1 -d' ' | grep -qE "^${repo}$" ; then
if ! grep -qE "^${repo}" "$repolist_cache" ; then
error "Can't enable repository \"${repo}\" — there is no repository with this name"
return 1
fi
done

for repo in "${disablerepo[@]}" ; do
if ! yum repolist all | cut -f1 -d' ' | grep -qE "^${repo}$" ; then
if ! grep -qE "^${repo}" "$repolist_cache" ; then
error "Can't disable repository \"${repo}\" — there is no repository with this name"
return 1
fi
Expand Down

0 comments on commit 9b79dff

Please sign in to comment.