diff --git a/.gitignore b/.gitignore index 6e00b9f67..b25b2779f 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,7 @@ *.swp *.swo /cnfs +/installed_cnf_files /results /tools/chaos_mesh /tools/helm diff --git a/CNF_TESTSUITE_YML_USAGE.md b/CNF_TESTSUITE_YML_USAGE.md index 74c5c4f0b..0da43acae 100644 --- a/CNF_TESTSUITE_YML_USAGE.md +++ b/CNF_TESTSUITE_YML_USAGE.md @@ -66,7 +66,7 @@ Missing config version is presumed to be config version `"v1"`, which is not sup #### Common Parameters -Common parameters are required for proper functioning of some tests. If these parameters are not set up, corresponding tests will be failed/skipped or would not function properly (in example - whitelist_container_names). +Common parameters are required for proper functioning of some tests. If these parameters are not set up, corresponding tests will be failed/skipped or would not function properly (in example - white_list_container_names). `common: ...` ##### container_names @@ -78,7 +78,7 @@ Array of container parameters for rolling version change tests, example: rollback_from_tag: 1.8.0 -##### whitelist_container_names +##### white_list_container_names The values of this key are the names of the 'containers' defined in the Kubernetes pod spec of pods that are allowed to be running in privileged mode. (Optional) This value is used to allow 'particular' pods to run in privileged mode on the K8s cluster where the CNF is installed. @@ -118,25 +118,9 @@ image_registry_fqdns: Described below: [link](#5G-parameters) -#### Dynamic parameters - -Dynamic parameters are not meant to be set up manually. They exist due to limitations of testsuite design. - -##### source_cnf_dir - -Directory where config is located. - -##### destintaion_cnf_dir - -Internal directory where CNF installation files are copied, currently in `cnfs` folder - -##### installation_method - -Installation method of the CNF and additional info according to it. - #### Deployments -Deployments are defined as three arrays, each for different installation method. Each array element represents one deployment, and they are meant to represent a single CNF together (Not implemented yet). +Deployments are defined as three arrays, each for different installation method. Each array element represents one deployment, and they are meant to represent a single CNF together. At least one deployment should exist in CNF config for it to be a proper config. All info for deployments is used in cnf_setup and cnf_cleanup tasks. diff --git a/INSTALL.md b/INSTALL.md index 2d2af333b..d72460ec9 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -235,9 +235,9 @@ For more details on points, see our [POINTS.md](./POINTS.md) documentation. #### Cleaning Up -Run the following to cleanup the specific cnf-testsuite test (this is assuming you installed the cnf-testsuite.yml in your present working directory): +Run the following to uninstall the CNF (this is assuming you installed the cnf-testsuite.yml in your present working directory): ``` -cnf-testsuite cnf_cleanup cnf-config=./cnf-testsuite.yml +cnf-testsuite cnf_cleanup ``` You can also run `cleanall` and cnf-testsuite will attempt to cleanup everything. diff --git a/SOURCE_INSTALL.md b/SOURCE_INSTALL.md index 70dac8754..1822e131c 100644 --- a/SOURCE_INSTALL.md +++ b/SOURCE_INSTALL.md @@ -151,7 +151,7 @@ crystal spec ### Setup -Now that we have a `cnf-testsuite` binary, we can run `setup` to ensure it has all the pre-requisites needed in order to successfully run tests and setup required cnfs/ directory and other files required for cnf-testsuite. +Now that we have a `cnf-testsuite` binary, we can run `setup` to ensure it has all the pre-requisites needed in order to successfully run tests and setup required installed_cnf_files/ directory and other files required for cnf-testsuite. - Run the following to setup cnf-testsuite: ``` @@ -255,10 +255,10 @@ For more details on points, see our [POINTS.md](./POINTS.md) documentation. #### Cleaning Up -Run the following to cleanup the specific cnf-testsuite test: +Run the following to uninstall the CNF: ``` -./cnf-testsuite cnf_cleanup cnf-config=./cnf-testsuite.yml +./cnf-testsuite cnf_cleanup ``` You can also run `cleanall` and cnf-testsuite will attempt to cleanup everything. diff --git a/example-cnfs/coredns/README.md b/example-cnfs/coredns/README.md index 84ceb7bf7..be15d3c84 100644 --- a/example-cnfs/coredns/README.md +++ b/example-cnfs/coredns/README.md @@ -35,8 +35,8 @@ Run the all the tests Check the results file -Cleanup the cnf test setup (including undeployment of CoreDNS) +Uninstall the CNF (including undeployment of CoreDNS) ``` -./cnf-testsuite cnf_cleanup cnf-path=example-cnfs/coredns +./cnf-testsuite cnf_cleanup ``` diff --git a/example-cnfs/envoy/README.md b/example-cnfs/envoy/README.md index d86483d94..f64fcacfd 100644 --- a/example-cnfs/envoy/README.md +++ b/example-cnfs/envoy/README.md @@ -30,8 +30,8 @@ Run the test suite: ./cnf-testsuite all ``` -Envoy cleanup +Envoy uninstallation ``` -./cnf-testsuite cnf_cleanup cnf-path=example-cnfs/envoy +./cnf-testsuite cnf_cleanup ``` \ No newline at end of file diff --git a/example-cnfs/ip-forwarder/README.md b/example-cnfs/ip-forwarder/README.md index c8a72e52f..9312754e9 100644 --- a/example-cnfs/ip-forwarder/README.md +++ b/example-cnfs/ip-forwarder/README.md @@ -31,19 +31,10 @@ export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite cnf_setup cnf-path=example ### Testing Run the test suite: `export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite all` -### Automated cleanup +### Automated uninstallation ``` -export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite cnf_cleanup cnf-path=example-cnfs/ip-forwarder/cnf-testsuite.yml +export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite cnf_cleanup ``` -### Manual installation -1. Install helm version 3 -1. Make the cnfs/ip-forwarder diretory -1. If you are testing the cnf source, clone the source into the cnfs/ip-forwarder directory -1. Copy the cnf-testsuite.yml into the cnfs/ip-forwarder directory -1. Deploy the CNF using helm: `helm install cnfs/ip-forwarder/vpp` -1. Wait for the installation to finish (all pods are ready) -1. Run the test suite: `export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite all` - diff --git a/example-cnfs/linkerd2/README.md b/example-cnfs/linkerd2/README.md index ba062c21e..9dfa48b71 100644 --- a/example-cnfs/linkerd2/README.md +++ b/example-cnfs/linkerd2/README.md @@ -33,8 +33,8 @@ Run the test suite: ./cnf-testsuite all ``` -linkerd cleanup +linkerd uninstallation ``` -./cnf-testsuite cnf_cleanup cnf-path=example-cnfs/linkerd2/cnf-testsuite.yml +./cnf-testsuite cnf_cleanup ``` diff --git a/example-cnfs/nsm/README.md b/example-cnfs/nsm/README.md index f04b24a8b..4b22b72f4 100644 --- a/example-cnfs/nsm/README.md +++ b/example-cnfs/nsm/README.md @@ -31,8 +31,8 @@ Run the all the tests Check the results file -Cleanup the cnf test setup (including undeployment of NSM) +Uninstall the CNF (including undeployment of NSM) ``` -./cnf-testsuite cnf_cleanup cnf-config=./example-cnfs/nsm/cnf-testsuite.yml +./cnf-testsuite cnf_cleanup ``` diff --git a/example-cnfs/pantheon-nsm-nat/README.md b/example-cnfs/pantheon-nsm-nat/README.md index ed496960e..cc90d14ba 100644 --- a/example-cnfs/pantheon-nsm-nat/README.md +++ b/example-cnfs/pantheon-nsm-nat/README.md @@ -41,9 +41,8 @@ Run the all the tests Check the results file -Cleanup the cnf test setup (including undeployment of nsm-nat) +Uninstall the CNF (including undeployment of nsm-nat) ``` -./cnf-testsuite cnf_cleanup cnf-config=./example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml -./cnf-testsuite cnf_cleanup cnf-config=./example-cnfs/nsm/cnf-testsuite.yml +./cnf-testsuite cnf_cleanup ``` diff --git a/example-cnfs/pantheon-nsm-nat/nat-cnf/README.md b/example-cnfs/pantheon-nsm-nat/nat-cnf/README.md index 373962e3f..331564fac 100644 --- a/example-cnfs/pantheon-nsm-nat/nat-cnf/README.md +++ b/example-cnfs/pantheon-nsm-nat/nat-cnf/README.md @@ -31,8 +31,8 @@ crystal src/cnf-testsuite.cr all Check the results file -Cleanup the cnf test setup (including undeployment of nsm-nat) +Uninstall the CNF (including undeployment of nsm-nat) ``` -crystal src/cnf-testsuite.cr cnf_cleanup cnf-config=./example-cnfs/pantheon-nsm-nat/cnf-testsuite.yml +crystal src/cnf-testsuite.cr cnf_cleanup ``` diff --git a/example-cnfs/vpp-3c2n-csp-use-case/README.md b/example-cnfs/vpp-3c2n-csp-use-case/README.md index 5788221bf..8914286f7 100644 --- a/example-cnfs/vpp-3c2n-csp-use-case/README.md +++ b/example-cnfs/vpp-3c2n-csp-use-case/README.md @@ -23,23 +23,14 @@ export KUBECONFIG=$(pwd)/ ; ./cnf-testsuite setup Setup and deploy service chain ``` -export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite example_cnf_setup example-cnf-path=example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml +export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite cnf_setup example-cnf-path=example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml ``` ### Testing Run the test suite: `export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite all` -### Automated cleanup +### Automated uninstallation ``` -export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite example_cnf_cleanup example-cnf-path=example-cnfs/vpp-3c2n-csp-use-case/cnf-testsuite.yml +export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite cnf_cleanup ``` - -### Manual installation -1. Install helm version 3 -1. Make the cnfs/vpp-3c2n-csp-use-case diretory -1. If you are testing the cnf source, clone the source into the cnfs/vpp-3c2n-csp-use-case directory -1. Copy the cnf-testsuite.yml into the cnfs/vpp-3c2n-csp-use-case directory -1. Deploy the service chain using helm: `helm install vpp-3c2n-csp-use-case cnfs/csp` -1. Wait for the installation to finish (all pods are ready) -1. Run the test suite: `export KUBECONFIG=$(pwd)/admin.conf ; ./cnf-testsuite all` diff --git a/spec/5g/core_spec.cr b/spec/5g/core_spec.cr index 9a772355c..dca901073 100644 --- a/spec/5g/core_spec.cr +++ b/spec/5g/core_spec.cr @@ -18,7 +18,7 @@ describe "Core" do result = ShellCmd.run_testsuite("smf_upf_heartbeat verbose") (/(PASSED).*(Chaos service degradation is less than 50%)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_open5gs/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -29,7 +29,7 @@ describe "Core" do result = ShellCmd.run_testsuite("smf_upf_heartbeat verbose baseline_count=300") (/(FAILED).*(Chaos service degradation is more than 50%)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_open5gs/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -40,7 +40,7 @@ describe "Core" do result = ShellCmd.run_testsuite("suci_enabled verbose") (/(PASSED).*(Core uses SUCI 5g authentication)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_open5gs/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -51,7 +51,7 @@ describe "Core" do result = ShellCmd.run_testsuite("suci_enabled verbose") (/(FAILED).*(Core does not use SUCI 5g authentication)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_open5gs_no_auth/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end diff --git a/spec/cluster_setup_spec.cr b/spec/cluster_setup_spec.cr index 5cba37a6f..97312bb55 100644 --- a/spec/cluster_setup_spec.cr +++ b/spec/cluster_setup_spec.cr @@ -6,8 +6,7 @@ require "cluster_tools" describe "Cluster Setup" do before_each do - result = ShellCmd.run_testsuite("cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() end it "'install_cluster_tools' should give a message if namespace does not exist", tags: ["cluster_setup"] do diff --git a/spec/cnf_testsuite_all/cnf_testsuite_spec.cr b/spec/cnf_testsuite_all/cnf_testsuite_spec.cr index f110faa96..ed3ef5caf 100644 --- a/spec/cnf_testsuite_all/cnf_testsuite_spec.cr +++ b/spec/cnf_testsuite_all/cnf_testsuite_spec.cr @@ -9,8 +9,7 @@ describe CnfTestSuite do end after_all do - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() end it "a task should fail with an exit code of 2 when there is an exception", tags: ["security"] do diff --git a/spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml b/spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml index d97e309ea..70b5af04d 100644 --- a/spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml +++ b/spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml @@ -1,5 +1,5 @@ --- -helm_directory: cnfs/coredns/helm_chart/coredns +helm_directory: installed_cnf_files/coredns/helm_chart/coredns release_name: coredns helm_repository: name: stable diff --git a/spec/platform/hardware_and_scheduler_spec.cr b/spec/platform/hardware_and_scheduler_spec.cr index 8f7d0cec1..9ab2ab322 100644 --- a/spec/platform/hardware_and_scheduler_spec.cr +++ b/spec/platform/hardware_and_scheduler_spec.cr @@ -4,8 +4,7 @@ require "./../../src/tasks/utils/utils.cr" describe "Platform" do before_all do - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("setup") result[:status].success?.should be_true end diff --git a/spec/platform/platform_spec.cr b/spec/platform/platform_spec.cr index 6ca72c4bb..486422779 100644 --- a/spec/platform/platform_spec.cr +++ b/spec/platform/platform_spec.cr @@ -4,19 +4,18 @@ require "../../src/tasks/utils/utils.cr" describe "Platform" do before_all do - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("setup") result[:status].success?.should be_true end it "'platform:*' should not error out when no cnf is installed", tags: ["platform"] do - result = ShellCmd.run_testsuite("cleanup") + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("platform:oci_compliant") puts result[:output] (/No cnf_testsuite.yml found/ =~ result[:output]).should be_nil end it "'platform' should not run prerequisites that are prefixed with a ~", tags: ["platform"] do - result = ShellCmd.run_testsuite("cleanup") + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("platform ~k8s_conformance") (/kind=namespace namespace=sonobuoy/ =~ (result[:output] + result[:error])).should be_nil end diff --git a/spec/setup_spec.cr b/spec/setup_spec.cr index 240b03032..15dc0b436 100644 --- a/spec/setup_spec.cr +++ b/spec/setup_spec.cr @@ -8,8 +8,7 @@ require "sam" describe "Setup" do after_each do - result = ShellCmd.run_testsuite("cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() end it "'setup' should completely setup the cnf testsuite environment before installing cnfs", tags: ["setup"] do @@ -18,205 +17,103 @@ describe "Setup" do (/Setup complete/ =~ result[:output]).should_not be_nil end - # (svteb) TODO: delete in #2171 - it "'cnf_setup/cnf_cleanup' should install/cleanup with cnf-path arg as alias for cnf-config", tags: ["setup"] do - begin - result = ShellCmd.cnf_setup("cnf-path=example-cnfs/coredns/cnf-testsuite.yml") - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=example-cnfs/coredns/cnf-testsuite.yml") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup/cnf_cleanup' should install/cleanup a cnf with a cnf-testsuite.yml", tags: ["setup"] do - begin - result = ShellCmd.cnf_setup("cnf-config=example-cnfs/coredns/cnf-testsuite.yml") - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=example-cnfs/coredns/cnf-testsuite.yml") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup/cnf_cleanup' should work with cnf-testsuite.yml that has no directory associated with it", tags: ["setup"] do - begin - #TODO force cnfs/ to be deployment name and not the directory name - result = ShellCmd.cnf_setup("cnf-config=spec/fixtures/cnf-testsuite.yml verbose") - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - ensure - - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=spec/fixtures/cnf-testsuite.yml verbose") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup/cnf_cleanup' should install/cleanup with helm_directory that descends multiple directories", tags: ["setup"] do - begin - result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/multi_helm_directories/cnf-testsuite.yml") - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/multi_helm_directories/cnf-testsuite.yml") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup/cnf_cleanup' should properly install/uninstall old versions of cnf configs", tags: ["setup"] do - begin - result = ShellCmd.cnf_setup("cnf-path=spec/fixtures/cnf-testsuite-v1-example.yml") - result[:status].success?.should be_true - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=spec/fixtures/cnf-testsuite-v1-example.yml") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup' should fail if another CNF is already installed", tags: ["setup"] do - begin - result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_coredns/cnf-testsuite.yml") - (/Successfully setup coredns/ =~ result[:output]).should_not be_nil - result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-minimal-cnf/cnf-testsuite.yml") - (/A CNF is already set up. Setting up multiple CNFs is not allowed./ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns/cnf-testsuite.yml") - result[:status].success?.should be_true - (/Successfully cleaned up/ =~ result[:output]).should_not be_nil - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-minimal-cnf/cnf-testsuite.yml") - end - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup' should pass with a minimal cnf-testsuite.yml", tags: ["setup"] do - ShellCmd.cnf_setup("cnf-path=./sample-cnfs/sample-minimal-cnf/") - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-minimal-cnf/") - end - - # (svteb) TODO: delete in #2171 - it "'cnf_setup' should support cnf-config as an alias for cnf-path", tags: ["setup"] do - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample-minimal-cnf/") - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-minimal-cnf/") - end - - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup' should pass with a minimal cnf-testsuite.yml", tags: ["setup"] do - result = ShellCmd.new_cnf_setup("cnf-path=./sample-cnfs/sample-minimal-cnf/") + result = ShellCmd.cnf_setup("cnf-path=./sample-cnfs/sample-minimal-cnf/") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should install/cleanup with cnf-config arg as an alias for cnf-path", tags: ["setup"] do - result = ShellCmd.new_cnf_setup("cnf-config=./sample-cnfs/sample-minimal-cnf/") + result = ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample-minimal-cnf/") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should install/cleanup with cnf-path arg as an alias for cnf-config", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=example-cnfs/coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=example-cnfs/coredns/cnf-testsuite.yml") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should fail on incorrect config", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=spec/fixtures/sample-bad-config.yml", expect_failure: true) + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-bad-config/cnf-testsuite.yml", expect_failure: true) (/Error during parsing CNF config/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup(expect_failure: true) + result = ShellCmd.cnf_cleanup(expect_failure: true) end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should install/cleanup a cnf with a cnf-testsuite.yml", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-config=example-cnfs/coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-config=example-cnfs/coredns/cnf-testsuite.yml") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should work with cnf-testsuite.yml that has no directory associated with it", tags: ["setup"] do begin #TODO force cnfs/ to be deployment name and not the directory name - result = ShellCmd.new_cnf_setup("cnf-config=spec/fixtures/cnf-testsuite.yml verbose") + result = ShellCmd.cnf_setup("cnf-config=spec/fixtures/cnf-testsuite.yml verbose") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should install/cleanup with helm_directory that descends multiple directories", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/multi_helm_directories/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/multi_helm_directories/cnf-testsuite.yml") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup/cnf_cleanup' should properly install/uninstall old versions of cnf configs", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=spec/fixtures/cnf-testsuite-v1-example.yml") + result = ShellCmd.cnf_setup("cnf-path=spec/fixtures/cnf-testsuite-v1-example.yml") (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 it "'cnf_setup' should fail if another CNF is already installed", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_coredns/cnf-testsuite.yml") (/CNF installation complete/ =~ result[:output]).should_not be_nil - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/sample-minimal-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-minimal-cnf/cnf-testsuite.yml") (/A CNF is already set up. Setting up multiple CNFs is not allowed./ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 AND CHANGE TAG TO tags: ["setup"] - it "'cnf_setup/cnf_cleanup' should install/cleanup a cnf with multiple deployments", tags: ["dummy-tag"] do + it "'cnf_setup/cnf_cleanup' should install/cleanup a cnf with multiple deployments", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/sample_multiple_deployments/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_multiple_deployments/cnf-testsuite.yml") (/All "coredns" deployment resources are up/ =~ result[:output]).should_not be_nil (/All "memcached" deployment resources are up/ =~ result[:output]).should_not be_nil (/All "nginx" deployment resources are up/ =~ result[:output]).should_not be_nil (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/Successfully uninstalled helm deployment "coredns"/ =~ result[:output]).should_not be_nil (/Successfully uninstalled helm deployment "memcached"/ =~ result[:output]).should_not be_nil (/Successfully uninstalled helm deployment "nginx"/ =~ result[:output]).should_not be_nil @@ -224,40 +121,37 @@ describe "Setup" do end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 AND CHANGE TAG TO tags: ["setup"] - it "'cnf_setup/cnf_cleanup' should install/cleanup deployment with mixed installation methods", tags: ["dummy-tag"] do + it "'cnf_setup/cnf_cleanup' should install/cleanup deployment with mixed installation methods", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/sample-nginx-redis/cnf-testsuite.yml") + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-nginx-redis/cnf-testsuite.yml") (/All "nginx" deployment resources are up/ =~ result[:output]).should_not be_nil (/All "redis" deployment resources are up/ =~ result[:output]).should_not be_nil (/CNF installation complete/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/Successfully uninstalled helm deployment "nginx"/ =~ result[:output]).should_not be_nil (/Successfully uninstalled manifest deployment "redis"/ =~ result[:output]).should_not be_nil (/All CNF deployments were uninstalled/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 AND CHANGE TAG TO tags: ["setup"] - it "'cnf_setup/cnf_cleanup' should handle partial deployment failures gracefully", tags: ["dummy-tag"] do + it "'cnf_setup/cnf_cleanup' should handle partial deployment failures gracefully", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=sample-cnfs/sample-partial-deployment-failure/cnf-testsuite.yml", expect_failure: true) + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-partial-deployment-failure/cnf-testsuite.yml", expect_failure: true) (/All "nginx" deployment resources are up/ =~ result[:output]).should_not be_nil (/Deployment of "coredns" failed during CNF installation/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.new_cnf_cleanup() + result = ShellCmd.cnf_cleanup() (/Successfully uninstalled helm deployment "nginx"/ =~ result[:output]).should_not be_nil end end - # (svteb) TODO: change new_cnf_setup/new_cnf_cleanup to cnf_setup/cnf_cleanup in #2171 AND CHANGE TAG TO tags: ["setup"] - it "'cnf_setup' should detect and report conflicts between deployments", tags: ["dummy-tag"] do + it "'cnf_setup' should detect and report conflicts between deployments", tags: ["setup"] do begin - result = ShellCmd.new_cnf_setup("cnf-path=spec/fixtures/sample-conflicting-deployments.yml", expect_failure: true) + result = ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-conflicting-deployments/cnf-testsuite.yml", expect_failure: true) (/Deployment names should be unique/ =~ result[:output]).should_not be_nil ensure - ShellCmd.new_cnf_cleanup(expect_failure: true) + ShellCmd.cnf_cleanup(expect_failure: true) end end end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index aa45ce13e..4fe7ac863 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -21,9 +21,9 @@ module ShellCmd run(cmd, log_prefix: "ShellCmd.run_testsuite", force_output: true, joined_output: true) end - # (svteb) TODO: delete in #2171 def self.cnf_setup(setup_params, cmd_prefix="", expect_failure=false) - result = run_testsuite("cnf_setup #{setup_params} wait_count=300", cmd_prefix) + timeout_parameter = setup_params.includes?("timeout") ? "" : "timeout=300" + result = run_testsuite("cnf_setup #{setup_params} #{timeout_parameter}", cmd_prefix) if !expect_failure result[:status].success?.should be_true else @@ -32,10 +32,9 @@ module ShellCmd result end - # (svteb) TODO: rename to cnf_setup in #2171 - def self.new_cnf_setup(setup_params, cmd_prefix="", expect_failure=false) - timeout_parameter = setup_params.includes?("timeout") ? "" : "timeout=300" - result = run_testsuite("new_cnf_setup #{setup_params} #{timeout_parameter}", cmd_prefix) + def self.cnf_cleanup(cleanup_params="", cmd_prefix="", expect_failure=false) + timeout_parameter = cleanup_params.includes?("timeout") ? "" : "timeout=300" + result = run_testsuite("cnf_cleanup #{cleanup_params} #{timeout_parameter}", cmd_prefix) if !expect_failure result[:status].success?.should be_true else @@ -44,15 +43,8 @@ module ShellCmd result end - # (svteb) TODO: rename to cnf_cleanup in #2171 - def self.new_cnf_cleanup(cleanup_params="", cmd_prefix="", expect_failure=false) + def self.environment_cleanup(cleanup_params="", cmd_prefix="") timeout_parameter = cleanup_params.includes?("timeout") ? "" : "timeout=300" - result = run_testsuite("new_cnf_cleanup #{cleanup_params} #{timeout_parameter}", cmd_prefix) - if !expect_failure - result[:status].success?.should be_true - else - result[:status].success?.should be_false - end - result + result = run_testsuite("cleanup #{cleanup_params} #{timeout_parameter}", cmd_prefix) end end diff --git a/spec/utils/cnf_manager_spec.cr b/spec/utils/cnf_manager_spec.cr index 4bcf6b00c..55f9a8274 100644 --- a/spec/utils/cnf_manager_spec.cr +++ b/spec/utils/cnf_manager_spec.cr @@ -10,18 +10,15 @@ require "sam" describe "SampleUtils" do before_all do + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("helm_local_install") result[:status].success?.should be_true - result = ShellCmd.run_testsuite("cleanup") - result[:status].success?.should be_true - # Ensure a results file is present to test different scenarios CNFManager::Points::Results.ensure_results_file! end after_each do - result = ShellCmd.run_testsuite("cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() end it "'points_yml' should parse and return the points yaml file", tags: ["points"] do @@ -139,136 +136,6 @@ describe "SampleUtils" do (CNFManager::Points.final_cnf_results_yml).should contain("cnf-testsuite-results") end - - it "'CNFManager.sample_setup_cli_args(args) and CNFManager.sample_setup(cli_args)' should set up a sample cnf", tags: ["cnf-setup"] do - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml", "verbose"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(cli_hash[:config_file])) - release_name = config.deployments.get_deployment_param(:name) - - (Dir.exists? "cnfs/#{release_name}").should be_true - (File.exists?("cnfs/#{release_name}/cnf-testsuite.yml")).should be_true - (File.exists?("cnfs/#{release_name}/exported_chart/Chart.yaml")).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.sample_setup' should set up a sample cnf", tags: ["cnf-setup"] do - config_file = "sample-cnfs/sample-generic-cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - # check if directory exists - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - - (Dir.exists? "cnfs/#{release_name}").should be_true - (File.exists?("cnfs/#{release_name}/cnf-testsuite.yml")).should be_true - (File.exists?("cnfs/#{release_name}/exported_chart/Chart.yaml")).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.sample_setup_args' should set up a sample cnf from a argument", tags: ["cnf-setup"] do - config_file = "sample-cnfs/sample-generic-cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - # check if directory exists - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - (Dir.exists? "cnfs/#{release_name}").should be_true - (File.exists?("cnfs/#{release_name}/cnf-testsuite.yml")).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.sample_setup_args' should set up a sample cnf from a config file", tags: ["cnf-setup"] do - config_file = "sample-cnfs/sample-generic-cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - # check if directory exists - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - (Dir.exists? "sample-cnfs/sample-generic-cnf").should be_true - (File.exists?("cnfs/#{release_name}/cnf-testsuite.yml")).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.sample_cleanup' should clean up a sample cnf from a argument", tags: ["cnf-setup"] do - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - cleanup = CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) - (cleanup).should be_true - (Dir.exists? "cnfs/coredns").should be_false - (File.exists?("cnfs/coredns/cnf-testsuite.yml")).should be_false - (File.exists?("cnfs/coredns/helm_chart/Chart.yaml")).should be_false - end - - it "'CNFManager.sample_setup_args' should be able to deploy using a helm_directory", tags: ["cnf-setup"] do - config_file = "sample-cnfs/sample_privileged_cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - (Dir.exists? "cnfs/#{release_name}").should be_true - # should not clone - (Dir.exists? "cnfs/#{release_name}/privileged-coredns").should be_false - (File.exists? "cnfs/#{release_name}/cnf-testsuite.yml").should be_true - (File.exists? "cnfs/#{release_name}/chart/Chart.yaml").should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample_privileged_cnf", verbose: true) - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.sample_setup_args and CNFManager.sample_cleanup' should be able to deploy and cleanup using a manifest_directory", tags: ["cnf-setup"] do - config_file = "sample-cnfs/k8s-non-helm" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - Log.info { "Running Setup" } - CNFManager.sample_setup(cli_hash) - Log.info { "Parse Config" } - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - (Dir.exists? "cnfs/#{release_name}").should be_true - (Dir.exists? "cnfs/#{release_name}/manifests").should be_true - (File.exists? "cnfs/#{release_name}/cnf-testsuite.yml").should be_true - (KubectlClient::Get.pod_exists?("nginx-webapp")).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/k8s-non-helm", installed_from_manifest: true, verbose: true) - # TODO check for pod status = terminating - (KubectlClient::Get.pod_exists?("nginx-webapp", check_ready: true)).should be_false - (Dir.exists? "cnfs/#{release_name}").should be_false - end - - it "'CNFManager.cnf_config_list' should return a list of all of the config files from the cnf directory", tags: ["cnf-setup"] do - config_file = "sample-cnfs/sample-generic-cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose", "skip_wait_for_install"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample_privileged_cnf/cnf-testsuite.yml", "verbose"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - CNFManager.sample_setup(cli_hash) - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - release_name = config.deployments.get_deployment_param(:name) - CNFManager.cnf_config_list()[0].should contain("#{release_name}/#{CONFIG_FILE}") - end - - it "'CNFManager.helm_repo_add' should add a helm repo if the helm repo is valid", tags: ["helm-repo"] do - config_file = "sample-cnfs/sample-generic-cnf" - args = Sam::Args.new(["cnf-config=./#{config_file}/cnf-testsuite.yml", "verbose"]) - cli_hash = CNFManager.sample_setup_cli_args(args) - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml"]) - CNFManager.helm_repo_add(args: args).should eq(true) - end - - it "'CNFManager.helm_repo_add' should return false if the helm repo is invalid", tags: ["helm-repo"] do - CNFManager.helm_repo_add("invalid", "invalid").should eq(false) - end - it "'validate_config' should pass, when a cnf has a valid config file yml", tags: ["validate_config"] do result = ShellCmd.run_testsuite("validate_config cnf-config=spec/fixtures/cnf-testsuite-v2-example.yml") result[:status].success?.should be_true @@ -307,30 +174,33 @@ describe "SampleUtils" do it "'CNFInstall::Config.parse_cnf_config_from_file' should return a populated CNFInstall::Config::Config", tags: ["cnf-config"] do begin config = CNFInstall::Config.parse_cnf_config_from_file("spec/fixtures/cnf-testsuite.yml") - (config.deployments.get_deployment_param(:name)).should eq("coredns") + (config.deployments.helm_charts[0].name).should eq("coredns") ensure end end it "'CNFManager.workload_resource_test' should accept an args and cnf-config argument, populate a deployment, container, and intialized argument, and then apply a test to a cnf", tags: ["cnf-config"] do - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml"]) - cli_hash = CNFManager.sample_setup_cli_args(args, false) - CNFManager.sample_setup(cli_hash) if cli_hash["config_file"] - config = CNFInstall::Config.parse_cnf_config_from_file("./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml") - task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - test_passed = true - begin - Log.for("verbose").debug { container.as_h["name"].as_s } if check_verbose(args) - container.as_h["livenessProbe"].as_h - rescue ex - Log.for("verbose").error { ex.message } if check_verbose(args) - test_passed = false - puts "No livenessProbe found for resource: #{resource} and container: #{container.as_h["name"].as_s}".colorize(:red) - end - test_passed + begin + args = Sam::Args.new() + config_path = "./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml" + ShellCmd.cnf_setup("cnf-config=#{config_path}") + config = CNFInstall::Config.parse_cnf_config_from_file(config_path) + task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| + test_passed = true + begin + Log.for("verbose").debug { container.as_h["name"].as_s } if check_verbose(args) + container.as_h["livenessProbe"].as_h + rescue ex + Log.for("verbose").error { ex.message } if check_verbose(args) + test_passed = false + puts "No livenessProbe found for resource: #{resource} and container: #{container.as_h["name"].as_s}".colorize(:red) + end + test_passed + end + (task_response).should be_true + ensure + ShellCmd.cnf_cleanup() end - (task_response).should be_true - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) end it "Helm_values should be used during the installation of a cnf", tags: ["cnf-config"] do @@ -342,7 +212,7 @@ describe "SampleUtils" do Log.info { "image_tags: #{image_tags}" } (/1.6.9/ =~ image_tags[0][:tag]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_coredns_values") + result = ShellCmd.cnf_cleanup() end end diff --git a/spec/utils/kubescape_spec.cr b/spec/utils/kubescape_spec.cr index 916751a92..a3df6ad9c 100644 --- a/spec/utils/kubescape_spec.cr +++ b/spec/utils/kubescape_spec.cr @@ -14,7 +14,7 @@ describe "K8sInstrumentation" do test_json = Kubescape.test_by_test_name(results_json, "Network policies") (test_json).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.ymll") + result = ShellCmd.cnf_cleanup() end end diff --git a/spec/utils/utils_spec.cr b/spec/utils/utils_spec.cr index c99521338..fb3f4f774 100644 --- a/spec/utils/utils_spec.cr +++ b/spec/utils/utils_spec.cr @@ -55,7 +55,6 @@ describe "Utils" do it "'check_cnf_config' should return the value for a cnf-config argument", tags: ["args"] do args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml"]) - #TODO make CNFManager.sample_setup_args accept the full path to the config yml instead of the directory (check_cnf_config(args)).should eq("./sample-cnfs/sample-generic-cnf") end @@ -73,49 +72,52 @@ describe "Utils" do (yaml["items"].as_a.find {|x| x["name"] == "ip_addresses" && x["points"] == 0 }).should be_truthy end - it "'single_task_runner' should accept a cnf-config argument and apply a test to that cnf", tags: ["task_runner"] do - args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml"]) - - cli_hash = CNFManager.sample_setup_cli_args(args, false) - CNFManager.sample_setup(cli_hash) if cli_hash["config_file"] - - task_response = CNFManager::Task.single_task_runner(args) do |args, config| - - Log.info { "single_task_runner spec args #{args.inspect}" } - - white_list_container_names = config.common.white_list_container_names - Log.info { "white_list_container_names #{white_list_container_names.inspect}" } - violation_list = [] of String - resource_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - - privileged_list = KubectlClient::Get.privileged_containers - resource_containers = KubectlClient::Get.resource_containers(resource["kind"],resource["name"],resource["namespace"]) - resource_containers_list = (JSON.parse(resource_containers.to_json).as_a).map { |element| element["name"] } - # Only check the containers that are in the deployed helm chart or manifest - (privileged_list & (resource_containers_list - white_list_container_names)).each do |x| - violation_list << x + # TODO (kosstennbl) Rework this spec, shouldn't contain a real test. + it "'single_task_runner' should accept a cnf-config argument and apply a test to that cnf", tags: ["task_runner"] do + begin + args = Sam::Args.new() + config_path = "./sample-cnfs/sample-generic-cnf/cnf-testsuite.yml" + ShellCmd.cnf_setup("cnf-config=#{config_path}") + + task_response = CNFManager::Task.single_task_runner(args) do |args, config| + + Log.info { "single_task_runner spec args #{args.inspect}" } + + white_list_container_names = config.common.white_list_container_names + Log.info { "white_list_container_names #{white_list_container_names.inspect}" } + violation_list = [] of String + resource_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| + + privileged_list = KubectlClient::Get.privileged_containers + resource_containers = KubectlClient::Get.resource_containers(resource["kind"],resource["name"],resource["namespace"]) + resource_containers_list = (JSON.parse(resource_containers.to_json).as_a).map { |element| element["name"] } + # Only check the containers that are in the deployed helm chart or manifest + (privileged_list & (resource_containers_list - white_list_container_names)).each do |x| + violation_list << x + end + if violation_list.size > 0 + false + else + true + end end - if violation_list.size > 0 - false + Log.debug { "violator list: #{violation_list.flatten}" } + emoji_security="" + if resource_response + resp = upsert_passed_task("privileged_containers", "✔️ PASSED: No privileged containers", Time.utc) else - true + resp = upsert_failed_task("privileged_containers", "✖️ FAILED: Found #{violation_list.size} privileged containers: #{violation_list.inspect}", Time.utc) end + Log.info { resp } + resp end - Log.debug { "violator list: #{violation_list.flatten}" } - emoji_security="" - if resource_response - resp = upsert_passed_task("privileged_containers", "✔️ PASSED: No privileged containers", Time.utc) - else - resp = upsert_failed_task("privileged_containers", "✖️ FAILED: Found #{violation_list.size} privileged containers: #{violation_list.inspect}", Time.utc) - end - Log.info { resp } - resp + (task_response).should eq("✔️ PASSED: No privileged containers") + ensure + ShellCmd.cnf_cleanup() end - (task_response).should eq("✔️ PASSED: No privileged containers") - ensure - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) end + # TODO (kosstennbl) Rework this spec, shouldn't contain a real test. it "'single_task_runner' should put a 1 in the results file if it has an exception", tags: ["task_runner"] do CNFManager::Points.clean_results_yml args = Sam::Args.new() @@ -177,13 +179,15 @@ describe "Utils" do end it "'logger' or verbose output should be shown when verbose flag is set", tags: ["logger"] do - ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-coredns-cnf") - result = ShellCmd.run_testsuite("helm_deploy verbose", cmd_prefix: "LOG_LEVEL=info") - puts result[:output] - result[:status].success?.should be_true - (/helm_deploy args/ =~ result[:output]).should_not be_nil - ensure - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-coredns-cnf", verbose: true) + begin + ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample-coredns-cnf") + result = ShellCmd.run_testsuite("helm_deploy verbose", cmd_prefix: "LOG_LEVEL=info") + puts result[:output] + result[:status].success?.should be_true + (/helm_deploy args/ =~ result[:output]).should_not be_nil + ensure + ShellCmd.cnf_cleanup() + end end it "'logger' should write logs to the file when LOG_PATH is set", tags: ["logger"] do diff --git a/spec/workload/compatibility_spec.cr b/spec/workload/compatibility_spec.cr index a5eb2d2fa..fd6fb0e29 100644 --- a/spec/workload/compatibility_spec.cr +++ b/spec/workload/compatibility_spec.cr @@ -28,7 +28,7 @@ describe "Compatibility" do (/(SKIPPED).*(cni_compatible test was temporarily disabled)/ =~ result[:output]).should_not be_nil #(/(PASSED).*(CNF compatible with both Calico and Cilium)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -40,7 +40,7 @@ describe "Compatibility" do result[:status].success?.should be_true (/(PASSED).*(Replicas increased to)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end end diff --git a/spec/workload/configuration_spec.cr b/spec/workload/configuration_spec.cr index 859d97840..0c4ee33bf 100644 --- a/spec/workload/configuration_spec.cr +++ b/spec/workload/configuration_spec.cr @@ -10,21 +10,20 @@ describe CnfTestSuite do result = ShellCmd.run("echo $KUBECONFIG") Log.debug { result[:output] } + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("setup") - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true result = ShellCmd.run_testsuite("configuration_file_setup") end it "'liveness' should pass when livenessProbe is set", tags: ["liveness"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml") result = ShellCmd.run_testsuite("liveness verbose", cmd_prefix:"LOG_LEVEL=debug") result[:status].success?.should be_true (/(PASSED).*(Helm liveness probe)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml deploy_with_chart=false ") + result = ShellCmd.cnf_cleanup() end end @@ -35,18 +34,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(No livenessProbe found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("sample_coredns_bad_liveness_cleanup") + result = ShellCmd.cnf_cleanup() end end it "'readiness' should pass when readinessProbe is set", tags: ["readiness"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml") result = ShellCmd.run_testsuite("readiness verbose", cmd_prefix: "LOG_LEVEL=debug") result[:status].success?.should be_true (/(PASSED).*(Helm readiness probe)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-testsuite.yml deploy_with_chart=false ") + result = ShellCmd.cnf_cleanup() end end @@ -57,7 +56,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(No readinessProbe found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("sample_coredns_bad_liveness_cleanup") + result = ShellCmd.cnf_cleanup() end end @@ -68,18 +67,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end it "'rolling_update' should fail when invalid version is given", tags: ["rolling_update"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml") result = ShellCmd.run_testsuite("rolling_update verbose") result[:status].success?.should be_true (/Failed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -99,18 +98,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end it "'rolling_downgrade' should fail when invalid version is given", tags: ["rolling_downgrade"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml") result = ShellCmd.run_testsuite("rolling_downgrade verbose") result[:status].success?.should be_true (/Failed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -121,18 +120,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end it "'rolling_version_change' should fail when invalid version is given", tags: ["rolling_version_change"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml") result = ShellCmd.run_testsuite("rolling_version_change verbose") result[:status].success?.should be_true (/Failed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling_invalid_version/cnf-testsuite.yml deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -143,7 +142,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_rolling/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -151,12 +150,12 @@ describe CnfTestSuite do it "'nodeport_not_used' should fail when a node port is being used", tags: ["nodeport_not_used"] do begin - ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_nodeport deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_nodeport") result = ShellCmd.run_testsuite("nodeport_not_used verbose") result[:status].success?.should be_true (/(FAILED).*(NodePort is being used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_nodeport deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -167,18 +166,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(NodePort is not used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end it "'hostport_not_used' should fail when a node port is being used", tags: ["hostport_not_used"] do begin - ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_hostport deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_hostport") result = ShellCmd.run_testsuite("hostport_not_used verbose") result[:status].success?.should be_true (/(FAILED).*(HostPort is being used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_hostport deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -189,18 +188,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(HostPort is not used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end it "'hardcoded_ip_addresses_in_k8s_runtime_configuration' should fail when a hardcoded ip is found in the K8s configuration", tags: ["ip_addresses"] do begin - ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_coredns_hardcoded_ips deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-path=sample-cnfs/sample_coredns_hardcoded_ips") result = ShellCmd.run_testsuite("hardcoded_ip_addresses_in_k8s_runtime_configuration verbose", cmd_prefix: "LOG_LEVEL=info") result[:status].success?.should be_true (/(FAILED).*(Hard-coded IP addresses found in the runtime K8s configuration)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns_hardcoded_ips deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -211,7 +210,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(No hard-coded IP addresses found in the runtime K8s configuration)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -222,7 +221,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(Secrets defined and used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_secret_volume verbose") + result = ShellCmd.cnf_cleanup("verbose") end end @@ -233,7 +232,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(SKIPPED).*(Secrets not used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_unmounted_secret_volume verbose") + result = ShellCmd.cnf_cleanup("verbose") end end @@ -244,7 +243,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(Secrets defined and used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_secret_env verbose") + result = ShellCmd.cnf_cleanup("verbose") end end @@ -255,7 +254,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(SKIPPED).*(Secrets not used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_secret_env verbose") + result = ShellCmd.cnf_cleanup("verbose") end end @@ -266,29 +265,29 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(SKIPPED).*(Secrets not used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns verbose") + result = ShellCmd.cnf_cleanup("verbose") end end it "'immutable_configmap' fail with some mutable configmaps in container env or volume mount", tags: ["immutable_configmap"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/ndn-mutable-configmap deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/ndn-mutable-configmap") result = ShellCmd.run_testsuite("immutable_configmap verbose") result[:status].success?.should be_true (/(FAILED).*(Found mutable configmap)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/ndn-mutable-configmap deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end it "'immutable_configmap' pass with all immutable configmaps in container env or volume mounts", tags: ["immutable_configmap"] do begin - ShellCmd.cnf_setup("cnf-config=./sample-cnfs/ndn-immutable-configmap deploy_with_chart=false") + ShellCmd.cnf_setup("cnf-config=./sample-cnfs/ndn-immutable-configmap") result = ShellCmd.run_testsuite("immutable_configmap verbose") result[:status].success?.should be_true (/(PASSED).*(All volume or container mounted configmaps immutable)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/ndn-immutable-configmap deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() end end @@ -299,7 +298,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(Pods should have the app.kubernetes.io\/name label)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -310,7 +309,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(Pods have the app.kubernetes.io\/name label)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -321,7 +320,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(Resources are created in the default namespace)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns_default_namespace") + result = ShellCmd.cnf_cleanup() KubectlClient::Utils.wait_for_terminations() end end @@ -333,7 +332,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(default namespace is not being used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_latest_tag") + result = ShellCmd.cnf_cleanup() KubectlClient::Utils.wait_for_terminations() end end @@ -345,7 +344,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(Container images are using the latest tag)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_latest_tag") + result = ShellCmd.cnf_cleanup() end end @@ -356,18 +355,14 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(Container images are not using the latest tag)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot") + result = ShellCmd.cnf_cleanup() end end it "'latest_tag' should require a cnf be installed to run", tags: ["latest_tag"] do - begin - # NOTE: Purposefully not installing a CNF to test - result = ShellCmd.run_testsuite("latest_tag verbose") - result[:status].success?.should be_false - (/You must install a CNF first./ =~ result[:output]).should_not be_nil - ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot") - end + # NOTE: Purposefully not installing a CNF to test + result = ShellCmd.run_testsuite("latest_tag verbose") + result[:status].success?.should be_false + (/You must install a CNF first./ =~ result[:output]).should_not be_nil end end diff --git a/spec/workload/installability_spec.cr b/spec/workload/installability_spec.cr index ae1219c32..0e0bf870a 100644 --- a/spec/workload/installability_spec.cr +++ b/spec/workload/installability_spec.cr @@ -3,8 +3,7 @@ require "colorize" describe CnfTestSuite do before_all do - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true + result = ShellCmd.environment_cleanup() result = ShellCmd.run_testsuite("setup") end @@ -14,7 +13,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(CNF has deployments that are not installed with helm)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/k8s-non-helm verbose") + result = ShellCmd.cnf_cleanup("verbose") end it "'helm_deploy' should fail if command is not supplied cnf-config argument", tags: ["helm"] do @@ -29,7 +28,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Helm chart lint passed on all charts/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml verbose") + result = ShellCmd.cnf_cleanup("verbose") end it "'helm_chart_valid' should fail on a bad helm chart", tags: ["helm"] do @@ -39,7 +38,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/Helm chart lint failed on one or more charts/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml verbose") + result = ShellCmd.cnf_cleanup("verbose") end end @@ -50,7 +49,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(All Helm charts are published)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -64,7 +63,7 @@ describe CnfTestSuite do (/(FAILED).*(One or more Helm charts are not published)/ =~ result[:output]).should_not be_nil ensure result = ShellCmd.run("#{Helm::BinarySingleton.helm} repo remove badrepo") - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-bad-helm-repo") + result = ShellCmd.cnf_cleanup() end end end diff --git a/spec/workload/microservice_spec.cr b/spec/workload/microservice_spec.cr index 95da12792..2c15d5401 100644 --- a/spec/workload/microservice_spec.cr +++ b/spec/workload/microservice_spec.cr @@ -23,7 +23,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(N\/A).*(No MariaDB containers were found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -35,7 +35,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(No shared database found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-statefulset-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -47,7 +47,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(No shared database found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-multi-db-connections-exempt/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -59,7 +59,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(Found a shared database)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/ndn-multi-db-connections-fail/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true KubectlClient::Delete.command("pvc data-test-mariadb-0 -n wordpress") end @@ -82,7 +82,7 @@ describe "Microservice" do ensure Helm.delete("multi-db") KubectlClient::Delete.command("pvc data-multi-db-mariadb-0") - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/ndn-multi-db-connections-fail/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -94,7 +94,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(Only one process type used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -106,7 +106,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(More than one process type used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/k8s-multiple-processes") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -118,7 +118,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(More than one process type used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample-multiple-processes") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -130,7 +130,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(CNF had a reasonable startup time)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -142,7 +142,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(CNF had a startup time of)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_envoy_slow_startup/cnf-testsuite.yml force=true") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -162,7 +162,7 @@ describe "Microservice" do result[:status].success?.should be_true (/Image size is good/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf}") + result = ShellCmd.cnf_cleanup() end it "'reasonable_image_size' should fail if image is larger than 5gb", tags: ["reasonable_image_size"] do @@ -178,7 +178,7 @@ describe "Microservice" do result[:status].success?.should be_true (/Containers do not use specialized init systems/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-coredns-cnf force=true") + result = ShellCmd.cnf_cleanup() end it "'specialized_init_system' should pass if pods use specialized init systems", tags: ["specialized_init_system"] do @@ -187,7 +187,7 @@ describe "Microservice" do result[:status].success?.should be_true (/Containers use specialized init systems/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-init-systems force=true") + result = ShellCmd.cnf_cleanup() end it "'service_discovery' should pass if any containers in the cnf are exposed as a service", tags: ["service_discovery"] do @@ -197,7 +197,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(Some containers exposed as a service)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -209,7 +209,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(No containers exposed as a service)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-ndn-privileged") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -226,7 +226,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(Sig Term handled)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_good_signal_handling/") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -243,7 +243,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(Sig Term not handled)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_bad_signal_handling/") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -264,7 +264,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(Sig Term handled)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_good_signal_handling_tini/") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -277,7 +277,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(PASSED).*(Zombie handled)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_good_zombie_handling/") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -289,7 +289,7 @@ describe "Microservice" do result[:status].success?.should be_true (/(FAILED).*(Zombie not handled)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-bad-zombie/") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end diff --git a/spec/workload/observability_spec.cr b/spec/workload/observability_spec.cr index 15dd34840..60e18eb25 100644 --- a/spec/workload/observability_spec.cr +++ b/spec/workload/observability_spec.cr @@ -17,7 +17,7 @@ describe "Observability" do result[:status].success?.should be_true (/(PASSED).*(Resources output logs to stdout and stderr)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -28,7 +28,7 @@ describe "Observability" do result[:status].success?.should be_true (/(FAILED).*(Resources do not output logs to stdout and stderr)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample_no_logs/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -49,7 +49,7 @@ describe "Observability" do test_result = ShellCmd.run_testsuite("prometheus_traffic") (/(PASSED).*(Your cnf is sending prometheus traffic)/ =~ test_result[:output]).should_not be_nil ensure - ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml") + ShellCmd.cnf_cleanup() result = ShellCmd.run("#{helm} delete prometheus", "helm_delete_prometheus") result[:status].success?.should be_true end @@ -63,7 +63,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("prometheus_traffic") (/(SKIPPED).*(Prometheus server not found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end it "'prometheus_traffic' should fail if the cnf is not registered with prometheus", tags: ["observability"] do @@ -80,7 +80,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("prometheus_traffic") (/(FAILED).*(Your cnf is not sending prometheus traffic)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run("#{helm} delete prometheus", force_output: true) result[:status].success?.should be_true end @@ -98,7 +98,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("open_metrics") (/(FAILED).*(Your cnf's metrics traffic is not OpenMetrics compatible)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-prom-pod-discovery/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run("#{helm} delete prometheus", force_output: true) result[:status].success?.should be_true end @@ -116,7 +116,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("open_metrics") (/(PASSED).*(Your cnf's metrics traffic is OpenMetrics compatible)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-openmetrics/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run("#{helm} delete prometheus", force_output: true) result[:status].success?.should be_true end @@ -127,7 +127,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("routed_logs") (/(PASSED).*(Your CNF's logs are being captured)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run_testsuite("uninstall_fluentdbitnami") result[:status].success?.should be_true end @@ -138,7 +138,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("routed_logs") (/(PASSED).*(Your CNF's logs are being captured)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-fluentbit") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run_testsuite("uninstall_fluentbit") result[:status].success?.should be_true end @@ -155,7 +155,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("routed_logs") (/(FAILED).*(Your CNF's logs are not being captured)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result = ShellCmd.run_testsuite("uninstall_fluentd") result[:status].success?.should be_true end diff --git a/spec/workload/operator_spec.cr b/spec/workload/operator_spec.cr index 8e57c6d3e..41deb90f6 100644 --- a/spec/workload/operator_spec.cr +++ b/spec/workload/operator_spec.cr @@ -27,7 +27,7 @@ describe "Operator" do result = ShellCmd.run_testsuite("operator_installed", cmd_prefix: "LOG_LEVEL=info") (/(PASSED).*(Operator is installed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample_operator", cmd_prefix: "LOG_LEVEL=info") + result = ShellCmd.cnf_cleanup(cmd_prefix: "LOG_LEVEL=info") result[:status].success?.should be_true pods = KubectlClient::Get.pods_by_resource(KubectlClient::Get.deployment("catalog-operator", "operator-lifecycle-manager"), "operator-lifecycle-manager") + KubectlClient::Get.pods_by_resource(KubectlClient::Get.deployment("olm-operator", "operator-lifecycle-manager"), "operator-lifecycle-manager") + KubectlClient::Get.pods_by_resource(KubectlClient::Get.deployment("packageserver", "operator-lifecycle-manager"), "operator-lifecycle-manager") @@ -71,7 +71,7 @@ describe "Operator" do result = ShellCmd.run_testsuite("operator_installed", cmd_prefix: "LOG_LEVEL=info") (/(N\/A).*(No Operators Found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=sample-cnfs/sample_coredns") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end diff --git a/spec/workload/registry_spec.cr b/spec/workload/registry_spec.cr index a88fa9616..ff26471d8 100644 --- a/spec/workload/registry_spec.cr +++ b/spec/workload/registry_spec.cr @@ -47,7 +47,7 @@ describe "Private Registry: Image" do result[:status].success?.should be_true (/Image size is good/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf}") + result = ShellCmd.cnf_cleanup() end it "'reasonable_image_size' should pass if using local registry, a port and an org", tags: ["private_registry_image"] do @@ -58,7 +58,7 @@ describe "Private Registry: Image" do result[:status].success?.should be_true (/Image size is good/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf}") + result = ShellCmd.cnf_cleanup() end after_all do @@ -96,7 +96,7 @@ describe "Private Registry: Rolling" do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf} wait_count=0") + result = ShellCmd.cnf_cleanup("timeout=0") end end @@ -109,7 +109,7 @@ describe "Private Registry: Rolling" do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf} wait_count=0") + result = ShellCmd.cnf_cleanup("timeout=0") end end @@ -122,7 +122,7 @@ describe "Private Registry: Rolling" do result[:status].success?.should be_true (/Passed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=#{cnf} wait_count=0") + result = ShellCmd.cnf_cleanup("timeout=0") end end diff --git a/spec/workload/resilience/disk_fill_spec.cr b/spec/workload/resilience/disk_fill_spec.cr index 42fe68ce8..0a5a6edc6 100644 --- a/spec/workload/resilience/disk_fill_spec.cr +++ b/spec/workload/resilience/disk_fill_spec.cr @@ -19,7 +19,7 @@ describe "Resilience Disk Fill Chaos" do result[:status].success?.should be_true (/(PASSED).*(disk_fill chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml wait_count=0") + result = ShellCmd.cnf_cleanup("timeout=0") result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/node_drain_spec.cr b/spec/workload/resilience/node_drain_spec.cr index 29d9fa5e1..a526a80fa 100644 --- a/spec/workload/resilience/node_drain_spec.cr +++ b/spec/workload/resilience/node_drain_spec.cr @@ -23,7 +23,7 @@ describe "Resilience Node Drain Chaos" do (/(SKIPPED).*(node_drain chaos test requires the cluster to have atleast two)/ =~ result[:output]).should_not be_nil end ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_delete_spec.cr b/spec/workload/resilience/pod_delete_spec.cr index 80fdb13e2..447835f0e 100644 --- a/spec/workload/resilience/pod_delete_spec.cr +++ b/spec/workload/resilience/pod_delete_spec.cr @@ -19,7 +19,7 @@ describe "Resilience pod delete Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_delete chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_dns_error_spec.cr b/spec/workload/resilience/pod_dns_error_spec.cr index f7902182a..fd00b3835 100644 --- a/spec/workload/resilience/pod_dns_error_spec.cr +++ b/spec/workload/resilience/pod_dns_error_spec.cr @@ -24,7 +24,7 @@ describe "Resilience pod dns error Chaos" do # The ensure block will cleanup the CNF and the litmus installation. raise "Test failed with #{ex.message}" ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=example-cnfs/envoy/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_io_stress_spec.cr b/spec/workload/resilience/pod_io_stress_spec.cr index f768409ce..41a73c808 100644 --- a/spec/workload/resilience/pod_io_stress_spec.cr +++ b/spec/workload/resilience/pod_io_stress_spec.cr @@ -19,7 +19,7 @@ describe "Resilience pod delete Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_io_stress chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_memory_hog_spec.cr b/spec/workload/resilience/pod_memory_hog_spec.cr index 80ec62d0f..0d982e60a 100644 --- a/spec/workload/resilience/pod_memory_hog_spec.cr +++ b/spec/workload/resilience/pod_memory_hog_spec.cr @@ -19,7 +19,7 @@ describe "Resilience pod memory hog Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_memory_hog chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_network_corruption_spec.cr b/spec/workload/resilience/pod_network_corruption_spec.cr index fbf8c23f3..8d726dd92 100644 --- a/spec/workload/resilience/pod_network_corruption_spec.cr +++ b/spec/workload/resilience/pod_network_corruption_spec.cr @@ -19,7 +19,7 @@ describe "Resilience Pod Network corruption Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_network_corruption chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_network_duplication_spec.cr b/spec/workload/resilience/pod_network_duplication_spec.cr index de60e895a..a827f5016 100644 --- a/spec/workload/resilience/pod_network_duplication_spec.cr +++ b/spec/workload/resilience/pod_network_duplication_spec.cr @@ -19,7 +19,7 @@ describe "Resilience Pod Network duplication Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_network_duplication chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/resilience/pod_network_latency_spec.cr b/spec/workload/resilience/pod_network_latency_spec.cr index 24b455323..18426d214 100644 --- a/spec/workload/resilience/pod_network_latency_spec.cr +++ b/spec/workload/resilience/pod_network_latency_spec.cr @@ -19,7 +19,7 @@ describe "Resilience Pod Network Latency Chaos" do result[:status].success?.should be_true (/(PASSED).*(pod_network_latency chaos test passed)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true result = ShellCmd.run_testsuite("uninstall_litmus") result[:status].success?.should be_true diff --git a/spec/workload/security_spec.cr b/spec/workload/security_spec.cr index 5c25eb71b..d05d08266 100644 --- a/spec/workload/security_spec.cr +++ b/spec/workload/security_spec.cr @@ -11,7 +11,7 @@ describe "Security" do result[:status].success?.should be_true (/No privileged containers/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-statefulset-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() Log.debug { result[:output] } end end @@ -23,9 +23,10 @@ describe "Security" do (/Found.*privileged containers.*/ =~ result[:output]).should_not be_nil (/Privileged container (privileged-coredns) in.*/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("sample_privileged_cnf_non_whitelisted_cleanup") + result = ShellCmd.cnf_cleanup() end end + it "'privileged_containers' should pass on a whitelisted, privileged cnf", tags: ["privileges"] do begin ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample_whitelisted_privileged_cnf/cnf-testsuite.yml verbose skip_wait_for_install") @@ -33,9 +34,10 @@ describe "Security" do result[:status].success?.should be_true (/Found.*privileged containers.*/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("sample_privileged_cnf_whitelisted_cleanup") + result = ShellCmd.cnf_cleanup() end end + it "'privilege_escalation' should fail on a cnf that has escalated privileges", tags: ["privileges"] do begin ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample-privilege-escalation/cnf-testsuite.yml") @@ -43,7 +45,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(No containers that allow privilege escalation were found)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-privilege-escalation/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -54,7 +56,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(No containers that allow privilege escalation were found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-nonroot-containers/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -65,7 +67,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(No containers allow a symlink attack)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-privilege-escalation/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -76,7 +78,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers with insecure capabilities were not found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -87,7 +89,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers with insecure capabilities were not found)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-insecure-capabilities/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -98,7 +100,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Security services are being used to harden applications)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -109,7 +111,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Found applications credentials in configuration files)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-appliciation-credentials/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -120,7 +122,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(No host network attached to pod)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-privilege-escalation/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -131,7 +133,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Service accounts automatically mapped)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-service-accounts/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -142,7 +144,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers have CPU limits set)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -153,7 +155,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers have memory limits set)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -164,7 +166,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Ingress and Egress traffic blocked on pods)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -175,7 +177,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Found containers with hostPID and hostIPC privileges)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -186,7 +188,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Found containers running with root user or user with root group membership)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-nonroot") + result = ShellCmd.cnf_cleanup() end end @@ -197,7 +199,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers are running with non-root user with non-root group membership)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -208,7 +210,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers have immutable file systems)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() end end @@ -219,7 +221,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Containers have immutable file systems)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-immutable-fs") + result = ShellCmd.cnf_cleanup() end end @@ -231,7 +233,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Found containers with hostPath mounts)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf") + result = ShellCmd.cnf_cleanup() ClusterTools.install end end @@ -244,7 +246,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Found containers with hostPath mounts)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-hostpath") + result = ShellCmd.cnf_cleanup() ClusterTools.install end end @@ -256,7 +258,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Container engine daemon sockets are not mounted as volumes)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -268,7 +270,7 @@ describe "Security" do (/(FAILED).*(Container engine daemon sockets are mounted as volumes)/ =~ result[:output]).should_not be_nil (/Unix socket is not allowed/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_container_sock_mount/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -279,7 +281,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Services are not using external IPs)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_coredns/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -290,7 +292,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Services are using external IPs)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_external_ips/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() end end @@ -301,7 +303,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Pods are using custom SELinux options that can be used for privilege escalations)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_latest_tag") + result = ShellCmd.cnf_cleanup() end end @@ -312,7 +314,7 @@ describe "Security" do result[:status].success?.should be_true (/(N\/A).*(Pods are not using SELinux)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot") + result = ShellCmd.cnf_cleanup() end end @@ -323,7 +325,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(Pods are not using custom SELinux options that can be used for privilege escalations)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_valid_selinux_options") + result = ShellCmd.cnf_cleanup() end end @@ -334,7 +336,7 @@ describe "Security" do result[:status].success?.should be_true (/(FAILED).*(Restricted values for are being used for sysctls)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_sysctls") + result = ShellCmd.cnf_cleanup() end end @@ -345,7 +347,7 @@ describe "Security" do result[:status].success?.should be_true (/(PASSED).*(No restricted values found for sysctls)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot") + result = ShellCmd.cnf_cleanup() end end end diff --git a/spec/workload/state_spec.cr b/spec/workload/state_spec.cr index bf0e580f3..2964ea623 100644 --- a/spec/workload/state_spec.cr +++ b/spec/workload/state_spec.cr @@ -18,7 +18,7 @@ describe "State" do result = ShellCmd.run_testsuite("elastic_volumes verbose", cmd_prefix: "LOG_LEVEL=info") (/(PASSED).*(All used volumes are elastic)/ =~ result[:output]).should be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-elastic-volume/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -31,7 +31,7 @@ describe "State" do result = ShellCmd.run_testsuite("elastic_volumes verbose", cmd_prefix: "LOG_LEVEL=info") (/FAILED/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample_nonroot") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -45,7 +45,7 @@ describe "State" do (/(PASSED).*(CNF uses database with cloud-native persistence)/ =~ result[:output]).should_not be_nil ensure #todo fix cleanup for helm directory with parameters - ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-mysql/cnf-testsuite.yml") + ShellCmd.cnf_cleanup() ShellCmd.run("kubectl delete pvc data-mysql-0", "delete_pvc") end end @@ -56,7 +56,7 @@ describe "State" do result = ShellCmd.run_testsuite("elastic_volumes verbose", cmd_prefix: "LOG_LEVEL=info") (/(FAILED).*(Some of the used volumes are not elastic)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=./sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -70,7 +70,7 @@ describe "State" do result = ShellCmd.run_testsuite("no_local_volume_configuration verbose") (/(FAILED).*(local storage configuration volumes found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-local-storage/cnf-testsuite.yml deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() update_yml("sample-cnfs/sample-local-storage/worker-node-value.yml", "worker_node", "") result[:status].success?.should be_true end @@ -82,7 +82,7 @@ describe "State" do result = ShellCmd.run_testsuite("no_local_volume_configuration verbose") (/(PASSED).*(local storage configuration volumes not found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml deploy_with_chart=false") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end diff --git a/src/cnf-testsuite.cr b/src/cnf-testsuite.cr index e963b35a1..ee79ae3bb 100644 --- a/src/cnf-testsuite.cr +++ b/src/cnf-testsuite.cr @@ -38,7 +38,7 @@ task "all", ["workload", "platform"] do |_, args| end desc "The CNF Test Suite program enables interoperability of CNFs from multiple vendors running on top of Kubernetes supplied by different vendors. The goal is to provide an open source test suite to enable both open and closed source CNFs to demonstrate conformance and implementation of best practices." -task "workload", ["automatic_cnf_install", "ensure_cnf_installed", "configuration_file_setup", "compatibility","state", "security", "configuration", "observability", "microservice", "resilience"] do |_, args| +task "workload", ["ensure_cnf_installed", "configuration_file_setup", "compatibility","state", "security", "configuration", "observability", "microservice", "resilience"] do |_, args| VERBOSE_LOGGING.info "workload" if check_verbose(args) total = CNFManager::Points.total_points("workload") @@ -92,13 +92,6 @@ task "upsert_release" do |_, args| end end -task "automatic_cnf_install" do |_, args| - VERBOSE_LOGGING.info "all_prereqs" if check_verbose(args) - # check_cnf_config_then_deploy(args) - cli_hash = CNFManager.sample_setup_cli_args(args, false) - CNFManager.sample_setup(cli_hash) if !cli_hash["config_file"].empty? -end - task "test" do LOGGING.debug "debug test" LOGGING.info "info test" diff --git a/src/tasks/cleanup.cr b/src/tasks/cleanup.cr index b639b72eb..f66b6cf6f 100644 --- a/src/tasks/cleanup.cr +++ b/src/tasks/cleanup.cr @@ -4,42 +4,7 @@ require "colorize" require "totem" desc "Cleans up the CNF test suite, the K8s cluster, and upstream projects" -# task "cleanup", ["samples_cleanup", "results_yml_cleanup"] do |_, args| -task "cleanup", ["samples_cleanup"] do |_, args| -end - -desc "Cleans up the CNF Test Suite sample projects" -task "samples_cleanup" do |_, args| - if args.named["force"]? && args.named["force"] == "true" - force = true - else - force = false - end - - CNFManager::Task.all_cnfs_task_runner(args) do |task_args, config| - Log.info { "Task args: #{task_args.inspect}" } - next unless task_args["cnf-config"]? - - cnf_config_file = task_args["cnf-config"].as(String) - cnf_config_file = CNFManager.ensure_cnf_testsuite_yml_path(cnf_config_file) - - config = CNFInstall::Config.parse_cnf_config_from_file(cnf_config_file) - install_method = config.dynamic.install_method - if install_method[0] == CNFInstall::InstallMethod::ManifestDirectory - installed_from_manifest = true - else - installed_from_manifest = false - end - - Log.info { "CNF CONFIG: #{cnf_config_file}" } - CNFManager.sample_cleanup( - config_file: cnf_config_file, - force: force, - installed_from_manifest: installed_from_manifest, - verbose: check_verbose(args) - ) - nil - end +task "cleanup", ["cnf_cleanup"] do |_, args| end desc "Cleans up the CNF Test Suite helper tools and containers" @@ -59,7 +24,7 @@ task "tools_cleanup", [ end desc "Cleans up the CNF Test Suite sample projects, helper tools, and containers" -task "cleanup_all", ["samples_cleanup", "tools_cleanup"] do |_, args| +task "cleanup_all", ["uninstall_cnf", "tools_cleanup"] do |_, args| end task "results_yml_cleanup" do |_, args| diff --git a/src/tasks/cnf_conformance_setup.cr b/src/tasks/cnf_conformance_setup.cr index 4424da64c..a062d4ef0 100644 --- a/src/tasks/cnf_conformance_setup.cr +++ b/src/tasks/cnf_conformance_setup.cr @@ -11,7 +11,7 @@ end desc "Sets up initial directories for the cnf-testsuite suite" task "cnf_directory_setup" do |_, args| begin - FileUtils.mkdir_p("cnfs") + FileUtils.mkdir_p(CNF_DIR) FileUtils.mkdir_p("tools") rescue File::AccessDeniedError Log.error {"ERROR: missing write permission in current directory"} diff --git a/src/tasks/cnf_setup.cr b/src/tasks/cnf_setup.cr index ba57384ec..d34949c3a 100644 --- a/src/tasks/cnf_setup.cr +++ b/src/tasks/cnf_setup.cr @@ -5,101 +5,14 @@ require "totem" require "yaml" require "./utils/utils.cr" -task "cnf_setup", ["helm_local_install", "create_namespace"] do |_, args| - Log.for("verbose").info { "cnf_setup" } if check_verbose(args) - Log.for("verbose").debug { "args = #{args.inspect}" } if check_verbose(args) - cli_hash = CNFManager.sample_setup_cli_args(args) - config_file = cli_hash[:config_file] - - # To avoid undefined behavior, only one CNF can be set up at any time. - if CNFManager.cnf_installed? - stdout_warning "A CNF is already set up. Setting up multiple CNFs is not allowed." - stdout_warning "To set up a new CNF, clean up the existing one by running: cnf_cleanup cnf-path=#{CNFManager.cnf_config_list.first}" - exit 0 - end - - if ClusterTools.install - stdout_success "ClusterTools installed" - else - stdout_failure "The ClusterTools installation timed out. Please check the status of the cluster-tools pods." - exit 1 - end - - stdout_success "cnf setup start" - CNFManager.sample_setup(cli_hash) - stdout_success "cnf setup complete" -end - -task "cnf_cleanup" do |_, args| - Log.for("verbose").info { "cnf_cleanup" } if check_verbose(args) - Log.for("verbose").debug { "args = #{args.inspect}" } if check_verbose(args) - if args.named.keys.includes? "cnf-config" - cnf = args.named["cnf-config"].as(String) - elsif args.named.keys.includes? "cnf-path" - cnf = args.named["cnf-path"].as(String) - else - stdout_failure "Error: You must supply either cnf-config or cnf-path" - exit 1 - end - Log.debug { "cnf_cleanup cnf: #{cnf}" } if check_verbose(args) - if args.named["force"]? && args.named["force"] == "true" - force = true - else - force = false - end - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(cnf)) - install_method = config.dynamic.install_method - if install_method[0] == CNFInstall::InstallMethod::ManifestDirectory - installed_from_manifest = true - else - installed_from_manifest = false - end - CNFManager.sample_cleanup(config_file: cnf, force: force, installed_from_manifest: installed_from_manifest, verbose: check_verbose(args)) -end - -task "CNFManager.helm_repo_add" do |_, args| - Log.for("verbose").info { "CNFManager.helm_repo_add" } if check_verbose(args) - Log.for("verbose").debug { "args = #{args.inspect}" } if check_verbose(args) - if args.named["cnf-config"]? || args.named["yml-file"]? - CNFManager.helm_repo_add(args: args) - else - CNFManager.helm_repo_add - end - -end - task "generate_config" do |_, args| interactively_create_config() end -#TODO force all cleanups to use generic cleanup -task "bad_helm_cnf_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-bad_helm_coredns-cnf", verbose: true) -end - -task "sample_privileged_cnf_whitelisted_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample_whitelisted_privileged_cnf", verbose: true) -end - -task "sample_privileged_cnf_non_whitelisted_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample_privileged_cnf", verbose: true) -end - -task "sample_coredns_bad_liveness_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample_coredns_bad_liveness", verbose: true) -end -task "sample_coredns_source_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-coredns-cnf-source", verbose: true) -end - -task "sample_generic_cnf_cleanup" do |_, args| - CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true) -end - -task "new_cnf_setup" do |_, args| +task "cnf_setup", ["helm_local_install", "create_namespace"] do |_, args| if CNFManager.cnf_installed? stdout_warning "A CNF is already set up. Setting up multiple CNFs is not allowed." - stdout_warning "To set up a new CNF, clean up the existing one by running: cnf_cleanup cnf-path=#{CNFManager.cnf_config_list.first}" + stdout_warning "To set up a new CNF, uninstall the existing one by running: cnf_cleanup" exit 0 end if ClusterTools.install @@ -113,7 +26,7 @@ task "new_cnf_setup" do |_, args| stdout_success "CNF installation complete." end -task "new_cnf_cleanup" do |_, args| +task "cnf_cleanup" do |_, args| CNFInstall.uninstall_cnf() end diff --git a/src/tasks/constants.cr b/src/tasks/constants.cr index 2874f1671..2f9c04267 100644 --- a/src/tasks/constants.cr +++ b/src/tasks/constants.cr @@ -1,7 +1,7 @@ require "./utils/embedded_file_manager.cr" ESSENTIAL_PASSED_THRESHOLD = 15 -CNF_DIR = "cnfs" +CNF_DIR = "installed_cnf_files" DEPLOYMENTS_DIR = File.join(CNF_DIR, "deployments") CNF_TEMP_FILES_DIR = File.join(CNF_DIR, "temp_files") CONFIG_FILE = "cnf-testsuite.yml" @@ -30,6 +30,8 @@ WORKLOAD_RESOURCE_KIND_NAMES = ["replicaset", "deployment", "statefulset", "pod" TESTSUITE_NAMESPACE = "cnf-testsuite" DEFAULT_CNF_NAMESPACE = "cnf-default" +# (kosstennbl) Needed only for manifest deployments, where we don't have control over installation namespace +CLUSTER_DEFAULT_NAMESPACE = "default" #Embedded global text variables EmbeddedFileManager.node_failure_values diff --git a/src/tasks/utils/cnf_installation/config.cr b/src/tasks/utils/cnf_installation/config.cr index e1b789541..c661d2e53 100644 --- a/src/tasks/utils/cnf_installation/config.cr +++ b/src/tasks/utils/cnf_installation/config.cr @@ -15,9 +15,8 @@ module CNFInstall exit 1 end yaml_content = File.read(path_to_config) - config_dir = CNFManager.ensure_cnf_testsuite_dir(path_to_config) begin - parse_cnf_config_from_yaml(yaml_content, config_dir) + parse_cnf_config_from_yaml(yaml_content) rescue exception stdout_failure "Error during parsing CNF config on #{path_to_config}" stdout_failure exception.message @@ -26,7 +25,7 @@ module CNFInstall end end - def self.parse_cnf_config_from_yaml(yaml_content, config_dir) + def self.parse_cnf_config_from_yaml(yaml_content) if !config_version_is_latest?(yaml_content) stdout_warning "CNF config version is not latest. Consider updating the CNF config with 'update_config' task." updater = CNFInstall::Config::ConfigUpdater.new(yaml_content) @@ -34,10 +33,6 @@ module CNFInstall yaml_content = updater.serialize_to_string end config = Config.from_yaml(yaml_content) - - config.dynamic.initialize_dynamic_properties(config, config_dir) - - config end # Detects the config version. @@ -60,22 +55,5 @@ module CNFInstall def self.config_version_is_latest?(tmp_content : String) : Bool detect_version(tmp_content) == ConfigVersion::Latest end - - def self.get_manifest_file_path(config) - File.join(config.dynamic.destination_cnf_dir, "temp_template.yml") - end - - def self.get_helm_chart_path(config) - helm_directory = config.deployments.get_deployment_param(:helm_directory) - if helm_directory.empty? - working_chart_directory = "exported_chart" - Log.for("configuration").info { "Using exported chart path" } - else - working_chart_directory = helm_directory - Log.for("configuration").info { "Not using exported chart path" } - end - helm_chart_path = File.join(config.dynamic.destination_cnf_dir, CNFManager.sandbox_helm_directory(working_chart_directory)) - helm_chart_path = Path[helm_chart_path].expand.to_s - end end end diff --git a/src/tasks/utils/cnf_installation/config_updater/v1_to_v2_transformation.cr b/src/tasks/utils/cnf_installation/config_updater/v1_to_v2_transformation.cr index 05494b7a4..1fe9aa398 100644 --- a/src/tasks/utils/cnf_installation/config_updater/v1_to_v2_transformation.cr +++ b/src/tasks/utils/cnf_installation/config_updater/v1_to_v2_transformation.cr @@ -12,7 +12,6 @@ module CNFInstall output_config_hash = { "config_version" => "v2", "common" => transform_common, - "dynamic" => transform_dynamic, "deployments" => transform_deployments, } @@ -51,13 +50,6 @@ module CNFInstall [] of Hash(String, String | Nil) end - - private def transform_dynamic : Hash(String, String | Nil) - { - "source_cnf_dir" => @input_config.source_cnf_dir, - "destination_cnf_dir" => @input_config.destination_cnf_dir - } - end private def transform_deployments : Hash(String, Array(Hash(String, String | Nil))) deployments = {} of String => Array(Hash(String, String | Nil)) diff --git a/src/tasks/utils/cnf_installation/config_versions/config_v2.cr b/src/tasks/utils/cnf_installation/config_versions/config_v2.cr index a7050170c..9c71c76f9 100644 --- a/src/tasks/utils/cnf_installation/config_versions/config_v2.cr +++ b/src/tasks/utils/cnf_installation/config_versions/config_v2.cr @@ -9,7 +9,6 @@ module CNFInstall class Config < CNFInstall::Config::ConfigBase getter config_version : String, common = CommonParameters.new(), - dynamic = DynamicParameters.new(), deployments : DeploymentsConfig end @@ -23,54 +22,21 @@ module CNFInstall end end - class DynamicParameters < CNFInstall::Config::ConfigBase - property source_cnf_dir = "", - destination_cnf_dir = "", - install_method : Tuple(CNFInstall::InstallMethod, String) = {CNFInstall::InstallMethod::Invalid, ""} - def initialize() - end - - def initialize_dynamic_properties(config, config_dir) - if @source_cnf_dir.empty? - @source_cnf_dir = config_dir - end - - if @install_method[0].is_a?(CNFInstall::InstallMethod::Invalid) - @install_method = config.deployments.get_install_method - end - - if @destination_cnf_dir.empty? - deployment_name = config.deployments.get_deployment_param(:name) - current_dir = FileUtils.pwd - @destination_cnf_dir = "#{current_dir}/#{CNF_DIR}/#{deployment_name}" - end - end - end - class DeploymentsConfig < CNFInstall::Config::ConfigBase getter helm_charts = [] of HelmChartConfig, helm_dirs = [] of HelmDirectoryConfig, manifests = [] of ManifestDirectoryConfig - # deployments.current and all related functionality should be removed with new installation process. - @@current : AnyDeploymentConfig | Nil def after_initialize if @helm_charts.empty? && @helm_dirs.empty? && @manifests.empty? raise YAML::Error.new("At least one deployment should be configured") end - - # To be removed with new installation process. - if @helm_charts.size + @helm_dirs.size + @manifests.size > 1 - raise YAML::Error.new("Multiple deployments are not supported yet") - end + deployment_names = Set(String).new {@helm_charts, @helm_dirs, @manifests}.each do |deployment_array| if deployment_array && !deployment_array.empty? - # To be removed with new installation process. - @@current = deployment_array[0] - deployment_array.each do |deployment| if deployment_names.includes?(deployment.name) raise YAML::Error.new("Deployment names should be unique: \"#{deployment.name}\"") @@ -81,62 +47,6 @@ module CNFInstall end end end - - # To be removed with new installation process. - def get_deployment_param(param : Symbol) : String - current = @@current.not_nil! - allowed_params = [ - :name, :helm_repo_name, :helm_repo_url, :helm_chart_name, :helm_chart, - :helm_values, :namespace, :helm_directory, :manifest_directory - ] - if !allowed_params.includes?(param) - raise ArgumentError.new("Unknown symbol for deployment: #{param}") - end - result = case current - when HelmChartConfig - case param - when :name then current.name - when :helm_repo_name then current.helm_repo_name - when :helm_repo_url then current.helm_repo_url - when :helm_chart_name then current.helm_chart_name - when :helm_chart then "#{current.helm_repo_name}/#{current.helm_chart_name}" - when :helm_values then current.helm_values - when :namespace then current.namespace - else "" - end - when HelmDirectoryConfig - case param - when :name then current.name - when :helm_directory then current.helm_directory - when :helm_values then current.helm_values - when :namespace then current.namespace - else "" - end - when ManifestDirectoryConfig - case param - when :name then current.name - when :manifest_directory then current.manifest_directory - else "" - end - end - result || "" - end - - # To be removed with new installation process. - def get_install_method - case @@current - when HelmChartConfig - {CNFInstall::InstallMethod::HelmChart, get_deployment_param(:helm_chart)} - when HelmDirectoryConfig - full_helm_directory = Path[File.join(CNF_DIR, get_deployment_param(:name), CNFManager.sandbox_helm_directory(get_deployment_param(:helm_directory)))].expand.to_s - {CNFInstall::InstallMethod::HelmDirectory, full_helm_directory} - when ManifestDirectoryConfig - full_manifest_directory = Path[File.join(CNF_DIR, get_deployment_param(:name), CNFManager.sandbox_helm_directory(get_deployment_param(:manifest_directory)))].expand.to_s - {CNFInstall::InstallMethod::ManifestDirectory, full_manifest_directory} - else - raise YAML::Error.new("At least one deployment should be configured") - end - end end class DeploymentConfig < CNFInstall::Config::ConfigBase @@ -146,7 +56,6 @@ module CNFInstall class HelmDeploymentConfig < DeploymentConfig getter helm_values = "", namespace = "" - end class HelmChartConfig < HelmDeploymentConfig diff --git a/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr b/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr index cde23fc38..58e36714b 100644 --- a/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr +++ b/src/tasks/utils/cnf_installation/deployment_management/helm_deployment_manager.cr @@ -46,9 +46,11 @@ module CNFInstall deployment_name = get_deployment_name() helm_uninstall_cmd = "#{deployment_name} -n #{get_deployment_namespace()}" result = Helm.uninstall(helm_uninstall_cmd) - if result[:status].success? + success = result[:status].success? + if success stdout_success "Successfully uninstalled helm deployment \"#{deployment_name}\"." end + success end def generate_manifest() diff --git a/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr b/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr index c5f9f9805..787f2d845 100644 --- a/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr +++ b/src/tasks/utils/cnf_installation/deployment_management/manifest_deployment_manager.cr @@ -25,9 +25,11 @@ module CNFInstall def uninstall() result = KubectlClient::Delete.file(@manifest_directory_path, wait: true) - if result[:status].success? + success = result[:status].success? + if success stdout_success "Successfully uninstalled manifest deployment \"#{@manifest_config.name}\"" end + success end def generate_manifest() diff --git a/src/tasks/utils/cnf_installation/install_common.cr b/src/tasks/utils/cnf_installation/install_common.cr index 1b2a2a11f..b57df2614 100644 --- a/src/tasks/utils/cnf_installation/install_common.cr +++ b/src/tasks/utils/cnf_installation/install_common.cr @@ -1,13 +1,6 @@ require "../utils.cr" module CNFInstall - enum InstallMethod - HelmChart - HelmDirectory - ManifestDirectory - Invalid - end - def self.install_cnf(cli_args) parsed_args = parse_cli_args(cli_args) cnf_config_path = parsed_args[:config_path] @@ -150,9 +143,15 @@ module CNFInstall end def self.uninstall_deployments(deployment_managers) + all_uninstallations_successfull = true deployment_managers.each do |deployment_manager| - deployment_manager.uninstall() + uninstall_success = deployment_manager.uninstall() + all_uninstallations_successfull = all_uninstallations_successfull && uninstall_success + end + if all_uninstallations_successfull + stdout_success "All CNF deployments were uninstalled, some time might be needed for all resources to be down." + else + stdout_failure "CNF uninstallation wasn't successfull, check logs for more info." end - stdout_success "All CNF deployments were uninstalled, some time might be needed for all resources to be down." end end \ No newline at end of file diff --git a/src/tasks/utils/cnf_installation/manifest.cr b/src/tasks/utils/cnf_installation/manifest.cr index cf0107562..a982a73e5 100644 --- a/src/tasks/utils/cnf_installation/manifest.cr +++ b/src/tasks/utils/cnf_installation/manifest.cr @@ -92,30 +92,5 @@ module CNFInstall Log.info { "#{deployment_name} manifest was appended into #{destination_file} file" } end end - - def self.generate_common_manifest(config, deployment_name, namespace) - manifest_generated_successfully = true - case config.dynamic.install_method[0] - when CNFInstall::InstallMethod::ManifestDirectory - destination_cnf_dir = config.dynamic.destination_cnf_dir - manifest_directory = config.deployments.get_deployment_param(:manifest_directory) - list_of_manifests = manifest_file_list( destination_cnf_dir + "/" + manifest_directory ) - list_of_manifests.each do |manifest_path| - manifest = File.read(manifest_path) - add_manifest_to_file(deployment_name, manifest, COMMON_MANIFEST_FILE_PATH) - end - - when CNFInstall::InstallMethod::HelmChart, CNFInstall::InstallMethod::HelmDirectory - begin - generated_manifest = Helm.generate_manifest(deployment_name, namespace) - generated_manifest_with_namespaces = add_namespace_to_resources(generated_manifest, namespace) - add_manifest_to_file(deployment_name, generated_manifest_with_namespaces, COMMON_MANIFEST_FILE_PATH) - rescue ex : Helm::ManifestGenerationError - Log.for("generate_common_manifest").error { ex.message } - manifest_generated_successfully = false - end - end - manifest_generated_successfully - end end end \ No newline at end of file diff --git a/src/tasks/utils/cnf_manager.cr b/src/tasks/utils/cnf_manager.cr index 253b258b3..e93f2f5e8 100644 --- a/src/tasks/utils/cnf_manager.cr +++ b/src/tasks/utils/cnf_manager.cr @@ -48,31 +48,11 @@ module CNFManager # ``` # CNFManager.cnf_workload_resources(args, config) {|cnf_config, resource| #your code} # ``` - - def self.get_deployment_namespace(config) - install_method = config.dynamic.install_method - case install_method[0] - when CNFInstall::InstallMethod::HelmChart, CNFInstall::InstallMethod::HelmDirectory - config_namespace = config.deployments.get_deployment_param(:namespace) - if !config_namespace.empty? - Log.info { "deployment namespace was set to: #{config_namespace}" } - config_namespace - else - Log.info { "deployment namespace was set to: #{DEFAULT_CNF_NAMESPACE}" } - DEFAULT_CNF_NAMESPACE - end - else - Log.info { "deployment namespace was set to: default" } - "default" - end - end - def self.cnf_workload_resources(args, config, &block) - deployment_namespace = CNFManager.get_deployment_namespace(config) manifest_ymls = cnf_resource_ymls(args, config) # call cnf cnf_resources to get unfiltered yml - resource_ymls = Helm.all_workload_resources(manifest_ymls, deployment_namespace) + resource_ymls = Helm.all_workload_resources(manifest_ymls, default_namespace: CLUSTER_DEFAULT_NAMESPACE) resource_resp = resource_ymls.map do | resource | resp = yield resource Log.debug { "cnf_workload_resource yield resp: #{resp}" } @@ -93,8 +73,7 @@ module CNFManager resource_ymls = cnf_workload_resources(args, config) do |resource| resource end - deployment_namespace = CNFManager.get_deployment_namespace(config) - resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: deployment_namespace) + resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: CLUSTER_DEFAULT_NAMESPACE) Log.info { "resource names: #{resource_names}" } if resource_names && resource_names.size > 0 initialized = true @@ -203,407 +182,8 @@ module CNFManager cnf_testsuite_helm_directory.split("/")[-1] end - def self.config_source_dir(config_file) - if File.directory?(config_file) - config_file - else - File.dirname(config_file) - end - end - - def self.helm_repo_add(helm_repo_name=nil, helm_repo_url=nil, args : Sam::Args=Sam::Args.new) - Log.info { "helm_repo_add repo_name: #{helm_repo_name} repo_url: #{helm_repo_url} args: #{args.inspect}" } - ret = false - if helm_repo_name == nil || helm_repo_url == nil - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(args.named["cnf-config"].as(String))) - Log.info { "helm path: #{Helm::BinarySingleton.helm}" } - helm = Helm::BinarySingleton.helm - helm_repo_name = config.deployments.get_deployment_param(:helm_repo_name) - helm_repo_url = config.deployments.get_deployment_param(:helm_repo_url) - Log.info { "helm_repo_name: #{helm_repo_name}" } - Log.info { "helm_repo_url: #{helm_repo_url}" } - end - if helm_repo_name && helm_repo_url - ret = Helm.helm_repo_add(helm_repo_name, helm_repo_url) - else - ret = false - end - ret - end - - def self.sample_setup_cli_args(args, noisy=true) - Log.for("verbose").info { "sample_setup_cli_args" } if check_verbose(args) - Log.for("verbose").debug { "args = #{args.inspect}" } if check_verbose(args) - cnf_path = "" - if args.named.keys.includes? "cnf-config" - cnf_path = args.named["cnf-config"].as(String) - elsif args.named.keys.includes? "cnf-path" - cnf_path = args.named["cnf-path"].as(String) - elsif noisy - stdout_failure "Error: You must supply either cnf-config or cnf-path" - exit 1 - else - cnf_path = "" - end - if args.named.keys.includes? "wait_count" - wait_count = args.named["wait_count"].to_i - elsif args.named.keys.includes? "wait-count" - wait_count = args.named["wait-count"].to_i - else - wait_count = 1800 - end - - skip_wait_for_install = args.raw.includes? "skip_wait_for_install" - - cli_args = {config_file: cnf_path, wait_count: wait_count, skip_wait_for_install: skip_wait_for_install, verbose: check_verbose(args)} - Log.debug { "cli_args: #{cli_args}" } - cli_args - end - - # Create a unique directory for the cnf that is to be installed under ./cnfs - # Only copy the cnf's cnf-testsuite.yml and it's helm_directory or manifest directory (if it exists) - # Use manifest directory if helm directory empty - def self.sandbox_setup(config, cli_args) - Log.info { "sandbox_setup" } - Log.info { "sandbox_setup config: #{config.inspect}" } - verbose = cli_args[:verbose] - config_file = config.dynamic.source_cnf_dir - install_method = config.dynamic.install_method - destination_cnf_dir = config.dynamic.destination_cnf_dir - - # Create a CNF sandbox dir - FileUtils.mkdir_p(destination_cnf_dir) - - # Copy cnf-testsuite.yml file to the cnf sandbox dir - copy_cnf_cmd = "cp -a #{ensure_cnf_testsuite_yml_path(config_file)} #{destination_cnf_dir}" - Log.info { copy_cnf_cmd } - status = Process.run(copy_cnf_cmd, shell: true) - - # Create dir for config maps - FileUtils.mkdir_p("#{destination_cnf_dir}/config_maps") - - # todo manifest_or_helm_directory should either be the source helm/manifest files or the destination - # directory that they will be copied to/generated into, but *not both* - case install_method[0] - when CNFInstall::InstallMethod::ManifestDirectory - Log.info { "preparing manifest_directory sandbox" } - manifest_directory = config.deployments.get_deployment_param(:manifest_directory) - source_directory = File.join(config_source_dir(config_file), manifest_directory) - src_path = Path[source_directory].expand.to_s - Log.info { "cp -a #{src_path} #{destination_cnf_dir}" } - - begin - FileUtils.cp_r(src_path, destination_cnf_dir) - rescue File::AlreadyExistsError - Log.info { "manifest sandbox dir already exists at #{destination_cnf_dir}/#{File.basename(src_path)}" } - end - when CNFInstall::InstallMethod::HelmDirectory - Log.info { "preparing helm_directory sandbox" } - helm_directory = config.deployments.get_deployment_param(:helm_directory) - source_directory = File.join(config_source_dir(config_file), helm_directory.split(" ")[0]) # todo support parameters separately - src_path = Path[source_directory].expand.to_s - Log.info { "cp -a #{src_path} #{destination_cnf_dir}" } - - begin - FileUtils.cp_r(src_path, destination_cnf_dir) - rescue File::AlreadyExistsError - Log.info { "helm sandbox dir already exists at #{destination_cnf_dir}/#{File.basename(src_path)}" } - rescue File::NotFoundError - Log.info { "helm directory not found at #{src_path}" } - stdout_warning "helm directory at #{helm_directory} is missing" - end - when CNFInstall::InstallMethod::HelmChart - Log.info { "preparing helm chart sandbox" } - FileUtils.mkdir_p(Path[destination_cnf_dir].expand.to_s + "/exported_chart") - end - - Log.for("verbose").debug { - stdout = IO::Memory.new - Process.run("ls -alR #{destination_cnf_dir}", shell: true, output: stdout, error: stdout) - "Contents of destination_cnf_dir #{destination_cnf_dir}: \n#{stdout}" - } - end - - # Retrieve the helm chart source: only works with helm chart - # installs (not helm directory or manifest directories) - def self.export_published_chart(config, cli_args) - Log.info { "exported_chart cli_args: #{cli_args}" } - verbose = cli_args[:verbose] - config_file = config.dynamic.source_cnf_dir - helm_chart = config.deployments.get_deployment_param(:helm_chart) - destination_cnf_dir = config.dynamic.destination_cnf_dir - config_path = CNFManager.ensure_cnf_testsuite_yml_path(config_file) - - # Pulling chart - # Delete pre-existing tgz files - files_to_delete = find_tgz_files(helm_chart) - files_to_delete.each do |file| - FileUtils.rm(file) - Log.info { "Deleted: #{file}" } - end - - # Pull new version - helm_info = Helm.pull(helm_chart) - unless helm_info[:status].success? - puts "Helm pull error".colorize(:red) - raise "Helm pull error" - end - - # Discover newly pulled tgz file - tgz_name = get_and_verify_tgz_name(helm_chart) - - Log.info { "tgz_name: #{tgz_name}" } - - TarClient.untar(tgz_name, "#{destination_cnf_dir}/exported_chart") - - Log.for("verbose").info { "mv #{destination_cnf_dir}/exported_chart/#{Helm.chart_name(helm_chart)}/* #{destination_cnf_dir}/exported_chart" } if verbose - Log.for("verbose").debug { - stdout = IO::Memory.new - Process.run("ls -alR #{destination_cnf_dir}", shell: true, output: stdout, error: stdout) - "Contents of destination_cnf_dir #{destination_cnf_dir} before move: \n#{stdout}" - } - - FileUtils.mv( - Dir.glob("#{destination_cnf_dir}/exported_chart/#{Helm.chart_name(helm_chart)}/*"), - "#{destination_cnf_dir}/exported_chart" - ) - - Log.for("verbose").debug { - stdout = IO::Memory.new - Process.run("ls -alR #{destination_cnf_dir}", shell: true, output: stdout, error: stdout) - "Contents of destination_cnf_dir #{destination_cnf_dir} after move: \n#{stdout}" - } - end - - #sample_setup({config_file: cnf_path, wait_count: wait_count}) - def self.sample_setup(cli_args) - Log.info { "sample_setup cli_args: #{cli_args}" } - config_file = cli_args[:config_file] - wait_count = cli_args[:wait_count] - skip_wait_for_install = cli_args[:skip_wait_for_install] - verbose = cli_args[:verbose] - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - Log.debug { "config in sample_setup: #{config.inspect}" } - - Log.for("verbose").info { "sample_setup" } if verbose - Log.info { "config_file #{config_file}" } - - release_name = config.deployments.get_deployment_param(:name) - install_method = config.dynamic.install_method - Log.info { "install_method #{install_method}" } - helm_values = config.deployments.get_deployment_param(:helm_values) - deployment_namespace = CNFManager.get_deployment_namespace(config) - helm_namespace_option = "-n #{deployment_namespace}" - ensure_namespace_exists!(deployment_namespace) - destination_cnf_dir = config.dynamic.destination_cnf_dir - - Log.for("verbose").info { "destination_cnf_dir: #{destination_cnf_dir}" } if verbose - Log.debug { "mkdir_p destination_cnf_dir: #{destination_cnf_dir}" } - FileUtils.mkdir_p(destination_cnf_dir) - - sandbox_setup(config, cli_args) - - helm = Helm::BinarySingleton.helm - Log.info { "helm path: #{Helm::BinarySingleton.helm}" } - - # This is to indicate if the release has already been setup. - # Set it to false by default to indicate a new release is being setup - fresh_install = true - - # todo separate out install methods into a module/function that accepts a block - Log.for("sample_setup:install_method").info { "#{install_method[0]}" } - Log.for("sample_setup:install_method").info { "#{install_method[1]}" } - case install_method[0] - when CNFInstall::InstallMethod::ManifestDirectory - Log.for("verbose").info { "deploying by manifest file" } if verbose - manifest_directory = config.deployments.get_deployment_param(:manifest_directory) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{manifest_directory}") - when CNFInstall::InstallMethod::HelmChart - helm_chart = config.deployments.get_deployment_param(:helm_chart) - helm_repo_name = config.deployments.get_deployment_param(:helm_repo_name) - helm_repo_url = config.deployments.get_deployment_param(:helm_repo_url) - if !helm_repo_name.empty? || !helm_repo_url.empty? - Helm.helm_repo_add(helm_repo_name, helm_repo_url) - end - Log.for("verbose").info { "deploying with chart repository" } if verbose - begin - Helm.install(release_name, helm_chart, helm_namespace_option, helm_values) - rescue e : Helm::InstallationFailed - stdout_failure "Helm installation failed" - stdout_failure "\t#{e.message}" - exit 1 - rescue e : Helm::CannotReuseReleaseNameError - stdout_warning "Release name #{release_name} has already been setup." - fresh_install = false - end - export_published_chart(config, cli_args) - when CNFInstall::InstallMethod::HelmDirectory - Log.for("verbose").info { "deploying with helm directory" } if verbose - #TODO Add helm options into cnf-testsuite yml - #e.g. helm install nsm --set insecure=true ./nsm/helm_chart - begin - Helm.install(release_name, "#{install_method[1]}", helm_namespace_option, helm_values) - rescue e : Helm::InstallationFailed - stdout_failure "Helm installation failed" - stdout_failure "\t#{e.message}" - exit 1 - rescue e : Helm::CannotReuseReleaseNameError - stdout_warning "Release name #{release_name} has already been setup." - fresh_install = false - end - else - raise "Deployment method not found" - end - - #Generating manifest from installed CNF - #Returns true or false in case when manifest was generated successfully or not - manifest_generated_successfully = CNFInstall::Manifest.generate_common_manifest(config, release_name, deployment_namespace) - - if !manifest_generated_successfully - stdout_failure "Manifest generation failed. Check CNF definition (helm charts, values, manifests, etc.)" - exit 1 - end - resource_ymls = cnf_workload_resources(nil, config) do |resource| - resource - end - resource_names = Helm.workload_resource_kind_names(resource_ymls, deployment_namespace) - if !skip_wait_for_install - stdout_success "Waiting for resource availability, timeout for each resource is #{wait_count} seconds\n" - workload_resource_names = resource_names.select { |resource| - WORKLOAD_RESOURCE_KIND_NAMES.includes?(resource[:kind].downcase) - } - total_resource_count = workload_resource_names.size() - current_resource_number = 1 - workload_resource_names.each do | resource | - stdout_success "Waiting for resource (#{current_resource_number}/#{total_resource_count}): [#{resource[:kind]}] #{resource[:name]}", same_line: true - ready = KubectlClient::Get.resource_wait_for_install(resource[:kind], resource[:name], wait_count: wait_count, namespace: resource[:namespace]) - if !ready - stdout_failure "CNF setup has timed-out, [#{resource[:kind]}] #{resource[:name]} is not ready after #{wait_count} seconds.", same_line: true - stdout_failure "Recommended course of actions would be to investigate the resource in cluster, then call cnf_cleanup and try to reinstall the CNF." - exit 1 - end - current_resource_number += 1 - end - stdout_success "All CNF resources are up!", same_line: true - end - - if fresh_install - stdout_success "Successfully setup #{release_name}" - end - ensure - #todo uninstall/reinstall clustertools because of tshark bug - end - def self.cnf_to_new_cluster(config, kubeconfig) - release_name = config.deployments.get_deployment_param(:name) - install_method = config.dynamic.install_method - destination_cnf_dir = config.dynamic.destination_cnf_dir - deployment_namespace = CNFManager.get_deployment_namespace(config) - helm_namespace_option = "-n #{deployment_namespace}" - ensure_namespace_exists!(deployment_namespace, kubeconfig: kubeconfig) - - Log.for("cnf_to_new_cluster").info { "Install method: #{install_method[0]}" } - case install_method[0] - when CNFInstall::InstallMethod::ManifestDirectory - manifest_directory = config.deployments.get_deployment_param(:manifest_directory) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{manifest_directory}", kubeconfig: kubeconfig) - when CNFInstall::InstallMethod::HelmChart - helm_repo_name = config.deployments.get_deployment_param(:helm_repo_name) - helm_repo_url = config.deployments.get_deployment_param(:helm_repo_url) - helm_chart = config.deployments.get_deployment_param(:helm_chart) - begin - Helm.install("#{release_name} #{helm_chart} --kubeconfig #{kubeconfig} #{helm_namespace_option}") - rescue e : Helm::CannotReuseReleaseNameError - stdout_warning "Release name #{release_name} has already been setup." - end - when CNFInstall::InstallMethod::HelmDirectory - helm_directory = config.deployments.get_deployment_param(:helm_directory) - begin - Helm.install("#{release_name} #{destination_cnf_dir}/#{helm_directory} --kubeconfig #{kubeconfig} #{helm_namespace_option}") - rescue e : Helm::CannotReuseReleaseNameError - stdout_warning "Release name #{release_name} has already been setup." - end - else - raise "Deployment method not found" - end - - resource_ymls = cnf_workload_resources(nil, config) do |resource| - resource - end - - resource_names = Helm.workload_resource_kind_names(resource_ymls, default_namespace: deployment_namespace) - - wait_list = resource_names.map do | resource | - case resource[:kind].downcase - when .in?(WORKLOAD_RESOURCE_KIND_NAMES) - Log.info { "waiting on resource of kind: #{resource[:kind].downcase}" } - KubectlClient::Get.resource_wait_for_install(resource[:kind], resource[:name], 180, namespace: resource[:namespace], kubeconfig: kubeconfig) - else - true - end - end - Log.info { "wait_list: #{wait_list}" } - # check list of booleans, make sure all are true (is ready) - !wait_list.any?(false) - end - - def self.sample_cleanup(config_file, force=false, installed_from_manifest=false, verbose=true) - Log.info { "sample_cleanup" } - Log.info { "sample_cleanup installed_from_manifest: #{installed_from_manifest}" } - - FileUtils.rm_rf(COMMON_MANIFEST_FILE_PATH) - Log.info { "#{COMMON_MANIFEST_FILE_PATH} file was removed." } - - config = CNFInstall::Config.parse_cnf_config_from_file(CNFManager.ensure_cnf_testsuite_yml_path(config_file)) - Log.for("verbose").info { "cleanup config: #{config.inspect}" } if verbose - destination_cnf_dir = config.dynamic.destination_cnf_dir - Log.info { "destination_cnf_dir: #{destination_cnf_dir}" } - - - config_maps_dir = "#{destination_cnf_dir}/config_maps" - if Dir.exists?(config_maps_dir) - Dir.entries(config_maps_dir).each do |config_map| - Log.info { "Deleting configmap: #{config_map}" } - KubectlClient::Delete.file("#{destination_cnf_dir}/config_maps/#{config_map}") - end - end - - # Strips all the helm options from the release name option in config - release_name = config.deployments.get_deployment_param(:name) - release_name = release_name.split(" ")[0] - - Log.for("sample_cleanup:helm_path").info { Helm::BinarySingleton.helm } - helm = Helm::BinarySingleton.helm - dir_exists = File.directory?(destination_cnf_dir) - if !dir_exists && force != true - Log.for("sample_cleanup").info { "Destination dir #{destination_cnf_dir} does not exist and force option not passed. Exiting." } - return false - elsif dir_exists - Log.for("sample_cleanup").info { "Destination dir #{destination_cnf_dir} exists" } - end - - install_method = config.dynamic.install_method - Log.for("sample_cleanup:install_method").info { install_method } - case install_method[0] - when CNFInstall::InstallMethod::HelmChart, CNFInstall::InstallMethod::HelmDirectory - deployment_namespace = CNFManager.get_deployment_namespace(config) - helm_namespace_option = "-n #{deployment_namespace}" - result = Helm.uninstall(release_name + " #{helm_namespace_option}") - Log.for("sample_cleanup:helm_uninstall").info { result[:output].to_s } if verbose - if result[:status].success? - stdout_success "Successfully cleaned up #{release_name}" - end - FileUtils.rm_rf(destination_cnf_dir) - return result[:status].success? - when CNFInstall::InstallMethod::ManifestDirectory - manifest_directory = config.deployments.get_deployment_param(:manifest_directory) - installed_manifest_directory = File.join(destination_cnf_dir, manifest_directory) - Log.for("cnf_cleanup:installed_manifest_directory").info { installed_manifest_directory } - result = KubectlClient::Delete.file("#{installed_manifest_directory}", wait: true) - FileUtils.rm_rf(destination_cnf_dir) - stdout_success "Successfully cleaned up #{manifest_directory} directory" - return true - end + # (kosstennbl) TODO: Redesign this method using new installation. end def self.ensure_namespace_exists!(name, kubeconfig : String | Nil = nil) @@ -615,8 +195,7 @@ module CNFManager def self.workload_resource_keys(args, config) resource_keys = CNFManager.cnf_workload_resources(args, config) do |resource| - deployment_namespace = CNFManager.get_deployment_namespace(config) - namespace = resource.dig?("metadata", "namespace") || deployment_namespace + namespace = resource.dig?("metadata", "namespace") || CLUSTER_DEFAULT_NAMESPACE kind = resource.dig?("kind") name = resource.dig?("metadata", "name") "#{namespace},#{kind}/#{name}".downcase diff --git a/src/tasks/utils/task.cr b/src/tasks/utils/task.cr index 74c839824..add6587c1 100644 --- a/src/tasks/utils/task.cr +++ b/src/tasks/utils/task.cr @@ -70,7 +70,7 @@ module CNFManager - name: "platform-test-dummy-deployment" helm_directory: "" YAML - config = CNFInstall::Config.parse_cnf_config_from_yaml(yaml_string, config_dir: FileUtils.pwd) + config = CNFInstall::Config.parse_cnf_config_from_yaml(yaml_string) end test_start_time = Time.utc if task diff --git a/src/tasks/workload/compatibility.cr b/src/tasks/workload/compatibility.cr index 4f0ce55bb..5792f852d 100644 --- a/src/tasks/workload/compatibility.cr +++ b/src/tasks/workload/compatibility.cr @@ -37,7 +37,7 @@ ROLLING_VERSION_CHANGE_TEST_NAMES.each do |tn| # note: all images are not on docker hub nor are they always on a docker hub compatible api task_response = update_applied && CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - namespace = resource["namespace"] || CNFManager.get_deployment_namespace(config) + namespace = resource["namespace"] test_passed = true valid_cnf_testsuite_yml = true Log.for(t.name).debug { "container: #{container}" } @@ -109,7 +109,7 @@ task "rollback" do |t, args| task_response = update_applied && CNFManager.workload_resource_test(args, config) do |resource, container, initialized| resource_kind = resource["kind"] resource_name = resource["name"] - namespace = resource["namespace"] || CNFManager.get_deployment_namespace(config) + namespace = resource["namespace"] container_name = container.as_h["name"].as_s full_image_name_tag = container.as_h["image"].as_s.rpartition(":") image_name = full_image_name_tag[0] @@ -389,10 +389,9 @@ task "helm_deploy" do |t, args| CNFManager::Task.task_runner(args, task: t, check_cnf_installed: false) do |args, config| if check_cnf_config(args) || CNFManager.destination_cnfs_exist? - install_method = config.deployments.get_install_method() - helm_used = install_method[0].is_a?(CNFInstall::InstallMethod::HelmDirectory) || install_method[0].is_a?(CNFInstall::InstallMethod::HelmChart) + helm_used = !config.deployments.helm_charts.empty? || !config.deployments.helm_dirs.empty? - if helm_used == "true" + if helm_used CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "CNF is installed via helm") else CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "CNF has deployments that are not installed with helm") @@ -463,12 +462,12 @@ task "helm_chart_valid", ["helm_local_install"] do |t, args| # Collect helm chart paths config.deployments.helm_charts.each do |deployment| - chart_dirs << {"#{current_dir}/#{CNF_DIR}/#{deployment.name}/exported_chart", deployment.name} + chart_dirs << { File.join(current_dir, DEPLOYMENTS_DIR, deployment.name, deployment.helm_chart_name), deployment.name} end # Collect helm directory paths config.deployments.helm_dirs.each do |deployment| - chart_dirs << {"#{current_dir}/#{CNF_DIR}/#{deployment.name}/chart", deployment.name} + chart_dirs << { File.join(current_dir, DEPLOYMENTS_DIR, deployment.name, deployment.helm_directory), deployment.name} end # Initialize flags to track the task state diff --git a/src/tasks/workload/configuration.cr b/src/tasks/workload/configuration.cr index b079ae69e..3289b7695 100644 --- a/src/tasks/workload/configuration.cr +++ b/src/tasks/workload/configuration.cr @@ -213,9 +213,6 @@ end desc "Does the CNF have hardcoded IPs in the K8s resource configuration" task "hardcoded_ip_addresses_in_k8s_runtime_configuration" do |t, args| task_response = CNFManager::Task.task_runner(args, task: t) do |args, config| - helm_chart = config.deployments.get_deployment_param(:helm_chart) - helm_directory = config.deployments.get_deployment_param(:helm_directory) - destination_cnf_dir = config.dynamic.destination_cnf_dir current_dir = FileUtils.pwd helm = Helm::BinarySingleton.helm VERBOSE_LOGGING.info "Helm Path: #{helm}" if check_verbose(args) @@ -293,7 +290,7 @@ task "secrets_used" do |t, args| # but do not have a corresponding k8s secret defined, this # is an installation problem, and does not stop the test from passing - namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + namespace = resource[:namespace] secrets = KubectlClient::Get.secrets(namespace: namespace) secrets["items"].as_a.each do |s| @@ -451,14 +448,13 @@ task "immutable_configmap" do |t, args| resp = "" task_response = CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir # https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/ # feature test to see if immutable_configmaps are enabled # https://github.com/cnti-testcatalog/testsuite/issues/508#issuecomment-758438413 - test_config_map_filename = "#{destination_cnf_dir}/config_maps/test_config_map.yml"; + test_config_map_filename = "#{CNF_TEMP_FILES_DIR}/test_config_map.yml"; template = ImmutableConfigMapTemplate.new("doesnt_matter").to_s Log.for(t.name).debug { "test immutable_configmap template: #{template}" } @@ -500,7 +496,7 @@ task "immutable_configmap" do |t, args| # If the install type is manifest, the namesapce would be in the manifest. # Else rely on config for helm-based install - namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + namespace = resource[:namespace] configmaps = KubectlClient::Get.configmaps(namespace: namespace) if configmaps.dig?("items") configmaps = configmaps.dig("items").as_a @@ -571,16 +567,16 @@ task "alpha_k8s_apis" do |t, args| Log.info { "apisnoop cluster kubeconfig: #{cluster.kubeconfig}" } ENV["KUBECONFIG"] = "#{cluster.kubeconfig}" - cnf_setup_complete = CNFManager.cnf_to_new_cluster(config, cluster.kubeconfig) + cnf_install_complete = CNFManager.cnf_to_new_cluster(config, cluster.kubeconfig) - # CNF setup failed on kind cluster. Inform in test output. - unless cnf_setup_complete + # CNF installation failed on kind cluster. Inform in test output. + unless cnf_install_complete puts "CNF failed to install on apisnoop cluster".colorize(:red) next CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Could not check CNF for usage of Kubernetes alpha APIs") end - # CNF setup was fine on kind cluster. Check for usage of alpha Kubernetes APIs. - Log.info { "CNF setup complete on apisnoop cluster" } + # CNF installation was fine on kind cluster. Check for usage of alpha Kubernetes APIs. + Log.info { "CNF installation complete on apisnoop cluster" } Log.info { "Query the apisnoop database" } k8s_major_minor_version = k8s_server_version.split(".")[0..1].join(".") diff --git a/src/tasks/workload/microservice.cr b/src/tasks/workload/microservice.cr index f20fabe1c..51d9c36c9 100644 --- a/src/tasks/workload/microservice.cr +++ b/src/tasks/workload/microservice.cr @@ -243,7 +243,7 @@ task "reasonable_image_size" do |t, args| Log.for(t.name).debug { "cnf_config: #{config}" } task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - source_cnf_dir = config.dynamic.source_cnf_dir + image_secrets_config_path = File.join(CNF_TEMP_FILES_DIR, "config.json") if resource["kind"].downcase == "deployment" || resource["kind"].downcase == "statefulset" || @@ -290,9 +290,9 @@ task "reasonable_image_size" do |t, args| }[0..-2]}}}) puts "str_auths: #{str_auths}" end - File.write("#{source_cnf_dir}/config.json", str_auths) + File.write(image_secrets_config_path, str_auths) Dockerd.exec("mkdir -p /root/.docker/") - KubectlClient.cp("#{source_cnf_dir}/config.json #{TESTSUITE_NAMESPACE}/dockerd:/root/.docker/config.json") + KubectlClient.cp("#{image_secrets_config_path} #{TESTSUITE_NAMESPACE}/dockerd:/root/.docker/config.json") end Log.info { "FQDN of the docker image: #{fqdn_image}" } diff --git a/src/tasks/workload/observability.cr b/src/tasks/workload/observability.cr index 2ffb14b58..6d10a7d58 100644 --- a/src/tasks/workload/observability.cr +++ b/src/tasks/workload/observability.cr @@ -42,7 +42,6 @@ end desc "Does the CNF emit prometheus traffic" task "prometheus_traffic" do |t, args| task_response = CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir do_this_on_each_retry = ->(ex : Exception, attempt : Int32, elapsed_time : Time::Span, next_interval : Time::Span) do Log.info { "#{ex.class}: '#{ex.message}' - #{attempt} attempt in #{elapsed_time} seconds and #{next_interval} seconds until the next try."} @@ -127,7 +126,7 @@ task "prometheus_traffic" do |t, args| end Log.debug { "metrics_config_map : #{metrics_config_map}" } - configmap_path = "#{destination_cnf_dir}/config_maps/metrics_configmap.yml" + configmap_path = "#{CNF_TEMP_FILES_DIR}/metrics_configmap.yml" File.write(configmap_path, "#{metrics_config_map}") KubectlClient::Delete.file(configmap_path) KubectlClient::Apply.file(configmap_path) diff --git a/src/tasks/workload/ran.cr b/src/tasks/workload/ran.cr index 5b31aa579..a2c21c947 100644 --- a/src/tasks/workload/ran.cr +++ b/src/tasks/workload/ran.cr @@ -16,7 +16,6 @@ end desc "Test if RAN uses the ORAN e2 interface" task "oran_e2_connection" do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - release_name = config.deployments.get_deployment_param(:name) if ORANMonitor.isCNFaRIC?(config) # (kosstennbl) TODO: Redesign oran_e2_connection test, preferably without usage of installation configmaps. More info in issue #2153 CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Skipped, "oran_e2_connection test is disabled, check #2153") diff --git a/src/tasks/workload/reliability.cr b/src/tasks/workload/reliability.cr index abc1096ff..90f8d9dea 100644 --- a/src/tasks/workload/reliability.cr +++ b/src/tasks/workload/reliability.cr @@ -87,10 +87,9 @@ task "pod_network_latency", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| #todo if args has list of labels to perform test on, go into pod specific mode #TODO tests should fail if cnf not installed - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| Log.info { "Current Resource Name: #{resource["name"]} Type: #{resource["kind"]}" } - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" @@ -162,9 +161,9 @@ task "pod_network_latency", ["install_litmus"] do |t, args| "#{spec_labels.as_h.first_value}" ).to_s end - - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end @@ -185,10 +184,9 @@ desc "Does the CNF crash when network corruption occurs" task "pod_network_corruption", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| #TODO tests should fail if cnf not installed - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| Log.info {"Current Resource Name: #{resource["name"]} Type: #{resource["kind"]}"} - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" test_passed = true @@ -221,8 +219,9 @@ task "pod_network_corruption", ["install_litmus"] do |t, args| "#{spec_labels.first_key}", "#{spec_labels.first_value}" ).to_s - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name, args, namespace: app_namespace) end @@ -239,9 +238,8 @@ desc "Does the CNF crash when network duplication occurs" task "pod_network_duplication", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| #TODO tests should fail if cnf not installed - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] Log.info{ "Current Resource Name: #{resource["name"]} Type: #{resource["kind"]} Namespace: #{resource["namespace"]}"} spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 && resource["kind"] == "Deployment" @@ -277,8 +275,9 @@ task "pod_network_duplication", ["install_litmus"] do |t, args| "#{spec_labels.first_key}", "#{spec_labels.first_value}" ).to_s - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end @@ -294,9 +293,8 @@ end desc "Does the CNF crash when disk fill occurs" task "disk_fill", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -333,8 +331,9 @@ task "disk_fill", ["install_litmus"] do |t, args| "#{spec_labels.first_key}", "#{spec_labels.first_value}" ).to_s - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name, chaos_experiment_name, args, namespace: app_namespace) end @@ -351,10 +350,9 @@ end desc "Does the CNF crash when pod-delete occurs" task "pod_delete", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir #todo clear all annotations task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -433,8 +431,9 @@ task "pod_delete", ["install_litmus"] do |t, args| end Log.info { "template: #{template}" } - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) end test_passed=LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) @@ -452,9 +451,8 @@ end desc "Does the CNF crash when pod-memory-hog occurs" task "pod_memory_hog", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -492,8 +490,9 @@ task "pod_memory_hog", ["install_litmus"] do |t, args| target_pod_name ).to_s - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end @@ -510,9 +509,8 @@ end desc "Does the CNF crash when pod-io-stress occurs" task "pod_io_stress", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -550,8 +548,9 @@ task "pod_io_stress", ["install_litmus"] do |t, args| target_pod_name ).to_s - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(chaos_test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end @@ -572,12 +571,11 @@ end desc "Does the CNF crash when pod-dns-error occurs" task "pod_dns_error", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| - destination_cnf_dir = config.dynamic.destination_cnf_dir runtimes = KubectlClient::Get.container_runtimes Log.info { "pod_dns_error runtimes: #{runtimes}" } if runtimes.find{|r| r.downcase.includes?("docker")} task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) if spec_labels.as_h? && spec_labels.as_h.size > 0 test_passed = true @@ -613,9 +611,9 @@ task "pod_dns_error", ["install_litmus"] do |t, args| "#{spec_labels.first_key}", "#{spec_labels.first_value}" ).to_s - - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end diff --git a/src/tasks/workload/state.cr b/src/tasks/workload/state.cr index 98bc8298c..664ad8ea0 100644 --- a/src/tasks/workload/state.cr +++ b/src/tasks/workload/state.cr @@ -219,9 +219,8 @@ desc "Does the CNF crash when node-drain occurs" task "node_drain", ["install_litmus"] do |t, args| CNFManager::Task.task_runner(args, task: t) do |args, config| skipped = false - destination_cnf_dir = config.dynamic.destination_cnf_dir task_response = CNFManager.workload_resource_test(args, config) do |resource, container, initialized| - app_namespace = resource[:namespace] || CNFManager.get_deployment_namespace(config) + app_namespace = resource[:namespace] Log.info { "Current Resource Name: #{resource["kind"]}/#{resource["name"]} Namespace: #{resource["namespace"]}" } spec_labels = KubectlClient::Get.resource_spec_labels(resource["kind"], resource["name"], resource["namespace"]) @@ -323,9 +322,9 @@ task "node_drain", ["install_litmus"] do |t, args| app_nodeName ).to_s Log.for("node_drain").info { "Chaos test name: #{test_name}; Experiment name: #{chaos_experiment_name}; Label #{deployment_label}=#{deployment_label_value}; namespace: #{app_namespace}" } - - File.write("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml", template) - KubectlClient::Apply.file("#{destination_cnf_dir}/#{chaos_experiment_name}-chaosengine.yml") + chaos_template_path = File.join(CNF_TEMP_FILES_DIR, "#{chaos_experiment_name}-chaosengine.yml") + File.write(chaos_template_path, template) + KubectlClient::Apply.file(chaos_template_path) LitmusManager.wait_for_test(test_name, chaos_experiment_name, args, namespace: app_namespace) test_passed = LitmusManager.check_chaos_verdict(chaos_result_name,chaos_experiment_name,args, namespace: app_namespace) end @@ -369,10 +368,9 @@ task "elastic_volumes" do |t, args| # todo use workload resource # elastic = WorkloadResource.elastic?(volumes) - namespace = CNFManager.get_deployment_namespace(config) - full_resource = KubectlClient::Get.resource(resource["kind"], resource["name"], namespace) - elastic_result = WorkloadResource.elastic?(full_resource, volumes.as_a, namespace) + full_resource = KubectlClient::Get.resource(resource["kind"], resource["name"], resource["namespace"]) + elastic_result = WorkloadResource.elastic?(full_resource, volumes.as_a, resource["namespace"]) Log.for("#{t.name}:elastic_result").info {elastic_result} unless elastic_result all_volumes_elastic = false @@ -408,7 +406,6 @@ task "database_persistence" do |t, args| non_elastic_database_statefulset_found = false match = Mysql.match Log.info {"database_persistence mysql: #{match}"} - deployment_namespace = CNFManager.get_deployment_namespace(config) if match && match[:found] task_response = CNFManager.workload_resource_test(args, config, check_containers: false) do |resource, containers, volumes, initialized| # Skip resources that do not have containers with mysql image @@ -422,7 +419,7 @@ task "database_persistence" do |t, args| next if resource["kind"].downcase != "statefulset" statefulset_found = true - namespace = resource["namespace"] || deployment_namespace + namespace = resource["namespace"] Log.info {"database_persistence namespace: #{namespace}"} Log.info {"database_persistence resource: #{resource}"} Log.info {"database_persistence volumes: #{volumes}"}