Skip to content

Commit 1808b95

Browse files
committed
(MODULES-9036) Fix Windows acceptance tests
While fixing the tests I uncovered that the docker_stack provider does not check for the existence of stacks properly on Windows. This appears to be due to it looking for containers tagged with latest, as not having any tag. As a result, the stack is created on every run and also cannot be destroyed. The changes here help rectify this however there is probably a better solution needed.
1 parent b95529d commit 1808b95

File tree

5 files changed

+24
-20
lines changed

5 files changed

+24
-20
lines changed

lib/puppet/provider/docker_stack/ruby.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def exists?
4040
end
4141
counts = Hash[*stack_services.each.map { |key, array|
4242
image = (array['image']) ? array['image'] : get_image(key, stack_services)
43+
image = "#{image}:latest" unless image.include?(':')
4344
Puppet.info("Checking for compose service #{key} #{image}")
4445
["#{key}-#{image}", stack_containers.count("#{key}-#{image}")]
4546
}.flatten]

spec/acceptance/docker_custom_source_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
if fact('osfamily') == 'windows'
66
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 = 'microsoft/nanoserver'
8-
default_image_tag = '10.0.14393.2189'
7+
default_image = 'winamd64/hello-world'
8+
default_image_tag = 'nanoserver-sac2016'
99
#The default args are set because:
1010
#restart => 'always' - there is no service created to manage containers
1111
#net => 'nat' - docker uses bridged by default when running a container. When installing docker on windows the default network is NAT.

spec/acceptance/docker_full_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
if fact('kernel') == 'windows'
44
docker_args = 'docker_ee => true'
5-
default_image = 'microsoft/nanoserver'
6-
default_image_tag = '10.0.14393.2189'
7-
second_image = 'hello-world'
8-
default_digest = 'sha256:204c41542c0927ac0296802e44c56b886b47e99cf8220fb49d46951bd5fc1742'
5+
default_image = 'winamd64/hello-world'
6+
default_image_tag = 'nanoserver-sac2016'
7+
default_digest = 'sha256:88f6207b9281e60dc4a91008e68b542cc7350d06985c7fc3c5132e6f6b9b3ebe'
8+
second_image = 'winamd64/hola-mundo'
99
default_dockerfile = 'C:/Users/Administrator/AppData/Local/Temp/Dockerfile'
1010
dockerfile_test = 'C:/Windows/Dockerfile_test.txt'
1111
#The default args are set because:

spec/acceptance/stack_spec.rb

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ class { 'docker': #{docker_args} }
5757
end
5858
end
5959

60-
it 'should find a docker container' do
61-
shell("docker ps | grep web_compose_test", :acceptable_exit_codes => [0])
62-
end
60+
it 'should not find a docker container' do
61+
shell("docker ps -a -q -f \"name=web_compose_test\"", :acceptable_exit_codes => [0])
62+
end
6363
end
6464

6565
context 'Destroying stack' do
@@ -87,10 +87,9 @@ class { 'docker': #{docker_args} }
8787
end
8888

8989
it 'should not find a docker stack' do
90-
sleep 5
91-
shell('docker stack ls') do |r|
92-
expect(r.stdout).to_not match(/web/)
93-
end
90+
shell('docker stack ls') do |r|
91+
expect(r.stdout).to_not match(/web/)
92+
end
9493
end
9594
end
9695

@@ -131,8 +130,10 @@ class { 'docker': #{docker_args} }
131130
}
132131
code
133132

134-
apply_manifest(@destroy_code, :catch_failures=>true)
135-
sleep 10# wait for containers to stop
133+
retry_on_error_matching(10, 3, /Removing network web_default/) do
134+
apply_manifest(@destroy_code, :catch_failures=>true)
135+
end
136+
sleep 15 # Wait for containers to stop and be destroyed
136137
end
137138

138139
it 'should be idempotent' do
@@ -148,7 +149,9 @@ class { 'docker': #{docker_args} }
148149
end
149150

150151
it 'should not find a docker container' do
151-
shell("docker ps | grep web_compose_test", :acceptable_exit_codes => [1])
152+
shell("docker ps", :acceptable_exit_codes => [0]) do |r|
153+
expect(r.stdout).not_to match(/web_compose_test/)
154+
end
152155
end
153156
end
154157

spec/spec_helper_acceptance.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, e
112112
version: "3"
113113
services:
114114
compose_test:
115-
image: hello-world:nanoserver
115+
image: winamd64/hello-world
116116
command: cmd.exe /C "ping 8.8.8.8 -t"
117117
networks:
118118
default:
@@ -123,7 +123,7 @@ def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, e
123123
version: "3"
124124
services:
125125
compose_test:
126-
image: hello-world:nanoserver-sac2016
126+
image: winamd64/hello-world:nanoserver-sac2016
127127
command: cmd.exe /C "ping 8.8.8.8 -t"
128128
networks:
129129
default:
@@ -134,14 +134,14 @@ def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, e
134134
version: "3"
135135
services:
136136
compose_test:
137-
image: hello-world:nanoserver
137+
image: winamd64/hello-world
138138
command: cmd.exe /C "ping 8.8.8.8 -t"
139139
EOS
140140
docker_stack_override_windows = <<-EOS
141141
version: "3"
142142
services:
143143
compose_test:
144-
image: hello-world:nanoserver-sac2016
144+
image: winamd64/hello-world:nanoserver-sac2016
145145
EOS
146146
if fact_on(host, 'osfamily') == 'windows'
147147
create_remote_file(host, '/tmp/docker-compose-v3.yml', docker_compose_content_v3_windows)

0 commit comments

Comments
 (0)