Skip to content

Commit f0869b3

Browse files
author
carabasdaniel
authored
Merge pull request #652 from adrianiurca/prepare_and_service_only_test
[IAC-1056] - Add acceptance test for prepare_service_only param
2 parents c3a9f56 + f9f80c5 commit f0869b3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

manifests/run.pp

+9-2
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@
8989
# configuration.
9090
# Default: Not included in unit file
9191
#
92+
# @param prepare_service_only
93+
# (optional) Prepare the service and enable it as usual but do not run it right away.
94+
# Useful when building VM images using masterless Puppet and then letting the Docker images
95+
# to be downloaded when a new VM is created.
96+
# Default: false
97+
#
9298
# @param image
9399
#
94100
# @param ensure
@@ -237,6 +243,7 @@
237243
Optional[Integer] $health_check_interval = undef,
238244
Optional[Variant[String,Array]] $custom_unless = [],
239245
Optional[String] $remain_after_exit = undef,
246+
Optional[Boolean] $prepare_service_only = false,
240247
) {
241248
include docker::params
242249

@@ -643,7 +650,7 @@
643650
}
644651

645652
service { "${service_prefix}${sanitised_title}":
646-
ensure => $running,
653+
ensure => $running and !$prepare_service_only,
647654
enable => true,
648655
provider => $service_provider_real,
649656
hasstatus => $hasstatus,
@@ -667,7 +674,7 @@
667674
}
668675
}
669676
}
670-
if $service_provider_real == 'systemd' {
677+
if $service_provider_real == 'systemd' and !$prepare_service_only {
671678
exec { "docker-${sanitised_title}-systemd-reload":
672679
path => ['/bin/', '/sbin/', '/usr/bin/', '/usr/sbin/'],
673680
command => 'systemctl daemon-reload',

spec/acceptance/docker_spec.rb

+43
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,49 @@ class { 'docker': #{docker_args},
5656
end
5757
end
5858

59+
context 'When prepare_service_only param is set(prepare_service_only => true)', win_broken: broken do
60+
let(:pp) do
61+
"
62+
class { 'docker': #{docker_args} }
63+
docker::run { 'servercore':
64+
image => 'hello-world:latest',
65+
prepare_service_only => true,
66+
}
67+
"
68+
end
69+
70+
it 'creates the service without starting it' do
71+
apply_manifest(pp, catch_failures: true)
72+
end
73+
74+
it 'not start the service' do
75+
run_shell('systemctl status docker-servercore', expect_failures: true) do |r|
76+
expect(r.stdout.include?('Main PID')).to be false
77+
end
78+
end
79+
end
80+
81+
context 'When prepare_service_only param is not set(prepare_service_only => false)', win_broken: broken do
82+
let(:pp) do
83+
"
84+
class { 'docker': #{docker_args} }
85+
docker::run { 'servercore':
86+
image => 'hello-world:latest',
87+
}
88+
"
89+
end
90+
91+
it 'creates the service and start it' do
92+
apply_manifest(pp, catch_failures: true)
93+
end
94+
95+
it 'start the service' do
96+
run_shell('systemctl status docker-servercore', expect_failures: true) do |r|
97+
expect(r.stdout.include?('Main PID')).to be true
98+
end
99+
end
100+
end
101+
59102
context 'When root_dir is set' do
60103
let(:pp) do
61104
"class { 'docker': #{docker_args}, root_dir => \"#{root_dir}\"}"

templates/docker-run-start.erb

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
/usr/bin/<%= @docker_command %> create \
1313
<%= @docker_run_flags %> \
1414
--name <%= @sanitised_title %> \
15-
<%= @image %> \
16-
<% if @command %> <%= @command %><% end %>
15+
<%= @image %> <% if @command %> \ <%= @command %><% end %>
1716

1817
<% if @after_create %><%= @after_create %><% end %>
1918
<% if @net.is_a? Array%>

0 commit comments

Comments
 (0)