Skip to content

Commit

Permalink
Feat: Update compatibility tests for new installation process
Browse files Browse the repository at this point in the history
Refs: #2153
- Removed functions that will not be available with new installation
process.
- Tests will have to be updated further once the new points
system is introduced.

Signed-off-by: svteb <[email protected]>
  • Loading branch information
svteb committed Oct 18, 2024
1 parent bd35849 commit 66a9f71
Showing 1 changed file with 58 additions and 59 deletions.
117 changes: 58 additions & 59 deletions src/tasks/workload/compatibility.cr
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ require "docker_client"
require "../utils/utils.cr"



desc "The CNF test suite checks to see if CNFs support horizontal scaling (across multiple machines) and vertical scaling (between sizes of machines) by using the native K8s kubectl"
task "compatibility", ["helm_chart_valid", "helm_chart_published", "helm_deploy", "cni_compatible", "increase_decrease_capacity", "rollback"].concat(ROLLING_VERSION_CHANGE_TEST_NAMES) do |_, args|
stdout_score("compatibility", "Compatibility, Installability, and Upgradeability")
Expand Down Expand Up @@ -406,86 +405,86 @@ task "helm_deploy" do |t, args|
end
end

# @svteb the test should be updated after the new installation/points process is introduced
# (currently only one result can be returned).
task "helm_chart_published", ["helm_local_install"] do |t, args|
CNFManager::Task.task_runner(args, task: t) do |args, config|
if check_verbose(args)
Log.for("verbose").debug { "helm_chart_published args.raw: #{args.raw}" }
Log.for("verbose").debug { "helm_chart_published args.named: #{args.named}" }
helm = Helm::BinarySingleton.helm

# Store chart search commands in an array
chart_searches = [] of String

# Collect helm chart search queries from deployments
config.deployments.helm_charts.each do |deployment|
helm_repo_name = deployment.helm_repo_name
helm_chart_name = deployment.helm_chart_name

helm_chart_full_name = "#{helm_repo_name}/#{helm_chart_name}"
chart_searches << helm_chart_full_name
end

helm_chart = config.deployments.get_deployment_param(:helm_chart)
current_dir = FileUtils.pwd
helm = Helm::BinarySingleton.helm
Log.for("verbose").debug { helm } if check_verbose(args)

if CNFManager.helm_repo_add(args: args)
unless helm_chart.empty?
helm_search_cmd = "#{helm} search repo #{helm_chart}"
Log.for(t.name).info { "helm search command: #{helm_search_cmd}" }
Process.run(
helm_search_cmd,
shell: true,
output: helm_search_stdout = IO::Memory.new,
error: helm_search_stderr = IO::Memory.new
)
helm_search = helm_search_stdout.to_s
Log.for("verbose").debug { "#{helm_search}" } if check_verbose(args)
unless helm_search =~ /No results found/
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "Published Helm Chart Found")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Published Helm Chart Not Found")
end
else
# Process the helm chart searches and collect results
results = chart_searches.map do |helm_chart_full_name|
helm_search_cmd = "#{helm} search repo #{helm_chart_full_name}"
helm_search_status = Process.run(helm_search_cmd, shell: true, output: helm_search_stdout = IO::Memory.new, error: helm_search_stderr = IO::Memory.new)
helm_search_output = helm_search_stdout.to_s
Log.for(t.name).info { "Helm search output: #{helm_search_output}" }

# Check if the chart was found
if helm_search_output =~ /No results found/
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Published Helm Chart Not Found")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "Published Helm Chart Found")
end
end

if results.empty?
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Skipped, "No Helm Charts Found to Search")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Published Helm Chart Not Found")
results.first
end
end
end

# @svteb the test should be updated after the new installation/points process is introduced
# (currently only one result can be returned).
task "helm_chart_valid", ["helm_local_install"] do |t, args|
CNFManager::Task.task_runner(args, task: t) do |args, config|
if check_verbose(args)
Log.for("verbose").debug { "helm_chart_valid args.raw: #{args.raw}" }
Log.for("verbose").debug { "helm_chart_valid args.named: #{args.named}" }
end
current_dir = FileUtils.pwd
helm = Helm::BinarySingleton.helm
Log.info { "current dir: #{current_dir}" }

response = String::Builder.new
# Store chart locations in an array
chart_dirs = [] of Tuple(String, String)

helm_directory = config.deployments.get_deployment_param(:helm_directory)
if helm_directory.empty?
working_chart_directory = "exported_chart"
else
working_chart_directory = helm_directory
# Collect helm chart paths
config.deployments.helm_charts.each do |deployment|
chart_dirs << {"#{current_dir}/#{CNF_DIR}/#{deployment.name}/exported_chart", deployment.name}
end

if args.named.keys.includes? "cnf_chart_path"
working_chart_directory = args.named["cnf_chart_path"]
# Collect helm directory paths
config.deployments.helm_dirs.each do |deployment|
chart_dirs << {"#{current_dir}/#{CNF_DIR}/#{deployment.name}/chart", deployment.name}
end

Log.for("verbose").debug { "working_chart_directory: #{working_chart_directory}" } if check_verbose(args)

current_dir = FileUtils.pwd
Log.for(t.name).debug { "current dir: #{current_dir}" }
helm = Helm::BinarySingleton.helm
# Iterate over chart directories and store the results for each lint
results = chart_dirs.map do |chart_dir, deployment_name|
helm_lint_cmd = "#{helm} lint #{chart_dir}"
helm_lint_status = Process.run(helm_lint_cmd, shell: true, output: helm_lint_stdout = IO::Memory.new, error: helm_lint_stderr = IO::Memory.new)
helm_lint_output = helm_lint_stdout.to_s
Log.for(t.name).info { "Helm Lint Output: #{helm_lint_output}" }

destination_cnf_dir = config.dynamic.destination_cnf_dir

helm_lint_cmd = "#{helm} lint #{destination_cnf_dir}/#{working_chart_directory}"
helm_lint_status = Process.run(
helm_lint_cmd,
shell: true,
output: helm_lint_stdout = IO::Memory.new,
error: helm_link_stderr = IO::Memory.new
)
helm_lint = helm_lint_stdout.to_s
Log.for(t.name).debug { "helm_lint: #{helm_lint}" } if check_verbose(args)
if helm_lint_status.success?
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "Helm Chart Lint Passed")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Helm Chart Lint Failed")
end
end

if helm_lint_status.success?
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Passed, "Helm Chart #{working_chart_directory} Lint Passed")
if results.empty?
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Skipped, "No Helm Charts or Directories Found to Lint")
else
CNFManager::TestcaseResult.new(CNFManager::ResultStatus::Failed, "Helm Chart #{working_chart_directory} Lint Failed")
results.first
end
end
end
Expand Down

0 comments on commit 66a9f71

Please sign in to comment.