beaker 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/HISTORY.md +258 -2
- data/beaker.gemspec +2 -1
- data/lib/beaker/answers/version20.rb +0 -1
- data/lib/beaker/answers/version28.rb +0 -1
- data/lib/beaker/answers/version34.rb +1 -1
- data/lib/beaker/command.rb +1 -1
- data/lib/beaker/dsl/helpers.rb +48 -20
- data/lib/beaker/dsl/install_utils.rb +110 -8
- data/lib/beaker/dsl/wrappers.rb +10 -2
- data/lib/beaker/host.rb +133 -18
- data/lib/beaker/host/pswindows.rb +23 -49
- data/lib/beaker/host/pswindows/file.rb +11 -2
- data/lib/beaker/host/pswindows/pkg.rb +12 -6
- data/lib/beaker/host/unix.rb +18 -14
- data/lib/beaker/host/windows.rb +18 -1
- data/lib/beaker/host/windows/file.rb +5 -0
- data/lib/beaker/host_prebuilt_steps.rb +41 -19
- data/lib/beaker/hypervisor.rb +3 -1
- data/lib/beaker/hypervisor/docker.rb +12 -4
- data/lib/beaker/hypervisor/openstack.rb +28 -5
- data/lib/beaker/options/presets.rb +1 -0
- data/lib/beaker/version.rb +1 -1
- data/spec/beaker/dsl/helpers_spec.rb +69 -22
- data/spec/beaker/dsl/install_utils_spec.rb +82 -4
- data/spec/beaker/dsl/wrappers_spec.rb +2 -2
- data/spec/beaker/host_spec.rb +30 -2
- metadata +18 -4
@@ -2,14 +2,23 @@ module PSWindows::File
|
|
2
2
|
include Beaker::CommandFactory
|
3
3
|
|
4
4
|
def tmpfile(name)
|
5
|
-
execute("echo C:\\Windows\\Temp\\#{name}
|
5
|
+
execute("echo C:\\Windows\\Temp\\#{name}.%RANDOM%")
|
6
6
|
end
|
7
7
|
|
8
8
|
def tmpdir(name)
|
9
|
-
|
9
|
+
# generate name
|
10
|
+
tmpdirname = execute("echo C:\\Windows\\Temp\\#{name}.%RANDOM%")
|
11
|
+
# created named dir
|
12
|
+
execute("md #{tmpdirname}")
|
13
|
+
tmpdirname
|
10
14
|
end
|
11
15
|
|
12
16
|
def path_split(paths)
|
13
17
|
paths.split(';')
|
14
18
|
end
|
19
|
+
|
20
|
+
def file_exist?(path)
|
21
|
+
result = exec(Beaker::Command.new("if exist #{path} echo true"), :acceptable_exit_codes => [0, 1])
|
22
|
+
result.stdout =~ /true/
|
23
|
+
end
|
15
24
|
end
|
@@ -7,15 +7,21 @@ module PSWindows::Pkg
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def check_for_package(name)
|
10
|
-
|
10
|
+
#HACK NOOP
|
11
|
+
#raise "Cannot check for package #{name} on #{self}"
|
12
|
+
0
|
11
13
|
end
|
12
14
|
|
13
15
|
def install_package(name, cmdline_args = '')
|
14
|
-
|
16
|
+
#HACK NOOP
|
17
|
+
#raise "Package #{name} cannot be installed on #{self}"
|
18
|
+
0
|
15
19
|
end
|
16
20
|
|
17
21
|
def uninstall_package(name, cmdline_args = '')
|
18
|
-
|
22
|
+
#HACK NOOP
|
23
|
+
#raise "Package #{name} cannot be uninstalled on #{self}"
|
24
|
+
0
|
19
25
|
end
|
20
26
|
|
21
27
|
private
|
@@ -23,7 +29,7 @@ module PSWindows::Pkg
|
|
23
29
|
# @api private
|
24
30
|
def identify_windows_architecture
|
25
31
|
arch = nil
|
26
|
-
execute("
|
32
|
+
execute("wmic os get osarchitecture",
|
27
33
|
:acceptable_exit_codes => (0...127)) do |result|
|
28
34
|
|
29
35
|
arch = if result.exit_code == 0
|
@@ -38,9 +44,9 @@ module PSWindows::Pkg
|
|
38
44
|
# @api private
|
39
45
|
def identify_windows_architecture_from_os_name_for_win2003
|
40
46
|
arch = nil
|
41
|
-
execute("
|
47
|
+
execute("wmic os get name",
|
42
48
|
:acceptable_exit_codes => (0...127)) do |result|
|
43
|
-
arch = result.
|
49
|
+
arch = result.stdout =~ /64/ ? '64' : '32'
|
44
50
|
end
|
45
51
|
arch
|
46
52
|
end
|
data/lib/beaker/host/unix.rb
CHANGED
@@ -61,20 +61,24 @@ module Unix
|
|
61
61
|
end
|
62
62
|
|
63
63
|
def self.aio_defaults
|
64
|
-
h =
|
65
|
-
h
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
64
|
+
h = Beaker::Options::OptionsHash.new
|
65
|
+
h.merge({
|
66
|
+
'user' => 'root',
|
67
|
+
'group' => 'puppet',
|
68
|
+
'puppetserver-confdir' => '/etc/puppetlabs/puppetserver/conf.d',
|
69
|
+
'puppetservice' => 'puppetserver',
|
70
|
+
'puppetpath' => '/etc/puppetlabs/puppet',
|
71
|
+
'puppetconfdir' => '/etc/puppetlabs/puppet',
|
72
|
+
'puppetvardir' => '/opt/puppetlabs/puppet/cache',
|
73
|
+
'puppetbin' => '/opt/puppetlabs/puppet/bin/puppet',
|
74
|
+
'puppetbindir' => '/opt/puppetlabs/bin',
|
75
|
+
'systembindir' => '/usr/bin',
|
76
|
+
'hieradatadir' => '/etc/puppetlabs/code/hieradata',
|
77
|
+
'hieraconf' => '/etc/puppetlabs/code/hiera.yaml',
|
78
|
+
'distmoduledir' => '/etc/puppetlabs/code/modules',
|
79
|
+
'sitemoduledir' => '/opt/puppetlabs/puppet/modules',
|
80
|
+
'pathseparator' => ':',
|
81
|
+
})
|
78
82
|
end
|
79
83
|
end
|
80
84
|
end
|
data/lib/beaker/host/windows.rb
CHANGED
@@ -55,7 +55,24 @@ module Windows
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def self.aio_defaults
|
58
|
-
|
58
|
+
h = Beaker::Options::OptionsHash.new
|
59
|
+
h.merge({
|
60
|
+
'user' => 'Administrator',
|
61
|
+
'group' => 'Administrators',
|
62
|
+
# 'puppetserver-confdir' not applicable on Windows
|
63
|
+
# 'puppetservice' not applicable on Windows
|
64
|
+
'puppetpath' => '`cygpath -smF 35`/PuppetLabs/puppet/etc',
|
65
|
+
'puppetconfdir' => '`cygpath -smF 35`/PuppetLabs/puppet/etc',
|
66
|
+
'puppetvardir' => '`cygpath -smF 35`/PuppetLabs/puppet/cache',
|
67
|
+
# 'puppetbin' not required on Windows
|
68
|
+
'puppetbindir' => '/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/bin:/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/sys/ruby/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/sys/ruby/bin',
|
69
|
+
# systembindir not required on Windows
|
70
|
+
'hieradatadir' => '`cygpath -smF 35`/Puppetlabs/code/hieradata',
|
71
|
+
'hieraconf' => '`cygpath -smF 35`/Puppetlabs/code/hiera.yaml',
|
72
|
+
'distmoduledir' => '`cygpath -smF 35`/PuppetLabs/code/modules',
|
73
|
+
# sitemoduledir not included (check PUP-4049 for more info)
|
74
|
+
'pathseparator' => ';',
|
75
|
+
})
|
59
76
|
end
|
60
77
|
end
|
61
78
|
end
|
@@ -14,6 +14,7 @@ module Beaker
|
|
14
14
|
TRIES = 5
|
15
15
|
UNIX_PACKAGES = ['curl', 'ntpdate']
|
16
16
|
WINDOWS_PACKAGES = ['curl']
|
17
|
+
PSWINDOWS_PACKAGES = []
|
17
18
|
SLES_PACKAGES = ['curl', 'ntp']
|
18
19
|
DEBIAN_PACKAGES = ['curl', 'ntpdate', 'lsb-release']
|
19
20
|
CUMULUS_PACKAGES = ['addons', 'ntpdate', 'lsb-release']
|
@@ -76,7 +77,8 @@ module Beaker
|
|
76
77
|
# {HostPrebuiltSteps::SLES_PACKAGES} on SUSE platform hosts,
|
77
78
|
# {HostPrebuiltSteps::DEBIAN_PACKAGES} on debian platform hosts,
|
78
79
|
# {HostPrebuiltSteps::CUMULUS_PACKAGES} on cumulus platform hosts,
|
79
|
-
#
|
80
|
+
# {HostPrebuiltSteps::WINDOWS_PACKAGES} on cygwin-installed windows platform hosts,
|
81
|
+
# and {HostPrebuiltSteps::PSWINDOWS_PACKAGES} on non-cygwin windows platform hosts.
|
80
82
|
#
|
81
83
|
# @param [Host, Array<Host>, String, Symbol] host One or more hosts to act upon
|
82
84
|
# @param [Hash{Symbol=>String}] opts Options to alter execution.
|
@@ -91,8 +93,10 @@ module Beaker
|
|
91
93
|
check_and_install_packages_if_needed(host, DEBIAN_PACKAGES)
|
92
94
|
when host['platform'] =~ /cumulus/
|
93
95
|
check_and_install_packages_if_needed(host, CUMULUS_PACKAGES)
|
94
|
-
when host['platform'] =~ /windows/
|
96
|
+
when (host['platform'] =~ /windows/ and host.is_cygwin?)
|
95
97
|
check_and_install_packages_if_needed(host, WINDOWS_PACKAGES)
|
98
|
+
when (host['platform'] =~ /windows/ and not host.is_cygwin?)
|
99
|
+
check_and_install_packages_if_needed(host, PSWINDOWS_PACKAGES)
|
96
100
|
when host['platform'] !~ /debian|aix|solaris|windows|sles-|osx-|cumulus/
|
97
101
|
check_and_install_packages_if_needed(host, UNIX_PACKAGES)
|
98
102
|
end
|
@@ -296,9 +300,11 @@ module Beaker
|
|
296
300
|
logger = opts[:logger]
|
297
301
|
block_on host do |host|
|
298
302
|
logger.debug "Give root a copy of current user's keys, on #{host.name}"
|
299
|
-
if host['platform'] =~ /windows/
|
303
|
+
if host['platform'] =~ /windows/ and host.is_cygwin?
|
300
304
|
host.exec(Command.new('cp -r .ssh /cygdrive/c/Users/Administrator/.'))
|
301
305
|
host.exec(Command.new('chown -R Administrator /cygdrive/c/Users/Administrator/.ssh'))
|
306
|
+
elsif host['platform'] =~ /windows/ and not host.is_cygwin?
|
307
|
+
host.exec(Command.new("if exist .ssh (xcopy .ssh C:\\Users\\Administrator\\.ssh /s /e)"))
|
302
308
|
elsif host['platform'] =~ /osx/
|
303
309
|
host.exec(Command.new('sudo cp -r .ssh /var/root/.'), {:pty => true})
|
304
310
|
else
|
@@ -433,7 +439,11 @@ module Beaker
|
|
433
439
|
# @param [String] val The string to 'echo' on the host
|
434
440
|
def echo_on_host host, val
|
435
441
|
#val = val.gsub(/"/, "\"").gsub(/\(/, "\(")
|
436
|
-
host.
|
442
|
+
if host.is_cygwin?
|
443
|
+
host.exec(Command.new("echo \"#{val}\"")).stdout.chomp
|
444
|
+
else
|
445
|
+
host.exec(Command.new("echo #{val}")).stdout.chomp
|
446
|
+
end
|
437
447
|
end
|
438
448
|
|
439
449
|
# Create the hash of default environment from host (:host_env), global options hash (:host_env) and default PE/Foss puppet variables
|
@@ -463,7 +473,7 @@ module Beaker
|
|
463
473
|
env['RUBYLIB'].map! { |val| echo_on_host(host, val) }
|
464
474
|
|
465
475
|
env.each_key do |key|
|
466
|
-
env[key] = env[key].join('
|
476
|
+
env[key] = env[key].join(host['pathseparator'])
|
467
477
|
end
|
468
478
|
env
|
469
479
|
end
|
@@ -479,10 +489,14 @@ module Beaker
|
|
479
489
|
logger.debug("setting local environment on #{host.name}")
|
480
490
|
case host['platform']
|
481
491
|
when /windows/
|
482
|
-
host.
|
483
|
-
|
484
|
-
|
485
|
-
|
492
|
+
if host.is_cygwin?
|
493
|
+
host.exec(Command.new("echo '\nPermitUserEnvironment yes' >> /etc/sshd_config"))
|
494
|
+
host.exec(Command.new("cygrunsrv -E sshd"))
|
495
|
+
host.exec(Command.new("cygrunsrv -S sshd"))
|
496
|
+
env['CYGWIN'] = 'nodosfilewarning'
|
497
|
+
else
|
498
|
+
#nothing to do here
|
499
|
+
end
|
486
500
|
when /osx/
|
487
501
|
host.exec(Command.new("echo '\nPermitUserEnvironment yes' >> /etc/sshd_config"))
|
488
502
|
host.exec(Command.new("launchctl unload /System/Library/LaunchDaemons/ssh.plist"))
|
@@ -505,22 +519,30 @@ module Beaker
|
|
505
519
|
host.exec(Command.new("startsrc -g ssh"))
|
506
520
|
end
|
507
521
|
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
522
|
+
if host['platform'] !~ /windows/ or (host['platform'] =~ /windows/ and host.is_cygwin?)
|
523
|
+
#ensure that ~/.ssh/environment exists
|
524
|
+
host.exec(Command.new("mkdir -p #{Pathname.new(host[:ssh_env_file]).dirname}"))
|
525
|
+
host.exec(Command.new("chmod 0600 #{Pathname.new(host[:ssh_env_file]).dirname}"))
|
526
|
+
host.exec(Command.new("touch #{host[:ssh_env_file]}"))
|
527
|
+
#add the constructed env vars to this host
|
528
|
+
host.add_env_var('RUBYLIB', '$RUBYLIB')
|
529
|
+
host.add_env_var('PATH', '$PATH')
|
530
|
+
end
|
531
|
+
#add the env var set to this test host
|
516
532
|
env.each_pair do |var, value|
|
517
533
|
host.add_env_var(var, value)
|
518
534
|
end
|
519
535
|
|
520
|
-
host.exec(Command.new("cat #{host[:ssh_env_file]}"))
|
521
|
-
|
522
536
|
#close the host to re-establish the connection with the new sshd settings
|
523
537
|
host.close
|
538
|
+
|
539
|
+
# print out the working env
|
540
|
+
if host.is_cygwin?
|
541
|
+
host.exec(Command.new("cat #{host[:ssh_env_file]}"))
|
542
|
+
else
|
543
|
+
host.exec(Command.new("SET"))
|
544
|
+
end
|
545
|
+
|
524
546
|
end
|
525
547
|
end
|
526
548
|
|
data/lib/beaker/hypervisor.rb
CHANGED
@@ -110,7 +110,9 @@ module Beaker
|
|
110
110
|
if @options[:disable_iptables]
|
111
111
|
disable_iptables @hosts, @options
|
112
112
|
end
|
113
|
-
|
113
|
+
if @options[:set_env]
|
114
|
+
set_env(@hosts, @options)
|
115
|
+
end
|
114
116
|
end
|
115
117
|
|
116
118
|
#Default validation steps to be run for a given hypervisor. Ensures that SUTs meet requirements to be
|
@@ -119,15 +119,15 @@ module Beaker
|
|
119
119
|
sshd_options = ''
|
120
120
|
|
121
121
|
# add platform-specific actions
|
122
|
+
service_name = "sshd"
|
122
123
|
case host['platform']
|
123
124
|
when /ubuntu/, /debian/
|
124
|
-
|
125
|
+
service_name = "ssh"
|
125
126
|
dockerfile += <<-EOF
|
126
127
|
RUN apt-get update
|
127
128
|
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::DEBIAN_PACKAGES.join(' ')}
|
128
129
|
EOF
|
129
130
|
when /cumulus/
|
130
|
-
sshd_options = '-o "PermitRootLogin yes" -o "PasswordAuthentication yes"'
|
131
131
|
dockerfile += <<-EOF
|
132
132
|
RUN apt-get update
|
133
133
|
RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')}
|
@@ -140,11 +140,11 @@ module Beaker
|
|
140
140
|
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
141
141
|
EOF
|
142
142
|
when /opensuse/, /sles/
|
143
|
-
sshd_options = '-o "PermitRootLogin yes" -o "PasswordAuthentication yes" -o "UsePAM no"'
|
144
143
|
dockerfile += <<-EOF
|
145
144
|
RUN zypper -n in openssh #{Beaker::HostPrebuiltSteps::SLES_PACKAGES.join(' ')}
|
146
145
|
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
|
147
146
|
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
|
147
|
+
RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
|
148
148
|
EOF
|
149
149
|
else
|
150
150
|
# TODO add more platform steps here
|
@@ -157,6 +157,13 @@ module Beaker
|
|
157
157
|
RUN echo root:#{root_password} | chpasswd
|
158
158
|
EOF
|
159
159
|
|
160
|
+
# Configure sshd service to allowroot login using password
|
161
|
+
dockerfile += <<-EOF
|
162
|
+
RUN sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
|
163
|
+
RUN sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
|
164
|
+
EOF
|
165
|
+
|
166
|
+
|
160
167
|
# Any extra commands specified for the host
|
161
168
|
dockerfile += (host['docker_image_commands'] || []).map { |command|
|
162
169
|
"RUN #{command}\n"
|
@@ -168,7 +175,8 @@ module Beaker
|
|
168
175
|
end
|
169
176
|
|
170
177
|
# How to start a sshd on port 22. May be an init for more supervision
|
171
|
-
|
178
|
+
# Ensure that the ssh server can be restarted (done from set_env) and container keeps running
|
179
|
+
cmd = host['docker_cmd'] || ["sh","-c","service #{service_name} start ; tail -f /dev/null"]
|
172
180
|
dockerfile += <<-EOF
|
173
181
|
EXPOSE 22
|
174
182
|
CMD #{cmd}
|
@@ -44,7 +44,8 @@ module Beaker
|
|
44
44
|
:provider => :openstack,
|
45
45
|
:openstack_api_key => @options[:openstack_api_key],
|
46
46
|
:openstack_username => @options[:openstack_username],
|
47
|
-
:openstack_auth_url => @options[:openstack_auth_url]
|
47
|
+
:openstack_auth_url => @options[:openstack_auth_url],
|
48
|
+
:openstack_tenant => @options[:openstack_tenant])
|
48
49
|
if not @network_client
|
49
50
|
|
50
51
|
raise "Unable to create OpenStack Network instance (api_key: #{@options[:openstack_api_key]}, username: #{@options[:openstack_username]}, auth_url: #{@options[:openstack_auth_url]}, tenant: #{@options[:openstack_tenant]})"
|
@@ -88,10 +89,7 @@ module Beaker
|
|
88
89
|
:nics => [ {'net_id' => network(@options[:openstack_network]).id } ],
|
89
90
|
:name => host[:vmhostname],
|
90
91
|
}
|
91
|
-
|
92
|
-
@logger.debug "Adding optional key_name #{@options[:openstack_keyname]} to #{host.name} (#{host[:vmhostname]})"
|
93
|
-
options[:key_name] = @options[:openstack_keyname]
|
94
|
-
end
|
92
|
+
options[:key_name] = key_name(host)
|
95
93
|
vm = @compute_client.servers.create(options)
|
96
94
|
|
97
95
|
#wait for the new instance to start up
|
@@ -149,6 +147,10 @@ module Beaker
|
|
149
147
|
end
|
150
148
|
@logger.debug "Destroying OpenStack host #{vm.name}"
|
151
149
|
vm.destroy
|
150
|
+
if @options[:openstack_keyname].nil?
|
151
|
+
@logger.debug "Deleting random keypair"
|
152
|
+
@compute_client.delete_key_pair vm.name
|
153
|
+
end
|
152
154
|
end
|
153
155
|
end
|
154
156
|
|
@@ -175,5 +177,26 @@ module Beaker
|
|
175
177
|
end
|
176
178
|
end
|
177
179
|
|
180
|
+
#Get key_name from options or generate a new rsa key and add it to
|
181
|
+
#OpenStack keypairs
|
182
|
+
#
|
183
|
+
#@param [Host] host The OpenStack host to provision
|
184
|
+
#@return [String] key_name
|
185
|
+
#@api private
|
186
|
+
def key_name(host)
|
187
|
+
if @options[:openstack_keyname]
|
188
|
+
@logger.debug "Adding optional key_name #{@options[:openstack_keyname]} to #{host.name} (#{host[:vmhostname]})"
|
189
|
+
@options[:openstack_keyname]
|
190
|
+
else
|
191
|
+
@logger.debug "Generate a new rsa key"
|
192
|
+
key = OpenSSL::PKey::RSA.new 2048
|
193
|
+
type = key.ssh_type
|
194
|
+
data = [ key.to_blob ].pack('m0')
|
195
|
+
@logger.debug "Creating Openstack keypair for public key '#{type} #{data}'"
|
196
|
+
@compute_client.create_key_pair host[:vmhostname], "#{type} #{data}"
|
197
|
+
host['ssh'][:key_data] = [ key.to_pem ]
|
198
|
+
host[:vmhostname]
|
199
|
+
end
|
200
|
+
end
|
178
201
|
end
|
179
202
|
end
|
data/lib/beaker/version.rb
CHANGED
@@ -258,7 +258,19 @@ describe ClassMixedWithDSLHelpers do
|
|
258
258
|
end
|
259
259
|
end
|
260
260
|
|
261
|
-
describe '#
|
261
|
+
describe '#rsync_to' do
|
262
|
+
it 'delegates to the host' do
|
263
|
+
allow( subject ).to receive( :hosts ).and_return( hosts )
|
264
|
+
|
265
|
+
hosts.each do |host|
|
266
|
+
expect( host ).to receive( :do_rsync_to ).and_return( result )
|
267
|
+
end
|
268
|
+
|
269
|
+
subject.rsync_to( hosts, '/var/log/my.log', 'log/my.log' )
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
describe '#create_remote_file using scp' do
|
262
274
|
it 'scps the contents passed in to the hosts' do
|
263
275
|
my_opts = { :silent => true }
|
264
276
|
tmpfile = double
|
@@ -277,6 +289,25 @@ describe ClassMixedWithDSLHelpers do
|
|
277
289
|
end
|
278
290
|
end
|
279
291
|
|
292
|
+
describe '#create_remote_file using rsync' do
|
293
|
+
it 'scps the contents passed in to the hosts' do
|
294
|
+
my_opts = { :silent => true, :protocol => 'rsync' }
|
295
|
+
tmpfile = double
|
296
|
+
|
297
|
+
expect( tmpfile ).to receive( :path ).exactly( 2 ).times.
|
298
|
+
and_return( '/local/path/to/blah' )
|
299
|
+
|
300
|
+
expect( Tempfile ).to receive( :open ).and_yield( tmpfile )
|
301
|
+
|
302
|
+
expect( File ).to receive( :open )
|
303
|
+
|
304
|
+
expect( subject ).to receive( :rsync_to ).
|
305
|
+
with( hosts, '/local/path/to/blah', '/remote/path', my_opts )
|
306
|
+
|
307
|
+
subject.create_remote_file( hosts, '/remote/path', 'blah', my_opts )
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
280
311
|
describe '#create_tmpdir_for_user' do
|
281
312
|
let(:host) { {} }
|
282
313
|
let(:result) { double.as_null_object }
|
@@ -784,12 +815,6 @@ describe ClassMixedWithDSLHelpers do
|
|
784
815
|
let( :result_pass ) { Beaker::Result.new( [], "" ) }
|
785
816
|
before :each do
|
786
817
|
allow( subject ).to receive( :sleep ).and_return( true )
|
787
|
-
result_fail.stdout = 'stdout'
|
788
|
-
result_fail.stderr = 'stderr'
|
789
|
-
result_fail.exit_code = 1
|
790
|
-
result_pass.stdout = 'stdout'
|
791
|
-
result_pass.stderr = 'stderr'
|
792
|
-
result_pass.exit_code = 0
|
793
818
|
end
|
794
819
|
|
795
820
|
it 'runs the pe-puppet on a system without pe-puppet-agent' do
|
@@ -797,9 +822,9 @@ describe ClassMixedWithDSLHelpers do
|
|
797
822
|
deb_agent = make_host( 'deb', :platform => 'debian-7-amd64' )
|
798
823
|
allow( deb_agent ).to receive( :puppet ).and_return( { 'vardir' => vardir } )
|
799
824
|
|
800
|
-
|
801
|
-
expect(
|
802
|
-
|
825
|
+
expect( deb_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
|
826
|
+
expect( deb_agent ).to receive( :file_exist? ).with("/etc/init.d/pe-puppet-agent").and_return(false)
|
827
|
+
|
803
828
|
expect( subject ).to receive( :puppet_resource ).with( "service", "pe-puppet", "ensure=stopped").once
|
804
829
|
expect( subject ).to receive( :on ).once
|
805
830
|
|
@@ -812,10 +837,10 @@ describe ClassMixedWithDSLHelpers do
|
|
812
837
|
el_agent = make_host( 'el', :platform => 'el-5-x86_64' )
|
813
838
|
allow( el_agent ).to receive( :puppet ).and_return( { 'vardir' => vardir } )
|
814
839
|
|
815
|
-
|
816
|
-
expect(
|
817
|
-
|
818
|
-
expect( subject ).to receive( :puppet_resource ).with("service", "pe-puppet-agent", "ensure=stopped").once
|
840
|
+
expect( el_agent ).to receive( :file_exist? ).with("/var/state/agent_catalog_run.lock").and_return(false)
|
841
|
+
expect( el_agent ).to receive( :file_exist? ).with("/etc/init.d/pe-puppet-agent").and_return(true)
|
842
|
+
|
843
|
+
expect( subject ).to receive( :puppet_resource ).with( "service", "pe-puppet-agent", "ensure=stopped").once
|
819
844
|
expect( subject ).to receive( :on ).once
|
820
845
|
|
821
846
|
subject.stop_agent_on( el_agent )
|
@@ -916,6 +941,12 @@ describe ClassMixedWithDSLHelpers do
|
|
916
941
|
}.to raise_error(RuntimeError, /puppet conf backup failed/)
|
917
942
|
end
|
918
943
|
|
944
|
+
it 'receives a Minitest::Assertion and fails the test correctly' do
|
945
|
+
allow( subject ).to receive( :backup_the_file ).and_raise( Minitest::Assertion.new('assertion failed!') )
|
946
|
+
expect( subject ).to receive( :fail_test )
|
947
|
+
subject.with_puppet_running_on(host, {})
|
948
|
+
end
|
949
|
+
|
919
950
|
describe 'with puppet-server' do
|
920
951
|
let(:default_confdir) { "/etc/puppet" }
|
921
952
|
let(:default_vardir) { "/var/lib/puppet" }
|
@@ -958,8 +989,11 @@ describe ClassMixedWithDSLHelpers do
|
|
958
989
|
stub_post_setup
|
959
990
|
allow( subject ).to receive( :options) .and_return( {:is_puppetserver => true})
|
960
991
|
allow( subject ).to receive( :modify_tk_config)
|
961
|
-
allow( host ).to receive(:puppet).with(
|
962
|
-
|
992
|
+
allow( host ).to receive(:puppet).with( any_args ).and_return({
|
993
|
+
'confdir' => default_confdir,
|
994
|
+
'vardir' => default_vardir,
|
995
|
+
'config' => "#{default_confdir}/puppet.conf"
|
996
|
+
})
|
963
997
|
end
|
964
998
|
|
965
999
|
describe 'and command line args passed' do
|
@@ -1087,7 +1121,7 @@ describe ClassMixedWithDSLHelpers do
|
|
1087
1121
|
execution = 0
|
1088
1122
|
expect do
|
1089
1123
|
subject.with_puppet_running_on(host, {}) do
|
1090
|
-
expect(host).to execute_commands_matching(/^puppet master/).
|
1124
|
+
expect(host).to execute_commands_matching(/^puppet master/).exactly(4).times
|
1091
1125
|
execution += 1
|
1092
1126
|
end
|
1093
1127
|
end.to change { execution }.by(1)
|
@@ -1103,9 +1137,22 @@ describe ClassMixedWithDSLHelpers do
|
|
1103
1137
|
end
|
1104
1138
|
|
1105
1139
|
describe 'backup and restore of puppet.conf' do
|
1106
|
-
|
1107
|
-
|
1108
|
-
|
1140
|
+
before :each do
|
1141
|
+
mock_puppetconf_reader = Object.new
|
1142
|
+
allow( mock_puppetconf_reader ).to receive( :[] ).with( 'config' ).and_return( '/root/mock/puppet.conf' )
|
1143
|
+
allow( mock_puppetconf_reader ).to receive( :[] ).with( 'confdir' ).and_return( '/root/mock' )
|
1144
|
+
allow( host ).to receive( :puppet ).with( any_args ).and_return( mock_puppetconf_reader )
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
let(:original_location) { host.puppet['config'] }
|
1148
|
+
let(:backup_location) {
|
1149
|
+
filename = File.basename(host.puppet['config'])
|
1150
|
+
File.join(tmpdir_path, "#{filename}.bak")
|
1151
|
+
}
|
1152
|
+
let(:new_location) {
|
1153
|
+
filename = File.basename(host.puppet['config'])
|
1154
|
+
File.join(tmpdir_path, filename)
|
1155
|
+
}
|
1109
1156
|
|
1110
1157
|
context 'when a puppetservice is used' do
|
1111
1158
|
let(:use_service) { true }
|
@@ -1299,13 +1346,13 @@ describe ClassMixedWithDSLHelpers do
|
|
1299
1346
|
let(:hierarchy) { [ 'nodes/%{::fqdn}', 'common' ] }
|
1300
1347
|
it 'on FOSS host' do
|
1301
1348
|
host = make_host('testhost', { :platform => 'ubuntu' } )
|
1302
|
-
expect(subject).to receive(:create_remote_file).with(host, host[
|
1349
|
+
expect(subject).to receive(:create_remote_file).with(host, host.puppet['hiera_config'], /#{host[:hieradatadir]}/)
|
1303
1350
|
subject.write_hiera_config_on(host, hierarchy)
|
1304
1351
|
end
|
1305
1352
|
|
1306
1353
|
it 'on PE host' do
|
1307
1354
|
host = make_host('testhost', { :platform => 'ubuntu', :type => 'pe' } )
|
1308
|
-
expect(subject).to receive(:create_remote_file).with(host, host[
|
1355
|
+
expect(subject).to receive(:create_remote_file).with(host, host.puppet['hiera_config'], /#{host[:hieradatadir]}/)
|
1309
1356
|
subject.write_hiera_config_on(host, hierarchy)
|
1310
1357
|
end
|
1311
1358
|
|