-
Notifications
You must be signed in to change notification settings - Fork 321
/
Copy pathspec_helper_acceptance.rb
172 lines (159 loc) · 6.11 KB
/
spec_helper_acceptance.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# frozen_string_literal: true
require 'beaker-rspec/spec_helper'
require 'beaker-rspec/helpers/serverspec'
require 'beaker/puppet_install_helper'
require 'rspec/retry'
begin
require 'pry'
rescue LoadError # rubocop:disable Lint/HandleExceptions for optional loading
end
# This method allows a block to be passed in and if an exception is raised
# that matches the 'error_matcher' matcher, the block will wait a set number
# of seconds before retrying.
# Params:
# - max_retry_count - Max number of retries
# - retry_wait_interval_secs - Number of seconds to wait before retry
# - error_matcher - Matcher which the exception raised must match to allow retry
# Example Usage:
# retry_on_error_matching(3, 5, /OpenGPG Error/) do
# apply_manifest(pp, :catch_failures => true)
# end
def retry_on_error_matching(max_retry_count = 3, retry_wait_interval_secs = 5, error_matcher = nil)
try = 0
begin
try += 1
yield
rescue StandardError => e
raise unless try < max_retry_count && (error_matcher.nil? || e.message =~ error_matcher)
sleep retry_wait_interval_secs
retry
end
end
run_puppet_install_helper unless ENV['BEAKER_provision'] == 'no'
RSpec.configure do |c|
# Add exclusive filter for Windows untill all the windows functionality is implemented
c.filter_run_excluding win_broken: true
# Project root
proj_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
# Readable test descriptions
c.formatter = :documentation
# show retry status in spec process
c.verbose_retry = true
# show exception that triggers a retry if verbose_retry is set to true
c.display_try_failure_messages = true
# Configure all nodes in nodeset
c.before :suite do
# Install module and dependencies
hosts.each do |host|
next unless not_controller(host)
copy_module_to(host, source: proj_root, module_name: 'docker')
# Due to RE-6764, running yum update renders the machine unable to install
# other software. Thus this workaround.
if fact_on(host, 'operatingsystem') == 'RedHat'
on(host, 'mv /etc/yum.repos.d/redhat.repo /etc/yum.repos.d/internal-mirror.repo')
on(host, 'rpm -ivh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm')
end
on(host, 'yum update -y -q') if fact_on(host, 'osfamily') == 'RedHat'
on host, puppet('module', 'install', 'puppetlabs-stdlib', '--version', '4.24.0'), acceptable_exit_codes: [0, 1]
on host, puppet('module', 'install', 'puppetlabs-apt', '--version', '4.4.1'), acceptable_exit_codes: [0, 1]
on host, puppet('module', 'install', 'puppetlabs-translate', '--version', '1.0.0'), acceptable_exit_codes: [0, 1]
on host, puppet('module', 'install', 'puppetlabs-powershell', '--version', '2.1.5'), acceptable_exit_codes: [0, 1]
on host, puppet('module', 'install', 'puppetlabs-reboot', '--version', '2.0.0'), acceptable_exit_codes: [0, 1]
# net-tools required for netstat utility being used by some tests
if fact_on(host, 'osfamily') == 'RedHat' && fact_on(host, 'operatingsystemmajrelease') == '7'
on(host, 'yum install -y net-tools device-mapper')
end
if fact_on(host, 'operatingsystem') == 'Debian'
on(host, 'apt-get install net-tools')
end
docker_compose_content_v3 = <<-EOS
version: "3.4"
x-images:
&default-image
alpine:3.8
services:
compose_test:
image: *default-image
command: /bin/sh -c "while true; do echo hello world; sleep 1; done"
EOS
docker_compose_override_v3 = <<-EOS
version: "3.4"
x-images:
&default-image
debian:stable-slim
services:
compose_test:
image: *default-image
command: /bin/sh -c "while true; do echo hello world; sleep 1; done"
EOS
docker_stack_override_v3 = <<-EOS
version: "3.4"
x-images:
&default-image
debian:stable-slim
services:
compose_test:
image: *default-image
command: /bin/sh -c "while true; do echo hello world; sleep 1; done"
EOS
docker_compose_content_v3_windows = <<-EOS
version: "3"
services:
compose_test:
image: hello-world:nanoserver
command: cmd.exe /C "ping 8.8.8.8 -t"
networks:
default:
external:
name: nat
EOS
docker_compose_override_v3_windows = <<-EOS
version: "3"
services:
compose_test:
image: hello-world:nanoserver-sac2016
command: cmd.exe /C "ping 8.8.8.8 -t"
networks:
default:
external:
name: nat
EOS
docker_stack_content_windows = <<-EOS
version: "3"
services:
compose_test:
image: hello-world:nanoserver
command: cmd.exe /C "ping 8.8.8.8 -t"
EOS
docker_stack_override_windows = <<-EOS
version: "3"
services:
compose_test:
image: hello-world:nanoserver-sac2016
command: cmd.exe /C "ping 8.8.8.8 -t"
EOS
if fact_on(host, 'osfamily') == 'windows'
create_remote_file(host, '/tmp/docker-compose-v3.yml', docker_compose_content_v3_windows)
create_remote_file(host, '/tmp/docker-stack.yml', docker_stack_content_windows)
create_remote_file(host, '/tmp/docker-compose-override-v3.yml', docker_compose_override_v3_windows)
create_remote_file(host, '/tmp/docker-stack-override.yml', docker_stack_override_windows)
else
create_remote_file(host, '/tmp/docker-compose-v3.yml', docker_compose_content_v3)
create_remote_file(host, '/tmp/docker-stack.yml', docker_compose_content_v3)
create_remote_file(host, '/tmp/docker-compose-override-v3.yml', docker_compose_override_v3)
create_remote_file(host, '/tmp/docker-stack-override.yml', docker_stack_override_v3)
end
next unless fact_on(host, 'osfamily') == 'windows'
win_host = only_host_with_role(hosts, 'default')
retry_on_error_matching(60, 5, %r{connection failure running}) do
@windows_ip = win_host.ip
end
apply_manifest_on(host, "class { 'docker': docker_ee => true, extra_parameters => '\"insecure-registries\": [ \"#{@windows_ip}:5000\" ]' }")
docker_path = '/cygdrive/c/Program Files/Docker'
host.add_env_var('PATH', docker_path)
host.add_env_var('TEMP', 'C:\Users\Administrator\AppData\Local\Temp')
puts 'Waiting for box to come online'
sleep 300
end
end
end