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

Commit 9e6d608

Browse files
committed
#59 fix enabling init.d services of additional agents
1 parent 1dfc518 commit 9e6d608

File tree

4 files changed

+44
-7
lines changed

4 files changed

+44
-7
lines changed

providers/agent.rb

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,13 @@
1717
owner new_resource.user
1818
group new_resource.group
1919
end
20-
# package manages the init.d script so we will not
21-
# and we will expect that init.d scripts are already installed
22-
link "/etc/init.d/#{agent_name}" do
23-
to "/etc/init.d/go-agent"
20+
# package manages the init.d/go-agent script so cookbook should not.
21+
bash "setup init.d for #{agent_name}" do
22+
code <<-EOH
23+
cp /etc/init.d/go-agent /etc/init.d/#{agent_name}
24+
sed -i 's/# Provides: go-agent$/# Provides: #{agent_name}/g' /etc/init.d/#{agent_name}
25+
EOH
26+
only_if "grep -q '# Provides: go-agent$' /etc/init.d/#{agent_name}"
2427
not_if { agent_name == 'go-agent' }
2528
end
2629
link "/usr/share/#{agent_name}" do

spec/go_agent_lwrp_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@
1010
end
1111
run.converge(described_recipe)
1212
end
13+
before do
14+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
15+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/my-go-agent").and_return(false)
16+
end
17+
1318
it_behaves_like :agent_linux_install
1419

1520
it 'creates my-go-agent chef resource' do

spec/go_agent_spec.rb

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@
5454
end
5555
run.converge(described_recipe)
5656
end
57+
before do
58+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
59+
end
5760
it_behaves_like :agent_recipe
5861
it_behaves_like :apt_repository_recipe
5962
it 'installs go-agent package' do
@@ -70,6 +73,9 @@
7073
end
7174
run.converge(described_recipe)
7275
end
76+
before do
77+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
78+
end
7379
it_behaves_like :agent_recipe
7480
it_behaves_like :yum_repository_recipe
7581
it 'installs go-agent package' do
@@ -90,6 +96,10 @@
9096
end
9197
run.converge(described_recipe)
9298
end
99+
before do
100+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
101+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent-1").and_return(true)
102+
end
93103
it_behaves_like :agent_recipe
94104
it_behaves_like :apt_repository_recipe
95105
it 'installs go-agent package' do
@@ -100,9 +110,7 @@
100110
expect(chef_run).to create_gocd_agent('go-agent-1')
101111
end
102112
it 'creates init.d script to start additional agent' do
103-
expect(chef_run).to create_link('/etc/init.d/go-agent-1').with(
104-
to: '/etc/init.d/go-agent'
105-
)
113+
expect(chef_run).to run_bash('setup init.d for go-agent-1')
106114
end
107115
it 'links /usr/share/go-agent script' do
108116
expect(chef_run).to create_link('/usr/share/go-agent-1').with(
@@ -152,6 +160,9 @@
152160
end
153161
run.converge(described_recipe)
154162
end
163+
before do
164+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
165+
end
155166
it_behaves_like :agent_recipe
156167
it 'downloads go-agent .deb from remote URL' do
157168
expect(chef_run).to create_remote_file('go-agent-15.2.0-2248.deb').with(
@@ -172,6 +183,9 @@
172183
end
173184
run.converge(described_recipe)
174185
end
186+
before do
187+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
188+
end
175189
it_behaves_like :agent_recipe
176190
it 'downloads go-agent .rpm from remote URL' do
177191
expect(chef_run).to create_remote_file('go-agent-15.2.0-2248.noarch.rpm').with(
@@ -199,6 +213,9 @@
199213
end
200214
run.converge(described_recipe)
201215
end
216+
before do
217+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
218+
end
202219
it_behaves_like :agent_recipe
203220
it 'includes apt recipe' do
204221
expect(chef_run).to include_recipe('apt')
@@ -226,6 +243,9 @@
226243
end
227244
run.converge(described_recipe)
228245
end
246+
before do
247+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
248+
end
229249
it_behaves_like :agent_recipe
230250
it 'includes yum recipe' do
231251
expect(chef_run).to include_recipe('yum')

spec/shared_examples.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
shared_examples_for :apt_repository_recipe do
2+
before do
3+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
4+
end
25
it 'includes apt recipe' do
36
expect(chef_run).to include_recipe('apt')
47
end
@@ -11,6 +14,9 @@
1114
end
1215
end
1316
shared_examples_for :yum_repository_recipe do
17+
before do
18+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
19+
end
1420
it 'includes yum recipe' do
1521
expect(chef_run).to include_recipe('yum')
1622
end
@@ -22,6 +28,9 @@
2228
end
2329
end
2430
shared_examples_for :agent_linux_install do
31+
before do
32+
stub_command("grep -q '# Provides: go-agent$' /etc/init.d/go-agent").and_return(false)
33+
end
2534
it 'includes java recipe' do
2635
expect(chef_run).to include_recipe('java::default')
2736
end

0 commit comments

Comments
 (0)