vanagon 0.19.1 → 0.22.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +27 -2
  3. data/lib/vanagon/cli/list.rb +12 -1
  4. data/lib/vanagon/cli/ship.rb +1 -17
  5. data/lib/vanagon/component.rb +3 -2
  6. data/lib/vanagon/component/dsl.rb +21 -15
  7. data/lib/vanagon/component/source.rb +1 -0
  8. data/lib/vanagon/component/source/git.rb +30 -5
  9. data/lib/vanagon/engine/pooler.rb +4 -1
  10. data/lib/vanagon/platform.rb +32 -0
  11. data/lib/vanagon/platform/defaults/debian-10-amd64.rb +11 -0
  12. data/lib/vanagon/platform/defaults/debian-11-amd64.rb +11 -0
  13. data/lib/vanagon/platform/defaults/debian-8-amd64.rb +12 -0
  14. data/lib/vanagon/platform/defaults/debian-8-i386.rb +12 -0
  15. data/lib/vanagon/platform/defaults/debian-9-amd64.rb +12 -0
  16. data/lib/vanagon/platform/defaults/debian-9-i386.rb +12 -0
  17. data/lib/vanagon/platform/defaults/el-6-i386.rb +11 -0
  18. data/lib/vanagon/platform/defaults/el-6-x86_64.rb +11 -0
  19. data/lib/vanagon/platform/defaults/el-7-aarch64.rb +13 -0
  20. data/lib/vanagon/platform/defaults/el-7-x86_64.rb +11 -0
  21. data/lib/vanagon/platform/defaults/el-8-aarch64.rb +10 -0
  22. data/lib/vanagon/platform/defaults/el-8-x86_64.rb +10 -0
  23. data/lib/vanagon/platform/defaults/fedora-30-x86_64.rb +11 -0
  24. data/lib/vanagon/platform/defaults/fedora-31-x86_64.rb +11 -0
  25. data/lib/vanagon/platform/defaults/fedora-32-x86_64.rb +11 -0
  26. data/lib/vanagon/platform/defaults/fedora-34-x86_64.rb +17 -0
  27. data/lib/vanagon/platform/defaults/osx-10.14-x86_64.rb +21 -0
  28. data/lib/vanagon/platform/defaults/osx-10.15-x86_64.rb +21 -0
  29. data/lib/vanagon/platform/defaults/osx-11-x86_64.rb +20 -0
  30. data/lib/vanagon/platform/defaults/redhatfips-7-x86_64.rb +11 -0
  31. data/lib/vanagon/platform/defaults/sles-12-x86_64.rb +11 -0
  32. data/lib/vanagon/platform/defaults/sles-15-x86_64.rb +10 -0
  33. data/lib/vanagon/platform/defaults/solaris-11-i386.rb +9 -0
  34. data/lib/vanagon/platform/defaults/solaris-11-sparc.rb +10 -0
  35. data/lib/vanagon/platform/defaults/ubuntu-16.04-amd64.rb +12 -0
  36. data/lib/vanagon/platform/defaults/ubuntu-16.04-i386.rb +12 -0
  37. data/lib/vanagon/platform/defaults/ubuntu-18.04-amd64.rb +12 -0
  38. data/lib/vanagon/platform/defaults/ubuntu-20.04-aarch64.rb +11 -0
  39. data/lib/vanagon/platform/defaults/ubuntu-20.04-amd64.rb +11 -0
  40. data/lib/vanagon/platform/dsl.rb +30 -2
  41. data/lib/vanagon/platform/osx.rb +9 -0
  42. data/lib/vanagon/platform/windows.rb +3 -21
  43. data/lib/vanagon/project.rb +5 -1
  44. data/lib/vanagon/utilities.rb +1 -0
  45. data/lib/vanagon/utilities/extra_files_signer.rb +42 -0
  46. data/resources/deb/postinst.erb +24 -13
  47. data/resources/deb/postrm.erb +9 -6
  48. data/resources/deb/prerm.erb +18 -8
  49. data/resources/rpm/project.spec.erb +11 -11
  50. data/spec/lib/vanagon/cli_spec.rb +59 -8
  51. data/spec/lib/vanagon/component/dsl_spec.rb +45 -8
  52. data/spec/lib/vanagon/component/source/git_spec.rb +17 -4
  53. data/spec/lib/vanagon/component_spec.rb +12 -0
  54. data/spec/lib/vanagon/platform_spec.rb +80 -0
  55. data/spec/lib/vanagon/utilities/extra_files_signer_spec.rb +123 -0
  56. data/spec/lib/vanagon/utilities_spec.rb +4 -1
  57. metadata +62 -30
@@ -351,10 +351,14 @@ class Vanagon
351
351
  # will return nil
352
352
  #
353
353
  # @param [string] name of service to grab
354
- # @return [@component.service obj] specific service
354
+ # @return [@component.service obj] specific service, or array of services
355
+ # if there's more than one
355
356
  def get_service(name)
356
357
  components.each do |component|
357
358
  if component.name == name
359
+ if component.service.size == 1
360
+ return component.service.first
361
+ end
358
362
  return component.service
359
363
  end
360
364
  end
@@ -10,6 +10,7 @@ require 'timeout'
10
10
  require 'English'
11
11
  require 'vanagon/extensions/string'
12
12
  require 'vanagon/logger'
13
+ require 'vanagon/utilities/extra_files_signer'
13
14
 
14
15
  class Vanagon
15
16
  module Utilities
@@ -0,0 +1,42 @@
1
+ class Vanagon
2
+ module Utilities
3
+ module ExtraFilesSigner
4
+ class << self
5
+ def commands(project, mktemp, source_dir) # rubocop:disable Metrics/AbcSize
6
+ tempdir = nil
7
+ commands = []
8
+ # Skip signing extra files if logging into the signing_host fails
9
+ # This enables things like CI being able to sign the additional files,
10
+ # but locally triggered builds by developers who don't have access to
11
+ # the signing host just print a message and skip the signing.
12
+ Vanagon::Utilities.retry_with_timeout(3, 5) do
13
+ tempdir = Vanagon::Utilities::remote_ssh_command("#{project.signing_username}@#{project.signing_hostname}", "#{mktemp} 2>/dev/null", return_command_output: true)
14
+ end
15
+
16
+ project.extra_files_to_sign.each do |file|
17
+ file_location = File.join(tempdir, File.basename(file))
18
+ local_source_path = File.join('$(tempdir)', source_dir, file)
19
+ remote_host = "#{project.signing_username}@#{project.signing_hostname}"
20
+ remote_destination_path = "#{remote_host}:#{tempdir}"
21
+ remote_file_location = "#{remote_host}:#{file_location}"
22
+ extra_flags = ''
23
+ extra_flags = '--extended-attributes' if project.platform.is_macos?
24
+
25
+ commands += [
26
+ "rsync -e '#{Vanagon::Utilities.ssh_command}' --verbose --recursive --hard-links --links --no-perms --no-owner --no-group #{extra_flags} #{local_source_path} #{remote_destination_path}",
27
+ "#{Vanagon::Utilities.ssh_command} #{remote_host} #{project.signing_command} #{file_location}",
28
+ "rsync -e '#{Vanagon::Utilities.ssh_command}' --verbose --recursive --hard-links --links --no-perms --no-owner --no-group #{extra_flags} #{remote_file_location} #{local_source_path}"
29
+ ]
30
+ end
31
+
32
+ commands
33
+ rescue RuntimeError
34
+ require 'vanagon/logger'
35
+ VanagonLogger.error "Unable to connect to #{project.signing_username}@#{project.signing_hostname}, skipping signing extra files: #{project.extra_files_to_sign.join(',')}"
36
+ raise if ENV['VANAGON_FORCE_SIGNING']
37
+ []
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -2,18 +2,29 @@
2
2
  <%- get_services.each do |service| -%>
3
3
  # switch based on systemd vs systemv
4
4
  #
5
- <%- if @platform.servicetype == "systemd" -%>
6
- if [ -z "$2" ]; then
7
- systemctl enable <%= service.name %>.service >/dev/null || :
8
- else
9
- systemctl try-restart <%= service.name %>.service >/dev/null || :
5
+ <%- if service.init_system.nil? || service.init_system.eql?('systemd') -%>
6
+ if [ -f '/proc/1/comm' ]; then
7
+ init_comm=`cat /proc/1/comm`
8
+ if [ "$init_comm" = "systemd" ]; then
9
+ if [ -z "$2" ]; then
10
+ systemctl enable <%= service.name %>.service >/dev/null || :
11
+ else
12
+ systemctl try-restart <%= service.name %>.service >/dev/null || :
13
+ fi
14
+ fi
10
15
  fi
11
- <%- elsif @platform.servicetype == "sysv" -%>
12
- if [ -x "<%= service.service_file %>" ]; then
13
- update-rc.d <%= service.name %> defaults > /dev/null
16
+ <%- end -%>
17
+ <%- if service.init_system.nil? || service.init_system.eql?('sysv') -%>
18
+ if [ -f '/proc/1/comm' ]; then
19
+ init_comm=`cat /proc/1/comm`
20
+ if [ "$init_comm" = "init" ]; then
21
+ if [ -x "<%= service.service_file %>" ]; then
22
+ update-rc.d <%= service.name %> defaults > /dev/null
14
23
 
15
- if [ -n "$2" ]; then
16
- invoke-rc.d <%= service.name %> condrestart || true
24
+ if [ -n "$2" ]; then
25
+ invoke-rc.d <%= service.name %> condrestart || true
26
+ fi
27
+ fi
17
28
  fi
18
29
  fi
19
30
  <%- end -%>
@@ -27,17 +38,17 @@ fi
27
38
 
28
39
  # Set up any specific permissions needed...
29
40
  <%- (get_directories + get_configfiles + get_files).select { |pathname| pathname.has_overrides? }.uniq.each do |file_or_directory| -%>
30
- <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}'" if file_or_directory.mode %>
41
+ <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}' &>/dev/null ||:" if file_or_directory.mode %>
31
42
  <%- if file_or_directory.owner -%>
32
43
  if getent passwd '<%= file_or_directory.owner %>' &> /dev/null; then
33
- chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>'
44
+ chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>' &>/dev/null ||:
34
45
  else
35
46
  echo "Error updating '<%= file_or_directory.path %>': user '<%= file_or_directory.owner %>' does not exist."
36
47
  fi
37
48
  <%- end -%>
38
49
  <%- if file_or_directory.group -%>
39
50
  if getent group '<%= file_or_directory.group %>' &> /dev/null; then
40
- chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>'
51
+ chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>' &>/dev/null ||:
41
52
  else
42
53
  echo "Error updating '<%= file_or_directory.path %>': group '<%= file_or_directory.group %>' does not exist."
43
54
  fi
@@ -13,11 +13,14 @@ fi
13
13
  <%- get_services.each do |service| -%>
14
14
  # switch based on systemd vs systemv
15
15
  #
16
- <%- if @platform.servicetype == "systemd" -%>
17
- systemctl daemon-reload >/dev/null 2>&1 || :
18
- <%- elsif @platform.servicetype == "sysv" -%>
19
- if [ "$1" = "purge" ] ; then
20
- update-rc.d <%= service.name %> remove > /dev/null
16
+ if [ -f '/proc/1/comm' ]; then
17
+ init_comm=`cat /proc/1/comm`
18
+ if [ "$init_comm" = "systemd" ]; then
19
+ systemctl daemon-reload >/dev/null 2>&1 || :
20
+ else
21
+ if [ "$1" = "purge" ] ; then
22
+ update-rc.d <%= service.name %> remove > /dev/null
23
+ fi
24
+ fi
21
25
  fi
22
- <%- end -%>
23
26
  <%- end -%>
@@ -13,15 +13,25 @@ fi
13
13
  <%- get_services.each do |service| -%>
14
14
  # switch based on systemd vs systemv
15
15
  #
16
- <%- if @platform.servicetype == "systemd" -%>
17
- if [ "$1" = remove ]; then
18
- systemctl --no-reload disable <%= service.name %>.service > /dev/null 2>&1 || :
19
- systemctl stop <%= service.name %>.service > /dev/null 2>&1 || :
16
+ <%- if service.init_system.nil? || service.init_system.eql?('systemd') -%>
17
+ if [ -f '/proc/1/comm' ]; then
18
+ init_comm=`cat /proc/1/comm`
19
+ if [ "$init_comm" = "systemd" ]; then
20
+ if [ "$1" = remove ]; then
21
+ systemctl --no-reload disable <%= service.name %>.service > /dev/null 2>&1 || :
22
+ systemctl stop <%= service.name %>.service > /dev/null 2>&1 || :
23
+ fi
24
+ fi
20
25
  fi
21
-
22
- <%- elsif @platform.servicetype == "sysv" -%>
23
- if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
24
- invoke-rc.d <%= service.name %> stop || true
26
+ <%- end -%>
27
+ <%- if service.init_system.nil? || service.init_system.eql?('sysv') -%>
28
+ if [ -f '/proc/1/comm' ]; then
29
+ init_comm=`cat /proc/1/comm`
30
+ if [ "$init_comm" = "init" ]; then
31
+ if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
32
+ invoke-rc.d <%= service.name %> stop || true
33
+ fi
34
+ fi
25
35
  fi
26
36
  <%- end -%>
27
37
  <%- end -%>
@@ -98,7 +98,7 @@ Requires(post): /bin/touch
98
98
  <%- end -%>
99
99
 
100
100
  <%- if has_services? -%>
101
- <%- if @platform.servicetype == "systemd" -%>
101
+ <%- if @platform.get_service_types.include?("systemd") -%>
102
102
  <%- if @platform.is_sles? -%>
103
103
  BuildRequires: systemd
104
104
  %{?systemd_requires}
@@ -108,7 +108,7 @@ Requires(post): systemd
108
108
  Requires(preun): systemd
109
109
  Requires(postun): systemd
110
110
  <%- end -%>
111
- <%- elsif @platform.servicetype == "sysv" -%>
111
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
112
112
  <%- if @platform.is_sles? -%>
113
113
  Requires: aaa_base
114
114
  <%- elsif @platform.is_linux? -%>
@@ -256,15 +256,15 @@ fi
256
256
  <%- get_services.each do |service| -%>
257
257
  # switch based on systemd vs systemv vs smf vs aix
258
258
  #
259
- <%- if @platform.servicetype == "systemd" -%>
259
+ <%- if @platform.get_service_types.include?("systemd") -%>
260
260
  <%- if @platform.is_sles? -%>
261
261
  %service_add_post <%= service.name %>.service
262
262
  <%- else -%>
263
263
  %systemd_post <%= service.name %>.service
264
264
  <%- end -%>
265
- <%- elsif @platform.servicetype == "sysv" -%>
265
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
266
266
  chkconfig --add <%= service.name %> >/dev/null 2>&1 || :
267
- <%- elsif @platform.servicetype == "aix" -%>
267
+ <%- elsif @platform.get_service_types.include?("aix") -%>
268
268
  if /usr/bin/lssrc -s <%= service.name -%> > /dev/null 2>&1; then
269
269
  /usr/bin/chssys -s <%= service.name -%> -p <%= service.service_command -%> -w 7 -S -n 15 -f 9 > /dev/null 2>&1 || :
270
270
  else
@@ -305,17 +305,17 @@ fi
305
305
  <%- get_services.each do |service| -%>
306
306
  # switch based on systemd vs systemv vs smf vs aix
307
307
  #
308
- <%- if @platform.servicetype == "systemd" -%>
308
+ <%- if @platform.get_service_types.include?("systemd") -%>
309
309
  <%- if @platform.is_sles? -%>
310
310
  %service_del_postun <%= service.name %>.service
311
311
  <%- else -%>
312
312
  %systemd_postun_with_restart <%= service.name %>.service
313
313
  <%- end -%>
314
- <%- elsif @platform.servicetype == "sysv" -%>
314
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
315
315
  if [ "$1" -eq 1 ]; then
316
316
  /sbin/service <%= service.name %> condrestart || :
317
317
  fi
318
- <%- elsif @platform.servicetype == "aix" -%>
318
+ <%- elsif @platform.get_service_types.include?("aix") -%>
319
319
  if [ "$1" -eq 0 ]; then
320
320
  /usr/bin/rmssys -s <%= service.name -%> > /dev/null 2>&1 || :
321
321
  /usr/sbin/rmitab <%= service.name -%> > /dev/null 2>&1 || :
@@ -336,18 +336,18 @@ if [ "$1" -eq 0 ] ; then
336
336
  fi
337
337
 
338
338
  <%- get_services.each do |service| -%>
339
- <%- if @platform.servicetype == "systemd" -%>
339
+ <%- if @platform.get_service_types.include?("systemd") -%>
340
340
  <%- if @platform.is_sles? -%>
341
341
  %service_del_preun <%= service.name %>.service
342
342
  <%- else -%>
343
343
  %systemd_preun <%= service.name %>.service
344
344
  <%- end -%>
345
- <%- elsif @platform.servicetype == "sysv" -%>
345
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
346
346
  if [ "$1" -eq 0 ]; then
347
347
  /sbin/service <%= service.name %> stop >/dev/null 2>&1 || :
348
348
  chkconfig --del <%= service.name %> || :
349
349
  fi
350
- <%- elsif @platform.servicetype == "aix" -%>
350
+ <%- elsif @platform.get_service_types.include?("aix") -%>
351
351
  # stop the service only on a real uninstall, not on upgrades
352
352
  if [ "$1" -eq 0 ] ; then
353
353
  /usr/bin/stopsrc -s <%= service.name -%> > /dev/null 2>&1 || :
@@ -93,13 +93,14 @@ describe Vanagon::CLI::List do
93
93
  end
94
94
 
95
95
  describe "#run" do
96
+ let(:defaults){ ['def1', 'def2', 'def3'] }
96
97
  let(:projects){ ['foo', 'bar', 'baz'] }
97
98
  let(:platforms){ ['1', '2', '3'] }
98
99
  let(:output_both){
99
100
  "- Projects
100
- foo
101
101
  bar
102
102
  baz
103
+ foo
103
104
 
104
105
  - Platforms
105
106
  1
@@ -115,6 +116,9 @@ baz
115
116
  expect(Dir).to receive(:exist?)
116
117
  .with("#{File.join(Dir.pwd, 'configs', 'projects')}")
117
118
  .and_return(true)
119
+ expect(Dir).to receive(:children)
120
+ .with("#{File.join(Dir.pwd, 'lib', 'vanagon' ,'cli', '..', 'platform', 'defaults')}")
121
+ .and_return(defaults)
118
122
  expect(Dir).to receive(:children)
119
123
  .with("#{File.join(Dir.pwd, 'configs', 'projects')}")
120
124
  .and_return(projects)
@@ -124,28 +128,32 @@ baz
124
128
  end
125
129
  let(:options_empty) { {
126
130
  nil=>false,
127
- :configdir=>"#{Dir.pwd}/configs",
131
+ :configdir=>"#{Dir.pwd}/configs",
132
+ :defaults=>false,
128
133
  :platforms=>false,
129
134
  :projects=>false,
130
135
  :use_spaces=>false
131
136
  } }
132
137
  let(:options_platforms_only) { {
133
138
  nil=>false,
134
- :configdir=>"#{Dir.pwd}/configs",
139
+ :configdir=>"#{Dir.pwd}/configs",
140
+ :defaults=>false,
135
141
  :platforms=>true,
136
142
  :projects=>false,
137
143
  :use_spaces=>false
138
144
  } }
139
145
  let(:options_projects_only) { {
140
146
  nil=>false,
141
- :configdir=>"#{Dir.pwd}/configs",
147
+ :configdir=>"#{Dir.pwd}/configs",
148
+ :defaults=>false,
142
149
  :platforms=>false,
143
150
  :projects=>true,
144
151
  :use_spaces=>false
145
152
  } }
146
153
  let(:options_space_only) { {
147
154
  nil=>false,
148
- :configdir=>"#{Dir.pwd}/configs",
155
+ :configdir=>"#{Dir.pwd}/configs",
156
+ :defaults=>false,
149
157
  :platforms=>false,
150
158
  :projects=>false,
151
159
  :use_spaces=>true
@@ -159,7 +167,7 @@ baz
159
167
 
160
168
  let(:output_both_space){
161
169
  "- Projects
162
- foo bar baz
170
+ bar baz foo
163
171
 
164
172
  - Platforms
165
173
  1 2 3
@@ -186,9 +194,9 @@ foo bar baz
186
194
 
187
195
  let(:output_projects){
188
196
  "- Projects
189
- foo
190
197
  bar
191
198
  baz
199
+ foo
192
200
  "
193
201
  }
194
202
  it "outputs only projects when projects is passed" do
@@ -202,14 +210,19 @@ baz
202
210
  let(:options_configdir) { {
203
211
  nil=>false,
204
212
  :configdir=> '/configs',
213
+ :defaults=>false,
205
214
  :platforms=>false,
206
215
  :projects=>false,
207
- :use_spaces=>false} }
216
+ :use_spaces=>false
217
+ } }
208
218
  it "it successfully takes the configs directory" do
209
219
  expect(Dir).to receive(:exist?).with('/configs' + '/platforms')
210
220
  .and_return(true)
211
221
  expect(Dir).to receive(:exist?).with('/configs' + '/projects')
212
222
  .and_return(true)
223
+ expect(Dir).to receive(:children)
224
+ .with("#{File.join(Dir.pwd, 'lib', 'vanagon' ,'cli', '..', 'platform', 'defaults')}")
225
+ .and_return(defaults)
213
226
  expect(Dir).to receive(:children).with('/configs' + '/projects')
214
227
  .and_return(projects)
215
228
  expect(Dir).to receive(:children).with('/configs' + '/platforms')
@@ -219,5 +232,43 @@ baz
219
232
  end.to output(output_both).to_stdout
220
233
  end
221
234
  end
235
+
236
+ context "spec to determine vanagon defaults" do
237
+ let(:options_default_platforms) { {
238
+ nil=>false,
239
+ :configdir=>"#{Dir.pwd}/configs",
240
+ :defaults=>true,
241
+ :platforms=>false,
242
+ :projects=>false,
243
+ :use_spaces=>false
244
+ } }
245
+ let(:output_defaults){
246
+ "- Defaults
247
+ def1
248
+ def2
249
+ def3
250
+ "
251
+ }
252
+ it "lists the vanagon defaults" do
253
+ expect(Dir).to receive(:exist?)
254
+ .with("#{File.join(Dir.pwd, 'configs', 'platforms')}")
255
+ .and_return(true)
256
+ expect(Dir).to receive(:exist?)
257
+ .with("#{File.join(Dir.pwd, 'configs', 'projects')}")
258
+ .and_return(true)
259
+ expect(Dir).to receive(:children)
260
+ .with("#{File.join(Dir.pwd, 'lib', 'vanagon' ,'cli', '..', 'platform', 'defaults')}")
261
+ .and_return(defaults)
262
+ expect(Dir).to receive(:children)
263
+ .with("#{File.join(Dir.pwd, 'configs', 'projects')}")
264
+ .and_return(projects)
265
+ expect(Dir).to receive(:children)
266
+ .with("#{File.join(Dir.pwd, 'configs', 'platforms')}")
267
+ .and_return(platforms)
268
+ expect do
269
+ cli.run(options_default_platforms)
270
+ end.to output(output_defaults).to_stdout
271
+ end
272
+ end
222
273
  end
223
274
  end
@@ -34,6 +34,16 @@ end" }
34
34
  plat._platform
35
35
  }
36
36
 
37
+ let (:dummy_platform_sysv_or_systemd) {
38
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
39
+ plat.instance_eval("platform 'debian-8-x86_64' do |plat|
40
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
41
+ plat.servicetype 'systemd', servicedir: '/usr/lib/systemd/system'
42
+ plat.defaultdir '/etc/default'
43
+ end")
44
+ plat._platform
45
+ }
46
+
37
47
  let (:dummy_platform_smf) {
38
48
  plat = Vanagon::Platform::DSL.new('debian-11-i386')
39
49
  plat.instance_eval("platform 'debian-11-i386' do |plat|
@@ -575,15 +585,15 @@ end" }
575
585
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
576
586
 
577
587
  # The component should now have a service registered
578
- expect(comp._component.service.name).to eq('service-test')
588
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
579
589
  end
580
590
 
581
591
  it 'reads from a file when the OS is AIX for services' do
582
592
  comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_aix)
583
593
  comp.install_service('spec/fixtures/component/mcollective.service', nil, 'mcollective')
584
- expect(comp._component.service.name).to eq('mcollective')
585
- expect(comp._component.service.service_command).to include('/opt/puppetlabs/puppet/bin/ruby')
586
- expect(comp._component.service.service_command).not_to include("\n")
594
+ expect(comp._component.service.flat_map(&:name).compact).to include('mcollective')
595
+ expect(comp._component.service.flat_map(&:service_command).compact.first).to include('/opt/puppetlabs/puppet/bin/ruby')
596
+ expect(comp._component.service.flat_map(&:service_command).compact.first).not_to include("\n")
587
597
  end
588
598
 
589
599
  it 'adds the correct command to the install for the component for systemd platforms' do
@@ -602,7 +612,34 @@ end" }
602
612
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
603
613
 
604
614
  # The component should now have a service registered
605
- expect(comp._component.service.name).to eq('service-test')
615
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
616
+ end
617
+
618
+ it 'adds the correct command when installing both systemd and sysv' do
619
+ comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_sysv_or_systemd)
620
+ comp.install_service('component-client.init', 'component-client.sysconfig', init_system: 'sysv')
621
+ comp.install_service('component-client.service', 'component-client.sysconfig', init_system: 'systemd')
622
+ # Look for servicedir creation and copy - sysv
623
+ expect(comp._component.install).to include("install -d '/etc/init.d'")
624
+ expect(comp._component.install).to include("cp -p 'component-client.init' '/etc/init.d/service-test'")
625
+
626
+ # Look for servicedir creation and copy - systemd
627
+ expect(comp._component.install).to include("install -d '/usr/lib/systemd/system'")
628
+ expect(comp._component.install).to include("cp -p 'component-client.service' '/usr/lib/systemd/system/service-test.service'")
629
+
630
+ # Look for defaultdir creation and copy
631
+ expect(comp._component.install).to include("install -d '/etc/default'")
632
+ expect(comp._component.install).to include("cp -p 'component-client.sysconfig' '/etc/default/service-test'")
633
+
634
+ # Look for files and configfiles - sysv
635
+ expect(comp._component.configfiles).to include(Vanagon::Common::Pathname.configfile('/etc/default/service-test'))
636
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
637
+
638
+ # Look for files and configfiles - systemd
639
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
640
+
641
+ # The component should now have a service registered
642
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
606
643
  end
607
644
 
608
645
  it 'adds the correct command to the install for smf services using a service_type' do
@@ -621,7 +658,7 @@ end" }
621
658
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/network/service-test.xml', mode: '0644'))
622
659
 
623
660
  # The component should now have a service registered
624
- expect(comp._component.service.name).to eq('service-test')
661
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
625
662
  end
626
663
 
627
664
  it 'adds the correct command to the install for smf services' do
@@ -640,7 +677,7 @@ end" }
640
677
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/service-test.xml', mode: '0644'))
641
678
 
642
679
  # The component should now have a service registered
643
- expect(comp._component.service.name).to eq('service-test')
680
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
644
681
  end
645
682
 
646
683
  it 'installs the file as a link when link_target is specified' do
@@ -661,7 +698,7 @@ end" }
661
698
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test'))
662
699
 
663
700
  # The component should now have a service registered
664
- expect(comp._component.service.name).to eq('service-test')
701
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
665
702
  end
666
703
  end
667
704