diff --git a/manifests/exec.pp b/manifests/exec.pp index 48d4441ef..acffd8b7d 100644 --- a/manifests/exec.pp +++ b/manifests/exec.pp @@ -31,7 +31,7 @@ if $sanitise_name { - $sanitised_container = regsubst($container, '[^0-9A-Za-z.\-]', '-', 'G') + $sanitised_container = regsubst($container, '[^0-9A-Za-z.\-_]', '-', 'G') } else { $sanitised_container = $container } diff --git a/manifests/run.pp b/manifests/run.pp index 03f8dbe11..085cc6458 100755 --- a/manifests/run.pp +++ b/manifests/run.pp @@ -193,19 +193,19 @@ volumes_from => any2array($volumes_from), }) - $sanitised_title = regsubst($title, '[^0-9A-Za-z.\-]', '-', 'G') + $sanitised_title = regsubst($title, '[^0-9A-Za-z.\-_]', '-', 'G') if empty($depends_array) { $sanitised_depends_array = [] } else { - $sanitised_depends_array = regsubst($depends_array, '[^0-9A-Za-z.\-]', '-', 'G') + $sanitised_depends_array = regsubst($depends_array, '[^0-9A-Za-z.\-_]', '-', 'G') } if empty($after_array) { $sanitised_after_array = [] } else { - $sanitised_after_array = regsubst($after_array, '[^0-9A-Za-z.\-]', '-', 'G') + $sanitised_after_array = regsubst($after_array, '[^0-9A-Za-z.\-_]', '-', 'G') } if $restart { diff --git a/spec/defines/exec_spec.rb b/spec/defines/exec_spec.rb index 56e15e361..e8e184b3d 100644 --- a/spec/defines/exec_spec.rb +++ b/spec/defines/exec_spec.rb @@ -35,4 +35,9 @@ let(:params) { {'command' => 'command', 'container' => 'container', 'interactive' => true,} } it { should contain_exec('docker exec --interactive=true container command').with_unless (nil) } end + + context 'with title that need sanitisation' do + let(:params) { {'command' => 'command', 'container' => 'container_sample/1', 'detach' => true, 'sanitise_name' => true} } + it { should contain_exec('docker exec --detach=true container_sample-1 command') } + end end diff --git a/spec/defines/run_spec.rb b/spec/defines/run_spec.rb index a30f5fbb1..cb5fbfd16 100755 --- a/spec/defines/run_spec.rb +++ b/spec/defines/run_spec.rb @@ -71,41 +71,51 @@ end context 'when passing `after` containers' do - let(:params) { {'command' => 'command', 'image' => 'base', 'after' => ['foo', 'bar']} } + let(:params) { {'command' => 'command', 'image' => 'base', 'after' => ['foo', 'bar', 'foo_bar/baz']} } if (systemd) it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo.service/) } it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-bar.service/) } + it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo_bar-baz.service/) } it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-foo.service/) } it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-bar.service/) } + it { should contain_file(initscript).with_content(/Wants=(.*\s+)?docker-foo_bar-baz.service/) } else if (osfamily == 'Gentoo') it { should contain_file(initscript).with_content(/after.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/after.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/after.*\s+docker-foo_bar-baz/) } else it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo_bar-baz/) } end end end context 'when passing `depends` containers' do - let(:params) { {'command' => 'command', 'image' => 'base', 'depends' => ['foo', 'bar']} } + let(:params) { {'command' => 'command', 'image' => 'base', 'depends' => ['foo', 'bar', 'foo_bar/baz']} } if (systemd) it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo.service/) } it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-bar.service/) } + it { should contain_file(initscript).with_content(/After=(.*\s+)?docker-foo_bar-baz.service/) } it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-foo.service/) } it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-bar.service/) } + it { should contain_file(initscript).with_content(/Requires=(.*\s+)?docker-foo_bar-baz.service/) } else if (osfamily == 'Gentoo') it { should contain_file(initscript).with_content(/after.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/after.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/after.*\s+docker-foo_bar-baz/) } it { should contain_file(initscript).with_content(/need.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/need.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/need.*\s+docker-foo_bar-baz/) } else it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/Required-Start:.*\s+docker-foo_bar-baz/) } it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-foo/) } it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-bar/) } + it { should contain_file(initscript).with_content(/Required-Stop:.*\s+docker-foo_bar-baz/) } end end end @@ -526,6 +536,22 @@ it { should contain_file(new_initscript) } end + context 'with title that need sanitisation' do + let(:title) { 'this/that_other' } + let(:params) { {'image' => 'base' } } + + if osfamily == 'Debian' + new_initscript = '/etc/init.d/docker-this-that_other' + elsif osfamily == 'Archlinux' + new_initscript = '/etc/systemd/system/docker-this-that_other.service' + else + new_initscript = '/etc/init.d/docker-this-that_other' + end + + it { should contain_service('docker-this-that_other') } + it { should contain_file(new_initscript) } + end + context 'with an invalid title' do let(:title) { 'with spaces' } it do