vanagon 0.18.0 → 0.20.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -2
  3. data/bin/build +3 -1
  4. data/bin/build_host_info +3 -1
  5. data/bin/build_requirements +3 -1
  6. data/bin/inspect +3 -1
  7. data/bin/render +3 -1
  8. data/bin/repo +3 -1
  9. data/bin/ship +3 -1
  10. data/bin/sign +3 -1
  11. data/lib/vanagon/cli.rb +4 -2
  12. data/lib/vanagon/cli/build.rb +2 -1
  13. data/lib/vanagon/cli/build_host_info.rb +3 -2
  14. data/lib/vanagon/cli/build_requirements.rb +4 -4
  15. data/lib/vanagon/cli/completion.rb +4 -3
  16. data/lib/vanagon/cli/inspect.rb +3 -2
  17. data/lib/vanagon/cli/list.rb +5 -6
  18. data/lib/vanagon/cli/render.rb +2 -1
  19. data/lib/vanagon/cli/ship.rb +4 -19
  20. data/lib/vanagon/cli/sign.rb +3 -2
  21. data/lib/vanagon/component.rb +13 -10
  22. data/lib/vanagon/component/dsl.rb +27 -20
  23. data/lib/vanagon/component/source.rb +2 -1
  24. data/lib/vanagon/component/source/git.rb +35 -10
  25. data/lib/vanagon/component/source/http.rb +3 -2
  26. data/lib/vanagon/component/source/local.rb +2 -1
  27. data/lib/vanagon/component/source/rewrite.rb +3 -2
  28. data/lib/vanagon/driver.rb +20 -21
  29. data/lib/vanagon/engine/always_be_scheduling.rb +12 -11
  30. data/lib/vanagon/engine/docker.rb +2 -1
  31. data/lib/vanagon/engine/ec2.rb +5 -4
  32. data/lib/vanagon/engine/hardware.rb +4 -3
  33. data/lib/vanagon/engine/pooler.rb +6 -5
  34. data/lib/vanagon/environment.rb +3 -2
  35. data/lib/vanagon/logger.rb +31 -0
  36. data/lib/vanagon/platform.rb +38 -5
  37. data/lib/vanagon/platform/dsl.rb +23 -6
  38. data/lib/vanagon/platform/windows.rb +3 -1
  39. data/lib/vanagon/project.rb +25 -15
  40. data/lib/vanagon/project/dsl.rb +6 -5
  41. data/lib/vanagon/utilities.rb +5 -4
  42. data/resources/deb/control.erb +1 -1
  43. data/resources/deb/postinst.erb +24 -13
  44. data/resources/deb/postrm.erb +9 -6
  45. data/resources/deb/prerm.erb +18 -8
  46. data/resources/osx/postinstall.erb +6 -2
  47. data/resources/rpm/project.spec.erb +12 -12
  48. data/resources/solaris/10/depend.erb +2 -2
  49. data/resources/solaris/10/postinstall.erb +11 -3
  50. data/resources/solaris/11/p5m.erb +2 -2
  51. data/spec/lib/vanagon/cli_spec.rb +1 -4
  52. data/spec/lib/vanagon/component/dsl_spec.rb +54 -10
  53. data/spec/lib/vanagon/component/source/git_spec.rb +4 -4
  54. data/spec/lib/vanagon/component_spec.rb +15 -2
  55. data/spec/lib/vanagon/engine/always_be_scheduling_spec.rb +4 -4
  56. data/spec/lib/vanagon/platform_spec.rb +80 -0
  57. data/spec/lib/vanagon/utilities_spec.rb +4 -1
  58. metadata +32 -31
@@ -1,4 +1,5 @@
1
1
  require 'vanagon/errors'
2
+ require 'vanagon/logger'
2
3
  require 'vanagon/project'
3
4
  require 'vanagon/utilities'
4
5
  require 'vanagon/component/source'
@@ -109,8 +110,8 @@ class Vanagon
109
110
  # Sets the run time requirements for the project. Mainly for use in packaging.
110
111
  #
111
112
  # @param req [String] of requirements of the project
112
- def requires(req)
113
- @project.requires << req
113
+ def requires(requirement, version = nil)
114
+ @project.requires << OpenStruct.new(:requirement => requirement, :version => version)
114
115
  end
115
116
 
116
117
  # Indicates that this component replaces a system level package. Replaces can be collected and used by the project and package.
@@ -185,7 +186,7 @@ class Vanagon
185
186
  last_tag = repo_object.describe('HEAD', { :abbrev => 0 })
186
187
  release(repo_object.rev_list("#{last_tag}..HEAD", { :count => true }))
187
188
  rescue Git::GitExecuteError
188
- warn "Directory '#{File.expand_path('..', @configdir)}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
189
+ VanagonLogger.error "Directory '#{File.expand_path('..', @configdir)}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
189
190
  end
190
191
 
191
192
  # Sets the version for the project based on a git describe of the
@@ -196,7 +197,7 @@ class Vanagon
196
197
  git_version = Git.open(File.expand_path("..", @configdir)).describe('HEAD', tags: true)
197
198
  version(git_version.split('-').reject(&:empty?).join('.'))
198
199
  rescue Git::GitExecuteError
199
- warn "Directory '#{File.expand_path('..', @configdir)}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
200
+ VanagonLogger.error "Directory '#{File.expand_path('..', @configdir)}' cannot be versioned by git. Maybe it hasn't been tagged yet?"
200
201
  end
201
202
 
202
203
  # Get the version string from a git branch name. This will look for a '.'
@@ -268,7 +269,7 @@ class Vanagon
268
269
  #
269
270
  # @param name [String] name of component to add. must be present in configdir/components and named $name.rb currently
270
271
  def component(name)
271
- warn "Loading #{name}" if @project.settings[:verbose]
272
+ VanagonLogger.info "Loading #{name}" if @project.settings[:verbose]
272
273
  if @include_components.empty? or @include_components.include?(name)
273
274
  component = Vanagon::Component.load_component(name, File.join(@configdir, "components"), @project.settings, @project.platform)
274
275
  @project.components << component
@@ -9,6 +9,7 @@ require 'timeout'
9
9
  # but it provides a wealth of useful constants
10
10
  require 'English'
11
11
  require 'vanagon/extensions/string'
12
+ require 'vanagon/logger'
12
13
 
13
14
  class Vanagon
14
15
  module Utilities
@@ -165,7 +166,7 @@ class Vanagon
165
166
  yield
166
167
  return true
167
168
  rescue StandardError => e
168
- warn 'An error was encountered evaluating block. Retrying..'
169
+ VanagonLogger.error 'An error was encountered evaluating block. Retrying..'
169
170
  error = e
170
171
  end
171
172
  end
@@ -238,7 +239,7 @@ class Vanagon
238
239
  # output of the command if return_command_output is true
239
240
  # @raise [RuntimeError] If there is no target given or the command fails an exception is raised
240
241
  def remote_ssh_command(target, command, port = 22, return_command_output: false)
241
- warn "Executing '#{command}' on '#{target}'"
242
+ VanagonLogger.info "Executing '#{command}' on '#{target}'"
242
243
  if return_command_output
243
244
  ret = %x(#{ssh_command(port)} -T #{target} '#{command.gsub("'", "'\\\\''")}').chomp
244
245
  if $CHILD_STATUS.success?
@@ -261,7 +262,7 @@ class Vanagon
261
262
  # @raise [RuntimeError] If the command fails an exception is raised
262
263
  def local_command(command, return_command_output: false)
263
264
  clean_environment do
264
- warn "Executing '#{command}' locally"
265
+ VanagonLogger.info "Executing '#{command}' locally"
265
266
  if return_command_output
266
267
  ret = %x(#{command}).chomp
267
268
  if $CHILD_STATUS.success?
@@ -305,7 +306,7 @@ class Vanagon
305
306
  outfile ||= File.join(Dir.mktmpdir, File.basename(erbfile).sub(File.extname(erbfile), ""))
306
307
  output = erb_string(erbfile, opts[:binding])
307
308
  File.open(outfile, 'w') { |f| f.write output }
308
- warn "Generated: #{outfile}"
309
+ VanagonLogger.info "Generated: #{outfile}"
309
310
  FileUtils.rm_rf erbfile if remove_orig
310
311
  outfile
311
312
  end
@@ -18,7 +18,7 @@ Breaks: <%= get_replaces.map { |replace| "#{replace.replacement} #{replace.versi
18
18
  Conflicts: <%= get_conflicts.map { |conflict| "#{conflict.pkgname} #{conflict.version ? "(#{conflict.version})" : ""}" }.join(", ") %>
19
19
  <%- end -%>
20
20
  <%- unless get_requires.empty? -%>
21
- Depends: <%= get_requires.join(", ") %>
21
+ Depends: <%= get_requires.map { |req| "#{req.requirement} #{req.version ? "(#{req.version})" : ""}" }.join(", ") %>
22
22
  <%- end -%>
23
23
  <%- unless get_provides.empty? -%>
24
24
  Provides: <%= get_provides.map { |prov| prov.provide }.join(", ") %>
@@ -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 -%>
@@ -5,8 +5,12 @@
5
5
  <%- get_configfiles.each do |config|
6
6
  dest_file = config.path.gsub(/\.pristine$/, '') -%>
7
7
 
8
- if [ -f "<%= dest_file %>" ] && ! diff "<%= config.path %>" "<%= dest_file %>" > /dev/null; then
9
- echo "Detected file at '<%= dest_file %>'; updated file at '<%= config.path %>'."
8
+ if [ -f "<%= dest_file %>" ]; then
9
+ if diff "<%= config.path %>" "<%= dest_file %>" > /dev/null; then
10
+ rm -f "<%= config.path %>"
11
+ else
12
+ echo "Detected file at '<%= dest_file %>'; updated file at '<%= config.path %>'."
13
+ fi
10
14
  else
11
15
  mv '<%= config.path %>' '<%= dest_file %>'
12
16
  fi
@@ -77,7 +77,7 @@ Source1: file-list-for-rpm
77
77
  Autoprov: 0
78
78
  Autoreq: 0
79
79
  <%- get_requires.each do |requires| -%>
80
- Requires: <%= requires %>
80
+ Requires: <%= requires.requirement %><%= requires.version ? " #{requires.version}" : "" %>
81
81
  <%- end -%>
82
82
 
83
83
  # All rpm packages built by vanagon have the pre-/post-install script
@@ -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 || :
@@ -1,3 +1,3 @@
1
- <%- get_requires.each do |requirement| -%>
2
- P <%= requirement %>
1
+ <%- get_requires.each do |requires| -%>
2
+ P <%= requires.requirement %>
3
3
  <%- end -%>
@@ -9,8 +9,12 @@
9
9
  <%- get_configfiles.each do |config|
10
10
  dest_file = config.path.gsub(/\.pristine$/, '') -%>
11
11
 
12
- if [ -f "<%= dest_file %>" ] && ! diff "<%= config.path %>" "<%= dest_file %>" > /dev/null; then
13
- echo "Detected file at '<%= dest_file %>'; updated file at '<%= config.path %>'."
12
+ if [ -f "<%= dest_file %>" ]; then
13
+ if diff "<%= config.path %>" "<%= dest_file %>" > /dev/null; then
14
+ rm -f "<%= config.path %>"
15
+ else
16
+ echo "Detected file at '<%= dest_file %>'; updated file at '<%= config.path %>'."
17
+ fi
14
18
  else
15
19
  cp -pr '<%= config.path %>' '<%= dest_file %>'
16
20
  fi
@@ -19,7 +23,11 @@ fi
19
23
 
20
24
  # Set up any specific permissions needed...
21
25
  <%- (get_directories + get_configfiles + get_files).select { |pathname| pathname.has_overrides? }.uniq.each do |file_or_directory| -%>
22
- <%= "chmod '#{file_or_directory.mode}' '#{file_or_directory.path}'" if file_or_directory.mode %>
26
+ <%- if file_or_directory.mode -%>
27
+ if [ -f "<%= file_or_directory.path %>" ] || [ -d "<%= file_or_directory.path %>" ]; then
28
+ chmod '<%= file_or_directory.mode %>' '<%= file_or_directory.path %>'
29
+ fi
30
+ <%- end -%>
23
31
  <%- if file_or_directory.owner -%>
24
32
  if getent passwd '<%= file_or_directory.owner %>' &> /dev/null; then
25
33
  chown '<%= file_or_directory.owner %>' '<%= file_or_directory.path %>'
@@ -17,8 +17,8 @@ set name=variant.opensolaris.zone value=global value=nonglobal
17
17
  %>
18
18
 
19
19
  # Add any needed dependencies
20
- <%- get_requires.each do |requirement| -%>
21
- depend fmri=pkg:/<%= requirement %> type=require
20
+ <%- get_requires.each do |requires| -%>
21
+ depend fmri=pkg:/<%= requires.requirement %> type=require
22
22
  <%- end -%>
23
23
 
24
24
  # Always drop /etc, /usr, and /var, it will cause conflicts with other system packages
@@ -164,7 +164,7 @@ foo bar baz
164
164
  - Platforms
165
165
  1 2 3
166
166
  "
167
- }
167
+ }
168
168
  it "outputs projects and platforms space separated" do
169
169
  expect do
170
170
  cli.run(options_space_only)
@@ -221,6 +221,3 @@ baz
221
221
  end
222
222
  end
223
223
  end
224
-
225
-
226
-
@@ -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|
@@ -313,11 +323,18 @@ end" }
313
323
  comp = Vanagon::Component::DSL.new('requires-test', {}, {})
314
324
  comp.requires('library1')
315
325
  comp.requires('library2')
316
- expect(comp._component.requires).to include('library1')
317
- expect(comp._component.requires).to include('library2')
326
+ expect(comp._component.requires.first.requirement).to include('library1')
327
+ expect(comp._component.requires.last.requirement).to include('library2')
318
328
  end
319
329
  end
320
330
 
331
+ it 'supports versioned requires' do
332
+ comp = Vanagon::Component::DSL.new('requires-test', {}, {})
333
+ comp.requires('library1', '1.2.3')
334
+ expect(comp._component.requires.first.requirement).to eq('library1')
335
+ expect(comp._component.requires.first.version).to eq('1.2.3')
336
+ end
337
+
321
338
  describe '#provides' do
322
339
  it 'adds the package provide to the list of provides' do
323
340
  comp = Vanagon::Component::DSL.new('provides-test', {}, {})
@@ -568,15 +585,15 @@ end" }
568
585
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test', mode: '0755'))
569
586
 
570
587
  # The component should now have a service registered
571
- expect(comp._component.service.name).to eq('service-test')
588
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
572
589
  end
573
590
 
574
591
  it 'reads from a file when the OS is AIX for services' do
575
592
  comp = Vanagon::Component::DSL.new('service-test', {}, dummy_platform_aix)
576
593
  comp.install_service('spec/fixtures/component/mcollective.service', nil, 'mcollective')
577
- expect(comp._component.service.name).to eq('mcollective')
578
- expect(comp._component.service.service_command).to include('/opt/puppetlabs/puppet/bin/ruby')
579
- 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")
580
597
  end
581
598
 
582
599
  it 'adds the correct command to the install for the component for systemd platforms' do
@@ -595,7 +612,34 @@ end" }
595
612
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/usr/lib/systemd/system/service-test.service', mode: '0644'))
596
613
 
597
614
  # The component should now have a service registered
598
- 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')
599
643
  end
600
644
 
601
645
  it 'adds the correct command to the install for smf services using a service_type' do
@@ -614,7 +658,7 @@ end" }
614
658
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/network/service-test.xml', mode: '0644'))
615
659
 
616
660
  # The component should now have a service registered
617
- expect(comp._component.service.name).to eq('service-test')
661
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
618
662
  end
619
663
 
620
664
  it 'adds the correct command to the install for smf services' do
@@ -633,7 +677,7 @@ end" }
633
677
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/var/svc/manifest/service-test.xml', mode: '0644'))
634
678
 
635
679
  # The component should now have a service registered
636
- expect(comp._component.service.name).to eq('service-test')
680
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
637
681
  end
638
682
 
639
683
  it 'installs the file as a link when link_target is specified' do
@@ -654,7 +698,7 @@ end" }
654
698
  expect(comp._component.files).to include(Vanagon::Common::Pathname.file('/etc/init.d/service-test'))
655
699
 
656
700
  # The component should now have a service registered
657
- expect(comp._component.service.name).to eq('service-test')
701
+ expect(comp._component.service.flat_map(&:name).compact).to include('service-test')
658
702
  end
659
703
  end
660
704