From 529a272ab6dabfc94555152de07f74d3e75f3a74 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 31 Jul 2021 12:27:33 +0300 Subject: [PATCH 1/6] Use our CentOS docker image instead of official one --- centos7.docker | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/centos7.docker b/centos7.docker index 1a3a3ee1..48b4fbc4 100644 --- a/centos7.docker +++ b/centos7.docker @@ -1,6 +1,6 @@ ## BUILDER ##################################################################### -FROM centos:7 as builder +FROM essentialkaos/centos:7 as builder RUN mkdir -p "/go/src" && chmod -R 777 "/go" @@ -21,7 +21,7 @@ RUN yum -y -q install https://yum.kaos.st/kaos-repo-latest.el7.noarch.rpm && \ ## FINAL IMAGE ################################################################# -FROM centos:7 +FROM essentialkaos/centos:7 LABEL name="Bibop Image on CentOS 7" \ vendor="ESSENTIAL KAOS" \ From 4b9a302ec14842e87cbe10c3ad1eb82c95f30487 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 31 Jul 2021 12:43:14 +0300 Subject: [PATCH 2/6] Update copyright header --- action/auxi.go | 2 +- action/backup.go | 2 +- action/common.go | 2 +- action/fs.go | 2 +- action/http.go | 2 +- action/io.go | 2 +- action/libs.go | 2 +- action/python.go | 2 +- action/service.go | 2 +- action/system.go | 2 +- action/users.go | 2 +- bibop.go | 2 +- cli/cli.go | 2 +- cli/executor/executor.go | 2 +- cli/executor/validators.go | 2 +- output/output_store.go | 2 +- parser/fuzz.go | 2 +- parser/parser.go | 2 +- parser/parser_test.go | 2 +- recipe/recipe.go | 2 +- recipe/recipe_test.go | 2 +- recipe/runtime_variables.go | 2 +- recipe/tokens.go | 2 +- render/render.go | 2 +- render/renderer_json.go | 2 +- render/renderer_quiet.go | 2 +- render/renderer_tap13.go | 2 +- render/renderer_terminal.go | 2 +- render/renderer_xml.go | 2 +- 29 files changed, 29 insertions(+), 29 deletions(-) diff --git a/action/auxi.go b/action/auxi.go index 4a45ec4b..99eef072 100644 --- a/action/auxi.go +++ b/action/auxi.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/backup.go b/action/backup.go index 390518b9..3309a810 100644 --- a/action/backup.go +++ b/action/backup.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/common.go b/action/common.go index 8925426e..d163fb4b 100644 --- a/action/common.go +++ b/action/common.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/fs.go b/action/fs.go index b7dcf0a5..8cb23790 100644 --- a/action/fs.go +++ b/action/fs.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/http.go b/action/http.go index 064610cf..534170ba 100644 --- a/action/http.go +++ b/action/http.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/io.go b/action/io.go index ef6c91a7..ce11bbf1 100644 --- a/action/io.go +++ b/action/io.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/libs.go b/action/libs.go index 47fb048f..b8996c03 100644 --- a/action/libs.go +++ b/action/libs.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/python.go b/action/python.go index 51ddac5f..404592c5 100644 --- a/action/python.go +++ b/action/python.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/service.go b/action/service.go index e146a075..8a653374 100644 --- a/action/service.go +++ b/action/service.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/system.go b/action/system.go index ad588e3c..d974aac6 100644 --- a/action/system.go +++ b/action/system.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/action/users.go b/action/users.go index 8979b527..ca8e214a 100644 --- a/action/users.go +++ b/action/users.go @@ -2,7 +2,7 @@ package action // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/bibop.go b/bibop.go index 4210dc1a..c4b0a258 100644 --- a/bibop.go +++ b/bibop.go @@ -4,7 +4,7 @@ package main // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/cli.go b/cli/cli.go index 66c18905..bd951d40 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -2,7 +2,7 @@ package cli // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 17275343..0673caac 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -2,7 +2,7 @@ package executor // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/cli/executor/validators.go b/cli/executor/validators.go index 6aed5cc3..f1677785 100644 --- a/cli/executor/validators.go +++ b/cli/executor/validators.go @@ -2,7 +2,7 @@ package executor // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/output/output_store.go b/output/output_store.go index f75fd801..61551c5d 100644 --- a/output/output_store.go +++ b/output/output_store.go @@ -2,7 +2,7 @@ package output // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/parser/fuzz.go b/parser/fuzz.go index bdaf8c61..b1a192a0 100644 --- a/parser/fuzz.go +++ b/parser/fuzz.go @@ -4,7 +4,7 @@ package parser // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/parser/parser.go b/parser/parser.go index ef2f4528..a1314026 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -2,7 +2,7 @@ package parser // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/parser/parser_test.go b/parser/parser_test.go index 3830fcf9..a18262c2 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -2,7 +2,7 @@ package parser // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/recipe/recipe.go b/recipe/recipe.go index 6c246284..6557168c 100644 --- a/recipe/recipe.go +++ b/recipe/recipe.go @@ -2,7 +2,7 @@ package recipe // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/recipe/recipe_test.go b/recipe/recipe_test.go index 93e9fda5..ad93b8eb 100644 --- a/recipe/recipe_test.go +++ b/recipe/recipe_test.go @@ -2,7 +2,7 @@ package recipe // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/recipe/runtime_variables.go b/recipe/runtime_variables.go index c97e7811..d4552900 100644 --- a/recipe/runtime_variables.go +++ b/recipe/runtime_variables.go @@ -2,7 +2,7 @@ package recipe // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/recipe/tokens.go b/recipe/tokens.go index 89faf9e2..09a4affc 100644 --- a/recipe/tokens.go +++ b/recipe/tokens.go @@ -2,7 +2,7 @@ package recipe // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/render.go b/render/render.go index 723cf118..52b62a7b 100644 --- a/render/render.go +++ b/render/render.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_json.go b/render/renderer_json.go index 9b5bb779..70d9d68b 100644 --- a/render/renderer_json.go +++ b/render/renderer_json.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_quiet.go b/render/renderer_quiet.go index ea73dd66..db44125e 100644 --- a/render/renderer_quiet.go +++ b/render/renderer_quiet.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_tap13.go b/render/renderer_tap13.go index 72282778..6380176d 100644 --- a/render/renderer_tap13.go +++ b/render/renderer_tap13.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_terminal.go b/render/renderer_terminal.go index 90ab0f9d..ea7fc5e7 100644 --- a/render/renderer_terminal.go +++ b/render/renderer_terminal.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/render/renderer_xml.go b/render/renderer_xml.go index 77685872..e7c35749 100644 --- a/render/renderer_xml.go +++ b/render/renderer_xml.go @@ -2,7 +2,7 @@ package render // ////////////////////////////////////////////////////////////////////////////////// // // // -// Copyright (c) 2020 ESSENTIAL KAOS // +// Copyright (c) 2021 ESSENTIAL KAOS // // Apache License, Version 2.0 // // // // ////////////////////////////////////////////////////////////////////////////////// // From 136041ac7c840ec053ba0810c1c3fc3dfb8d58f5 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 31 Jul 2021 14:24:42 +0300 Subject: [PATCH 3/6] Add teardown tag support --- COOKBOOK.md | 236 +++++++++++++++++++++++++++++++++++---- cli/cli.go | 2 +- cli/executor/executor.go | 23 +++- recipe/recipe.go | 14 +++ 4 files changed, 248 insertions(+), 27 deletions(-) diff --git a/COOKBOOK.md b/COOKBOOK.md index f4e5ecc1..6c288ce8 100644 --- a/COOKBOOK.md +++ b/COOKBOOK.md @@ -269,6 +269,8 @@ You can execute the command as another user. For using this feature, you should You can define tag and execute the command with a tag on demand (using `-t` /` --tag` option of CLI). By default, all commands with tags are ignored. +Also, there is a special tag — `teardown`. If a command has this tag, this command will be executed even if `fast-finish` is set to true. + **Syntax:** `command:tag [description]` **Arguments:** @@ -1985,17 +1987,28 @@ command "mkcryptpasswd --abcd" "Return error about unsupported argument" ``` ```yang -# Bibop recipe for webkaos +# Bibop recipe for webkaos (CentOS 7+) + +pkg webkaos webkaos-debug webkaos-nginx webkaos-module-brotli webkaos-module-naxsi require-root yes unsafe-actions yes +https-skip-verify yes var service_name webkaos var user_name webkaos - -var config /etc/webkaos/{service_name}.conf -var pid_file /var/run/{service_name}.pid -var log_dir /var/log/{service_name} +var prefix_dir /etc/webkaos +var config {prefix_dir}/webkaos.conf +var binary /usr/sbin/webkaos +var modules_config {prefix_dir}/modules.conf +var modules_dir /usr/share/webkaos/modules +var pid_file /var/run/webkaos.pid +var ssl_dir {prefix_dir}/ssl +var dh_param {ssl_dir}/dhparam.pem +var log_dir /var/log/webkaos + +var lua_ver 2.1.0-beta3 +var lua_dir /usr/share/webkaos/luajit/share/luajit-{lua_ver} command "-" "System environment validation" user-exist {user_name} @@ -2005,46 +2018,229 @@ command "-" "System environment validation" exist {config} exist {log_dir} -command "systemctl start {service_name}" "Starting service" - wait-pid {pid_file} 180 +command "-" "Debug version" + exist {binary}.debug + service-present webkaos-debug + +command "-" "Check linking with LuaJIT" + lib-rpath {binary} /usr/share/webkaos/luajit/lib + lib-linked {binary} "libluajit-5.1.so.*" + +command "-" "Check Resty core and lrucache" + dir {lua_dir}/ngx + dir {lua_dir}/ngx/ssl + dir {lua_dir}/resty + dir {lua_dir}/resty/core + dir {lua_dir}/resty/lrucache + + exist {lua_dir}/ngx/balancer.lua + exist {lua_dir}/ngx/base64.lua + exist {lua_dir}/ngx/errlog.lua + exist {lua_dir}/ngx/ocsp.lua + exist {lua_dir}/ngx/pipe.lua + exist {lua_dir}/ngx/process.lua + exist {lua_dir}/ngx/re.lua + exist {lua_dir}/ngx/req.lua + exist {lua_dir}/ngx/resp.lua + exist {lua_dir}/ngx/semaphore.lua + exist {lua_dir}/ngx/ssl.lua + exist {lua_dir}/ngx/ssl/session.lua + exist {lua_dir}/resty/core.lua + exist {lua_dir}/resty/lrucache.lua + exist {lua_dir}/resty/core/base.lua + exist {lua_dir}/resty/core/base64.lua + exist {lua_dir}/resty/core/ctx.lua + exist {lua_dir}/resty/core/exit.lua + exist {lua_dir}/resty/core/hash.lua + exist {lua_dir}/resty/core/misc.lua + exist {lua_dir}/resty/core/ndk.lua + exist {lua_dir}/resty/core/phase.lua + exist {lua_dir}/resty/core/regex.lua + exist {lua_dir}/resty/core/request.lua + exist {lua_dir}/resty/core/response.lua + exist {lua_dir}/resty/core/shdict.lua + exist {lua_dir}/resty/core/socket.lua + exist {lua_dir}/resty/core/time.lua + exist {lua_dir}/resty/core/uri.lua + exist {lua_dir}/resty/core/utils.lua + exist {lua_dir}/resty/core/var.lua + exist {lua_dir}/resty/core/worker.lua + exist {lua_dir}/resty/lrucache/pureffi.lua + + mode {lua_dir}/ngx/balancer.lua 644 + mode {lua_dir}/ngx/base64.lua 644 + mode {lua_dir}/ngx/errlog.lua 644 + mode {lua_dir}/ngx/ocsp.lua 644 + mode {lua_dir}/ngx/pipe.lua 644 + mode {lua_dir}/ngx/process.lua 644 + mode {lua_dir}/ngx/re.lua 644 + mode {lua_dir}/ngx/req.lua 644 + mode {lua_dir}/ngx/resp.lua 644 + mode {lua_dir}/ngx/semaphore.lua 644 + mode {lua_dir}/ngx/ssl.lua 644 + mode {lua_dir}/ngx/ssl/session.lua 644 + mode {lua_dir}/resty/core.lua 644 + mode {lua_dir}/resty/lrucache.lua 644 + mode {lua_dir}/resty/core/base.lua 644 + mode {lua_dir}/resty/core/base64.lua 644 + mode {lua_dir}/resty/core/ctx.lua 644 + mode {lua_dir}/resty/core/exit.lua 644 + mode {lua_dir}/resty/core/hash.lua 644 + mode {lua_dir}/resty/core/misc.lua 644 + mode {lua_dir}/resty/core/ndk.lua 644 + mode {lua_dir}/resty/core/phase.lua 644 + mode {lua_dir}/resty/core/regex.lua 644 + mode {lua_dir}/resty/core/request.lua 644 + mode {lua_dir}/resty/core/response.lua 644 + mode {lua_dir}/resty/core/shdict.lua 644 + mode {lua_dir}/resty/core/socket.lua 644 + mode {lua_dir}/resty/core/time.lua 644 + mode {lua_dir}/resty/core/uri.lua 644 + mode {lua_dir}/resty/core/utils.lua 644 + mode {lua_dir}/resty/core/var.lua 644 + mode {lua_dir}/resty/core/worker.lua 644 + mode {lua_dir}/resty/lrucache/pureffi.lua 644 + +command "-" "Nginx compatibility package" + exist /etc/nginx + exist /var/log/nginx + exist /etc/nginx/nginx.conf + exist /usr/sbin/nginx + service-present nginx + service-present nginx-debug + +command "-" "Original configuration backup" + backup {config} + backup {modules_config} + +command "-" "Add modules configuration" + copy modules.conf {modules_config} + +command "-" "Replace original configuration" + copy webkaos.conf {config} + +command "-" "Add test DH params file" + copy dhparam.pem {dh_param} + chmod {dh_param} 600 + +command "-" "Add self-signed certificate" + copy ssl.key {ssl_dir}/ssl.key + copy ssl.crt {ssl_dir}/ssl.crt + chmod {ssl_dir}/ssl.key 600 + chmod {ssl_dir}/ssl.crt 600 + +command "-" "Clear old log files" + touch {log_dir}/access.log + touch {log_dir}/error.log + truncate {log_dir}/access.log + truncate {log_dir}/error.log + +command "-" "Check brotli module" + exist {prefix_dir}/xtra/brotli.conf + exist {modules_dir}/ngx_http_brotli_filter_module.so + exist {modules_dir}/ngx_http_brotli_static_module.so + mode {prefix_dir}/xtra/brotli.conf 644 + mode {modules_dir}/ngx_http_brotli_filter_module.so 755 + mode {modules_dir}/ngx_http_brotli_static_module.so 755 + +command "-" "Check NAXSI module" + exist {prefix_dir}/naxsi_core.rules + exist {modules_dir}/ngx_http_naxsi_module.so + mode {prefix_dir}/naxsi_core.rules 644 + mode {modules_dir}/ngx_http_naxsi_module.so 755 + +command "systemctl start {service_name}" "Start service" + wait-pid {pid_file} 5 service-works {service_name} - http-status GET "http://127.0.0.1:80" 200 - http-header GET "http://127.0.0.1:80" server webkaos + +command "-" "Make HTTP requests" + http-status GET "http://127.0.0.1" 200 + http-header GET "http://127.0.0.1" server webkaos + http-contains GET "http://127.0.0.1/lua" "LUA MODULE WORKS" !empty {log_dir}/access.log + truncate {log_dir}/access.log + +command "-" "Make HTTPS requests" + http-status GET "https://127.0.0.1" 200 + http-header GET "https://127.0.0.1" server webkaos + http-contains GET "https://127.0.0.1/lua" "LUA MODULE WORKS" + !empty {log_dir}/access.log + truncate {log_dir}/access.log + +command "-" "Save PID file checksum" checksum-read {pid_file} pid_sha -command "service {service_name} upgrade" "Upgrading binary" +command "service {service_name} upgrade" "Binary upgrade" wait 3 exist {pid_file} service-works {service_name} - http-status GET "http://127.0.0.1:80" 200 + http-status GET "http://127.0.0.1" 200 !checksum {pid_file} {pid_sha} -command "-" "Updating config to broken one" - copy webkaos-broken.conf {config} +command "-" "Update configuration to broken one" + copy broken.conf {config} -command "service {service_name} check" "Checking broken config" +command "service {service_name} check" "Broken config check" !exit 0 !empty {log_dir}/error.log -command "service {service_name} reload" "Reloading broken config" +command "service {service_name} reload" "Broken config reload" !exit 0 -command "service {service_name} restart" "Restarting with broken config" +command "service {service_name} restart" "Restart with broken config" !exit 0 -command "-" "Updating config to working one" - copy webkaos-ok.conf {config} +command "-" "Restore working configuration" + copy webkaos.conf {config} -command "service {service_name} reload" "Reloading working config" +command "service {service_name} reload" "Reload with original config" exit 0 -command "systemctl stop {service_name}" "Stopping service" +command "systemctl stop {service_name}" "Stop service" !wait-pid {pid_file} 5 !service-works {service_name} !connect tcp ":http" !exist {pid_file} +command "-" "Clear old log files" + truncate {log_dir}/access.log + truncate {log_dir}/error.log + +command "systemctl start {service_name}-debug" "Start debug version of service" + wait-pid {pid_file} 5 + service-works {service_name}-debug + +command "-" "Make HTTP requests" + http-status GET "http://127.0.0.1" 200 + http-header GET "http://127.0.0.1" server webkaos + http-contains GET "http://127.0.0.1/lua" "LUA MODULE WORKS" + !empty {log_dir}/access.log + truncate {log_dir}/access.log + +command "-" "Make HTTPS requests" + http-status GET "https://127.0.0.1" 200 + http-header GET "https://127.0.0.1" server webkaos + http-contains GET "https://127.0.0.1/lua" "LUA MODULE WORKS" + !empty {log_dir}/access.log + truncate {log_dir}/access.log + +command "systemctl stop {service_name}-debug" "Stop debug version of service" + !wait-pid {pid_file} 5 + !service-works {service_name}-debug + !connect tcp ":http" + !exist {pid_file} + +command:teardown "-" "Configuration restore" + backup-restore {config} + backup-restore {modules_config} + +command:teardown "-" "DH param cleanup" + remove {dh_param} + +command:teardown "-" "Self-signed certificate cleanup" + remove {ssl_dir}/ssl.key + remove {ssl_dir}/ssl.crt + ``` More working examples you can find in [our repository](https://github.com/essentialkaos/kaos-repo/tree/master/tests) with recipes for our rpm packages. diff --git a/cli/cli.go b/cli/cli.go index bd951d40..4b1e5f1a 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -37,7 +37,7 @@ import ( // Application info const ( APP = "bibop" - VER = "4.6.1" + VER = "4.7.0" DESC = "Utility for testing command-line tools" ) diff --git a/cli/executor/executor.go b/cli/executor/executor.go index 0673caac..6cebefa9 100644 --- a/cli/executor/executor.go +++ b/cli/executor/executor.go @@ -206,12 +206,14 @@ func processRecipe(e *Executor, rr render.Renderer, r *recipe.Recipe, tags []str e.start = time.Now() e.skipped = len(r.Commands) + finished := false + for index, command := range r.Commands { if r.LockWorkdir && r.Dir != "" { os.Chdir(r.Dir) // Set current dir to working dir for every command } - if skipCommand(command, tags) { + if skipCommand(command, tags, finished) { e.skipped-- continue } @@ -227,7 +229,11 @@ func processRecipe(e *Executor, rr render.Renderer, r *recipe.Recipe, tags []str if r.FastFinish { rr.CommandDone(command, true) - break + finished = true + + if !r.HasTeardown() { + break + } } } else { e.passes++ @@ -427,16 +433,21 @@ func outputIOLoop(cmdEnv *CommandEnv) { } } -// skipCommand return true if command should be skipped -func skipCommand(c *recipe.Command, tags []string) bool { - if c.Tag == "" { +// skipCommand returns true if command should be skipped +func skipCommand(c *recipe.Command, tags []string, finished bool) bool { + switch { + case c.Tag == recipe.TEARDOWN_TAG: + return false + case finished == true: + return true + case c.Tag == "": return false } return !sliceutil.Contains(tags, c.Tag) && !sliceutil.Contains(tags, "*") } -// logError log error data +// logError logs error data func logError(e *Executor, c *recipe.Command, a *recipe.Action, ce *CommandEnv, err error) { if e.config.ErrsDir == "" { return diff --git a/recipe/recipe.go b/recipe/recipe.go index 6557168c..a6e0c428 100644 --- a/recipe/recipe.go +++ b/recipe/recipe.go @@ -21,6 +21,9 @@ import ( // MAX_VAR_NESTING maximum variables nesting const MAX_VAR_NESTING = 32 +// TEARDOWN_TAG contains teardown tag +const TEARDOWN_TAG = "teardown" + // ////////////////////////////////////////////////////////////////////////////////// // // Recipe contains recipe data @@ -170,6 +173,17 @@ func (r *Recipe) GetPackages() string { return strings.Join(r.Packages, " ") } +// HasTeardown returns true if recipe contains command with teardown tag +func (r *Recipe) HasTeardown() bool { + for _, c := range r.Commands { + if c.Tag == TEARDOWN_TAG { + return true + } + } + + return false +} + // ////////////////////////////////////////////////////////////////////////////////// // // AddAction appends command to actions slice From 1c3f7a6ac77c15f3eefe2e7e59e85f072fa33326 Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 31 Jul 2021 14:35:59 +0300 Subject: [PATCH 4/6] Add command tag rendering to terminal renderer --- render/renderer_terminal.go | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/render/renderer_terminal.go b/render/renderer_terminal.go index ea7fc5e7..bdfb266b 100644 --- a/render/renderer_terminal.go +++ b/render/renderer_terminal.go @@ -53,23 +53,29 @@ func (rr *TerminalRenderer) Start(r *recipe.Recipe) { // CommandStarted prints info about started command func (rr *TerminalRenderer) CommandStarted(c *recipe.Command) { + prefix := " " + + if c.Tag != "" { + prefix += fmt.Sprintf("{s}(%s){!} ", c.Tag) + } + switch { case c.Cmdline == "-" && c.Description == "": - rr.renderMessage(" {*}- Empty command -{!}") + rr.renderMessage(prefix + "{*}- Empty command -{!}") case c.Cmdline == "-" && c.Description != "": - rr.renderMessage(" {*}%s{!}", c.Description) + rr.renderMessage(prefix+"{*}%s{!}", c.Description) case c.Cmdline != "-" && c.Description == "": - rr.renderMessage(" {c-}%s{!}", c.Cmdline) + rr.renderMessage(prefix+"{c-}%s{!}", c.Cmdline) case c.Cmdline != "-" && c.Description == "" && c.User != "": - rr.renderMessage(" {c*}[%s]{!} {c-}%s{!}", c.User, c.Cmdline) + rr.renderMessage(prefix+"{c*}[%s]{!} {c-}%s{!}", c.User, c.Cmdline) case c.Cmdline != "-" && c.Description != "" && c.User != "": rr.renderMessage( - " {*}%s{!} {s}→{!} {c*}[%s]{!} {c-}%s{!}", + prefix+"{*}%s{!} {s}→{!} {c*}[%s]{!} {c-}%s{!}", c.Description, c.User, c.GetCmdline(), ) default: rr.renderMessage( - " {*}%s{!} {s}→{!} {c-}%s{!}", + prefix+"{*}%s{!} {s}→{!} {c-}%s{!}", c.Description, c.GetCmdline(), ) } From ae2fafdf6ea339f2e7e8f513cea1d9f1156e885c Mon Sep 17 00:00:00 2001 From: Anton Novojilov Date: Sat, 31 Jul 2021 14:39:31 +0300 Subject: [PATCH 5/6] Fix bug with rendering user and tag info in XML renderer --- render/renderer_xml.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/render/renderer_xml.go b/render/renderer_xml.go index e7c35749..021249b1 100644 --- a/render/renderer_xml.go +++ b/render/renderer_xml.go @@ -48,11 +48,11 @@ func (rr *XMLRenderer) CommandStarted(c *recipe.Command) { rr.data += " Date: Sat, 31 Jul 2021 14:50:50 +0300 Subject: [PATCH 6/6] Increase code coverage --- recipe/recipe_test.go | 12 ++++++++++++ testdata/test1.recipe | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/recipe/recipe_test.go b/recipe/recipe_test.go index ad93b8eb..abe9ed45 100644 --- a/recipe/recipe_test.go +++ b/recipe/recipe_test.go @@ -296,4 +296,16 @@ func (s *RecipeSuite) TestAux(c *C) { c.Assert(k.HasProp("TEST"), Equals, true) } +func (s *RecipeSuite) TestTags(c *C) { + r, k := &Recipe{}, &Command{} + r.AddCommand(k, "teardown") + + c.Assert(r.HasTeardown(), Equals, true) + + r, k = &Recipe{}, &Command{} + r.AddCommand(k, "") + + c.Assert(r.HasTeardown(), Equals, false) +} + // ////////////////////////////////////////////////////////////////////////////////// // diff --git a/testdata/test1.recipe b/testdata/test1.recipe index fd4b37c2..77ec9ea9 100644 --- a/testdata/test1.recipe +++ b/testdata/test1.recipe @@ -18,4 +18,4 @@ command "{user}:echo" "Simple echo command" exit 1 command:special "echo" "Simple echo command" - exit 1 \ No newline at end of file + exit 1