From df5f452b12c04478d39f0a82d31549008b5a35e9 Mon Sep 17 00:00:00 2001 From: Konstantin Yarovoy Date: Fri, 1 Nov 2024 09:06:23 +0000 Subject: [PATCH] new-cnf-installation: Fully transition to new CNF installation method Remove old installation method, use the new one instead. Change specs accordingly. Remove unnecessary config parameters. Fully enable multiple deployments installation. Refs: #2169 Signed-off-by: Konstantin Yarovoy --- INSTALL.md | 4 +- SOURCE_INSTALL.md | 4 +- example-cnfs/coredns/README.md | 4 +- example-cnfs/envoy/README.md | 4 +- example-cnfs/ip-forwarder/README.md | 4 +- example-cnfs/linkerd2/README.md | 4 +- example-cnfs/nsm/README.md | 4 +- example-cnfs/pantheon-nsm-nat/README.md | 5 +- .../pantheon-nsm-nat/nat-cnf/README.md | 4 +- example-cnfs/vpp-3c2n-csp-use-case/README.md | 6 +- spec/5g/core_spec.cr | 8 +- spec/5g/ran_spec.cr | 4 +- spec/cnf_testsuite_all/cnf_testsuite_spec.cr | 3 +- spec/platform/hardware_and_scheduler_spec.cr | 3 +- spec/platform/platform_spec.cr | 3 +- spec/setup_spec.cr | 15 +- spec/spec_helper.cr | 14 +- spec/utils/cnf_manager_spec.cr | 163 +----- spec/utils/kubescape_spec.cr | 2 +- spec/utils/utils_spec.cr | 92 ++-- spec/workload/compatibility_spec.cr | 4 +- spec/workload/configuration_spec.cr | 87 ++-- spec/workload/installability_spec.cr | 13 +- spec/workload/microservice_spec.cr | 40 +- spec/workload/observability_spec.cr | 24 +- spec/workload/operator_spec.cr | 4 +- spec/workload/registry_spec.cr | 10 +- spec/workload/resilience/disk_fill_spec.cr | 2 +- spec/workload/resilience/node_drain_spec.cr | 2 +- spec/workload/resilience/pod_delete_spec.cr | 2 +- .../workload/resilience/pod_dns_error_spec.cr | 2 +- .../workload/resilience/pod_io_stress_spec.cr | 2 +- .../resilience/pod_memory_hog_spec.cr | 2 +- .../resilience/pod_network_corruption_spec.cr | 2 +- .../pod_network_duplication_spec.cr | 2 +- .../resilience/pod_network_latency_spec.cr | 2 +- spec/workload/security_spec.cr | 64 +-- spec/workload/state_spec.cr | 12 +- src/cnf-testsuite.cr | 9 +- src/tasks/cleanup.cr | 39 +- src/tasks/cnf_setup.cr | 93 +--- src/tasks/utils/cnf_manager.cr | 473 ------------------ src/tasks/workload/configuration.cr | 10 +- 43 files changed, 271 insertions(+), 979 deletions(-) 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..493c9900d 100644 --- a/SOURCE_INSTALL.md +++ b/SOURCE_INSTALL.md @@ -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..6f4c96882 100644 --- a/example-cnfs/ip-forwarder/README.md +++ b/example-cnfs/ip-forwarder/README.md @@ -31,9 +31,9 @@ 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 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..920076084 100644 --- a/example-cnfs/vpp-3c2n-csp-use-case/README.md +++ b/example-cnfs/vpp-3c2n-csp-use-case/README.md @@ -23,15 +23,15 @@ 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 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/5g/ran_spec.cr b/spec/5g/ran_spec.cr index 67b495cfa..f1011ebae 100644 --- a/spec/5g/ran_spec.cr +++ b/spec/5g/ran_spec.cr @@ -44,7 +44,7 @@ describe "5g" do ensure result = Helm.delete("open5gs -n oran") result[:status].success?.should be_true - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-oran-ric/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end @@ -59,7 +59,7 @@ describe "5g" do ensure result = Helm.delete("open5gs -n oran") result[:status].success?.should be_true - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-oran-noric/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() result[:status].success?.should be_true end end diff --git a/spec/cnf_testsuite_all/cnf_testsuite_spec.cr b/spec/cnf_testsuite_all/cnf_testsuite_spec.cr index f110faa96..94a970800 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.cnf_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/platform/hardware_and_scheduler_spec.cr b/spec/platform/hardware_and_scheduler_spec.cr index 8f7d0cec1..8b0edf461 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.cnf_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..1ff8617f6 100644 --- a/spec/platform/platform_spec.cr +++ b/spec/platform/platform_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.cnf_cleanup() result = ShellCmd.run_testsuite("setup") result[:status].success?.should be_true end diff --git a/spec/setup_spec.cr b/spec/setup_spec.cr index a2ffe959d..ad400eb9b 100644 --- a/spec/setup_spec.cr +++ b/spec/setup_spec.cr @@ -24,7 +24,7 @@ describe "Setup" do 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 = ShellCmd.cnf_cleanup() result[:status].success?.should be_true (/Successfully cleaned up/ =~ result[:output]).should_not be_nil end @@ -35,7 +35,7 @@ describe "Setup" do 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 = ShellCmd.cnf_cleanup() result[:status].success?.should be_true (/Successfully cleaned up/ =~ result[:output]).should_not be_nil end @@ -48,7 +48,7 @@ describe "Setup" do (/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 = ShellCmd.cnf_cleanup("verbose") result[:status].success?.should be_true (/Successfully cleaned up/ =~ result[:output]).should_not be_nil end @@ -59,19 +59,19 @@ describe "Setup" do 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 = ShellCmd.cnf_cleanup() result[:status].success?.should be_true (/Successfully cleaned up/ =~ result[:output]).should_not be_nil end end - it "'cnf_setup/cnf_cleanup' should properly install/uninstall old versions of cnf configs", tags: ["setup"] do + it "'cnf_setup/cnf_cleanup' should properly install/cleanup 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 = ShellCmd.cnf_cleanup() result[:status].success?.should be_true (/Successfully cleaned up/ =~ result[:output]).should_not be_nil end @@ -84,10 +84,9 @@ describe "Setup" do 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 = ShellCmd.cnf_cleanup() 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 end diff --git a/spec/spec_helper.cr b/spec/spec_helper.cr index 7cc84b974..e60f21b93 100644 --- a/spec/spec_helper.cr +++ b/spec/spec_helper.cr @@ -22,7 +22,19 @@ module ShellCmd end 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.contains?("timeout") ? "" : "timeout=300" + result = run_testsuite("cnf_setup #{setup_params} #{timeout_parameter}", cmd_prefix) + if !expect_failure + result[:status].success?.should be_true + else + result[:status].success?.should be_false + end + result + end + + def self.cnf_cleanup(cleanup_params="", cmd_prefix="", expect_failure=false) + timeout_parameter = cleanup_params.contains?("timeout") ? "" : "timeout=300" + result = run_testsuite("cnf_cleanup #{cleanup_params} #{timeout_parameter}", cmd_prefix) if !expect_failure result[:status].success?.should be_true else diff --git a/spec/utils/cnf_manager_spec.cr b/spec/utils/cnf_manager_spec.cr index 29d0fa265..2458f6ca0 100644 --- a/spec/utils/cnf_manager_spec.cr +++ b/spec/utils/cnf_manager_spec.cr @@ -27,13 +27,13 @@ describe "SampleUtils" do it "'cnf_setup' should pass with a minimal cnf-testsuite.yml", tags: ["cnf-setup"] do ShellCmd.cnf_setup("cnf-path=./sample-cnfs/sample-minimal-cnf/ skip_wait_for_install") ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-minimal-cnf/ force=true") + result = ShellCmd.cnf_cleanup() end it "'cnf_setup' should support cnf-config as an alias for cnf-path", tags: ["cnf-setup"] do ShellCmd.cnf_setup("cnf-config=./sample-cnfs/sample-minimal-cnf/ skip_wait_for_install") ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-path=./sample-cnfs/sample-minimal-cnf/ force=true") + result = ShellCmd.cnf_cleanup() end it "'points_yml' should parse and return the points yaml file", tags: ["points"] do @@ -152,127 +152,7 @@ describe "SampleUtils" do 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 @@ -325,24 +205,27 @@ describe "SampleUtils" do 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 @@ -354,7 +237,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 0a8dacb47..47dfde3c9 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(["cnf-config=./cnf-testsuite.yml"]) @@ -198,13 +200,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 563c43864..a204ae13c 100644 --- a/spec/workload/compatibility_spec.cr +++ b/spec/workload/compatibility_spec.cr @@ -27,7 +27,7 @@ describe "Compatibility" do Log.info { "Status: #{result[:output]}" } (/(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 @@ -39,7 +39,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 51b239105..608ad8b12 100644 --- a/spec/workload/configuration_spec.cr +++ b/spec/workload/configuration_spec.cr @@ -11,20 +11,19 @@ describe CnfTestSuite do Log.debug { result[:output] } result = ShellCmd.run_testsuite("setup") - result = ShellCmd.run_testsuite("samples_cleanup") - result[:status].success?.should be_true + result = ShellCmd.cnf_cleanup() 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,7 +188,7 @@ 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 @@ -200,18 +199,18 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(PASSED).*(No IP addresses found)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("sample_coredns_source_cleanup verbose") + 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 @@ -222,7 +221,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 @@ -233,7 +232,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 @@ -244,7 +243,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 @@ -255,7 +254,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 @@ -266,7 +265,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 @@ -277,29 +276,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 @@ -310,7 +309,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 @@ -321,7 +320,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 @@ -332,7 +331,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 @@ -344,7 +343,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 @@ -356,7 +355,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 @@ -367,7 +366,7 @@ 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 @@ -378,7 +377,7 @@ describe CnfTestSuite do 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") + result = ShellCmd.cnf_cleanup() end end end diff --git a/spec/workload/installability_spec.cr b/spec/workload/installability_spec.cr index daf15e524..9ff08606f 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.cnf_cleanup() result = ShellCmd.run_testsuite("setup") end @@ -14,7 +13,7 @@ describe CnfTestSuite do result[:status].success?.should be_true (/(FAILED).*(Helm deploy failed)/ =~ 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 (/Lint Passed/ =~ 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 (/Lint Failed/ =~ 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).*(Published Helm Chart Found)/ =~ 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).*(Published Helm Chart Not Found)/ =~ 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 ad7671f83..218b1306d 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 @@ -168,7 +168,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("tracing") (/(FAILED).*(Tracing not used)/ =~ 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() JaegerManager.uninstall KubectlClient::Get.resource_wait_for_uninstall("Statefulset", "jaeger-cassandra") KubectlClient::Get.resource_wait_for_uninstall("Deployment", "jaeger-collector") @@ -184,7 +184,7 @@ describe "Observability" do result = ShellCmd.run_testsuite("tracing") (/(PASSED).*(Tracing used)/ =~ result[:output]).should_not be_nil ensure - result = ShellCmd.run_testsuite("cnf_cleanup cnf-config=sample-cnfs/sample-tracing/cnf-testsuite.yml") + result = ShellCmd.cnf_cleanup() JaegerManager.uninstall KubectlClient::Get.resource_wait_for_uninstall("Statefulset", "jaeger-cassandra") KubectlClient::Get.resource_wait_for_uninstall("Deployment", "jaeger-collector") 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_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/utils/cnf_manager.cr b/src/tasks/utils/cnf_manager.cr index 7082bf3cc..92033fc2a 100644 --- a/src/tasks/utils/cnf_manager.cr +++ b/src/tasks/utils/cnf_manager.cr @@ -212,14 +212,6 @@ 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 @@ -240,412 +232,6 @@ module CNFManager 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 - - helm_install = {status: nil, output: "", error: ""} - - # todo determine what the ric is/if there is a ric installed (labeling) - #option 1 - # todo determine what pad/node the ric is in (pod/node by label) - # todo start tshark capture of the e2 traffic - # todo restart the ric pod when running the ric e2 test - # todo validate the e2 traffic - #option 2 - # todo start tshark capture of the e2 traffic (on all nodes?) - # todo install the ric/xapp (the xapp should be installed last?) - # todo note which pad/node the ric is in (what if cluster tools tshark was not executed on the node with the ric?) - # todo alternative (capture on gnodeb node) - # todo validate the e2 traffic - # todo save off the result to a config map - # todo check the config map in the e2 test - - match = JaegerManager.match() - if match[:found] - baselines = JaegerManager.unique_services_total - Log.info { "baselines: #{baselines}" } - end - - # todo start tshark monitoring the e2 traffic - capture = ORANMonitor.start_e2_capture?(config) - - # todo separate out install methods into a module/function that accepts a block - liveness_time = 0 - Log.for("sample_setup:install_method").info { "#{install_method[0]}" } - Log.for("sample_setup:install_method").info { "#{install_method[1]}" } - elapsed_time = Time.measure do - 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 = 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." - # Mark that install is not fresh - 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 = 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." - # Mark that install is not fresh - 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) - #TODO move to kubectlclient and make resource_install_and_wait_for_all function - # get liveness probe initialDelaySeconds and FailureThreshold - # if ((periodSeconds * failureThreshhold) + initialDelaySeconds) / defaultFailureThreshold) > startuptimelimit then fail; else pass - # get largest startuptime of all resoures, then save into config map - resource_ymls.map do |resource| - kind = resource["kind"].as_s.downcase - case kind - when "pod" - Log.info { "resource: #{resource}" } - containers = resource.dig("spec", "containers") - when "deployment","statefulset","replicaset","daemonset" - Log.info { "resource: #{resource}" } - containers = resource.dig("spec", "template", "spec", "containers") - end - containers && containers.as_a.map do |container| - initialDelaySeconds = container.dig?("livenessProbe", "initialDelaySeconds") - failureThreshhold = container.dig?("livenessProbe", "failureThreshhold") - periodSeconds = container.dig?("livenessProbe", "periodSeconds") - total_period_failure = 0 - total_extended_period = 0 - adjusted_with_default = 0 - defaultFailureThreshold = 3 - defaultPeriodSeconds = 10 - - if !failureThreshhold.nil? && failureThreshhold.as_i? - ft = failureThreshhold.as_i - else - ft = defaultFailureThreshold - end - - if !periodSeconds.nil? && periodSeconds.as_i? - ps = periodSeconds.as_i - else - ps = defaultPeriodSeconds - end - - total_period_failure = ps * ft - - if !initialDelaySeconds.nil? && initialDelaySeconds.as_i? - total_extended_period = initialDelaySeconds.as_i + total_period_failure - else - total_extended_period = total_period_failure - end - - adjusted_with_default = (total_extended_period / defaultFailureThreshold).round.to_i - - Log.info { "total_period_failure: #{total_period_failure}" } - Log.info { "total_extended_period: #{total_extended_period}" } - Log.info { "liveness_time: #{liveness_time}" } - Log.info { "adjusted_with_default: #{adjusted_with_default}" } - if liveness_time < adjusted_with_default - liveness_time = adjusted_with_default - end - end - end - 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| - ["replicaset", "deployment", "statefulset", "pod", "daemonset"].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 - end - - if match[:found] - sleep(120.seconds) - metrics_checkpoints = JaegerManager.unique_services_total - Log.info { "metrics_checkpoints: #{metrics_checkpoints}" } - tracing_used = JaegerManager.tracing_used?(baselines, metrics_checkpoints) - Log.info { "tracing_used: #{tracing_used}" } - else - tracing_used = false - end - - if ORANMonitor.isCNFaRIC?(config) - sleep(30.seconds) - e2_found = ORANMonitor.e2_session_established?(capture) - else - e2_found = false - end - - Log.info { "final e2_found: #{e2_found}" } - Log.info { "final liveness_time: #{liveness_time}" } - Log.info { "elapsed_time.seconds: #{elapsed_time.seconds}" } - Log.info { "helm_install: #{helm_install}" } - Log.info { "helm_install[:error].to_s: #{helm_install[:error].to_s}" } - Log.info { "helm_install[:error].to_s.size: #{helm_install[:error].to_s.size}" } - - if fresh_install - stdout_success "Successfully setup #{release_name}" - end - - # Not required to write elapsed time configmap if the cnf already exists due to a previous Helm install - return true if !fresh_install - - # Immutable config maps are only supported in Kubernetes 1.19+ - immutable_configmap = true - if version_less_than(KubectlClient.server_version, "1.19.0") - immutable_configmap = false - end - - helm_used = !helm_install[:status].nil? - #TODO if helm_install then set helm_deploy = true in template - Log.info { "save config" } - elapsed_time_template = ElapsedTimeConfigMapTemplate.new( - "cnf-testsuite-#{release_name}-startup-information", - helm_used, - # "#{elapsed_time.seconds}", - "#{liveness_time}", - immutable_configmap, - tracing_used, - e2_found - ).to_s - #TODO find a way to kubectlapply directly without a map - Log.debug { "elapsed_time_template : #{elapsed_time_template}" } - configmap_path = "#{destination_cnf_dir}/config_maps/elapsed_time.yml" - File.write(configmap_path, "#{elapsed_time_template}") - # TODO if the config map exists on install, complain, delete then overwrite? - KubectlClient::Delete.file(configmap_path) - #TODO call kubectl apply on file - KubectlClient::Apply.file(configmap_path) - # TODO when uninstalling, remove config map - 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 @@ -699,65 +285,6 @@ module CNFManager !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 - end - def self.ensure_namespace_exists!(name, kubeconfig : String | Nil = nil) KubectlClient::Create.namespace(name, kubeconfig: kubeconfig) Log.for("ensure_namespace_exists").info { "Created kubernetes namespace #{name} for the CNF install" } diff --git a/src/tasks/workload/configuration.cr b/src/tasks/workload/configuration.cr index 5d793181a..4b330f26d 100644 --- a/src/tasks/workload/configuration.cr +++ b/src/tasks/workload/configuration.cr @@ -622,16 +622,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(".")