Skip to content

Commit

Permalink
Merge pull request #119 from chef/SHACK-191/jm/basic_a2
Browse files Browse the repository at this point in the history
SHACK-191 Basic Automate 2 Reporting
  • Loading branch information
jonsmorrow authored May 14, 2018
2 parents 5520e1f + ca603cc commit 673eb99
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 0 deletions.
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 @@ -62,6 +62,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
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

0 comments on commit 673eb99

Please sign in to comment.