Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SHACK-191 Basic Automate 2 Reporting #119

Merged
merged 1 commit into from
May 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions components/chef-cli/lib/chef-cli/action/converge_target.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ def create_remote_config(dir)
exception_handlers << reporter
EOM

# Maybe add data collector endpoint.
dc = ChefCLI::Config.data_collector
if !dc.url.nil? && !dc.token.nil?
workstation_rb << <<~EOM
data_collector.server_url "#{dc.url}"
data_collector.token "#{dc.token}"
data_collector.mode :solo
data_collector.organization "Chef Workstation"
EOM
end

begin
config_file = Tempfile.new
config_file.write(workstation_rb)
Expand Down
4 changes: 4 additions & 0 deletions components/chef-cli/lib/chef-cli/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,9 @@ def reset
default(:cookbook_repo_paths, ChefConfig::Config[:cookbook_path])
end

config_context :data_collector do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not also need to define mode and organization within this context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No we hard code that when we write the remote config since it will always be local mode and in this case "Chef Workstation" as the org.

default :url, nil
default :token, nil
end
end
end
56 changes: 56 additions & 0 deletions components/chef-cli/spec/unit/action/converge_target_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,62 @@
# ensure the tempfile is deleted locally
expect(local_tempfile.closed?).to eq(true)
end

describe "when data_collector is set in config" do
before do
ChefCLI::Config.data_collector.url = "dc.url"
ChefCLI::Config.data_collector.token = "dc.token"
end

it "creates a config file with data collector config values" do
expect(Tempfile).to receive(:new).and_return(local_tempfile)
expect(local_tempfile).to receive(:write).with(<<~EOM
local_mode true
color false
cache_path "\#{ENV['APPDATA']}/chef-workstation"
chef_repo_path "\#{ENV['APPDATA']}/chef-workstation"
require_relative "reporter"
reporter = ChefCLI::Reporter.new
report_handlers << reporter
exception_handlers << reporter
data_collector.server_url "dc.url"
data_collector.token "dc.token"
data_collector.mode :solo
data_collector.organization "Chef Workstation"
EOM
)
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config)
expect(action.create_remote_config(remote_folder)).to eq(remote_config)
# ensure the tempfile is deleted locally
expect(local_tempfile.closed?).to eq(true)
end
end

describe "when data_collector is not set" do
before do
ChefCLI::Config.data_collector.url = nil
ChefCLI::Config.data_collector.token = nil
end

it "creates a config file without data collector config values" do
expect(Tempfile).to receive(:new).and_return(local_tempfile)
expect(local_tempfile).to receive(:write).with(<<~EOM
local_mode true
color false
cache_path "\#{ENV['APPDATA']}/chef-workstation"
chef_repo_path "\#{ENV['APPDATA']}/chef-workstation"
require_relative "reporter"
reporter = ChefCLI::Reporter.new
report_handlers << reporter
exception_handlers << reporter
EOM
)
expect(target_host).to receive(:upload_file).with(local_tempfile.path, remote_config)
expect(action.create_remote_config(remote_folder)).to eq(remote_config)
# ensure the tempfile is deleted locally
expect(local_tempfile.closed?).to eq(true)
end
end
end

describe "#create_remote_handler" do
Expand Down