vanagon 0.15.8 → 0.15.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b888b83c086532fafab1b26a95612b9aec0c1449
4
- data.tar.gz: 0f83ce37ec9de2f7a2d300a39c4c13be2fa31e5e
3
+ metadata.gz: d495893440327f099e0b318c1d7e5966a7c186e6
4
+ data.tar.gz: c626b8ca9a1e48dbe0d08d6bc3857e7226223233
5
5
  SHA512:
6
- metadata.gz: cb032a8851cf6ca13d90d6b68093d91fc0bd0b9bb3750f426a77d34471697cee71f98cffa8783da7bf91180e814f4ac0fbb4b821585e02c4802353a3d5b6e09e
7
- data.tar.gz: 50c1814cc34f4be7182b4cce7b41c8852041de4b8a9fa7c8c9775195287e70db9ae9d3557a4605f82d38bebcbba6e4b2cc791264004b6c9034bf979a9907ea30
6
+ metadata.gz: 78aee1207d6b21ac432bf07bda73f9491d1b19ae80271b545fad51e1cffcf27e8b3f5adba2a3b70bf1713c555feb5000a6b8f50a0f40b0fc184d9e49b3c21127
7
+ data.tar.gz: b81d5f2cf49c8de57cbbc4d5b952eaecaed7af319a03b500c9aaa1c001b91cff03584e20976470caf84dccae6858cf1572dad59e2f26553ee5c1c1939b00a51f
@@ -175,6 +175,7 @@ class Vanagon
175
175
  @preremove_actions = []
176
176
  @postremove_actions = []
177
177
  @install_only = false
178
+ @service = []
178
179
  end
179
180
 
180
181
  # Adds the given file to the list of files and returns @files.
@@ -163,36 +163,40 @@ class Vanagon
163
163
  #
164
164
  # @param service_file [String] path to the service file relative to the source
165
165
  # @param default_file [String] path to the default file relative to the source
166
- # @param service_name [String] name of the service
167
- # @param service_type [String] type of the service (network, application, system, etc)
168
- # @param link_target [String] executable service file should be linked to
169
- def install_service(service_file, default_file = nil, service_name = @component.name, service_type: nil, link_target: nil) # rubocop:disable Metrics/AbcSize
170
- case @component.platform.servicetype
166
+ # @param options optional extra parameters
167
+ # service_name [String] name of the service
168
+ # service_type [String] type of the service (network, application, system, etc)
169
+ # link_target [String] executable service file should be linked to
170
+ def install_service(service_file, default_file = nil, service_name = @component.name, **options) # rubocop:disable Metrics/AbcSize
171
+ init_system = options[:init_system] || @component.platform.servicetype
172
+ servicedir = @component.platform.get_service_dir(init_system)
173
+
174
+ case init_system
171
175
  when "sysv"
172
- target_service_file = File.join(@component.platform.servicedir, service_name)
176
+ target_service_file = File.join(servicedir, service_name)
173
177
  target_default_file = File.join(@component.platform.defaultdir, service_name)
174
178
  target_mode = '0755'
175
179
  default_mode = '0644'
176
180
  when "systemd"
177
- target_service_file = File.join(@component.platform.servicedir, "#{service_name}.service")
181
+ target_service_file = File.join(servicedir, "#{service_name}.service")
178
182
  target_default_file = File.join(@component.platform.defaultdir, service_name)
179
183
  target_mode = '0644'
180
184
  default_mode = '0644'
181
185
  when "launchd"
182
- target_service_file = File.join(@component.platform.servicedir, "#{service_name}.plist")
186
+ target_service_file = File.join(servicedir, "#{service_name}.plist")
183
187
  target_mode = '0644'
184
188
  default_mode = '0644'
185
189
  when "smf"
186
- target_service_file = File.join(@component.platform.servicedir, service_type.to_s, "#{service_name}.xml")
190
+ target_service_file = File.join(servicedir, options[:service_type].to_s, "#{service_name}.xml")
187
191
  target_default_file = File.join(@component.platform.defaultdir, service_name)
188
192
  target_mode = '0644'
189
193
  default_mode = '0755'
190
194
  when "aix"
191
- @component.service = OpenStruct.new(:name => service_name, :service_command => File.read(service_file).chomp)
195
+ @component.service << OpenStruct.new(:name => service_name, :service_command => File.read(service_file).chomp)
192
196
  # Return here because there is no file to install, just a string read in
193
197
  return
194
198
  when "windows"
195
- @component.service = OpenStruct.new(\
199
+ @component.service << OpenStruct.new(\
196
200
  :bindir_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '').upcase}BINDIR", \
197
201
  :service_file => service_file, \
198
202
  :component_group_id => "#{service_name.gsub(/[^A-Za-z0-9]/, '')}Component"\
@@ -200,13 +204,13 @@ class Vanagon
200
204
  # return here as we are just collecting the name of the service file to put into the harvest filter list.
201
205
  return
202
206
  else
203
- fail "Don't know how to install the #{@component.platform.servicetype}. Please teach #install_service how to do this."
207
+ fail "Don't know how to install the #{init_system}. Please teach #install_service how to do this."
204
208
  end
205
209
 
206
210
  # Install the service and default files
207
- if link_target
208
- install_file(service_file, link_target, mode: target_mode)
209
- link link_target, target_service_file
211
+ if options[:link_target]
212
+ install_file(service_file, options[:link_target], mode: target_mode)
213
+ link options[:link_target], target_service_file
210
214
  else
211
215
  install_file(service_file, target_service_file, mode: target_mode)
212
216
  end
@@ -217,7 +221,7 @@ class Vanagon
217
221
  end
218
222
 
219
223
  # Register the service for use in packaging
220
- @component.service = OpenStruct.new(:name => service_name, :service_file => target_service_file, :type => service_type)
224
+ @component.service << OpenStruct.new(:name => service_name, :service_file => target_service_file, :type => options[:service_type])
221
225
  end
222
226
 
223
227
  # Copies a file from source to target during the install phase of the component
@@ -32,6 +32,9 @@ class Vanagon
32
32
  # Where does a given platform expect to find init scripts/service files?
33
33
  # e.g. /etc/init.d, /usr/lib/systemd/system
34
34
  attr_accessor :servicedir
35
+ # Array of OpenStructs containing the servicetype and the corresponding
36
+ # servicedir
37
+ attr_accessor :servicetypes
35
38
  # Where does a given platform's init system expect to find
36
39
  # something resembling 'defaults' files. Most likely to apply
37
40
  # to Linux systems that use SysV-ish, upstart, or systemd init systems.
@@ -239,6 +242,7 @@ class Vanagon
239
242
  # Our first attempt at defining metadata about a platform
240
243
  @cross_compiled ||= false
241
244
  @valid_operators ||= ['<', '>', '<=', '>=', '=']
245
+ @servicetypes = []
242
246
  end
243
247
 
244
248
  def shell # rubocop:disable Lint/DuplicateMethods
@@ -530,5 +534,33 @@ class Vanagon
530
534
  def validate_operator(operator_string)
531
535
  valid_operators.include?(operator_string)
532
536
  end
537
+
538
+ # Get all configured service types (added through plat.servicetype)
539
+ # @return array of service types, empty array if none have been configured
540
+ def get_service_types
541
+ if @servicetypes.any?
542
+ @servicetypes.flat_map(&:servicetype).compact
543
+ elsif @servicetype
544
+ [@servicetype]
545
+ else
546
+ []
547
+ end
548
+ end
549
+
550
+ # Get configured service dir (added through plat.servicedir, or plat.servicetype 'foo', servicedir: 'bar')
551
+ # @param servicetype the service type you want the service dir for (optional)
552
+ # @raises VanagonError if more than one service dir is found
553
+ def get_service_dir(servicetype = '')
554
+ if @servicetypes.empty?
555
+ return @servicedir
556
+ end
557
+ servicedir = @servicetypes.select { |s| s.servicetype.include?(servicetype) }.flat_map(&:servicedir).compact
558
+
559
+ if servicedir.size > 1
560
+ raise Vanagon::Error, "You can only have one service dir for each service type. Found '#{servicedir.join(',')}' for service type #{servicetype}"
561
+ end
562
+
563
+ servicedir.first
564
+ end
533
565
  end
534
566
  end
@@ -9,6 +9,7 @@ require 'vanagon/platform/solaris_10'
9
9
  require 'vanagon/platform/solaris_11'
10
10
  require 'vanagon/platform/windows'
11
11
  require 'securerandom'
12
+ require 'ostruct'
12
13
  require 'uri'
13
14
 
14
15
  class Vanagon
@@ -218,6 +219,11 @@ class Vanagon
218
219
  # @param dir [String] Directory where service files live on the platform
219
220
  def servicedir(dir)
220
221
  @platform.servicedir = dir
222
+
223
+ # Add to the servicetypes array if we haven't already
224
+ if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
225
+ @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
226
+ end
221
227
  end
222
228
 
223
229
  # Set the directory where default or sysconfig files live for the platform
@@ -230,8 +236,18 @@ class Vanagon
230
236
  # Set the servicetype for the platform so that services can be installed correctly.
231
237
  #
232
238
  # @param type [String] service type for the platform ('sysv' for example)
233
- def servicetype(type)
234
- @platform.servicetype = type
239
+ # @param servicedir [String] service dir for this platform and service type ('/etc/init.d' for example). Optional.
240
+ def servicetype(type, servicedir: nil) # rubocop:disable Metrics/AbcSize
241
+ if servicedir
242
+ @platform.servicetypes << OpenStruct.new(:servicetype => type, :servicedir => servicedir)
243
+ else
244
+ @platform.servicetype = type
245
+ end
246
+
247
+ # Add to the servicetypes array if we haven't already
248
+ if @platform.servicetype && @platform.servicedir && @platform.servicetypes.select { |s| s.servicetype == @platform.servicetype }.empty?
249
+ @platform.servicetypes << OpenStruct.new(:servicetype => @platform.servicetype, :servicedir => @platform.servicedir)
250
+ end
235
251
  end
236
252
 
237
253
  # Set the list of possible host to perform a build on (when not using
@@ -289,10 +289,14 @@ class Vanagon
289
289
  # will return nil
290
290
  #
291
291
  # @param [string] name of service to grab
292
- # @return [@component.service obj] specific service
292
+ # @return [@component.service obj] specific service, or array of services
293
+ # if there's more than one
293
294
  def get_service(name)
294
295
  components.each do |component|
295
296
  if component.name == name
297
+ if component.service.size == 1
298
+ return component.service.first
299
+ end
296
300
  return component.service
297
301
  end
298
302
  end
@@ -2,18 +2,23 @@
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.eq?('systemd') -%>
6
+ if [ -d '/run/systemd/system' ] ; then
7
+ if [ -z "$2" ]; then
8
+ systemctl enable <%= service.name %>.service >/dev/null || :
9
+ else
10
+ systemctl try-restart <%= service.name %>.service >/dev/null || :
11
+ fi
10
12
  fi
11
- <%- elsif @platform.servicetype == "sysv" -%>
12
- if [ -x "<%= service.service_file %>" ]; then
13
- update-rc.d <%= service.name %> defaults > /dev/null
13
+ <%- end -%>
14
+ <%- if service.init_system.nil? || service.init_system.eq?('sysv') -%>
15
+ if [ ! -d '/run/systemd/system' ] ; then
16
+ if [ -x "<%= service.service_file %>" ]; then
17
+ update-rc.d <%= service.name %> defaults > /dev/null
14
18
 
15
- if [ -n "$2" ]; then
16
- invoke-rc.d <%= service.name %> condrestart || true
19
+ if [ -n "$2" ]; then
20
+ invoke-rc.d <%= service.name %> condrestart || true
21
+ fi
17
22
  fi
18
23
  fi
19
24
  <%- end -%>
@@ -27,17 +32,17 @@ fi
27
32
 
28
33
  # Set up any specific permissions needed...
29
34
  <%- (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 %>
35
+ <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}' &>/dev/null ||:" if file_or_directory.mode %>
31
36
  <%- if file_or_directory.owner -%>
32
37
  if getent passwd '<%= file_or_directory.owner %>' &> /dev/null; then
33
- chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>'
38
+ chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>' &>/dev/null ||:
34
39
  else
35
40
  echo "Error updating '<%= file_or_directory.path %>': user '<%= file_or_directory.owner %>' does not exist."
36
41
  fi
37
42
  <%- end -%>
38
43
  <%- if file_or_directory.group -%>
39
44
  if getent group '<%= file_or_directory.group %>' &> /dev/null; then
40
- chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>'
45
+ chgrp '<%= file_or_directory.group %>' '<%= file_or_directory.path %>' &>/dev/null ||:
41
46
  else
42
47
  echo "Error updating '<%= file_or_directory.path %>': group '<%= file_or_directory.group %>' does not exist."
43
48
  fi
@@ -13,11 +13,11 @@ 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 [ -d '/run/systemd/system' ] ; then
17
+ systemctl daemon-reload >/dev/null 2>&1 || :
18
+ else
19
+ if [ "$1" = "purge" ] ; then
20
+ update-rc.d <%= service.name %> remove > /dev/null
21
+ fi
21
22
  fi
22
- <%- end -%>
23
23
  <%- end -%>
@@ -13,15 +13,19 @@ 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.eq?('systemd') -%>
17
+ if [ -d '/run/systemd/system' ] ; then
18
+ if [ "$1" = remove ]; then
19
+ systemctl --no-reload disable <%= service.name %>.service > /dev/null 2>&1 || :
20
+ systemctl stop <%= service.name %>.service > /dev/null 2>&1 || :
21
+ fi
20
22
  fi
21
-
22
- <%- elsif @platform.servicetype == "sysv" -%>
23
- if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
24
- invoke-rc.d <%= service.name %> stop || true
23
+ <%- end -%>
24
+ <%- if service.init_system.nil? || service.init_system.eq?('sysv') -%>
25
+ if [ ! -d '/run/systemd/system' ] ; then
26
+ if [ -x "<%= service.service_file %>" ] && [ "$1" = remove ]; then
27
+ invoke-rc.d <%= service.name %> stop || true
28
+ fi
25
29
  fi
26
30
  <%- end -%>
27
31
  <%- end -%>
@@ -76,7 +76,7 @@ Requires(post): /bin/touch
76
76
  <%- end -%>
77
77
 
78
78
  <%- if has_services? -%>
79
- <%- if @platform.servicetype == "systemd" -%>
79
+ <%- if @platform.get_service_types.include?("systemd") -%>
80
80
  <%- if @platform.is_sles? -%>
81
81
  BuildRequires: systemd
82
82
  %{?systemd_requires}
@@ -86,7 +86,7 @@ Requires(post): systemd
86
86
  Requires(preun): systemd
87
87
  Requires(postun): systemd
88
88
  <%- end -%>
89
- <%- elsif @platform.servicetype == "sysv" -%>
89
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
90
90
  <%- if @platform.is_sles? -%>
91
91
  Requires: aaa_base
92
92
  <%- elsif @platform.is_linux? -%>
@@ -230,15 +230,15 @@ fi
230
230
  <%- get_services.each do |service| -%>
231
231
  # switch based on systemd vs systemv vs smf vs aix
232
232
  #
233
- <%- if @platform.servicetype == "systemd" -%>
233
+ <%- if @platform.get_service_types.include?("systemd") -%>
234
234
  <%- if @platform.is_sles? -%>
235
235
  %service_add_post <%= service.name %>.service
236
236
  <%- else -%>
237
237
  %systemd_post <%= service.name %>.service
238
238
  <%- end -%>
239
- <%- elsif @platform.servicetype == "sysv" -%>
239
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
240
240
  chkconfig --add <%= service.name %> >/dev/null 2>&1 || :
241
- <%- elsif @platform.servicetype == "aix" -%>
241
+ <%- elsif @platform.get_service_types.include?("aix") -%>
242
242
  if /usr/bin/lssrc -s <%= service.name -%> > /dev/null 2>&1; then
243
243
  /usr/bin/chssys -s <%= service.name -%> -p <%= service.service_command -%> -w 7 -S -n 15 -f 9 > /dev/null 2>&1 || :
244
244
  else
@@ -279,17 +279,17 @@ fi
279
279
  <%- get_services.each do |service| -%>
280
280
  # switch based on systemd vs systemv vs smf vs aix
281
281
  #
282
- <%- if @platform.servicetype == "systemd" -%>
282
+ <%- if @platform.get_service_types.include?("systemd") -%>
283
283
  <%- if @platform.is_sles? -%>
284
284
  %service_del_postun <%= service.name %>.service
285
285
  <%- else -%>
286
286
  %systemd_postun_with_restart <%= service.name %>.service
287
287
  <%- end -%>
288
- <%- elsif @platform.servicetype == "sysv" -%>
288
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
289
289
  if [ "$1" -eq 1 ]; then
290
290
  /sbin/service <%= service.name %> condrestart || :
291
291
  fi
292
- <%- elsif @platform.servicetype == "aix" -%>
292
+ <%- elsif @platform.get_service_types.include?("aix") -%>
293
293
  if [ "$1" -eq 0 ]; then
294
294
  /usr/bin/rmssys -s <%= service.name -%> > /dev/null 2>&1 || :
295
295
  /usr/sbin/rmitab <%= service.name -%> > /dev/null 2>&1 || :
@@ -310,18 +310,18 @@ if [ "$1" -eq 0 ] ; then
310
310
  fi
311
311
 
312
312
  <%- get_services.each do |service| -%>
313
- <%- if @platform.servicetype == "systemd" -%>
313
+ <%- if @platform.get_service_types.include?("systemd") -%>
314
314
  <%- if @platform.is_sles? -%>
315
315
  %service_del_preun <%= service.name %>.service
316
316
  <%- else -%>
317
317
  %systemd_preun <%= service.name %>.service
318
318
  <%- end -%>
319
- <%- elsif @platform.servicetype == "sysv" -%>
319
+ <%- elsif @platform.get_service_types.include?("sysv") -%>
320
320
  if [ "$1" -eq 0 ]; then
321
321
  /sbin/service <%= service.name %> stop >/dev/null 2>&1 || :
322
322
  chkconfig --del <%= service.name %> || :
323
323
  fi
324
- <%- elsif @platform.servicetype == "aix" -%>
324
+ <%- elsif @platform.get_service_types.include?("aix") -%>
325
325
  # stop the service only on a real uninstall, not on upgrades
326
326
  if [ "$1" -eq 0 ] ; then
327
327
  /usr/bin/stopsrc -s <%= service.name -%> > /dev/null 2>&1 || :
@@ -33,6 +33,16 @@ end" }
33
33
  plat._platform
34
34
  }
35
35
 
36
+ let (:dummy_platform_sysv_or_systemd) {
37
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
38
+ plat.instance_eval("platform 'debian-8-x86_64' do |plat|
39
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
40
+ plat.servicetype 'systemd', servicedir: '/usr/lib/systemd/system'
41
+ plat.defaultdir '/etc/default'
42
+ end")
43
+ plat._platform
44
+ }
45
+
36
46
  let (:dummy_platform_smf) {
37
47
  plat = Vanagon::Platform::DSL.new('debian-11-i386')
38
48
  plat.instance_eval("platform 'debian-11-i386' do |plat|
@@ -567,15 +577,15 @@ end" }
567
577
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
568
578
 
569
579
  # The component should now have a service registered
570
- expect(comp._component.service.name).to eq('service-test')
580
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
571
581
  end
572
582
 
573
583
  it 'reads from a file when the OS is AIX for services' do
574
584
  comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_aix)
575
585
  comp.install_service('spec/fixtures/component/mcollective.service', nil, 'mcollective')
576
- expect(comp._component.service.name).to eq('mcollective')
577
- expect(comp._component.service.service_command).to include('/opt/puppetlabs/puppet/bin/ruby')
578
- expect(comp._component.service.service_command).not_to include("\n")
586
+ expect(comp._component.service.flat_map(&:name).compact).to include('mcollective')
587
+ expect(comp._component.service.flat_map(&:service_command).compact.first).to include('/opt/puppetlabs/puppet/bin/ruby')
588
+ expect(comp._component.service.flat_map(&:service_command).compact.first).not_to include("\n")
579
589
  end
580
590
 
581
591
  it 'adds the correct command to the install for the component for systemd platforms' do
@@ -594,7 +604,34 @@ end" }
594
604
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
595
605
 
596
606
  # The component should now have a service registered
597
- expect(comp._component.service.name).to eq('service-test')
607
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
608
+ end
609
+
610
+ it 'adds the correct command when installing both systemd and sysv' do
611
+ comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_sysv_or_systemd)
612
+ comp.install_service('component-client.init', 'component-client.sysconfig', init_system: 'sysv')
613
+ comp.install_service('component-client.service', 'component-client.sysconfig', init_system: 'systemd')
614
+ # Look for servicedir creation and copy - sysv
615
+ expect(comp._component.install).to include("install -d '/etc/init.d'")
616
+ expect(comp._component.install).to include("cp -p 'component-client.init' '/etc/init.d/service-test'")
617
+
618
+ # Look for servicedir creation and copy - systemd
619
+ expect(comp._component.install).to include("install -d '/usr/lib/systemd/system'")
620
+ expect(comp._component.install).to include("cp -p 'component-client.service' '/usr/lib/systemd/system/service-test.service'")
621
+
622
+ # Look for defaultdir creation and copy
623
+ expect(comp._component.install).to include("install -d '/etc/default'")
624
+ expect(comp._component.install).to include("cp -p 'component-client.sysconfig' '/etc/default/service-test'")
625
+
626
+ # Look for files and configfiles - sysv
627
+ expect(comp._component.configfiles).to include(Vanagon::Common::Pathname.configfile('/etc/default/service-test'))
628
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
629
+
630
+ # Look for files and configfiles - systemd
631
+ expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
632
+
633
+ # The component should now have a service registered
634
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
598
635
  end
599
636
 
600
637
  it 'adds the correct command to the install for smf services using a service_type' do
@@ -613,7 +650,7 @@ end" }
613
650
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/network/service-test.xml', mode: '0644'))
614
651
 
615
652
  # The component should now have a service registered
616
- expect(comp._component.service.name).to eq('service-test')
653
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
617
654
  end
618
655
 
619
656
  it 'adds the correct command to the install for smf services' do
@@ -632,7 +669,7 @@ end" }
632
669
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/service-test.xml', mode: '0644'))
633
670
 
634
671
  # The component should now have a service registered
635
- expect(comp._component.service.name).to eq('service-test')
672
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
636
673
  end
637
674
 
638
675
  it 'installs the file as a link when link_target is specified' do
@@ -653,7 +690,7 @@ end" }
653
690
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test'))
654
691
 
655
692
  # The component should now have a service registered
656
- expect(comp._component.service.name).to eq('service-test')
693
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
657
694
  end
658
695
  end
659
696
 
@@ -1,6 +1,33 @@
1
1
  require 'vanagon/platform'
2
2
 
3
3
  describe "Vanagon::Platform" do
4
+ let(:deb_platform_just_servicedir) { "platform 'debian-test-fixture' do |plat|
5
+ plat.servicedir '/etc/init.d'
6
+ end
7
+ "}
8
+ let(:deb_platform_just_servicetype) { "platform 'debian-test-fixture' do |plat|
9
+ plat.servicetype 'sysv'
10
+ end
11
+ "}
12
+ let(:deb_platform_multi_servicetypes) { "platform 'debian-test-fixture' do |plat|
13
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
14
+ plat.servicetype 'systemd', servicedir: '/lib/systemd/system'
15
+ end
16
+ "}
17
+ let(:deb_platform_no_service) { "platform 'debian-test-fixture' do |plat|
18
+ end
19
+ "}
20
+ let(:deb_platform_servicetype) { "platform 'debian-test-fixture' do |plat|
21
+ plat.servicetype 'sysv'
22
+ plat.servicedir '/etc/init.d'
23
+ end
24
+ "}
25
+ let(:deb_platform_bad_servicedir_block) { "platform 'debian-test-fixture' do |plat|
26
+ plat.servicetype 'sysv', servicedir: '/etc/init.d'
27
+ plat.servicetype 'sysv', servicedir: '/etc/rc.d'
28
+ end
29
+ "}
30
+
4
31
  let(:platforms) do
5
32
  [
6
33
  {
@@ -172,4 +199,57 @@ describe "Vanagon::Platform" do
172
199
  end
173
200
  end
174
201
  end
202
+
203
+ describe "#get_service_type" do
204
+ it "returns plat.servicetype if that's the only thing set" do
205
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
206
+ plat.instance_eval(deb_platform_just_servicetype)
207
+ expect(plat._platform.get_service_types).to include('sysv')
208
+ end
209
+
210
+ it "returns from servicetypes if that's set" do
211
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
212
+ plat.instance_eval(deb_platform_servicetype)
213
+ expect(plat._platform.get_service_types).to include('sysv')
214
+ end
215
+
216
+ it "returns multiples if there's more than one" do
217
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
218
+ plat.instance_eval(deb_platform_multi_servicetypes)
219
+ expect(plat._platform.get_service_types).to include('sysv')
220
+ expect(plat._platform.get_service_types).to include('systemd')
221
+ end
222
+
223
+ it "returns an empty array if nothing is set" do
224
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
225
+ plat.instance_eval(deb_platform_no_service)
226
+ expect(plat._platform.get_service_types.size).to eq(0)
227
+ end
228
+ end
229
+
230
+ describe "#get_service_dir" do
231
+ it "returns plat.servicedir if that's the only thing set" do
232
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
233
+ plat.instance_eval(deb_platform_just_servicedir)
234
+ expect(plat._platform.get_service_dir).to eq('/etc/init.d')
235
+ end
236
+
237
+ it "returns servicedirs set via servicetype" do
238
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
239
+ plat.instance_eval(deb_platform_servicetype)
240
+ expect(plat._platform.get_service_dir).to eq('/etc/init.d')
241
+ end
242
+
243
+ it "returns the servicedir based on servicetype" do
244
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
245
+ plat.instance_eval(deb_platform_multi_servicetypes)
246
+ expect(plat._platform.get_service_dir('systemd')).to eq('/lib/systemd/system')
247
+ end
248
+
249
+ it "fails if there are >1 servicedir for a service type" do
250
+ plat = Vanagon::Platform::DSL.new('debian-8-x86_64')
251
+ plat.instance_eval(deb_platform_bad_servicedir_block)
252
+ expect { plat._platform.get_service_dir('sysv') }.to raise_error(Vanagon::Error)
253
+ end
254
+ end
175
255
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.8
4
+ version: 0.15.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet Labs
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-04-17 00:00:00.000000000 Z
11
+ date: 2018-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: git
@@ -264,41 +264,41 @@ signing_key:
264
264
  specification_version: 3
265
265
  summary: All of your packages will fit into this van with this one simple trick.
266
266
  test_files:
267
- - spec/lib/vanagon/component_spec.rb
268
- - spec/lib/vanagon/project_spec.rb
269
- - spec/lib/vanagon/optparse_spec.rb
270
- - spec/lib/vanagon/driver_spec.rb
271
- - spec/lib/vanagon/environment_spec.rb
272
- - spec/lib/vanagon/platform/windows_spec.rb
273
- - spec/lib/vanagon/platform/solaris_11_spec.rb
274
- - spec/lib/vanagon/platform/solaris_10_spec.rb
275
- - spec/lib/vanagon/platform/dsl_spec.rb
276
- - spec/lib/vanagon/platform/osx_spec.rb
277
- - spec/lib/vanagon/platform/deb_spec.rb
278
- - spec/lib/vanagon/platform/rpm_spec.rb
279
- - spec/lib/vanagon/platform/rpm/aix_spec.rb
280
- - spec/lib/vanagon/component/source/rewrite_spec.rb
267
+ - spec/lib/git/rev_list_spec.rb
268
+ - spec/lib/makefile_spec.rb
269
+ - spec/lib/vanagon/common/pathname_spec.rb
270
+ - spec/lib/vanagon/common/user_spec.rb
271
+ - spec/lib/vanagon/component/dsl_spec.rb
272
+ - spec/lib/vanagon/component/rules_spec.rb
281
273
  - spec/lib/vanagon/component/source/git_spec.rb
282
- - spec/lib/vanagon/component/source/local_spec.rb
283
274
  - spec/lib/vanagon/component/source/http_spec.rb
284
- - spec/lib/vanagon/component/dsl_spec.rb
275
+ - spec/lib/vanagon/component/source/local_spec.rb
276
+ - spec/lib/vanagon/component/source/rewrite_spec.rb
285
277
  - spec/lib/vanagon/component/source_spec.rb
286
- - spec/lib/vanagon/component/rules_spec.rb
287
- - spec/lib/vanagon/extensions/string_spec.rb
288
- - spec/lib/vanagon/extensions/set/json_spec.rb
289
- - spec/lib/vanagon/extensions/ostruct/json_spec.rb
290
- - spec/lib/vanagon/project/dsl_spec.rb
291
- - spec/lib/vanagon/utilities/shell_utilities_spec.rb
292
- - spec/lib/vanagon/utilities_spec.rb
293
- - spec/lib/vanagon/common/pathname_spec.rb
294
- - spec/lib/vanagon/common/user_spec.rb
295
- - spec/lib/vanagon/platform_spec.rb
278
+ - spec/lib/vanagon/component_spec.rb
279
+ - spec/lib/vanagon/driver_spec.rb
296
280
  - spec/lib/vanagon/engine/always_be_scheduling_spec.rb
281
+ - spec/lib/vanagon/engine/base_spec.rb
297
282
  - spec/lib/vanagon/engine/docker_spec.rb
298
283
  - spec/lib/vanagon/engine/ec2_spec.rb
299
284
  - spec/lib/vanagon/engine/hardware_spec.rb
300
285
  - spec/lib/vanagon/engine/local_spec.rb
301
- - spec/lib/vanagon/engine/base_spec.rb
302
286
  - spec/lib/vanagon/engine/pooler_spec.rb
303
- - spec/lib/makefile_spec.rb
304
- - spec/lib/git/rev_list_spec.rb
287
+ - spec/lib/vanagon/environment_spec.rb
288
+ - spec/lib/vanagon/extensions/ostruct/json_spec.rb
289
+ - spec/lib/vanagon/extensions/set/json_spec.rb
290
+ - spec/lib/vanagon/extensions/string_spec.rb
291
+ - spec/lib/vanagon/optparse_spec.rb
292
+ - spec/lib/vanagon/platform/deb_spec.rb
293
+ - spec/lib/vanagon/platform/dsl_spec.rb
294
+ - spec/lib/vanagon/platform/osx_spec.rb
295
+ - spec/lib/vanagon/platform/rpm/aix_spec.rb
296
+ - spec/lib/vanagon/platform/rpm_spec.rb
297
+ - spec/lib/vanagon/platform/solaris_10_spec.rb
298
+ - spec/lib/vanagon/platform/solaris_11_spec.rb
299
+ - spec/lib/vanagon/platform/windows_spec.rb
300
+ - spec/lib/vanagon/platform_spec.rb
301
+ - spec/lib/vanagon/project/dsl_spec.rb
302
+ - spec/lib/vanagon/project_spec.rb
303
+ - spec/lib/vanagon/utilities/shell_utilities_spec.rb
304
+ - spec/lib/vanagon/utilities_spec.rb