beaker-puppet 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/beaker-puppet.rb +2 -1
- data/lib/beaker-puppet/helpers/facter_helpers.rb +8 -2
- data/lib/beaker-puppet/helpers/host_helpers.rb +36 -0
- data/lib/beaker-puppet/install_utils/aio_defaults.rb +13 -7
- data/lib/beaker-puppet/version.rb +1 -1
- data/spec/beaker-puppet/helpers/facter_helpers_spec.rb +24 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 400c5005acf587cae1d5e1fe8afbcc14d9d88d8f
|
4
|
+
data.tar.gz: 9392fc5d8c862d5c83bdebdd46504102dbfb2ef4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e8db28e64c428caf4b4a253e70ad0ce9dfb9c3dcda51622d32cd9f1b5768ac1023d10797f6e4366bf88aeebc0057f7a94983cdc2c96f8ad2c9b7d30e745f45c
|
7
|
+
data.tar.gz: 41d0fd41083c3a4e8ea4e57f9d25524c5a3ab94bb578d2336187078314fdf43f783878ac9b520f77c4805989a5f0a6d000a87b994696f1cca023ab4eab521f68
|
data/lib/beaker-puppet.rb
CHANGED
@@ -13,7 +13,7 @@ end
|
|
13
13
|
[ 'windows', 'foss', 'puppet', 'ezbake', 'module' ].each do |lib|
|
14
14
|
require "beaker-puppet/install_utils/#{lib}_utils"
|
15
15
|
end
|
16
|
-
[ 'tk', 'facter', 'puppet' ].each do |lib|
|
16
|
+
[ 'tk', 'facter', 'puppet', 'host' ].each do |lib|
|
17
17
|
require "beaker-puppet/helpers/#{lib}_helpers"
|
18
18
|
end
|
19
19
|
|
@@ -35,6 +35,7 @@ module BeakerPuppet
|
|
35
35
|
include Beaker::DSL::Helpers::TKHelpers
|
36
36
|
include Beaker::DSL::Helpers::FacterHelpers
|
37
37
|
include Beaker::DSL::Helpers::PuppetHelpers
|
38
|
+
include Beaker::DSL::Helpers::HostHelpers
|
38
39
|
|
39
40
|
include Beaker::DSL::Wrappers
|
40
41
|
end
|
@@ -37,11 +37,17 @@ module Beaker
|
|
37
37
|
# @return String The value of the fact 'name' on the provided host
|
38
38
|
# @raise [FailTest] Raises an exception if call to facter fails
|
39
39
|
def fact_on(host, name, opts = {})
|
40
|
+
if opts.kind_of?(Hash)
|
41
|
+
opts.merge!({json: nil})
|
42
|
+
else
|
43
|
+
opts << ' --json'
|
44
|
+
end
|
45
|
+
|
40
46
|
result = on host, facter(name, opts)
|
41
47
|
if result.kind_of?(Array)
|
42
|
-
result.map { |res| res.stdout
|
48
|
+
result.map { |res| JSON.parse(res.stdout)[name] }
|
43
49
|
else
|
44
|
-
result.stdout
|
50
|
+
JSON.parse(result.stdout)[name]
|
45
51
|
end
|
46
52
|
end
|
47
53
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Beaker
|
2
|
+
module DSL
|
3
|
+
module Helpers
|
4
|
+
# Methods that help you interact with your facter installation, facter must be installed
|
5
|
+
# for these methods to execute correctly
|
6
|
+
#
|
7
|
+
module HostHelpers
|
8
|
+
|
9
|
+
def ruby_command(host)
|
10
|
+
"env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
|
11
|
+
end
|
12
|
+
|
13
|
+
# Returns an array containing the owner, group and mode of
|
14
|
+
# the file specified by path. The returned mode is an integer
|
15
|
+
# value containing only the file mode, excluding the type, e.g
|
16
|
+
# S_IFDIR 0040000
|
17
|
+
def stat(host, path)
|
18
|
+
ruby = ruby_command(host)
|
19
|
+
owner = on(host, "#{ruby} -e 'require \"etc\"; puts (Etc.getpwuid(File.stat(\"#{path}\").uid).name)'").stdout.chomp
|
20
|
+
group = on(host, "#{ruby} -e 'require \"etc\"; puts (Etc.getgrgid(File.stat(\"#{path}\").gid).name)'").stdout.chomp
|
21
|
+
mode = on(host, "#{ruby} -e 'puts (File.stat(\"#{path}\").mode & 0777).to_s(8)'").stdout.chomp.to_i
|
22
|
+
|
23
|
+
[owner, group, mode]
|
24
|
+
end
|
25
|
+
|
26
|
+
def assert_ownership_permissions(host, location, expected_user, expected_group, expected_permissions)
|
27
|
+
permissions = stat(host, location)
|
28
|
+
assert_equal(expected_user, permissions[0], "Owner #{permissions[0]} does not match expected #{expected_user}")
|
29
|
+
assert_equal(expected_group, permissions[1], "Group #{permissions[1]} does not match expected #{expected_group}")
|
30
|
+
assert_equal(expected_permissions, permissions[2], "Permissions #{permissions[2]} does not match expected #{expected_permissions}")
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -15,22 +15,28 @@ module Beaker
|
|
15
15
|
'distmoduledir' => '/etc/puppetlabs/code/modules',
|
16
16
|
'sitemoduledir' => '/opt/puppetlabs/puppet/modules',
|
17
17
|
},
|
18
|
-
|
18
|
+
# sitemoduledir not included on Windows (check PUP-4049 for more info).
|
19
|
+
#
|
20
|
+
# Paths to the puppet's vendored ruby installation on Windows were
|
21
|
+
# updated in Puppet 6 to more closely match those of *nix agents.
|
22
|
+
# These path values include both the older (puppet <= 5) paths (which
|
23
|
+
# include sys/ruby) and the newer versions, which have no custom ruby
|
24
|
+
# directory
|
25
|
+
'windows' => { # windows with cygwin
|
19
26
|
'puppetbindir' => '/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/bin',
|
20
|
-
'privatebindir' => '/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/sys/ruby/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/sys/ruby/bin',
|
27
|
+
'privatebindir' => '/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/puppet/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/puppet/bin:/cygdrive/c/Program Files (x86)/Puppet Labs/Puppet/sys/ruby/bin:/cygdrive/c/Program Files/Puppet Labs/Puppet/sys/ruby/bin',
|
21
28
|
'distmoduledir' => '`cygpath -smF 35`/PuppetLabs/code/modules',
|
22
|
-
# sitemoduledir not included (check PUP-4049 for more info)
|
23
29
|
},
|
24
|
-
'
|
30
|
+
'pswindows' => { # pure windows
|
25
31
|
'puppetbindir' => '"C:\\Program Files (x86)\\Puppet Labs\\Puppet\\bin";"C:\\Program Files\\Puppet Labs\\Puppet\\bin"',
|
26
|
-
'privatebindir' => '"C:\\Program Files (x86)\\Puppet Labs\\Puppet\\sys\\ruby\\bin";"C:\\Program Files\\Puppet Labs\\Puppet\\sys\\ruby\\bin"',
|
32
|
+
'privatebindir' => '"C:\\Program Files (x86)\\Puppet Labs\\Puppet\\puppet\\bin";"C:\\Program Files\\Puppet Labs\\Puppet\\puppet\\bin";"C:\\Program Files (x86)\\Puppet Labs\\Puppet\\sys\\ruby\\bin";"C:\\Program Files\\Puppet Labs\\Puppet\\sys\\ruby\\bin"',
|
27
33
|
'distmoduledir' => 'C:\\ProgramData\\PuppetLabs\\code\\modules',
|
28
34
|
}
|
29
35
|
}
|
30
36
|
|
31
37
|
# Add the appropriate aio defaults to the host object so that they can be accessed using host[option], set host[:type] = aio
|
32
38
|
# @param [Host] host A single host to act upon
|
33
|
-
# @param [String] platform The platform type of this host, one of windows or unix
|
39
|
+
# @param [String] platform The platform type of this host, one of 'windows', 'pswindows', or 'unix'
|
34
40
|
def add_platform_aio_defaults(host, platform)
|
35
41
|
AIO_DEFAULTS[platform].each_pair do |key, val|
|
36
42
|
host[key] = val
|
@@ -49,7 +55,7 @@ module Beaker
|
|
49
55
|
def add_aio_defaults_on(hosts)
|
50
56
|
block_on hosts do | host |
|
51
57
|
if host.is_powershell?
|
52
|
-
platform = '
|
58
|
+
platform = 'pswindows'
|
53
59
|
elsif host['platform'] =~ /windows/
|
54
60
|
platform = 'windows'
|
55
61
|
else
|
@@ -33,22 +33,39 @@ describe ClassMixedWithDSLHelpers do
|
|
33
33
|
|
34
34
|
describe '#fact_on' do
|
35
35
|
it 'retrieves a fact on a single host' do
|
36
|
-
result.stdout = "family\n"
|
37
|
-
expect( subject ).to receive(:facter).with('osfamily',{}).once
|
36
|
+
result.stdout = "{\"osfamily\": \"family\"}\n"
|
37
|
+
expect( subject ).to receive(:facter).with('osfamily',{json: nil}).once
|
38
38
|
expect( subject ).to receive(:on).and_return(result)
|
39
39
|
|
40
|
-
expect( subject.fact_on('host','osfamily') ).to be === result.stdout
|
40
|
+
expect( subject.fact_on('host','osfamily') ).to be === JSON.parse(result.stdout)['osfamily']
|
41
41
|
end
|
42
42
|
|
43
|
-
it '
|
44
|
-
result.stdout = "family\n"
|
43
|
+
it 'converts each element to a structured fact when it receives an array of results from #on' do
|
44
|
+
result.stdout = "{\"os\": {\"name\":\"name\", \"family\": \"family\"}}\n"
|
45
45
|
times = hosts.length
|
46
46
|
results_array = [result] * times
|
47
|
-
|
47
|
+
parsed_array = [JSON.parse(result.stdout)['os']] * times
|
48
48
|
allow( subject ).to receive( :on ).and_return( results_array )
|
49
49
|
|
50
|
-
expect( subject.fact_on(hosts,'
|
50
|
+
expect( subject.fact_on(hosts,'os') ).to be === parsed_array
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'returns a single result for single host' do
|
54
|
+
result.stdout = "{\"osfamily\": \"family\"}\n"
|
55
|
+
parsed_result = JSON.parse(result.stdout)['osfamily']
|
56
|
+
allow( subject ).to receive( :on ).and_return( result )
|
57
|
+
|
58
|
+
expect( subject.fact_on('host','osfamily') ).to be === parsed_result
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'preserves data types' do
|
62
|
+
result.stdout = "{\"identity\": { \"uid\": 0, \"user\": \"root\", \"privileged\": true }}"
|
63
|
+
allow( subject ).to receive( :on ).and_return( result )
|
64
|
+
structured_fact = subject.fact_on('host','identity')
|
51
65
|
|
66
|
+
expect(structured_fact['uid'].class).to be Fixnum
|
67
|
+
expect(structured_fact['user'].class).to be String
|
68
|
+
expect(structured_fact['privileged'].class).to be (TrueClass or FalseClass)
|
52
69
|
end
|
53
70
|
end
|
54
71
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker-puppet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppet
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-09-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -233,6 +233,7 @@ files:
|
|
233
233
|
- bin/beaker-puppet
|
234
234
|
- lib/beaker-puppet.rb
|
235
235
|
- lib/beaker-puppet/helpers/facter_helpers.rb
|
236
|
+
- lib/beaker-puppet/helpers/host_helpers.rb
|
236
237
|
- lib/beaker-puppet/helpers/puppet_helpers.rb
|
237
238
|
- lib/beaker-puppet/helpers/rake_helpers.rb
|
238
239
|
- lib/beaker-puppet/helpers/tk_helpers.rb
|