Skip to content
This repository has been archived by the owner on Feb 18, 2020. It is now read-only.

Commit

Permalink
#59 fix enabling init.d services of additional agents
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzo committed Dec 21, 2015
1 parent 1dfc518 commit 9e6d608
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
11 changes: 7 additions & 4 deletions providers/agent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
owner new_resource.user
group new_resource.group
end
# package manages the init.d script so we will not
# and we will expect that init.d scripts are already installed
link "/etc/init.d/#{agent_name}" do
to "/etc/init.d/go-agent"
# package manages the init.d/go-agent script so cookbook should not.
bash "setup init.d for #{agent_name}" do
code <<-EOH
cp /etc/init.d/go-agent /etc/init.d/#{agent_name}
sed -i 's/# Provides: go-agent$/# Provides: #{agent_name}/g' /etc/init.d/#{agent_name}
EOH
only_if "grep -q '# Provides: go-agent$' /etc/init.d/#{agent_name}"
not_if { agent_name == 'go-agent' }
end
link "/usr/share/#{agent_name}" do
Expand Down
5 changes: 5 additions & 0 deletions spec/go_agent_lwrp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/my-go-agent").and_return(false)
end

it_behaves_like :agent_linux_install

it 'creates my-go-agent chef resource' do
Expand Down
26 changes: 23 additions & 3 deletions spec/go_agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it_behaves_like :apt_repository_recipe
it 'installs go-agent package' do
Expand All @@ -70,6 +73,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it_behaves_like :yum_repository_recipe
it 'installs go-agent package' do
Expand All @@ -90,6 +96,10 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent-1").and_return(true)
end
it_behaves_like :agent_recipe
it_behaves_like :apt_repository_recipe
it 'installs go-agent package' do
Expand All @@ -100,9 +110,7 @@
expect(chef_run).to create_gocd_agent('go-agent-1')
end
it 'creates init.d script to start additional agent' do
expect(chef_run).to create_link('/etc/init.d/go-agent-1').with(
to: '/etc/init.d/go-agent'
)
expect(chef_run).to run_bash('setup init.d for go-agent-1')
end
it 'links /usr/share/go-agent script' do
expect(chef_run).to create_link('/usr/share/go-agent-1').with(
Expand Down Expand Up @@ -152,6 +160,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it 'downloads go-agent .deb from remote URL' do
expect(chef_run).to create_remote_file('go-agent-15.2.0-2248.deb').with(
Expand All @@ -172,6 +183,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it 'downloads go-agent .rpm from remote URL' do
expect(chef_run).to create_remote_file('go-agent-15.2.0-2248.noarch.rpm').with(
Expand Down Expand Up @@ -199,6 +213,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it 'includes apt recipe' do
expect(chef_run).to include_recipe('apt')
Expand Down Expand Up @@ -226,6 +243,9 @@
end
run.converge(described_recipe)
end
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it_behaves_like :agent_recipe
it 'includes yum recipe' do
expect(chef_run).to include_recipe('yum')
Expand Down
9 changes: 9 additions & 0 deletions spec/shared_examples.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
shared_examples_for :apt_repository_recipe do
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it 'includes apt recipe' do
expect(chef_run).to include_recipe('apt')
end
Expand All @@ -11,6 +14,9 @@
end
end
shared_examples_for :yum_repository_recipe do
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it 'includes yum recipe' do
expect(chef_run).to include_recipe('yum')
end
Expand All @@ -22,6 +28,9 @@
end
end
shared_examples_for :agent_linux_install do
before do
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
end
it 'includes java recipe' do
expect(chef_run).to include_recipe('java::default')
end
Expand Down

0 comments on commit 9e6d608

Please sign in to comment.