1+ require 'spec_helper_acceptance'
2+
3+ if fact ( 'osfamily' ) == 'windows'
4+ install_dir = '/cygdrive/c/Program Files/Docker'
5+ file_extension = '.exe'
6+ docker_args = 'docker_ee => true'
7+ tmp_path = 'C:/cygwin64/tmp'
8+ test_docker_image = 'hello-world:nanoserver'
9+ test_docker_command = 'cmd.exe /C "ping /t 8.8.8.8"'
10+ else
11+ install_dir = '/usr/local/bin'
12+ file_extension = ''
13+ docker_args = ''
14+ tmp_path = '/tmp'
15+ test_docker_image = 'ubuntu:16.04'
16+ test_docker_command = '/bin/sh -c "while true; do echo hello world; sleep 1; done"'
17+ end
18+
19+ skip_tests = false
20+
21+ begin
22+ swarm_manager = only_host_with_role ( hosts , 'swarm-manager' )
23+ swarm_worker = only_host_with_role ( hosts , 'swarm-worker' )
24+ manager_ip = swarm_manager . ip
25+ rescue ArgumentError
26+ skip_tests = true
27+ end
28+
29+ describe 'docker swarm' , :skip => skip_tests do
30+ before ( :all ) do
31+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
32+ @install_code = <<-code
33+ class { 'docker': #{ docker_args } }
34+ code
35+ apply_manifest_on ( swarm_manager , @install_code , :catch_failures => true )
36+ end
37+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
38+ apply_manifest_on ( swarm_worker , @install_code , :catch_failures => true )
39+ end
40+ end
41+
42+ context 'Creating a swarm master' do
43+ before ( :all ) do
44+ @setup_manager = <<-code
45+ docker::swarm {'cluster_manager':
46+ init => true,
47+ advertise_addr => '#{ manager_ip } ',
48+ listen_addr => '#{ manager_ip } ',
49+ ensure => 'present',
50+ }
51+ code
52+
53+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
54+ apply_manifest_on ( swarm_manager , @setup_manager , :catch_failures => true )
55+ end
56+
57+ if fact ( 'osfamily' ) == 'windows'
58+ on swarm_manager , 'netsh advfirewall firewall add rule name="Swarm mgmgt" dir=in action=allow protocol=TCP localport=2377' , :acceptable_exit_codes => [ 0 ]
59+ on swarm_manager , 'netsh advfirewall firewall add rule name="Swarm comm tcp" dir=in action=allow protocol=TCP localport=7946' , :acceptable_exit_codes => [ 0 ]
60+ on swarm_manager , 'netsh advfirewall firewall add rule name="Swarm comm udp" dir=in action=allow protocol=UDP localport=7946' , :acceptable_exit_codes => [ 0 ]
61+ on swarm_manager , 'netsh advfirewall firewall add rule name="Swarm network" dir=in action=allow protocol=UDP localport=4789' , :acceptable_exit_codes => [ 0 ]
62+ end
63+ end
64+
65+ it 'should be idempotent' do
66+ apply_manifest_on ( swarm_manager , @setup_manager , :catch_failures => true )
67+ end
68+
69+ it 'should display nodes' do
70+ on swarm_manager , 'docker node ls' , :acceptable_exit_codes => [ 0 ] do |result |
71+ expect ( result . stdout ) . to match ( /Leader/ )
72+ end
73+ end
74+
75+ it 'should join a node' do
76+ token = shell ( 'docker swarm join-token -q worker' ) . stdout . strip
77+ @setup_slave = <<-code
78+ docker::swarm {'cluster_worker':
79+ join => true,
80+ advertise_addr => '#{ swarm_worker . ip } ',
81+ listen_addr => '#{ swarm_worker . ip } ',
82+ manager_ip => '#{ manager_ip } ',
83+ token => '#{ token } ',
84+ }
85+ code
86+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
87+ apply_manifest_on ( swarm_worker , @setup_slave , :catch_failures => true )
88+ end
89+
90+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
91+ on swarm_worker , 'docker info' do |result |
92+ expect ( result . stdout ) . to match ( /Swarm: active/ )
93+ end
94+ end
95+
96+ if fact ( 'osfamily' ) == 'windows'
97+ on swarm_worker , 'netsh advfirewall firewall add rule name="Swarm mgmgt" dir=in action=allow protocol=TCP localport=2377' , :acceptable_exit_codes => [ 0 ]
98+ on swarm_worker , 'netsh advfirewall firewall add rule name="Swarm comm tcp" dir=in action=allow protocol=TCP localport=7946' , :acceptable_exit_codes => [ 0 ]
99+ on swarm_worker , 'netsh advfirewall firewall add rule name="Swarm comm udp" dir=in action=allow protocol=UDP localport=7946' , :acceptable_exit_codes => [ 0 ]
100+ on swarm_worker , 'netsh advfirewall firewall add rule name="Swarm network" dir=in action=allow protocol=UDP localport=4789' , :acceptable_exit_codes => [ 0 ]
101+ end
102+
103+ on swarm_manager , 'docker network create --driver=overlay swarmnet' , :acceptable_exit_codes => [ 0 ]
104+ end
105+
106+ it 'should start a container' do
107+ on swarm_manager , "docker service create --name=helloworld --endpoint-mode dnsrr --network=swarmnet #{ test_docker_image } #{ test_docker_command } " , :acceptable_exit_codes => [ 0 ]
108+ on swarm_manager , 'docker service ps helloworld' , :acceptable_exit_codes => [ 0 ] do |result |
109+ expect ( result . stdout ) . to match ( /Running/ )
110+ end
111+ end
112+
113+ after ( :all ) do
114+ remove_worker = <<-code
115+ docker::swarm {'cluster_worker':
116+ ensure => 'absent',
117+ }
118+ code
119+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
120+ apply_manifest_on ( swarm_worker , remove_worker , :catch_failures => true )
121+ end
122+ remove_mgr = <<-code
123+ docker::swarm {'cluster_manager':
124+ ensure => 'absent',
125+ }
126+ code
127+ retry_on_error_matching ( 60 , 5 , /connection failure running/ ) do
128+ apply_manifest_on ( swarm_manager , remove_mgr , :catch_failures => true )
129+ end
130+ end
131+ end
132+ end
0 commit comments