Skip to content

Commit

Permalink
Merge pull request #435 from cncf/feature/#402-ipaddresses
Browse files Browse the repository at this point in the history
Update frequently failing static workload test that checks for ip addresses #402
  • Loading branch information
nupejosh authored Oct 19, 2020
2 parents a7a5bd8 + 4778e5d commit 43630a9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions spec/configuration_lifecycle_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ describe CnfConformance do
# $?.success?.should be_true
end

it "'ip_addresses' should fail when ip addresses are found in the source that is set", tags: "happy-path" do
it "'ip_addresses' should pass when no uncommented ip addresses are found in helm chart source", tags: "happy-path" do
begin
`./cnf-conformance sample_coredns_source_setup verbose`
$?.success?.should be_true
response_s = `./cnf-conformance ip_addresses verbose`
LOGGING.info response_s
$?.success?.should be_true
(/FAILURE: IP addresses found/ =~ response_s).should_not be_nil
(/PASSED: No IP addresses found/ =~ response_s).should_not be_nil
ensure
`./cnf-conformance sample_coredns_source_cleanup verbose`
end
Expand Down
34 changes: 24 additions & 10 deletions src/tasks/configuration_lifecycle.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,34 @@ task "ip_addresses" do |_, args|
LOGGING.info("ip_addresses args #{args.inspect}")
cdir = FileUtils.pwd()
response = String::Builder.new
Dir.cd(CNF_DIR)
Process.run("grep -rnw -E -o '([0-9]{1,3}[\.]){3}[0-9]{1,3}'", shell: true) do |proc|
while line = proc.output.gets
response << line
VERBOSE_LOGGING.info "#{line}" if check_verbose(args)
config = CNFManager.parsed_config_file(CNFManager.ensure_cnf_conformance_yml_path(args.named["cnf-config"].as(String)))
helm_directory = "#{config.get("helm_directory").as_s?}"
LOGGING.info "ip_addresses helm_directory: #{CNFManager.ensure_cnf_conformance_dir(args.named["cnf-config"].as(String)) + helm_directory}"
if File.directory?(CNFManager.ensure_cnf_conformance_dir(args.named["cnf-config"].as(String)) + helm_directory)
# Switch to the helm chart directory
Dir.cd(CNFManager.ensure_cnf_conformance_dir(args.named["cnf-config"].as(String)) + helm_directory)
# Look for all ip addresses that are not comments
LOGGING.info "current directory: #{ FileUtils.pwd()}"
# should catch comments (# // or /*) and ignore 0.0.0.0
# note: grep wants * escaped twice
Process.run("grep -r -P '^(?!.+0\.0\.0\.0)(?![[:space:]]*0\.0\.0\.0)(?!#)(?![[:space:]]*#)(?!\/\/)(?![[:space:]]*\/\/)(?!\/\\*)(?![[:space:]]*\/\\*)(.+([0-9]{1,3}[\.]){3}[0-9]{1,3})'", shell: true) do |proc|
while line = proc.output.gets
response << line
VERBOSE_LOGGING.info "#{line}" if check_verbose(args)
end
end
end
Dir.cd(cdir)
if response.to_s.size > 0
resp = upsert_failed_task("ip_addresses","✖️ FAILURE: IP addresses found")
Dir.cd(cdir)
if response.to_s.size > 0
resp = upsert_failed_task("ip_addresses","✖️ FAILURE: IP addresses found")
else
resp = upsert_passed_task("ip_addresses", "✔️ PASSED: No IP addresses found")
end
resp
else
# TODO If no helm chart directory, exit with 0 points
Dir.cd(cdir)
resp = upsert_passed_task("ip_addresses", "✔️ PASSED: No IP addresses found")
end
resp
end
end

Expand Down
12 changes: 6 additions & 6 deletions src/tasks/utils/cnf_manager.cr
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ module CNFManager
stdout = IO::Memory.new
stderror = IO::Memory.new
begin
process = Process.new("#{helm}", ["repo", "add", "#{helm_repo_name}", "#{helm_repo_url}"], output: stdout, error: stderror)
status = process.wait
helm_resp = stdout.to_s
error = stderror.to_s
LOGGING.info "error: #{error}"
LOGGING.info "helm_resp (add): #{helm_resp}"
process = Process.new("#{helm}", ["repo", "add", "#{helm_repo_name}", "#{helm_repo_url}"], output: stdout, error: stderror)
status = process.wait
helm_resp = stdout.to_s
error = stderror.to_s
LOGGING.info "error: #{error}"
LOGGING.info "helm_resp (add): #{helm_resp}"
rescue
LOGGING.error "helm repo add command critically failed: #{helm} repo add #{helm_repo_name} #{helm_repo_url}"
end
Expand Down

0 comments on commit 43630a9

Please sign in to comment.