Skip to content

Commit e9aea3f

Browse files
Merge pull request #391 from cncf/refactor_sample_utils
sample_utils now CNFManager
2 parents a0edc6f + 6826c9f commit e9aea3f

19 files changed

+566
-568
lines changed

spec/cnf_conformance_spec.cr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe CnfConformance do
4040
(/PASSED: Replicas decreased to 1/ =~ response_s).should_not be_nil
4141
(/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil
4242
(/Final score:/ =~ response_s).should_not be_nil
43-
(all_result_test_names(final_cnf_results_yml)).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published","helm_deploy", "reasonable_image_size", "reasonable_startup_time", "chaos_network_loss", "chaos_cpu_hog", "chaos_container_kill"])
43+
(all_result_test_names(CNFManager.final_cnf_results_yml)).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published","helm_deploy", "reasonable_image_size", "reasonable_startup_time", "chaos_network_loss", "chaos_cpu_hog", "chaos_container_kill"])
4444
end
4545

4646
it "'scalability' should run all of the scalability tests", tags: "happy-path" do

spec/utils/sample_utils_spec.cr renamed to spec/utils/cnf_manager_spec.cr

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ describe "SampleUtils" do
2626
$?.success?.should be_true
2727
end
2828

29-
it "'wait_for_install' should wait for a cnf to be installed", tags: "happy-path" do
29+
it "'CNFManager.wait_for_install' should wait for a cnf to be installed", tags: "happy-path" do
3030
`./cnf-conformance sample_coredns_setup`
3131
$?.success?.should be_true
3232

@@ -36,118 +36,118 @@ describe "SampleUtils" do
3636
LOGGING.info helm
3737
helm_install = `#{helm} install coredns stable/coredns`
3838
LOGGING.info helm_install
39-
wait_for_install("coredns-coredns")
39+
CNFManager.wait_for_install("coredns-coredns")
4040
current_replicas = `kubectl get deployments coredns-coredns -o=jsonpath='{.status.readyReplicas}'`
4141
(current_replicas.to_i > 0).should be_true
4242
end
4343

44-
it "'sample_setup' should set up a sample cnf", tags: "happy-path" do
44+
it "'CNFManager.sample_setup' should set up a sample cnf", tags: "happy-path" do
4545
args = Sam::Args.new
46-
sample_setup(config_file: "sample-cnfs/sample-generic-cnf", release_name: "coredns", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "helm_chart", git_clone_url: "https://github.com/coredns/coredns.git", wait_count: 0 )
46+
CNFManager.sample_setup(config_file: "sample-cnfs/sample-generic-cnf", release_name: "coredns", deployment_name: "coredns-coredns", helm_chart: "stable/coredns", helm_directory: "helm_chart", git_clone_url: "https://github.com/coredns/coredns.git", wait_count: 0 )
4747
# check if directory exists
4848
(Dir.exists? "cnfs/coredns-coredns").should be_true
4949
(File.exists?("cnfs/coredns-coredns/cnf-conformance.yml")).should be_true
5050
(File.exists?("cnfs/coredns-coredns/helm_chart/Chart.yaml")).should be_true
51-
sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
51+
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
5252
(Dir.exists? "cnfs/coredns-coredns").should be_false
5353
end
5454

55-
it "'sample_setup_args' should set up a sample cnf from a argument", tags: "happy-path" do
55+
it "'CNFManager.sample_setup_args' should set up a sample cnf from a argument", tags: "happy-path" do
5656
args = Sam::Args.new
57-
sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
57+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
5858
# check if directory exists
5959
(Dir.exists? "cnfs/coredns-coredns").should be_true
6060
(File.exists?("cnfs/coredns-coredns/cnf-conformance.yml")).should be_true
6161
(File.exists?("cnfs/coredns-coredns/helm_chart/Chart.yaml")).should be_true
62-
sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
62+
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
6363
(Dir.exists? "cnfs/coredns-coredns").should be_false
6464
end
6565

66-
it "'sample_setup_args' should set up a sample cnf from a config file", tags: "happy-path" do
66+
it "'CNFManager.sample_setup_args' should set up a sample cnf from a config file", tags: "happy-path" do
6767
args = Sam::Args.new
68-
sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf/cnf-conformance.yml", args: args, verbose: true, wait_count: 0 )
68+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf/cnf-conformance.yml", args: args, verbose: true, wait_count: 0 )
6969
# check if directory exists
7070
(Dir.exists? "sample-cnfs/sample-generic-cnf").should be_true
7171
(File.exists?("cnfs/coredns-coredns/cnf-conformance.yml")).should be_true
7272
(File.exists?("cnfs/coredns-coredns/helm_chart/Chart.yaml")).should be_true
73-
sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
73+
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
7474
(Dir.exists? "cnfs/coredns-coredns").should be_false
7575
end
7676

77-
it "'sample_cleanup' should clean up a sample cnf from a argument", tags: "happy-path" do
77+
it "'CNFManager.sample_cleanup' should clean up a sample cnf from a argument", tags: "happy-path" do
7878
args = Sam::Args.new
79-
sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
80-
cleanup = sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
79+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 0 )
80+
cleanup = CNFManager.sample_cleanup(config_file: "sample-cnfs/sample-generic-cnf", verbose: true)
8181
(cleanup).should be_true
8282
(Dir.exists? "cnfs/coredns-coredns").should be_false
8383
(File.exists?("cnfs/coredns-coredns/cnf-conformance.yml")).should be_false
8484
(File.exists?("cnfs/coredns-coredns/helm_chart/Chart.yaml")).should be_false
8585
end
8686

87-
it "'sample_setup_args' should be able to deploy using a helm_directory", tags: "happy-path" do
87+
it "'CNFManager.sample_setup_args' should be able to deploy using a helm_directory", tags: "happy-path" do
8888
args = Sam::Args.new
89-
sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
89+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", deploy_with_chart: false, args: args, verbose: true, wait_count: 0 )
9090
(Dir.exists? "cnfs/privileged-coredns-coredns").should be_true
9191
# should not clone
9292
(Dir.exists? "cnfs/privileged-coredns-coredns/privileged-coredns").should be_false
9393
(File.exists? "cnfs/privileged-coredns-coredns/cnf-conformance.yml").should be_true
9494
(File.exists? "cnfs/privileged-coredns-coredns/chart/Chart.yaml").should be_true
95-
sample_cleanup(config_file: "sample-cnfs/sample_privileged_cnf", verbose: true)
95+
CNFManager.sample_cleanup(config_file: "sample-cnfs/sample_privileged_cnf", verbose: true)
9696
(Dir.exists? "cnfs/privileged-coredns-coredns").should be_false
9797
end
9898

9999
it "'cnf_destination_dir' should return the full path of the potential destination cnf directory based on the deployment name", tags: "WIP" do
100100
args = Sam::Args.new
101-
cnf_destination_dir("spec/fixtures/cnf-conformance.yml").should contain("/cnfs/coredns-coredns")
101+
CNFManager.cnf_destination_dir("spec/fixtures/cnf-conformance.yml").should contain("/cnfs/coredns-coredns")
102102
end
103103

104-
it "'cnf_config_list' should return a list of all of the config files from the cnf directory", tags: "happy-path" do
104+
it "'CNFManager.cnf_config_list' should return a list of all of the config files from the cnf directory", tags: "happy-path" do
105105
args = Sam::Args.new
106-
sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
107-
sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: args, verbose: true )
108-
cnf_config_list()[0].should contain("coredns-coredns/#{CONFIG_FILE}")
106+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
107+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample_privileged_cnf", args: args, verbose: true )
108+
CNFManager.cnf_config_list()[0].should contain("coredns-coredns/#{CONFIG_FILE}")
109109
end
110110

111-
it "'helm_repo_add' should add a helm repo if the helm repo is valid", tags: "happy-path" do
111+
it "'CNFManager.helm_repo_add' should add a helm repo if the helm repo is valid", tags: "happy-path" do
112112
args = Sam::Args.new
113-
sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
114-
# helm_repo_add.should eq(true)
113+
CNFManager.sample_setup_args(sample_dir: "sample-cnfs/sample-generic-cnf", args: args, verbose: true, wait_count: 1 )
114+
# CNFManager.helm_repo_add.should eq(true)
115115
args = Sam::Args.new(["cnf-config=./sample-cnfs/sample-generic-cnf/cnf-conformance.yml"])
116-
helm_repo_add(args: args).should eq(true)
116+
CNFManager.helm_repo_add(args: args).should eq(true)
117117
end
118118

119-
it "'helm_repo_add' should return false if the helm repo is invalid", tags: "happy-path" do
120-
helm_repo_add("invalid", "invalid").should eq(false)
119+
it "'CNFManager.helm_repo_add' should return false if the helm repo is invalid", tags: "happy-path" do
120+
CNFManager.helm_repo_add("invalid", "invalid").should eq(false)
121121
end
122122

123-
it "'validate_cnf_conformance_yml' (function) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
123+
it "'CNFManager.validate_cnf_conformance_yml' (function) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
124124
args = Sam::Args.new(["cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml"])
125125

126-
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
126+
yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
127127
LOGGING.info yml.inspect
128128
("#{yml.get("release_name").as_s?}").should eq("coredns")
129129

130-
valid, command_output = validate_cnf_conformance_yml(yml)
130+
valid, command_output = CNFManager.validate_cnf_conformance_yml(yml)
131131

132132
(valid).should eq(true)
133133
(command_output).should eq (nil)
134134
end
135135

136-
it "'validate_cnf_conformance_yml' (command) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
136+
it "'CNFManager.validate_cnf_conformance_yml' (command) should pass, when a cnf has a valid config file yml", tags: ["unhappy-path", "validate_config"] do
137137
response_s = `./cnf-conformance validate_config cnf-config=sample-cnfs/sample-coredns-cnf/cnf-conformance.yml`
138138
$?.success?.should be_true
139139
(/PASSED: CNF configuration validated/ =~ response_s).should_not be_nil
140140
end
141141

142142

143-
it "'validate_cnf_conformance_yml' (function) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
143+
it "'CNFManager.validate_cnf_conformance_yml' (function) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
144144
args = Sam::Args.new(["cnf-config=./spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml"])
145145

146-
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
146+
yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
147147
LOGGING.info yml.inspect
148148
("#{yml.get("release_name").as_s?}").should eq("coredns")
149149

150-
status, warning_output = validate_cnf_conformance_yml(yml)
150+
status, warning_output = CNFManager.validate_cnf_conformance_yml(yml)
151151

152152
LOGGING.warn "WARNING: #{warning_output}"
153153

@@ -156,7 +156,7 @@ describe "SampleUtils" do
156156
end
157157

158158

159-
it "'validate_cnf_conformance_yml' (command) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
159+
it "'CNFManager.validate_cnf_conformance_yml' (command) should warn, but be valid when a cnf config file yml has fields that are not a part of the validation type", tags: ["unhappy-path", "validate_config"] do
160160
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-unmapped-keys-and-subkeys.yml`
161161
$?.success?.should be_true
162162
(/WARNING: Unmapped cnf_conformance.yml keys. Please add them to the validator/ =~ response_s).should_not be_nil
@@ -165,28 +165,28 @@ describe "SampleUtils" do
165165
end
166166

167167

168-
it "'validate_cnf_conformance_yml' (function) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
168+
it "'CNFManager.validate_cnf_conformance_yml' (function) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
169169
args = Sam::Args.new(["cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml"])
170170

171-
yml = parsed_config_file(ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
171+
yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
172172
LOGGING.info yml.inspect
173173
("#{yml.get("release_name").as_s?}").should eq("coredns")
174174

175-
status, warning_output = validate_cnf_conformance_yml(yml)
175+
status, warning_output = CNFManager.validate_cnf_conformance_yml(yml)
176176

177177
(status).should eq(false)
178178
(warning_output).should eq(nil)
179179
end
180180

181-
it "'validate_cnf_conformance_yml' (command) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
181+
it "'CNFManager.validate_cnf_conformance_yml' (command) should fail when an invalid cnf config file yml is used", tags: ["unhappy-path", "validate_config"] do
182182
response_s = `./cnf-conformance validate_config cnf-config=spec/fixtures/cnf-conformance-invalid-and-unmapped-keys.yml`
183183
$?.success?.should be_true
184184

185185
(/ERROR: cnf_conformance.yml field validation error/ =~ response_s).should_not be_nil
186186
(/FAILURE: Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ response_s).should_not be_nil
187187
end
188188

189-
it "'validate_cnf_conformance_yml' (command) should pass, for all sample-cnfs", tags: ["unhappy-path", "validate_config"] do
189+
it "'CNFManager.validate_cnf_conformance_yml' (command) should pass, for all sample-cnfs", tags: ["unhappy-path", "validate_config"] do
190190

191191
get_dirs = Dir.entries("sample-cnfs")
192192
dir_list = get_dirs - [".", ".."]
@@ -200,7 +200,7 @@ describe "SampleUtils" do
200200
end
201201
end
202202

203-
it "'validate_cnf_conformance_yml' (command) should pass, for all example-cnfs", tags: ["unhappy-path", "validate_config"] do
203+
it "'CNFManager.validate_cnf_conformance_yml' (command) should pass, for all example-cnfs", tags: ["unhappy-path", "validate_config"] do
204204

205205
get_dirs = Dir.entries("example-cnfs")
206206
dir_list = get_dirs - [".", ".."]

0 commit comments

Comments
 (0)