Skip to content

Commit

Permalink
Merge pull request #607 from cncf/refactor/utils
Browse files Browse the repository at this point in the history
Refactor of utils in preparation of #603
  • Loading branch information
agentpoyo authored Feb 18, 2021
2 parents 37331cd + de3941f commit 696b129
Show file tree
Hide file tree
Showing 9 changed files with 446 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ describe "CNF Conformance all Container Chaos" do
# ensure
# LOGGING.info `./cnf-conformance cnf_cleanup cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false `
# end

end
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ describe "CNF Conformance all Network Chaos" do

it "'all' should run the whole test suite", tags: "happy-path" do
`./cnf-conformance samples_cleanup`

# response_s = `./cnf-conformance all ~platform ~compatibilty ~statelessness ~security ~scalability ~configuration_lifecycle ~observability ~installability ~hardware_and_scheduling ~microservice ~chaos_cpu_hog ~chaos_container_kill cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false verbose`
# response_s = `./cnf-conformance all ~platform ~compatibilty ~statelessness ~security ~scalability ~configuration_lifecycle ~observability ~installability ~hardware_and_scheduling ~microservice ~chaos_network_loss ~chaos_cpu_hog ~chaos_container_kill cnf-config=./sample-cnfs/k8s-multiple-deployments/cnf-conformance.yml deploy_with_chart=false verbose`
# LOGGING.info response_s
Expand All @@ -24,5 +25,6 @@ describe "CNF Conformance all Network Chaos" do
# $?.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 `

end
end
2 changes: 1 addition & 1 deletion spec/cnf_conformance_all/cnf_conformance_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,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", "immutable_configmap", "pod_network_latency"].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
Expand Down
4 changes: 2 additions & 2 deletions spec/utils/cnf_manager_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down
7 changes: 0 additions & 7 deletions src/tasks/chaos_mesh_setup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,6 @@ 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}")
# LOGGING.info "Status: #{get_status}"
# LOGGING.debug("#{status_data}")
# status = status_data.get("status").as_h["experiment"].as_h["phase"].as_s
# 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,
Expand Down
13 changes: 3 additions & 10 deletions src/tasks/utils/cnf_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ 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

Expand Down Expand Up @@ -479,16 +482,6 @@ END
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}")
Expand Down
110 changes: 110 additions & 0 deletions src/tasks/utils/config.cr
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
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

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
Loading

0 comments on commit 696b129

Please sign in to comment.