Skip to content

Commit

Permalink
Merge pull request #652 from adrianiurca/prepare_and_service_only_test
Browse files Browse the repository at this point in the history
[IAC-1056] - Add acceptance test for  prepare_service_only param
  • Loading branch information
carabasdaniel committed Aug 20, 2020
2 parents c3a9f56 + f9f80c5 commit f0869b3
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
11 changes: 9 additions & 2 deletions manifests/run.pp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
# configuration.
# Default: Not included in unit file
#
# @param prepare_service_only
# (optional) Prepare the service and enable it as usual but do not run it right away.
# Useful when building VM images using masterless Puppet and then letting the Docker images
# to be downloaded when a new VM is created.
# Default: false
#
# @param image
#
# @param ensure
Expand Down Expand Up @@ -237,6 +243,7 @@
Optional[Integer] $health_check_interval = undef,
Optional[Variant[String,Array]] $custom_unless = [],
Optional[String] $remain_after_exit = undef,
Optional[Boolean] $prepare_service_only = false,
) {
include docker::params

Expand Down Expand Up @@ -643,7 +650,7 @@
}

service { "${service_prefix}${sanitised_title}":
ensure => $running,
ensure => $running and !$prepare_service_only,
enable => true,
provider => $service_provider_real,
hasstatus => $hasstatus,
Expand All @@ -667,7 +674,7 @@
}
}
}
if $service_provider_real == 'systemd' {
if $service_provider_real == 'systemd' and !$prepare_service_only {
exec { "docker-${sanitised_title}-systemd-reload":
path => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
command => 'systemctl daemon-reload',
Expand Down
43 changes: 43 additions & 0 deletions spec/acceptance/docker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,49 @@ class { 'docker': #{docker_args},
end
end

context 'When prepare_service_only param is set(prepare_service_only => true)', win_broken: broken do
let(:pp) do
"
class { 'docker': #{docker_args} }
docker::run { 'servercore':
image => 'hello-world:latest',
prepare_service_only => true,
}
"
end

it 'creates the service without starting it' do
apply_manifest(pp, catch_failures: true)
end

it 'not start the service' do
run_shell('systemctl status docker-servercore', expect_failures: true) do |r|
expect(r.stdout.include?('Main PID')).to be false
end
end
end

context 'When prepare_service_only param is not set(prepare_service_only => false)', win_broken: broken do
let(:pp) do
"
class { 'docker': #{docker_args} }
docker::run { 'servercore':
image => 'hello-world:latest',
}
"
end

it 'creates the service and start it' do
apply_manifest(pp, catch_failures: true)
end

it 'start the service' do
run_shell('systemctl status docker-servercore', expect_failures: true) do |r|
expect(r.stdout.include?('Main PID')).to be true
end
end
end

context 'When root_dir is set' do
let(:pp) do
"class { 'docker': #{docker_args}, root_dir => \"#{root_dir}\"}"
Expand Down
3 changes: 1 addition & 2 deletions templates/docker-run-start.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
/usr/bin/<%= @docker_command %> create \
<%= @docker_run_flags %> \
--name <%= @sanitised_title %> \
<%= @image %> \
<% if @command %> <%= @command %><% end %>
<%= @image %> <% if @command %> \ <%= @command %><% end %>
<% if @after_create %><%= @after_create %><% end %>
<% if @net.is_a? Array%>
Expand Down

0 comments on commit f0869b3

Please sign in to comment.