Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support refreshonly flag #201

Merged
merged 1 commit into from
Mar 18, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,7 @@ docker::exec { 'cron_allow_root':
command => '/bin/echo root >> /usr/lib/cron/cron.allow',
tty => true,
unless => 'grep root /usr/lib/cron/cron.allow 2>/dev/null',
refreshonly => true,
}
```

Expand Down
2 changes: 2 additions & 0 deletions manifests/exec.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
Optional[String] $command = undef,
Optional[String] $unless = undef,
Optional[Boolean] $sanitise_name = true,
Optional[Boolean] $refreshonly = false,
) {
include docker::params

Expand Down Expand Up @@ -37,6 +38,7 @@
exec { $exec:
environment => 'HOME=/root',
path => ['/bin', '/usr/bin'],
refreshonly => $refreshonly,
timeout => 0,
unless => $unless_command,
}
Expand Down
49 changes: 49 additions & 0 deletions spec/acceptance/docker_full_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,55 @@ class { 'docker':}
expect(r.stdout).to match(/test_command_file.txt/)
end
end

it 'should only run if notified when refreshonly is true' do
container_name = 'container_4_2'
pp=<<-EOS
class { 'docker': }

docker::image { 'ubuntu': }

docker::run { '#{container_name}':
image => 'ubuntu',
command => 'init',
}

docker::exec { 'test_command':
container => '#{container_name}',
command => 'touch /root/test_command_file.txt',
refreshonly => true,
}
EOS

apply_manifest(pp, :catch_failures => true)
apply_manifest(pp, :catch_changes => true) unless fact('selinux') == 'true'

# A sleep to give docker time to execute properly
sleep 4

shell("docker exec #{container_name} ls /root") do |r|
expect(r.stdout).to_not match(/test_command_file.txt/)
end

pp_extra=<<-EOS
file { '/tmp/dummy_file':
ensure => 'present',
notify => Docker::Exec['test_command'],
}
EOS

pp2 = pp + pp_extra

apply_manifest(pp2, :catch_failures => true)
apply_manifest(pp2, :catch_changes => true) unless fact('selinux') == 'true'

# A sleep to give docker time to execute properly
sleep 4

shell("docker exec #{container_name} ls /root") do |r|
expect(r.stdout).to match(/test_command_file.txt/)
end
end
end
end
end