From 58b29d98c4b951f8bfb633a388c57fecb5ca28b2 Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 10 Feb 2021 16:35:51 -0500 Subject: [PATCH 1/7] points, config, and task now in separate file --- src/tasks/utils/cnf_manager.cr | 404 +-------------------------------- src/tasks/utils/config.cr | 111 +++++++++ src/tasks/utils/points.cr | 244 ++++++++++++++++++++ src/tasks/utils/task.cr | 75 ++++++ 4 files changed, 433 insertions(+), 401 deletions(-) create mode 100644 src/tasks/utils/config.cr create mode 100644 src/tasks/utils/points.cr create mode 100644 src/tasks/utils/task.cr diff --git a/src/tasks/utils/cnf_manager.cr b/src/tasks/utils/cnf_manager.cr index 6621d1178..d77584054 100644 --- a/src/tasks/utils/cnf_manager.cr +++ b/src/tasks/utils/cnf_manager.cr @@ -4,410 +4,12 @@ require "colorize" require "./types/cnf_conformance_yml_type.cr" require "./helm.cr" require "uuid" +require "./points.cr" +require "./task.cr" +require "./config.cr" module CNFManager - module Points - def self.points_yml - # TODO get points.yml from remote http - points = File.open("points.yml") do |f| - YAML.parse(f) - end - # LOGGING.debug "points: #{points.inspect}" - points.as_a - end - def self.create_points_yml - unless File.exists?("#{POINTSFILE}") - branch = ENV.has_key?("SCORING_ENV") ? ENV["SCORING_ENV"] : "master" - default_scoring_yml = "https://raw.githubusercontent.com/cncf/cnf-conformance/#{branch}/scoring_config/#{DEFAULT_POINTSFILENAME}" - `wget #{ENV.has_key?("SCORING_YML") ? ENV["SCORING_YML"] : default_scoring_yml}` - `mv #{DEFAULT_POINTSFILENAME} #{POINTSFILE}` - end - end - - def self.create_final_results_yml_name - FileUtils.mkdir_p("results") unless Dir.exists?("results") - "results/cnf-conformance-results-" + Time.local.to_s("%Y%m%d-%H%M%S-%L") + ".yml" - end - - def self.clean_results_yml(verbose=false) - if File.exists?("#{CNFManager::Points::Results.file}") - results = File.open("#{CNFManager::Points::Results.file}") do |f| - YAML.parse(f) - end - File.open("#{CNFManager::Points::Results.file}", "w") do |f| - YAML.dump({name: results["name"], - status: results["status"], - exit_code: results["exit_code"], - points: results["points"], - items: [] of YAML::Any}, f) - end - end - end - - def self.task_points(task, passed=true) - if passed - field_name = "pass" - else - field_name = "fail" - end - points =CNFManager::Points.points_yml.find {|x| x["name"] == task} - LOGGING.warn "****Warning**** task #{task} not found in points.yml".colorize(:yellow) unless points - if points && points[field_name]? - points[field_name].as_i if points - else - points =CNFManager::Points.points_yml.find {|x| x["name"] == "default_scoring"} - points[field_name].as_i if points - end - end - - def self.total_points(tag=nil) - if tag - tasks = CNFManager::Points.tasks_by_tag(tag) - else - tasks = CNFManager::Points.all_task_test_names - end - yaml = File.open("#{CNFManager::Points::Results.file}") do |file| - YAML.parse(file) - end - yaml["items"].as_a.reduce(0) do |acc, i| - if i["points"].as_i? && i["name"].as_s? && - tasks.find{|x| x == i["name"]} - (acc + i["points"].as_i) - else - acc - end - end - end - - def self.total_max_points(tag=nil) - if tag - tasks = CNFManager::Points.tasks_by_tag(tag) - else - tasks = CNFManager::Points.all_task_test_names - end - tasks.reduce(0) do |acc, x| - points = CNFManager::Points.task_points(x) - if points - acc + points - else - acc - end - end - end - - def self.upsert_task(task, status, points) - results = File.open("#{CNFManager::Points::Results.file}") do |f| - YAML.parse(f) - end - - result_items = results["items"].as_a - # remove the existing entry - result_items = result_items.reject do |x| - x["name"] == task - end - - result_items << YAML.parse "{name: #{task}, status: #{status}, points: #{points}}" - File.open("#{CNFManager::Points::Results.file}", "w") do |f| - YAML.dump({name: results["name"], - status: results["status"], - points: results["points"], - exit_code: results["exit_code"], - items: result_items}, f) - end - end - - def self.failed_task(task, msg) - CNFManager::Points.upsert_task(task, FAILED, CNFManager::Points.task_points(task, false)) - stdout_failure "#{msg}" - end - - def self.passed_task(task, msg) - CNFManager::Points.upsert_task(task, PASSED, CNFManager::Points.task_points(task)) - stdout_success "#{msg}" - end - - def self.failed_required_tasks - yaml = File.open("#{CNFManager::Points::Results.file}") do |file| - YAML.parse(file) - end - yaml["items"].as_a.reduce([] of String) do |acc, i| - if i["status"].as_s == "failed" && - i["name"].as_s? && - CNFManager::Points.task_required(i["name"].as_s) - (acc << i["name"].as_s) - else - acc - end - end - end - - def self.task_required(task) - points =CNFManager::Points.points_yml.find {|x| x["name"] == task} - LOGGING.warn "task #{task} not found in points.yml".colorize(:yellow) unless points - if points && points["required"]? && points["required"].as_bool == true - true - else - false - end - end - - def self.all_task_test_names - result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| - if x["name"].as_s == "default_scoring" || - x["tags"].as_s.split(",").find{|x|x=="platform"} - acc - else - acc << x["name"].as_s - end - end - end - - def self.tasks_by_tag(tag) - #TODO cross reference points.yml tags with results - found = false - result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| - if x["tags"].as_s? && x["tags"].as_s.includes?(tag) - acc << x["name"].as_s - else - acc - end - end - end - - def self.all_result_test_names(results_file) - results = File.open(results_file) do |f| - YAML.parse(f) - end - result_items = results["items"].as_a.reduce([] of String) do |acc, x| - acc << x["name"].as_s - end - end - - def self.results_by_tag(tag) - task_list = tasks_by_tag(tag) - - results = File.open("#{CNFManager::Points::Results.file}") do |f| - YAML.parse(f) - end - - found = false - result_items = results["items"].as_a.reduce([] of YAML::Any) do |acc, x| - if x["name"].as_s? && task_list.find{|tl| tl == x["name"].as_s} - acc << x - else - acc - end - end - end - - class Results - @@file : String - @@file = CNFManager::Points.create_final_results_yml_name - LOGGING.info "CNFManager::Points::Results.file" - continue = false - LOGGING.info "file exists?:#{File.exists?(@@file)}" - if File.exists?("#{@@file}") - stdout_info "Do you wish to overwrite the #{@@file} file? If so, your previous results.yml will be lost." - print "(Y/N) (Default N): > " - if ENV["CRYSTAL_ENV"]? == "TEST" - continue = true - else - user_input = gets - if user_input == "Y" || user_input == "y" - continue = true - end - end - else - continue = true - end - if continue - File.open("#{@@file}", "w") do |f| - YAML.dump(CNFManager::Points.template_results_yml, f) - end - end - def self.file - @@file - end - end - - def self.template_results_yml - #TODO add tags for category summaries - YAML.parse <<-END -name: cnf conformance -status: -points: -exit_code: 0 -items: [] -END - end - end - - module Task - def self.task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) - LOGGING.info("task_runner args: #{args.inspect}") - if check_cnf_config(args) - CNFManager::Task.single_task_runner(args, &block) - else - CNFManager::Task.all_cnfs_task_runner(args, &block) - end - end - - # TODO give example for calling - def CNFManager::Task.all_cnfs_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) - - # Platforms tests dont have any cnfs - if CNFManager.cnf_config_list(silent: true).size == 0 - CNFManager::Task.single_task_runner(args, &block) - else - CNFManager.cnf_config_list(silent: true).map do |x| - new_args = Sam::Args.new(args.named, args.raw) - new_args.named["cnf-config"] = x - CNFManager::Task.single_task_runner(new_args, &block) - end - end - end - # TODO give example for calling - def CNFManager::Task.single_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) - LOGGING.debug("single_task_runner args: #{args.inspect}") - begin - if args.named["cnf-config"]? # platform tests don't have a cnf-config - config = CNFManager::Config.parse_config_yml(args.named["cnf-config"].as(String)) - else - config = CNFManager::Config.new({ destination_cnf_dir: "", - source_cnf_file: "", - source_cnf_dir: "", - yml_file_path: "", - install_method: {:helm_chart, ""}, - manifest_directory: "", - helm_directory: "", - helm_chart_path: "", - manifest_file_path: "", - git_clone_url: "", - install_script: "", - release_name: "", - service_name: "", - docker_repository: "", - helm_repository: {name: "", repo_url: ""}, - helm_chart: "", - helm_chart_container_name: "", - rolling_update_tag: "", - container_names: [{"name" => "", "rolling_update_test_tag" => ""}], - white_list_container_names: [""]} ) - end - yield args, config - rescue ex - # Set exception key/value in results - # file to -1 - update_yml("#{CNFManager::Points::Results.file}", "exit_code", "1") - LOGGING.error ex.message - ex.backtrace.each do |x| - LOGGING.error x - end - end - end - end - - class Config - def initialize(cnf_config) - @cnf_config = cnf_config - end - property cnf_config : NamedTuple(destination_cnf_dir: String, - source_cnf_file: String, - source_cnf_dir: String, - yml_file_path: String, - install_method: Tuple(Symbol, String), - manifest_directory: String, - helm_directory: String, - helm_chart_path: String, - manifest_file_path: String, - git_clone_url: String, - install_script: String, - release_name: String, - service_name: String, - docker_repository: String, - helm_repository: NamedTuple(name: String, - repo_url: String) | Nil, - helm_chart: String, - helm_chart_container_name: String, - rolling_update_tag: String, - container_names: Array(Hash(String, String )) | Nil, - white_list_container_names: Array(String)) - - def self.parse_config_yml(config_yml_path : String) : CNFManager::Config - LOGGING.debug "parse_config_yml config_yml_path: #{config_yml_path}" - yml_file = CNFManager.ensure_cnf_conformance_yml_path(config_yml_path) - config = CNFManager.parsed_config_file(yml_file) - - install_method = CNFManager.cnf_installation_method(config) - - CNFManager.generate_and_set_release_name(config_yml_path) - - destination_cnf_dir = CNFManager.cnf_destination_dir(yml_file) - - yml_file_path = CNFManager.ensure_cnf_conformance_dir(config_yml_path) - source_cnf_file = yml_file - source_cnf_dir = yml_file_path - manifest_directory = optional_key_as_string(config, "manifest_directory") - if config["helm_repository"]? - helm_repository = config["helm_repository"].as_h - helm_repo_name = optional_key_as_string(helm_repository, "name") - helm_repo_url = optional_key_as_string(helm_repository, "repo_url") - else - helm_repo_name = "" - helm_repo_url = "" - end - helm_chart = optional_key_as_string(config, "helm_chart") - release_name = "#{config.get("release_name").as_s?}" - service_name = optional_key_as_string(config, "service_name") - helm_directory = optional_key_as_string(config, "helm_directory") - git_clone_url = optional_key_as_string(config, "git_clone_url") - install_script = optional_key_as_string(config, "install_script") - docker_repository = optional_key_as_string(config, "docker_repository") - if helm_directory.empty? - working_chart_directory = "exported_chart" - else - working_chart_directory = helm_directory - end - helm_chart_path = destination_cnf_dir + "/" + working_chart_directory - manifest_file_path = destination_cnf_dir + "/" + "temp_template.yml" - white_list_container_names = config.get("white_list_helm_chart_container_names").as_a.map do |c| - "#{c.as_s?}" - end - container_names_totem = config["container_names"] - container_names = container_names_totem.as_a.map do |container| - {"name" => optional_key_as_string(container, "name"), - "rolling_update_test_tag" => optional_key_as_string(container, "rolling_update_test_tag"), - "rolling_downgrade_test_tag" => optional_key_as_string(container, "rolling_downgrade_test_tag"), - "rolling_version_change_test_tag" => optional_key_as_string(container, "rolling_version_change_test_tag"), - "rollback_from_tag" => optional_key_as_string(container, "rollback_from_tag"), - } - end - - CNFManager::Config.new({ destination_cnf_dir: destination_cnf_dir, - source_cnf_file: source_cnf_file, - source_cnf_dir: source_cnf_dir, - yml_file_path: yml_file_path, - install_method: install_method, - manifest_directory: manifest_directory, - helm_directory: helm_directory, - helm_chart_path: helm_chart_path, - manifest_file_path: manifest_file_path, - git_clone_url: git_clone_url, - install_script: install_script, - release_name: release_name, - service_name: service_name, - docker_repository: docker_repository, - helm_repository: {name: helm_repo_name, repo_url: helm_repo_url}, - helm_chart: helm_chart, - helm_chart_container_name: "", - rolling_update_tag: "", - container_names: container_names, - white_list_container_names: white_list_container_names }) - - end - end - # Applies a block to each cnf resource # # `CNFManager.cnf_workload_resources(args, config) {|cnf_config, resource| #your code} diff --git a/src/tasks/utils/config.cr b/src/tasks/utils/config.cr new file mode 100644 index 000000000..d6616ef02 --- /dev/null +++ b/src/tasks/utils/config.cr @@ -0,0 +1,111 @@ +# coding: utf-8 +require "totem" +require "colorize" +require "./types/cnf_conformance_yml_type.cr" +require "./helm.cr" +require "uuid" +require "./points.cr" +require "./task.cr" + +module CNFManager + + class Config + def initialize(cnf_config) + @cnf_config = cnf_config + end + property cnf_config : NamedTuple(destination_cnf_dir: String, + source_cnf_file: String, + source_cnf_dir: String, + yml_file_path: String, + install_method: Tuple(Symbol, String), + manifest_directory: String, + helm_directory: String, + helm_chart_path: String, + manifest_file_path: String, + git_clone_url: String, + install_script: String, + release_name: String, + service_name: String, + docker_repository: String, + helm_repository: NamedTuple(name: String, + repo_url: String) | Nil, + helm_chart: String, + helm_chart_container_name: String, + rolling_update_tag: String, + container_names: Array(Hash(String, String )) | Nil, + white_list_container_names: Array(String)) + + def self.parse_config_yml(config_yml_path : String) : CNFManager::Config + LOGGING.debug "parse_config_yml config_yml_path: #{config_yml_path}" + yml_file = CNFManager.ensure_cnf_conformance_yml_path(config_yml_path) + config = CNFManager.parsed_config_file(yml_file) + + install_method = CNFManager.cnf_installation_method(config) + + CNFManager.generate_and_set_release_name(config_yml_path) + + destination_cnf_dir = CNFManager.cnf_destination_dir(yml_file) + + yml_file_path = CNFManager.ensure_cnf_conformance_dir(config_yml_path) + source_cnf_file = yml_file + source_cnf_dir = yml_file_path + manifest_directory = optional_key_as_string(config, "manifest_directory") + if config["helm_repository"]? + helm_repository = config["helm_repository"].as_h + helm_repo_name = optional_key_as_string(helm_repository, "name") + helm_repo_url = optional_key_as_string(helm_repository, "repo_url") + else + helm_repo_name = "" + helm_repo_url = "" + end + helm_chart = optional_key_as_string(config, "helm_chart") + release_name = "#{config.get("release_name").as_s?}" + service_name = optional_key_as_string(config, "service_name") + helm_directory = optional_key_as_string(config, "helm_directory") + git_clone_url = optional_key_as_string(config, "git_clone_url") + install_script = optional_key_as_string(config, "install_script") + docker_repository = optional_key_as_string(config, "docker_repository") + if helm_directory.empty? + working_chart_directory = "exported_chart" + else + working_chart_directory = helm_directory + end + helm_chart_path = destination_cnf_dir + "/" + working_chart_directory + manifest_file_path = destination_cnf_dir + "/" + "temp_template.yml" + white_list_container_names = config.get("white_list_helm_chart_container_names").as_a.map do |c| + "#{c.as_s?}" + end + container_names_totem = config["container_names"] + container_names = container_names_totem.as_a.map do |container| + {"name" => optional_key_as_string(container, "name"), + "rolling_update_test_tag" => optional_key_as_string(container, "rolling_update_test_tag"), + "rolling_downgrade_test_tag" => optional_key_as_string(container, "rolling_downgrade_test_tag"), + "rolling_version_change_test_tag" => optional_key_as_string(container, "rolling_version_change_test_tag"), + "rollback_from_tag" => optional_key_as_string(container, "rollback_from_tag"), + } + end + + CNFManager::Config.new({ destination_cnf_dir: destination_cnf_dir, + source_cnf_file: source_cnf_file, + source_cnf_dir: source_cnf_dir, + yml_file_path: yml_file_path, + install_method: install_method, + manifest_directory: manifest_directory, + helm_directory: helm_directory, + helm_chart_path: helm_chart_path, + manifest_file_path: manifest_file_path, + git_clone_url: git_clone_url, + install_script: install_script, + release_name: release_name, + service_name: service_name, + docker_repository: docker_repository, + helm_repository: {name: helm_repo_name, repo_url: helm_repo_url}, + helm_chart: helm_chart, + helm_chart_container_name: "", + rolling_update_tag: "", + container_names: container_names, + white_list_container_names: white_list_container_names }) + + end + end +end diff --git a/src/tasks/utils/points.cr b/src/tasks/utils/points.cr new file mode 100644 index 000000000..1b928fd6d --- /dev/null +++ b/src/tasks/utils/points.cr @@ -0,0 +1,244 @@ +# coding: utf-8 +require "totem" +require "colorize" +require "./types/cnf_conformance_yml_type.cr" +require "./helm.cr" +require "uuid" +module CNFManager + + module Points + def self.points_yml + # TODO get points.yml from remote http + points = File.open("points.yml") do |f| + YAML.parse(f) + end + # LOGGING.debug "points: #{points.inspect}" + points.as_a + end + def self.create_points_yml + unless File.exists?("#{POINTSFILE}") + branch = ENV.has_key?("SCORING_ENV") ? ENV["SCORING_ENV"] : "master" + default_scoring_yml = "https://raw.githubusercontent.com/cncf/cnf-conformance/#{branch}/scoring_config/#{DEFAULT_POINTSFILENAME}" + `wget #{ENV.has_key?("SCORING_YML") ? ENV["SCORING_YML"] : default_scoring_yml}` + `mv #{DEFAULT_POINTSFILENAME} #{POINTSFILE}` + end + end + + def self.create_final_results_yml_name + FileUtils.mkdir_p("results") unless Dir.exists?("results") + "results/cnf-conformance-results-" + Time.local.to_s("%Y%m%d-%H%M%S-%L") + ".yml" + end + + def self.clean_results_yml(verbose=false) + if File.exists?("#{CNFManager::Points::Results.file}") + results = File.open("#{CNFManager::Points::Results.file}") do |f| + YAML.parse(f) + end + File.open("#{CNFManager::Points::Results.file}", "w") do |f| + YAML.dump({name: results["name"], + status: results["status"], + exit_code: results["exit_code"], + points: results["points"], + items: [] of YAML::Any}, f) + end + end + end + + def self.task_points(task, passed=true) + if passed + field_name = "pass" + else + field_name = "fail" + end + points =CNFManager::Points.points_yml.find {|x| x["name"] == task} + LOGGING.warn "****Warning**** task #{task} not found in points.yml".colorize(:yellow) unless points + if points && points[field_name]? + points[field_name].as_i if points + else + points =CNFManager::Points.points_yml.find {|x| x["name"] == "default_scoring"} + points[field_name].as_i if points + end + end + + def self.total_points(tag=nil) + if tag + tasks = CNFManager::Points.tasks_by_tag(tag) + else + tasks = CNFManager::Points.all_task_test_names + end + yaml = File.open("#{CNFManager::Points::Results.file}") do |file| + YAML.parse(file) + end + yaml["items"].as_a.reduce(0) do |acc, i| + if i["points"].as_i? && i["name"].as_s? && + tasks.find{|x| x == i["name"]} + (acc + i["points"].as_i) + else + acc + end + end + end + + def self.total_max_points(tag=nil) + if tag + tasks = CNFManager::Points.tasks_by_tag(tag) + else + tasks = CNFManager::Points.all_task_test_names + end + tasks.reduce(0) do |acc, x| + points = CNFManager::Points.task_points(x) + if points + acc + points + else + acc + end + end + end + + def self.upsert_task(task, status, points) + results = File.open("#{CNFManager::Points::Results.file}") do |f| + YAML.parse(f) + end + + result_items = results["items"].as_a + # remove the existing entry + result_items = result_items.reject do |x| + x["name"] == task + end + + result_items << YAML.parse "{name: #{task}, status: #{status}, points: #{points}}" + File.open("#{CNFManager::Points::Results.file}", "w") do |f| + YAML.dump({name: results["name"], + status: results["status"], + points: results["points"], + exit_code: results["exit_code"], + items: result_items}, f) + end + end + + def self.failed_task(task, msg) + CNFManager::Points.upsert_task(task, FAILED, CNFManager::Points.task_points(task, false)) + stdout_failure "#{msg}" + end + + def self.passed_task(task, msg) + CNFManager::Points.upsert_task(task, PASSED, CNFManager::Points.task_points(task)) + stdout_success "#{msg}" + end + + def self.failed_required_tasks + yaml = File.open("#{CNFManager::Points::Results.file}") do |file| + YAML.parse(file) + end + yaml["items"].as_a.reduce([] of String) do |acc, i| + if i["status"].as_s == "failed" && + i["name"].as_s? && + CNFManager::Points.task_required(i["name"].as_s) + (acc << i["name"].as_s) + else + acc + end + end + end + + def self.task_required(task) + points =CNFManager::Points.points_yml.find {|x| x["name"] == task} + LOGGING.warn "task #{task} not found in points.yml".colorize(:yellow) unless points + if points && points["required"]? && points["required"].as_bool == true + true + else + false + end + end + + def self.all_task_test_names + result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| + if x["name"].as_s == "default_scoring" || + x["tags"].as_s.split(",").find{|x|x=="platform"} + acc + else + acc << x["name"].as_s + end + end + end + + def self.tasks_by_tag(tag) + #TODO cross reference points.yml tags with results + found = false + result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| + if x["tags"].as_s? && x["tags"].as_s.includes?(tag) + acc << x["name"].as_s + else + acc + end + end + end + + def self.all_result_test_names(results_file) + results = File.open(results_file) do |f| + YAML.parse(f) + end + result_items = results["items"].as_a.reduce([] of String) do |acc, x| + acc << x["name"].as_s + end + end + + def self.results_by_tag(tag) + task_list = tasks_by_tag(tag) + + results = File.open("#{CNFManager::Points::Results.file}") do |f| + YAML.parse(f) + end + + found = false + result_items = results["items"].as_a.reduce([] of YAML::Any) do |acc, x| + if x["name"].as_s? && task_list.find{|tl| tl == x["name"].as_s} + acc << x + else + acc + end + end + end + + class Results + @@file : String + @@file = CNFManager::Points.create_final_results_yml_name + LOGGING.info "CNFManager::Points::Results.file" + continue = false + LOGGING.info "file exists?:#{File.exists?(@@file)}" + if File.exists?("#{@@file}") + stdout_info "Do you wish to overwrite the #{@@file} file? If so, your previous results.yml will be lost." + print "(Y/N) (Default N): > " + if ENV["CRYSTAL_ENV"]? == "TEST" + continue = true + else + user_input = gets + if user_input == "Y" || user_input == "y" + continue = true + end + end + else + continue = true + end + if continue + File.open("#{@@file}", "w") do |f| + YAML.dump(CNFManager::Points.template_results_yml, f) + end + end + def self.file + @@file + end + end + + def self.template_results_yml + #TODO add tags for category summaries + YAML.parse <<-END +name: cnf conformance +status: +points: +exit_code: 0 +items: [] +END + end + end +end diff --git a/src/tasks/utils/task.cr b/src/tasks/utils/task.cr new file mode 100644 index 000000000..ebc7b2307 --- /dev/null +++ b/src/tasks/utils/task.cr @@ -0,0 +1,75 @@ +# coding: utf-8 +require "totem" +require "colorize" +require "./types/cnf_conformance_yml_type.cr" +require "./helm.cr" +require "uuid" +require "./points.cr" + +module CNFManager + + module Task + def self.task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) + LOGGING.info("task_runner args: #{args.inspect}") + if check_cnf_config(args) + CNFManager::Task.single_task_runner(args, &block) + else + CNFManager::Task.all_cnfs_task_runner(args, &block) + end + end + + # TODO give example for calling + def CNFManager::Task.all_cnfs_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) + + # Platforms tests dont have any cnfs + if CNFManager.cnf_config_list(silent: true).size == 0 + CNFManager::Task.single_task_runner(args, &block) + else + CNFManager.cnf_config_list(silent: true).map do |x| + new_args = Sam::Args.new(args.named, args.raw) + new_args.named["cnf-config"] = x + CNFManager::Task.single_task_runner(new_args, &block) + end + end + end + # TODO give example for calling + def CNFManager::Task.single_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) + LOGGING.debug("single_task_runner args: #{args.inspect}") + begin + if args.named["cnf-config"]? # platform tests don't have a cnf-config + config = CNFManager::Config.parse_config_yml(args.named["cnf-config"].as(String)) + else + config = CNFManager::Config.new({ destination_cnf_dir: "", + source_cnf_file: "", + source_cnf_dir: "", + yml_file_path: "", + install_method: {:helm_chart, ""}, + manifest_directory: "", + helm_directory: "", + helm_chart_path: "", + manifest_file_path: "", + git_clone_url: "", + install_script: "", + release_name: "", + service_name: "", + docker_repository: "", + helm_repository: {name: "", repo_url: ""}, + helm_chart: "", + helm_chart_container_name: "", + rolling_update_tag: "", + container_names: [{"name" => "", "rolling_update_test_tag" => ""}], + white_list_container_names: [""]} ) + end + yield args, config + rescue ex + # Set exception key/value in results + # file to -1 + update_yml("#{CNFManager::Points::Results.file}", "exit_code", "1") + LOGGING.error ex.message + ex.backtrace.each do |x| + LOGGING.error x + end + end + end + end +end From eceed81947d01077ae809d30586dad78ad69087a Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 10 Feb 2021 16:41:16 -0500 Subject: [PATCH 2/7] final_cnf_results_yml now in points file --- .../cnf_conformance_container_chaos_spec.cr | 2 +- .../cnf_conformance_network_chaos_spec.cr | 2 +- spec/cnf_conformance_all/cnf_conformance_spec.cr | 2 +- spec/utils/cnf_manager_spec.cr | 4 ++-- src/tasks/utils/cnf_manager.cr | 10 ---------- src/tasks/utils/points.cr | 9 +++++++++ 6 files changed, 14 insertions(+), 15 deletions(-) diff --git a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr index 3715f97d0..39d6d203d 100644 --- a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Container Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager.final_cnf_results_yml)).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr index 1fb08c76b..0226efb1d 100644 --- a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Network Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager.final_cnf_results_yml)).should eq([ "chaos_network_loss"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.).should eq([ "chaos_network_loss"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_spec.cr b/spec/cnf_conformance_all/cnf_conformance_spec.cr index 69f993f68..3cee253e7 100644 --- a/spec/cnf_conformance_all/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_spec.cr @@ -27,7 +27,7 @@ describe CnfConformance do (/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager.final_cnf_results_yml).sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml..sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) (/^.*\.cr:[0-9].*/ =~ response_s).should be_nil $?.success?.should be_true end diff --git a/spec/utils/cnf_manager_spec.cr b/spec/utils/cnf_manager_spec.cr index 740cf74ee..60a051199 100644 --- a/spec/utils/cnf_manager_spec.cr +++ b/spec/utils/cnf_manager_spec.cr @@ -135,8 +135,8 @@ describe "SampleUtils" do (yaml["exit_code"]).should eq(0) end - it "'CNFManager.final_cnf_results_yml' should return the latest time stamped results file" do - (CNFManager.final_cnf_results_yml).should contain("cnf-conformance-results") + it "'CNFManager::Points.final_cnf_results_yml. should return the latest time stamped results file" do + (CNFManager::Points.final_cnf_results_yml..should contain("cnf-conformance-results") end diff --git a/src/tasks/utils/cnf_manager.cr b/src/tasks/utils/cnf_manager.cr index d77584054..7a8f5b7db 100644 --- a/src/tasks/utils/cnf_manager.cr +++ b/src/tasks/utils/cnf_manager.cr @@ -81,16 +81,6 @@ module CNFManager initialized && test_passed end - - def self.final_cnf_results_yml - LOGGING.info "final_cnf_results_yml" - results_file = `find ./results/* -name "cnf-conformance-results-*.yml"`.split("\n")[-2].gsub("./", "") - if results_file.empty? - raise "No cnf_conformance-results-*.yml found! Did you run the all task?" - end - results_file - end - def self.cnf_config_list(silent=false) LOGGING.info("cnf_config_list") LOGGING.info("find: find #{CNF_DIR}/* -name #{CONFIG_FILE}") diff --git a/src/tasks/utils/points.cr b/src/tasks/utils/points.cr index 1b928fd6d..a5a8217db 100644 --- a/src/tasks/utils/points.cr +++ b/src/tasks/utils/points.cr @@ -241,4 +241,13 @@ items: [] END end end + + def self.final_cnf_results_yml + LOGGING.info "final_cnf_results_yml" + results_file = `find ./results/* -name "cnf-conformance-results-*.yml"`.split("\n")[-2].gsub("./", "") + if results_file.empty? + raise "No cnf_conformance-results-*.yml found! Did you run the all task?" + end + results_file + end end From 929d4acf7df34a0572aae1c17ff5dda77ec52730 Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 10 Feb 2021 17:06:31 -0500 Subject: [PATCH 3/7] Extra prefixes now removed. --- .../cnf_conformance_spec.cr | 2 +- spec/utils/cnf_manager_spec.cr | 2 +- src/tasks/utils/config.cr | 3 +- src/tasks/utils/points.cr | 118 +++++++++--------- src/tasks/utils/task.cr | 13 +- 5 files changed, 68 insertions(+), 70 deletions(-) diff --git a/spec/cnf_conformance_all/cnf_conformance_spec.cr b/spec/cnf_conformance_all/cnf_conformance_spec.cr index 3cee253e7..f809a2a36 100644 --- a/spec/cnf_conformance_all/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_spec.cr @@ -27,7 +27,7 @@ describe CnfConformance do (/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml..sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) (/^.*\.cr:[0-9].*/ =~ response_s).should be_nil $?.success?.should be_true end diff --git a/spec/utils/cnf_manager_spec.cr b/spec/utils/cnf_manager_spec.cr index 60a051199..ceb1fa75e 100644 --- a/spec/utils/cnf_manager_spec.cr +++ b/spec/utils/cnf_manager_spec.cr @@ -136,7 +136,7 @@ describe "SampleUtils" do end it "'CNFManager::Points.final_cnf_results_yml. should return the latest time stamped results file" do - (CNFManager::Points.final_cnf_results_yml..should contain("cnf-conformance-results") + (CNFManager::Points.final_cnf_results_yml).should contain("cnf-conformance-results") end diff --git a/src/tasks/utils/config.cr b/src/tasks/utils/config.cr index d6616ef02..4d10b6704 100644 --- a/src/tasks/utils/config.cr +++ b/src/tasks/utils/config.cr @@ -1,4 +1,3 @@ -# coding: utf-8 require "totem" require "colorize" require "./types/cnf_conformance_yml_type.cr" @@ -85,7 +84,7 @@ module CNFManager } end - CNFManager::Config.new({ destination_cnf_dir: destination_cnf_dir, + new({ destination_cnf_dir: destination_cnf_dir, source_cnf_file: source_cnf_file, source_cnf_dir: source_cnf_dir, yml_file_path: yml_file_path, diff --git a/src/tasks/utils/points.cr b/src/tasks/utils/points.cr index a5a8217db..8fb7eec08 100644 --- a/src/tasks/utils/points.cr +++ b/src/tasks/utils/points.cr @@ -1,4 +1,3 @@ -# coding: utf-8 require "totem" require "colorize" require "./types/cnf_conformance_yml_type.cr" @@ -7,6 +6,36 @@ require "uuid" module CNFManager module Points + class Results + @@file : String + @@file = CNFManager::Points.create_final_results_yml_name + LOGGING.info "Results.file" + continue = false + LOGGING.info "file exists?:#{File.exists?(@@file)}" + if File.exists?("#{@@file}") + stdout_info "Do you wish to overwrite the #{@@file} file? If so, your previous results.yml will be lost." + print "(Y/N) (Default N): > " + if ENV["CRYSTAL_ENV"]? == "TEST" + continue = true + else + user_input = gets + if user_input == "Y" || user_input == "y" + continue = true + end + end + else + continue = true + end + if continue + File.open("#{@@file}", "w") do |f| + YAML.dump(CNFManager::Points.template_results_yml, f) + end + end + def self.file + @@file + end + end + def self.points_yml # TODO get points.yml from remote http points = File.open("points.yml") do |f| @@ -30,11 +59,11 @@ module CNFManager end def self.clean_results_yml(verbose=false) - if File.exists?("#{CNFManager::Points::Results.file}") - results = File.open("#{CNFManager::Points::Results.file}") do |f| + if File.exists?("#{Results.file}") + results = File.open("#{Results.file}") do |f| YAML.parse(f) end - File.open("#{CNFManager::Points::Results.file}", "w") do |f| + File.open("#{Results.file}", "w") do |f| YAML.dump({name: results["name"], status: results["status"], exit_code: results["exit_code"], @@ -50,23 +79,23 @@ module CNFManager else field_name = "fail" end - points =CNFManager::Points.points_yml.find {|x| x["name"] == task} + points =points_yml.find {|x| x["name"] == task} LOGGING.warn "****Warning**** task #{task} not found in points.yml".colorize(:yellow) unless points if points && points[field_name]? points[field_name].as_i if points else - points =CNFManager::Points.points_yml.find {|x| x["name"] == "default_scoring"} + points =points_yml.find {|x| x["name"] == "default_scoring"} points[field_name].as_i if points end end def self.total_points(tag=nil) if tag - tasks = CNFManager::Points.tasks_by_tag(tag) + tasks = tasks_by_tag(tag) else - tasks = CNFManager::Points.all_task_test_names + tasks = all_task_test_names end - yaml = File.open("#{CNFManager::Points::Results.file}") do |file| + yaml = File.open("#{Results.file}") do |file| YAML.parse(file) end yaml["items"].as_a.reduce(0) do |acc, i| @@ -81,12 +110,12 @@ module CNFManager def self.total_max_points(tag=nil) if tag - tasks = CNFManager::Points.tasks_by_tag(tag) + tasks = tasks_by_tag(tag) else - tasks = CNFManager::Points.all_task_test_names + tasks = all_task_test_names end tasks.reduce(0) do |acc, x| - points = CNFManager::Points.task_points(x) + points = task_points(x) if points acc + points else @@ -96,7 +125,7 @@ module CNFManager end def self.upsert_task(task, status, points) - results = File.open("#{CNFManager::Points::Results.file}") do |f| + results = File.open("#{Results.file}") do |f| YAML.parse(f) end @@ -107,7 +136,7 @@ module CNFManager end result_items << YAML.parse "{name: #{task}, status: #{status}, points: #{points}}" - File.open("#{CNFManager::Points::Results.file}", "w") do |f| + File.open("#{Results.file}", "w") do |f| YAML.dump({name: results["name"], status: results["status"], points: results["points"], @@ -117,23 +146,23 @@ module CNFManager end def self.failed_task(task, msg) - CNFManager::Points.upsert_task(task, FAILED, CNFManager::Points.task_points(task, false)) + upsert_task(task, FAILED, task_points(task, false)) stdout_failure "#{msg}" end def self.passed_task(task, msg) - CNFManager::Points.upsert_task(task, PASSED, CNFManager::Points.task_points(task)) + upsert_task(task, PASSED, task_points(task)) stdout_success "#{msg}" end def self.failed_required_tasks - yaml = File.open("#{CNFManager::Points::Results.file}") do |file| + yaml = File.open("#{Results.file}") do |file| YAML.parse(file) end yaml["items"].as_a.reduce([] of String) do |acc, i| if i["status"].as_s == "failed" && i["name"].as_s? && - CNFManager::Points.task_required(i["name"].as_s) + task_required(i["name"].as_s) (acc << i["name"].as_s) else acc @@ -142,7 +171,7 @@ module CNFManager end def self.task_required(task) - points =CNFManager::Points.points_yml.find {|x| x["name"] == task} + points =points_yml.find {|x| x["name"] == task} LOGGING.warn "task #{task} not found in points.yml".colorize(:yellow) unless points if points && points["required"]? && points["required"].as_bool == true true @@ -152,7 +181,7 @@ module CNFManager end def self.all_task_test_names - result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| + result_items =points_yml.reduce([] of String) do |acc, x| if x["name"].as_s == "default_scoring" || x["tags"].as_s.split(",").find{|x|x=="platform"} acc @@ -165,7 +194,7 @@ module CNFManager def self.tasks_by_tag(tag) #TODO cross reference points.yml tags with results found = false - result_items =CNFManager::Points.points_yml.reduce([] of String) do |acc, x| + result_items =points_yml.reduce([] of String) do |acc, x| if x["tags"].as_s? && x["tags"].as_s.includes?(tag) acc << x["name"].as_s else @@ -186,7 +215,7 @@ module CNFManager def self.results_by_tag(tag) task_list = tasks_by_tag(tag) - results = File.open("#{CNFManager::Points::Results.file}") do |f| + results = File.open("#{Results.file}") do |f| YAML.parse(f) end @@ -200,36 +229,6 @@ module CNFManager end end - class Results - @@file : String - @@file = CNFManager::Points.create_final_results_yml_name - LOGGING.info "CNFManager::Points::Results.file" - continue = false - LOGGING.info "file exists?:#{File.exists?(@@file)}" - if File.exists?("#{@@file}") - stdout_info "Do you wish to overwrite the #{@@file} file? If so, your previous results.yml will be lost." - print "(Y/N) (Default N): > " - if ENV["CRYSTAL_ENV"]? == "TEST" - continue = true - else - user_input = gets - if user_input == "Y" || user_input == "y" - continue = true - end - end - else - continue = true - end - if continue - File.open("#{@@file}", "w") do |f| - YAML.dump(CNFManager::Points.template_results_yml, f) - end - end - def self.file - @@file - end - end - def self.template_results_yml #TODO add tags for category summaries YAML.parse <<-END @@ -240,14 +239,15 @@ exit_code: 0 items: [] END end - end - def self.final_cnf_results_yml - LOGGING.info "final_cnf_results_yml" - results_file = `find ./results/* -name "cnf-conformance-results-*.yml"`.split("\n")[-2].gsub("./", "") - if results_file.empty? - raise "No cnf_conformance-results-*.yml found! Did you run the all task?" + def self.final_cnf_results_yml + LOGGING.info "final_cnf_results_yml" + results_file = `find ./results/* -name "cnf-conformance-results-*.yml"`.split("\n")[-2].gsub("./", "") + if results_file.empty? + raise "No cnf_conformance-results-*.yml found! Did you run the all task?" + end + results_file end - results_file end + end diff --git a/src/tasks/utils/task.cr b/src/tasks/utils/task.cr index ebc7b2307..f9fe86748 100644 --- a/src/tasks/utils/task.cr +++ b/src/tasks/utils/task.cr @@ -1,4 +1,3 @@ -# coding: utf-8 require "totem" require "colorize" require "./types/cnf_conformance_yml_type.cr" @@ -12,28 +11,28 @@ module CNFManager def self.task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) LOGGING.info("task_runner args: #{args.inspect}") if check_cnf_config(args) - CNFManager::Task.single_task_runner(args, &block) + single_task_runner(args, &block) else - CNFManager::Task.all_cnfs_task_runner(args, &block) + all_cnfs_task_runner(args, &block) end end # TODO give example for calling - def CNFManager::Task.all_cnfs_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) + def self.all_cnfs_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) # Platforms tests dont have any cnfs if CNFManager.cnf_config_list(silent: true).size == 0 - CNFManager::Task.single_task_runner(args, &block) + single_task_runner(args, &block) else CNFManager.cnf_config_list(silent: true).map do |x| new_args = Sam::Args.new(args.named, args.raw) new_args.named["cnf-config"] = x - CNFManager::Task.single_task_runner(new_args, &block) + single_task_runner(new_args, &block) end end end # TODO give example for calling - def CNFManager::Task.single_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) + def self.single_task_runner(args, &block : Sam::Args, CNFManager::Config -> String | Colorize::Object(String) | Nil) LOGGING.debug("single_task_runner args: #{args.inspect}") begin if args.named["cnf-config"]? # platform tests don't have a cnf-config From 9392c7421b9e2e5a31683398c4218cf38a5024f3 Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 10 Feb 2021 17:39:34 -0500 Subject: [PATCH 4/7] cnf_conformance_spec* now use final_cnf_results_yml. --- .../cnf_conformance_all/cnf_conformance_container_chaos_spec.cr | 2 +- spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr | 2 +- spec/cnf_conformance_all/cnf_conformance_spec.cr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr index 39d6d203d..27490ef66 100644 --- a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Container Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr index 0226efb1d..0b5cbea4b 100644 --- a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Network Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.).should eq([ "chaos_network_loss"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).should eq([ "chaos_network_loss"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_spec.cr b/spec/cnf_conformance_all/cnf_conformance_spec.cr index f809a2a36..811796b22 100644 --- a/spec/cnf_conformance_all/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_spec.cr @@ -27,7 +27,7 @@ describe CnfConformance do (/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.sort)).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) (/^.*\.cr:[0-9].*/ =~ response_s).should be_nil $?.success?.should be_true end From 8f8dc9174ae72e3c20ca3eb4d2a483d21839712f Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 10 Feb 2021 17:50:20 -0500 Subject: [PATCH 5/7] cnf_conformance_spec* now have proper parenthesis. --- .../cnf_conformance_all/cnf_conformance_container_chaos_spec.cr | 2 +- spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr | 2 +- spec/cnf_conformance_all/cnf_conformance_spec.cr | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr index 27490ef66..49945fdb6 100644 --- a/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_container_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Container Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml)).should eq([ "chaos_cpu_hog", "chaos_container_kill"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr index 0b5cbea4b..96de4c57f 100644 --- a/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_network_chaos_spec.cr @@ -19,7 +19,7 @@ describe "CNF Conformance all Network Chaos" do LOGGING.info response_s (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).should eq([ "chaos_network_loss"]) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml)).should eq([ "chaos_network_loss"]) $?.success?.should be_true ensure LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false ` diff --git a/spec/cnf_conformance_all/cnf_conformance_spec.cr b/spec/cnf_conformance_all/cnf_conformance_spec.cr index 811796b22..e6ebba80d 100644 --- a/spec/cnf_conformance_all/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_spec.cr @@ -27,7 +27,7 @@ describe CnfConformance do (/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml.sort)).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used" ].sort) (/^.*\.cr:[0-9].*/ =~ response_s).should be_nil $?.success?.should be_true end From 480538af67f2f7c9cd7302b8404d3698c4f3893e Mon Sep 17 00:00:00 2001 From: wwatson Date: Thu, 11 Feb 2021 19:08:38 -0500 Subject: [PATCH 6/7] choas mesh wait now uses json. --- src/tasks/chaos_mesh_setup.cr | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/tasks/chaos_mesh_setup.cr b/src/tasks/chaos_mesh_setup.cr index 38b89982c..6dee3593c 100644 --- a/src/tasks/chaos_mesh_setup.cr +++ b/src/tasks/chaos_mesh_setup.cr @@ -48,12 +48,26 @@ module ChaosMeshSetup until (status.empty? != true && status == "Finished") || second_count > wait_count.to_i LOGGING.debug "second_count = #{second_count}" sleep 1 - get_status = `kubectl get "#{test_type}" "#{test_name}" -o yaml` - LOGGING.info("#{get_status}") - status_data = Totem.from_yaml("#{get_status}") + # get_status = `kubectl get "#{test_type}" "#{test_name}" -o yaml` + LOGGING.info "kubectl get #{test_type} #{test_name} -o json" + status = Process.run("kubectl get #{test_type} #{test_name} -o json", + shell: true, + output: output = IO::Memory.new, + error: stderr = IO::Memory.new) + LOGGING.info "KubectlClient.exec output: #{output.to_s}" + LOGGING.info "KubectlClient.exec stderr: #{stderr.to_s}" + get_status = output.to_s + # LOGGING.info("#{get_status}") + # status_data = Totem.from_yaml("#{get_status}") + if get_status && !get_status.empty? + status_data = JSON.parse(get_status) + else + status_data = JSON.parse(%({})) + end LOGGING.info "Status: #{get_status}" - LOGGING.debug("#{status_data}") - status = status_data.get("status").as_h["experiment"].as_h["phase"].as_s + # LOGGING.debug("#{status_data}") + # status = status_data.get("status").as_h["experiment"].as_h["phase"].as_s + status = status_data.dig?("status", "experiment", "phase").to_s second_count = second_count + 1 LOGGING.info "#{get_status}" LOGGING.info "#{second_count}" From 2458214ca662ee581392c4b3534eba8552aea0ac Mon Sep 17 00:00:00 2001 From: wwatson Date: Wed, 17 Feb 2021 11:16:57 -0500 Subject: [PATCH 7/7] #610 pod_network_latency in generic spec --- spec/cnf_conformance_all/cnf_conformance_spec.cr | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/cnf_conformance_all/cnf_conformance_spec.cr b/spec/cnf_conformance_all/cnf_conformance_spec.cr index 2101222ef..9174301ba 100644 --- a/spec/cnf_conformance_all/cnf_conformance_spec.cr +++ b/spec/cnf_conformance_all/cnf_conformance_spec.cr @@ -27,7 +27,7 @@ describe CnfConformance do (/PASSED: Published Helm Chart Found/ =~ response_s).should_not be_nil (/Final workload score:/ =~ response_s).should_not be_nil (/Final score:/ =~ response_s).should_not be_nil - (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used", "immutable_configmap"].sort) + (CNFManager::Points.all_result_test_names(CNFManager::Points.final_cnf_results_yml).sort).should eq(["volume_hostpath_not_found", "privileged", "increase_capacity", "decrease_capacity", "ip_addresses", "liveness", "readiness", "rolling_update", "rolling_downgrade", "rolling_version_change", "nodeport_not_used", "pod_network_latency", "hardcoded_ip_addresses_in_k8s_runtime_configuration", "install_script_helm", "helm_chart_valid", "helm_chart_published", "reasonable_image_size", "rollback", "secrets_used", "immutable_configmap"].sort) (/^.*\.cr:[0-9].*/ =~ response_s).should be_nil $?.success?.should be_true end