Skip to content

Commit

Permalink
config: Switch to usage of new config
Browse files Browse the repository at this point in the history
Adapt all usages of config to the new format.
Remove code that was used by old config.
Update all sample and example configs.

Refs: cnti-testcatalog#2135
Signed-off-by: Konstantin Yarovoy <[email protected]>
  • Loading branch information
kosstennbl committed Aug 15, 2024
1 parent 88276d6 commit 5f4a7bc
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 111 deletions.
59 changes: 12 additions & 47 deletions spec/utils/cnf_manager_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -293,72 +293,37 @@ describe "SampleUtils" do
CNFManager.helm_repo_add("invalid", "invalid").should eq(false)
end

it "'CNFManager.validate_cnf_testsuite_yml' (function) should pass, when a cnf has a valid config file yml", tags: ["validate_config"] do
args = Sam::Args.new(["cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml"])

yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_testsuite_yml_path(args.named["cnf-config"].as(String)))
Log.info { yml.inspect }
("#{yml.get("release_name").as_s?}").should eq("coredns")

valid, command_output = CNFManager.validate_cnf_testsuite_yml(yml)

(valid).should eq(true)
(command_output).should eq (nil)
end

it "'CNFManager.validate_cnf_testsuite_yml' (command) should pass, when a cnf has a valid config file yml", tags: ["validate_config"] do
result = ShellCmd.run_testsuite("validate_config cnf-config=sample-cnfs/sample-coredns-cnf/cnf-testsuite.yml")
result[:status].success?.should be_true
(/CNF configuration validated/ =~ result[:output]).should_not be_nil
end


it "'CNFManager.validate_cnf_testsuite_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: ["validate_config"] do
args = Sam::Args.new(["cnf-config=./spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml"])

yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_testsuite_yml_path(args.named["cnf-config"].as(String)))
Log.info { yml.inspect }
("#{yml.get("release_name").as_s?}").should eq("coredns")

status, warning_output = CNFManager.validate_cnf_testsuite_yml(yml)

Log.warn { "WARNING: #{warning_output}" }

(status).should eq(true)
(warning_output).should_not be_nil
end


it "'CNFManager.validate_cnf_testsuite_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: ["validate_config"] do
result = ShellCmd.run_testsuite("validate_config cnf-config=spec/fixtures/cnf-testsuite-unmapped-keys-and-subkeys.yml")
it "'validate_config' should pass, when a cnf has a valid config file yml", tags: ["validate_config"] do
result = ShellCmd.run_testsuite("validate_config cnf-config=embedded_files/cnf-testsuite-v2-example.yml")
result[:status].success?.should be_true
Log.debug { "validate_config resp: #{result[:output]}" }
(/CNF configuration validated/ =~ result[:output]).should_not be_nil
(/Successfully validated CNF config/ =~ result[:output]).should_not be_nil
end


it "'CNFManager.validate_cnf_testsuite_yml' (command) should pass, for all sample-cnfs", tags: ["validate_config"] do
it "'validate_config' should pass, for all sample-cnfs", tags: ["validate_config"] do

get_dirs = Dir.entries("sample-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
testsuite_yml = "sample-cnfs/#{dir}/cnf-testsuite.yml"
result = ShellCmd.run_testsuite("validate_config cnf-config=#{testsuite_yml}")
(/CNF configuration validated/ =~ result[:output]).should_not be_nil
unless result[:status].success?
Log.info {"Could not validate config: #{testsuite_yml}"}
end
(/Successfully validated CNF config/ =~ result[:output]).should_not be_nil
end
end

it "'CNFManager.validate_cnf_testsuite_yml' (command) should pass, for all example-cnfs", tags: ["validate_config"] do
it "'validate_config' should pass, for all example-cnfs", tags: ["validate_config"] do

get_dirs = Dir.entries("example-cnfs")
dir_list = get_dirs - [".", ".."]
dir_list.each do |dir|
testsuite_yml = "example-cnfs/#{dir}/cnf-testsuite.yml"
result = ShellCmd.run_testsuite("validate_config cnf-config=#{testsuite_yml}")
if (/Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file/ =~ result[:output])
Log.info { "\n #{testsuite_yml}: #{result[:output]}" }
unless result[:status].success?
Log.info {"Could not validate config: #{testsuite_yml}"}
end
(/CNF configuration validated/ =~ result[:output]).should_not be_nil
(/Successfully validated CNF config/ =~ result[:output]).should_not be_nil
end
end

Expand Down
10 changes: 6 additions & 4 deletions src/tasks/setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ task "configuration_file_setup" do |_, args|
CNFManager::Points.create_points_yml
end

task "test_config" do |_, args|
if args.named["cfg"]?
puts CNFInstall::Config.parse_cnf_config_from_file(args.named["cfg"].to_s).inspect
task "validate_config" do |_, args|
if args.named["cnf-config"]?
config = CNFInstall::Config.parse_cnf_config_from_file(args.named["cnf-config"].to_s)
puts "Successfully validated CNF config"
Log.info {"Config: #{config.inspect}"}
else
stdout_failure "cfg parameter needed"
stdout_failure "cnf-config parameter needed"
exit 1
end
end
18 changes: 18 additions & 0 deletions src/tasks/utils/cnf_installation/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,23 @@ module CNFInstall
raise YAML::Error.new("At least one deployment should be configured")
end
end

def self.get_helm_chart_path(config)
helm_directory = config.deployments.helm_dirs[0].helm_directory
if helm_directory.empty?
working_chart_directory = "exported_chart"
Log.info { "USING EXPORTED CHART PATH" }
else
working_chart_directory = helm_directory
Log.info { "NOT USING EXPORTED CHART PATH" }
end
helm_chart_path = config.dynamic.destination_cnf_dir + "/" + CNFManager.sandbox_helm_directory(working_chart_directory)
helm_chart_path = Path[helm_chart_path].expand.to_s
end

def self.get_manifest_file_path(config)
manifest_file_path = config.dynamic.destination_cnf_dir + "/" + "temp_template.yml"
end

end
end
51 changes: 2 additions & 49 deletions src/tasks/utils/cnf_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -27,60 +27,15 @@ module CNFManager
ECR.def_to_s("src/templates/elapsed_time_configmap.yml.ecr")
end

# TODO: figure out recursively check for unmapped json and warn on that
# https://github.com/Nicolab/crystal-validator#check
def self.validate_cnf_testsuite_yml(config)
ccyt_validator = nil
valid = true

begin
ccyt_validator = CnfTestSuiteYmlType.from_json(config.settings.to_json)
rescue ex
valid = false
Log.error { "✖ ERROR: cnf_testsuite.yml field validation error.".colorize(:red) }
Log.error { " please check info in the the field name near the text 'CnfTestSuiteYmlType#' in the error below".colorize(:red) }
Log.error { ex.message }
ex.backtrace.each do |x|
Log.error { x }
end
end

unmapped_keys_warning_msg = "WARNING: Unmapped cnf_testsuite.yml keys. Please add them to the validator".colorize(:yellow)
unmapped_subkeys_warning_msg = "WARNING: helm_repository is unset or has unmapped subkeys. Please update your cnf_testsuite.yml".colorize(:yellow)

if ccyt_validator && !ccyt_validator.try &.json_unmapped.empty?
warning_output = [unmapped_keys_warning_msg] of String | Colorize::Object(String)
warning_output.push(ccyt_validator.try &.json_unmapped.to_s)
if warning_output.size > 1
Log.warn { warning_output.join("\n") }
end
end

#TODO Differentiate between unmapped subkeys or unset top level key.
if ccyt_validator && !ccyt_validator.try &.helm_repository.try &.json_unmapped.empty?
root = {} of String => (Hash(String, JSON::Any) | Nil)
root["helm_repository"] = ccyt_validator.try &.helm_repository.try &.json_unmapped

warning_output = [unmapped_subkeys_warning_msg] of String | Colorize::Object(String)
warning_output.push(root.to_s)
if warning_output.size > 1
Log.warn { warning_output.join("\n") }
end
end

{ valid, warning_output }
end

def self.cnf_resource_ymls(args, config)
Log.info { "cnf_resource_ymls" }
destination_cnf_dir = config.cnf_config[:destination_cnf_dir]
helm_directory = sandbox_helm_directory(config.cnf_config[:helm_directory])
manifest_directory = config.cnf_config[:manifest_directory]
release_name = config.cnf_config[:release_name]
helm_chart_path = Config.get_helm_chart_path(config)
manifest_file_path = Config.get_manifest_file_path(config)
helm_chart_path = CNFInstall::Config.get_helm_chart_path(config)

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_corruption)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_latency)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_network_duplication)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (zombie)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_io_stress)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (oran)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_memory_hog)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (pod_delete)

undefined constant CNFInstall::Config

Check failure on line 36 in src/tasks/utils/cnf_manager.cr

View workflow job for this annotation

GitHub Actions / Chaos & Oran Tests (disk_fill)

undefined constant CNFInstall::Config
manifest_file_path = CNFInstall::Config.get_manifest_file_path(config)
helm_values = config.cnf_config[:helm_values]
test_passed = true

deployment_namespace = CNFManager.get_deployment_namespace(config)
install_method = config.cnf_config[:install_method]
Expand Down Expand Up @@ -870,8 +825,6 @@ module CNFManager
end

def self.cnf_to_new_cluster(config, kubeconfig)
release_name = config.cnf_config[:release_name]
install_method = config.cnf_config[:install_method]
release_name = config.cnf_config[:release_name]
install_method = config.cnf_config[:install_method]
helm_directory = config.cnf_config[:helm_directory]
Expand Down
11 changes: 0 additions & 11 deletions src/tasks/workload/compatibility.cr
Original file line number Diff line number Diff line change
Expand Up @@ -495,17 +495,6 @@ task "helm_chart_valid", ["helm_local_install"] do |t, args|
end
end

task "validate_config" do |_, args|
yml = CNFManager.parsed_config_file(CNFManager.ensure_cnf_testsuite_yml_path(args.named["cnf-config"].as(String)))
valid, warning_output = CNFManager.validate_cnf_testsuite_yml(yml)
emoji_config="📋"
if valid
stdout_success "CNF configuration validated #{emoji_config}"
else
stdout_failure "Critical Error with CNF Configuration. Please review USAGE.md for steps to set up a valid CNF configuration file #{emoji_config}"
end
end

def setup_calico_cluster(cluster_name : String) : KindManager::Cluster
Log.info { "Running cni_compatible(Cluster Creation)" }
Helm.helm_repo_add("projectcalico","https://docs.projectcalico.org/charts")
Expand Down

0 comments on commit 5f4a7bc

Please sign in to comment.