CFINSPEC-137: Set the target_id to blank string if unable to fetch it from train

Signed-off-by: Vasu1105 <vasundhara.jagdale@chef.io>
This commit is contained in:
Vasu1105 2022-03-11 14:21:35 +05:30
parent ab01652ee2
commit adfe38c161
4 changed files with 8 additions and 7 deletions

View file

@ -21,7 +21,7 @@ module Inspec::Reporters
final_report[:type] = "inspec_report"
final_report[:end_time] = Time.now.utc.strftime("%FT%TZ")
final_report[:node_uuid] = report[:platform][:target_id] || @config["node_uuid"] || @config["target_id"]
final_report[:node_uuid] = report[:platform][:target_id] || @config["node_uuid"] || ""
raise Inspec::ReporterError, "Cannot find a UUID for your node. Please specify one via json-config." if final_report[:node_uuid].nil?
final_report[:report_uuid] = @config["report_uuid"] || uuid_from_string(final_report[:end_time] + final_report[:node_uuid])

View file

@ -76,7 +76,7 @@ module Inspec::Reporters
}
header["Failure Message"] = profile[:status_message] if profile[:status] == "failed"
header["Target"] = run_data[:platform][:target] unless run_data[:platform][:target].nil?
header["Target ID"] = run_data[:platform][:target_id] || @config["target_id"]
header["Target ID"] = run_data[:platform][:target_id] || ""
pad = header.keys.max_by(&:length).length + 1
header.each do |title, value|

View file

@ -29,7 +29,7 @@ module Inspec::Reporters
{
name: run_data[:platform][:name],
release: run_data[:platform][:release],
target_id: run_data[:platform][:target_id] || @config["target_id"],
target_id: run_data[:platform][:target_id] || "",
}.reject { |_k, v| v.nil? }
end

View file

@ -111,10 +111,11 @@ describe "inspec exec" do
assert_exit_code 0, out
end
it "can execute the profile with a target_id passthrough and overrides the --target-id with platform uuid" do
it "shows deprecation warning for --target-id opition ignore the its value." do
skip_windows!
inspec("exec #{complete_profile} --no-create-lockfile --target-id 1d3e399f-4d71-4863-ac54-84d437fbc444")
_(stdout).must_include "The --target-id option is deprecated in InSpec 5. Its value will be ignored."
_(stdout).must_include "Target ID: #{inspec_os_uuid}"
_(stderr).must_equal ""
@ -983,7 +984,7 @@ describe "inspec exec" do
describe "when using the legacy --json-config" do
let(:cli_args) { "--json-config " + File.join(config_dir_path, "json-config", "good.json") }
it "should override the custom target ID value with platform uuid" do
it "should ignore the custom target ID value and override it with platform uuid" do
skip_windows!
_(stderr).must_be_empty # TODO: one day deprecate the --json-config option
_(seen_target_id).wont_equal "from-config-file"
@ -1152,8 +1153,8 @@ describe "inspec exec" do
describe "when a target URI with a known credset is used" do
let(:cli_args) { "--target mock://mycredset" + " --config " + File.join(config_dir_path, "json-config", "mock-credset.json") }
it "should connect to the mock platform" do
_(seen_platform).must_equal({ "name" => "mock", "release" => "unknown", "target_id" => "from-mock-credset-config-file" })
it "should connect to the mock platform and ignore the target_id set in the config file." do
_(seen_platform).must_equal({ "name" => "mock", "release" => "unknown", "target_id" => "" })
end
end
end