Skip to content

Commit a2fa909

Browse files
committed
(MODULES-9029) Fix rubocop offenses
1 parent d4f1cfb commit a2fa909

39 files changed

+3108
-2510
lines changed

.puppet-lint.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--relative

.sync.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ Gemfile:
3737
- mswin
3838
- mingw
3939
- x64_mingw
40-
- gem: 'rspec-retry'
40+
- gem: 'rspec-retry'
41+
42+
spec/spec_helper.rb:
43+
unmanaged: true

spec/acceptance/compose_v3_spec.rb

Lines changed: 82 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
tmp_path = 'C:/cygwin64/tmp'
88
test_container = 'nanoserver-sac2016'
99
else
10-
if fact('os.name') == 'RedHat'
11-
docker_args = "repo_opt => '--enablerepo=localmirror-extras'"
12-
elsif fact('os.name') == 'Centos'
13-
docker_args = "repo_opt => '--enablerepo=localmirror-extras'"
14-
elsif fact('os.name') == 'Ubuntu' && fact('os.release.full') == '14.04'
15-
docker_args = "version => '18.06.1~ce~3-0~ubuntu'"
16-
else
17-
docker_args = ''
18-
end
10+
docker_args = if fact('os.name') == 'RedHat'
11+
"repo_opt => '--enablerepo=localmirror-extras'"
12+
elsif fact('os.name') == 'Centos'
13+
"repo_opt => '--enablerepo=localmirror-extras'"
14+
elsif fact('os.name') == 'Ubuntu' && fact('os.release.full') == '14.04'
15+
"version => '18.06.1~ce~3-0~ubuntu'"
16+
else
17+
''
18+
end
1919
install_dir = '/usr/local/bin'
2020
file_extension = ''
2121
tmp_path = '/tmp'
@@ -24,134 +24,134 @@
2424

2525
describe 'docker compose' do
2626
before(:all) do
27-
retry_on_error_matching(60, 5, /connection failure running/) do
27+
retry_on_error_matching(60, 5, %r{connection failure running}) do
2828
install_code = <<-code
2929
class { 'docker': #{docker_args} }
3030
class { 'docker::compose':
3131
version => '1.23.2',
3232
}
3333
code
34-
apply_manifest(install_code, :catch_failures=>true)
34+
apply_manifest(install_code, catch_failures: true)
3535
end
3636
end
3737

3838
context 'Creating compose v3 projects' do
39-
it 'should have docker compose installed' do
40-
shell('docker-compose --help', :acceptable_exit_codes => [0])
39+
let(:install_pp) do
40+
<<-MANIFEST
41+
docker_compose { 'web':
42+
compose_files => ['#{tmp_path}/docker-compose-v3.yml'],
43+
ensure => present,
44+
}
45+
MANIFEST
4146
end
42-
before(:all) do
43-
@install = <<-code
44-
docker_compose { 'web':
45-
compose_files => ['#{tmp_path}/docker-compose-v3.yml'],
46-
ensure => present,
47-
}
48-
code
49-
apply_manifest(@install, :catch_failures=>true)
47+
48+
it 'is idempotent' do
49+
idempotent_apply(default, install_pp, {})
5050
end
5151

52-
it 'should be idempotent' do
53-
apply_manifest(@install, :catch_changes=>true)
52+
it 'has docker compose installed' do
53+
shell('docker-compose --help', acceptable_exit_codes: [0])
5454
end
5555

56-
it 'should find a docker container' do
57-
shell('docker inspect web_compose_test_1', :acceptable_exit_codes => [0])
56+
it 'finds a docker container' do
57+
shell('docker inspect web_compose_test_1', acceptable_exit_codes: [0])
5858
end
5959
end
6060

6161
context 'creating compose projects with multi compose files' do
6262
before(:all) do
63-
@install = <<-pp1
64-
docker_compose { 'web1':
65-
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
66-
ensure => present,
67-
}
68-
pp1
63+
install_pp = <<-MANIFEST
64+
docker_compose { 'web1':
65+
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
66+
ensure => present,
67+
}
68+
MANIFEST
6969

70-
apply_manifest(@install, :catch_failures=>true)
70+
apply_manifest(install_pp, catch_failures: true)
7171
end
7272

7373
it "should find container with #{test_container} tag" do
74-
shell("docker inspect web1_compose_test_1 | grep #{test_container}", :acceptable_exit_codes => [0])
74+
shell("docker inspect web1_compose_test_1 | grep #{test_container}", acceptable_exit_codes: [0])
7575
end
7676
end
7777

7878
context 'Destroying project with multiple compose files' do
79+
let(:destroy_pp) do
80+
<<-MANIFEST
81+
docker_compose { 'web1':
82+
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
83+
ensure => absent,
84+
}
85+
MANIFEST
86+
end
87+
7988
before(:all) do
80-
@install = <<-pp1
81-
docker_compose { 'web1':
82-
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
83-
ensure => present,
84-
}
85-
pp1
89+
install_pp = <<-MANIFEST
90+
docker_compose { 'web1':
91+
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
92+
ensure => present,
93+
}
94+
MANIFEST
8695

87-
@destroy = <<-pp2
88-
docker_compose { 'web1':
89-
compose_files => ['#{tmp_path}/docker-compose-v3.yml', '#{tmp_path}/docker-compose-override-v3.yml'],
90-
ensure => absent,
91-
}
92-
pp2
93-
apply_manifest(@install, :catch_failures=>true)
94-
apply_manifest(@destroy, :catch_failures=>true)
96+
apply_manifest(install_pp, catch_failures: true)
9597
end
9698

97-
it 'should be idempotent' do
98-
apply_manifest(@destroy, :catch_changes=>true)
99+
it 'is idempotent' do
100+
idempotent_apply(default, destroy_pp, {})
99101
end
100102

101-
it 'should not find a docker container' do
102-
shell('docker inspect web1_compose_test_1', :acceptable_exit_codes => [1])
103+
it 'does not find a docker container' do
104+
shell('docker inspect web1_compose_test_1', acceptable_exit_codes: [1])
103105
end
104106
end
105107

106108
context 'Requesting a specific version of compose' do
107-
before(:all) do
108-
@version = '1.21.2'
109-
@pp = <<-code
110-
class { 'docker::compose':
111-
version => '#{@version}',
112-
}
113-
code
114-
apply_manifest(@pp, :catch_failures=>true)
109+
let(:version) do
110+
'1.21.2'
115111
end
116112

117-
it 'should be idempotent' do
118-
apply_manifest(@pp, :catch_changes=>true)
113+
it 'is idempotent' do
114+
pp = <<-MANIFEST
115+
class { 'docker::compose':
116+
version => '#{version}',
117+
}
118+
MANIFEST
119+
idempotent_apply(default, pp, {})
119120
end
120121

121-
it 'should have installed the requested version' do
122-
shell('docker-compose --version', :acceptable_exit_codes => [0]) do |r|
123-
expect(r.stdout).to match(/#{@version}/)
122+
it 'has installed the requested version' do
123+
shell('docker-compose --version', acceptable_exit_codes: [0]) do |r|
124+
expect(r.stdout).to match(%r{#{version}})
124125
end
125126
end
126127
end
127128

128129
context 'Removing docker compose' do
129-
before(:all) do
130-
@version = '1.21.2'
131-
@pp = <<-code
132-
class { 'docker::compose':
133-
ensure => absent,
134-
version => '#{@version}',
135-
}
136-
code
137-
apply_manifest(@pp, :catch_failures=>true)
130+
let(:version) do
131+
'1.21.2'
138132
end
139133

140-
it 'should be idempotent' do
141-
apply_manifest(@pp, :catch_changes=>true)
134+
it 'is idempotent' do
135+
pp = <<-MANIFEST
136+
class { 'docker::compose':
137+
ensure => absent,
138+
version => '#{version}',
139+
}
140+
MANIFEST
141+
idempotent_apply(default, pp, {})
142142
end
143143

144-
it 'should have removed the relevant files' do
145-
shell("test -e \"#{install_dir}/docker-compose#{file_extension}\"", :acceptable_exit_codes => [1])
146-
shell("test -e \"#{install_dir}/docker-compose-#{@version}#{file_extension}\"", :acceptable_exit_codes => [1])
144+
it 'has removed the relevant files' do
145+
shell("test -e \"#{install_dir}/docker-compose#{file_extension}\"", acceptable_exit_codes: [1])
146+
shell("test -e \"#{install_dir}/docker-compose-#{version}#{file_extension}\"", acceptable_exit_codes: [1])
147147
end
148148

149149
after(:all) do
150-
install_code = <<-code
150+
install_pp = <<-MANIFEST
151151
class { 'docker': #{docker_args}}
152152
class { 'docker::compose': }
153-
code
154-
apply_manifest(install_code, :catch_failures=>true)
153+
MANIFEST
154+
apply_manifest(install_pp, catch_failures: true)
155155
end
156156
end
157-
end
157+
end

spec/acceptance/docker_custom_source_spec.rb

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,56 +3,57 @@
33
skip = false
44

55
if fact('osfamily') == 'windows'
6-
docker_args = 'docker_ee => true, docker_ee_source_location => "https://download.docker.com/components/engine/windows-server/17.06/docker-17.06.2-ee-14.zip"'
7-
default_image = 'winamd64/hello-world'
8-
default_image_tag = 'nanoserver-sac2016'
9-
#The default args are set because:
10-
#restart => 'always' - there is no service created to manage containers
11-
#net => 'nat' - docker uses bridged by default when running a container. When installing docker on windows the default network is NAT.
12-
default_docker_run_arg = "restart => 'always', net => 'nat',"
13-
default_run_command = "ping 127.0.0.1 -t"
14-
docker_command = "\"/cygdrive/c/Program Files/Docker/docker\""
15-
skip = false
6+
docker_args = 'docker_ee => true, docker_ee_source_location => "https://download.docker.com/components/engine/windows-server/17.06/docker-17.06.2-ee-14.zip"'
7+
default_image = 'winamd64/hello-world'
8+
# The default args are set because:
9+
# restart => 'always' - there is no service created to manage containers
10+
# net => 'nat' - docker uses bridged by default when running a container. When installing docker on windows the default network is NAT.
11+
default_docker_run_arg = "restart => 'always', net => 'nat',"
12+
default_run_command = 'ping 127.0.0.1 -t'
13+
docker_command = '"/cygdrive/c/Program Files/Docker/docker"'
14+
skip = false
1615
elsif fact('os.name') == 'Ubuntu' && fact('os.release.full') == '14.04'
17-
docker_args = "version => '18.06.1~ce~3-0~ubuntu'"
18-
skip = true
16+
docker_args = "version => '18.06.1~ce~3-0~ubuntu'"
17+
skip = true
1918
else
20-
docker_args = ''
21-
skip = true
19+
docker_args = ''
20+
skip = true
2221
end
2322

2423
describe 'the Puppet Docker module' do
25-
context 'with download location', :skip => skip do
26-
let(:pp) {"
27-
class { 'docker': #{docker_args} }
28-
"}
24+
context 'with download location', skip: skip do
25+
let(:pp) do
26+
"
27+
class { 'docker': #{docker_args} }
28+
"
29+
end
2930

30-
it 'should run successfully' do
31-
apply_manifest(pp, :catch_failures => true)
31+
it 'runs successfully' do
32+
apply_manifest(pp, catch_failures: true)
3233
end
3334

34-
it 'should run idempotently' do
35-
apply_manifest(pp, :catch_changes => true) unless fact('selinux') == 'true'
35+
it 'runs idempotently' do
36+
apply_manifest(pp, catch_changes: true) unless fact('selinux') == 'true'
3637
end
3738

38-
it 'should be start a docker process' do
39-
if fact('osfamily') == 'windows'
39+
it 'is start a docker process' do
40+
if fact('osfamily') == 'windows'
4041
shell('powershell Get-Process -Name dockerd') do |r|
41-
expect(r.stdout).to match(/ProcessName/)
42+
expect(r.stdout).to match(%r{ProcessName})
4243
end
43-
else
44+
else
4445
shell('ps aux | grep docker') do |r|
45-
expect(r.stdout).to match(/dockerd -H unix:\/\/\/var\/run\/docker.sock/)
46-
end
46+
expect(r.stdout).to match %r{dockerd -H unix:\/\/\/var\/run\/docker.sock}
4747
end
48+
end
4849
end
4950

50-
it 'should install a working docker client' do
51-
shell("#{docker_command} ps", :acceptable_exit_codes => [0] )
51+
it 'installs a working docker client' do
52+
shell("#{docker_command} ps", acceptable_exit_codes: [0])
5253
end
5354

54-
it 'should stop a running container and remove container' do
55-
pp=<<-EOS
55+
it 'stops a running container and remove container' do
56+
pp = <<-EOS
5657
class { 'docker': #{docker_args} }
5758
5859
docker::image { '#{default_image}':
@@ -67,7 +68,7 @@ class { 'docker': #{docker_args} }
6768
}
6869
EOS
6970

70-
pp2=<<-EOS
71+
pp2 = <<-EOS
7172
class { 'docker': #{docker_args} }
7273
7374
docker::image { '#{default_image}':
@@ -81,26 +82,26 @@ class { 'docker': #{docker_args} }
8182
}
8283
EOS
8384

84-
apply_manifest(pp, :catch_failures => true)
85-
apply_manifest(pp, :catch_changes => true) unless fact('selinux') == 'true'
85+
apply_manifest(pp, catch_failures: true)
86+
apply_manifest(pp, catch_changes: true) unless fact('selinux') == 'true'
8687

87-
# A sleep to give docker time to execute properly
88-
sleep 15
88+
# A sleep to give docker time to execute properly
89+
sleep 15
8990

90-
shell("#{docker_command} ps", :acceptable_exit_codes => [0])
91+
shell("#{docker_command} ps", acceptable_exit_codes: [0])
9192

92-
apply_manifest(pp2, :catch_failures => true)
93-
apply_manifest(pp2, :catch_changes => true) unless fact('selinux') == 'true'
93+
apply_manifest(pp2, catch_failures: true)
94+
apply_manifest(pp2, catch_changes: true) unless fact('selinux') == 'true'
9495

95-
# A sleep to give docker time to execute properly
96-
sleep 15
96+
# A sleep to give docker time to execute properly
97+
sleep 15
9798

98-
shell("#{docker_command} inspect container-3-6", :acceptable_exit_codes => [1])
99-
if fact('osfamily') == 'windows'
100-
shell('test -f /cygdrive/c/Users/Administrator/AppData/Local/Temp/container-3-6.service', :acceptable_exit_codes => [1])
101-
else
102-
shell('test -f /etc/systemd/system/container-3-6.service', :acceptable_exit_codes => [1])
99+
shell("#{docker_command} inspect container-3-6", acceptable_exit_codes: [1])
100+
if fact('osfamily') == 'windows'
101+
shell('test -f /cygdrive/c/Users/Administrator/AppData/Local/Temp/container-3-6.service', acceptable_exit_codes: [1])
102+
else
103+
shell('test -f /etc/systemd/system/container-3-6.service', acceptable_exit_codes: [1])
104+
end
103105
end
104106
end
105107
end
106-
end

0 commit comments

Comments
 (0)