beaker-puppet 0.10.0 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTBjMzQ0ZjEzZTNkMDI3ODE1NGIwYWU2YzllZDA3NjFhNmU1YmM3ZQ==
5
- data.tar.gz: !binary |-
6
- MzY0ZWZiNTEzNDk0M2YwZTdlODcxNWQyM2E3MWRiYWE5YWNkNzE4YQ==
2
+ SHA1:
3
+ metadata.gz: 02ec1da775402ec80c54b00f614d7b18f90c0a27
4
+ data.tar.gz: eb6d32c7c507cd87055c287d99e44b8a7b69bedc
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YmRiOTAwYjU1NDU5ODBhZjdiMmFmNTIwODcxNGRhNDhhZWYzODA1YWJlYWZi
10
- NTFlYzU5NjMwMTY3ZWZiODc4YjUxMjE0MGVkMmE0YzdkNTE2Njg0NDVhMmZm
11
- MjEyMTliNTRhNGNmNmVhZGMxNjYzZGFhNWZhYjExOTk2MmNmZTU=
12
- data.tar.gz: !binary |-
13
- ODczODMyZjcwZWNhNTgwMzg5YTljYTBiNTM4MWIzYmQ4MTkwNmVkYTE5ZGQ2
14
- YWE0NGFhNDNiY2EwMGYwNWYyZDU0YmRhNmM2NzJjODYzNzc4MWM2OWZkMjg1
15
- YjBlNDAxM2I0YWIwNzVhNjI1ZjNiN2MzMTBiNDFkODY2N2EyZTU=
6
+ metadata.gz: 8ae33a0aba67b868c412302688b813524b84ee72f512ae8425c884c276f7608ddadda199847b4444b7f8edc886186cd16f594e3778f11790bd1bb122fc74f758
7
+ data.tar.gz: 424bdbafc891afb87f12f95456f4c4bf9d15bb2c8233173d829baa6142f8451b8349f1d3bc02b8a700d1fc95c0b50f7eabd10ee7ae2a0a3d2e9d54f95c73655b
data/lib/beaker-puppet.rb CHANGED
@@ -3,6 +3,8 @@ require 'in_parallel'
3
3
  require 'beaker-puppet/version'
4
4
  require 'beaker-puppet/wrappers'
5
5
 
6
+ require 'beaker-puppet/helpers/rake_helpers'
7
+
6
8
  [ 'aio', 'foss' ].each do |lib|
7
9
  require "beaker-puppet/install_utils/#{lib}_defaults"
8
10
  end
@@ -0,0 +1,21 @@
1
+ module Beaker
2
+ module DSL
3
+ module Helpers
4
+ # Methods that help you interact with rake during ci setup
5
+ module RakeHelpers
6
+ class << self
7
+ def load_tasks(beaker_root = File.expand_path("#{__dir__}/../../.."))
8
+ task_dir = File.join(beaker_root, 'tasks')
9
+ tasks = [
10
+ 'ci.rake'
11
+ ]
12
+
13
+ tasks.each do |task|
14
+ load File.join(task_dir, task)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1353,6 +1353,83 @@ module Beaker
1353
1353
 
1354
1354
  end
1355
1355
  end
1356
+
1357
+ # Installs packages on the hosts.
1358
+ #
1359
+ # @param hosts [Array<Host>] Array of hosts to install packages to.
1360
+ # @param package_hash [Hash{Symbol=>Array<String,Array<String,String>>}]
1361
+ # Keys should be a symbol for a platform in PLATFORM_PATTERNS. Values
1362
+ # should be an array of package names to install, or of two element
1363
+ # arrays where a[0] is the command we expect to find on the platform
1364
+ # and a[1] is the package name (when they are different).
1365
+ # @param options [Hash{Symbol=>Boolean}]
1366
+ # @option options [Boolean] :check_if_exists First check to see if
1367
+ # command is present before installing package. (Default false)
1368
+ # @return true
1369
+ def install_packages_on(hosts, package_hash, options = {})
1370
+ platform_patterns = {
1371
+ :redhat => /fedora|el-|centos/,
1372
+ :debian => /debian|ubuntu|cumulus/,
1373
+ :debian_ruby18 => /debian|ubuntu-lucid|ubuntu-precise/,
1374
+ :solaris_10 => /solaris-10/,
1375
+ :solaris_11 => /solaris-11/,
1376
+ :windows => /windows/,
1377
+ :eos => /^eos-/,
1378
+ }.freeze
1379
+
1380
+ check_if_exists = options[:check_if_exists]
1381
+ Array(hosts).each do |host|
1382
+ package_hash.each do |platform_key,package_list|
1383
+ if pattern = platform_patterns[platform_key]
1384
+ if pattern.match(host['platform'])
1385
+ package_list.each do |cmd_pkg|
1386
+ if cmd_pkg.kind_of?(Array)
1387
+ command, package = cmd_pkg
1388
+ else
1389
+ command = package = cmd_pkg
1390
+ end
1391
+ if !check_if_exists || !host.check_for_package(command)
1392
+ host.logger.notify("Installing #{package}")
1393
+ additional_switches = '--allow-unauthenticated' if platform_key == :debian
1394
+ host.install_package(package, additional_switches)
1395
+ end
1396
+ end
1397
+ end
1398
+ else
1399
+ raise("Unknown platform '#{platform_key}' in package_hash")
1400
+ end
1401
+ end
1402
+ end
1403
+ return true
1404
+ end
1405
+
1406
+ def ruby_command(host)
1407
+ "env PATH=\"#{host['privatebindir']}:${PATH}\" ruby"
1408
+ end
1409
+
1410
+ def gem_command(host, type = 'aio')
1411
+ if type == 'aio'
1412
+ if host['platform'] =~ /windows/
1413
+ "env PATH=\"#{host['privatebindir']}:${PATH}\" cmd /c gem"
1414
+ else
1415
+ "env PATH=\"#{host['privatebindir']}:${PATH}\" gem"
1416
+ end
1417
+ else
1418
+ on(host, 'which gem').stdout.chomp
1419
+ end
1420
+ end
1421
+
1422
+ # Configures gem sources on hosts to use a mirror, if specified
1423
+ # This is a duplicate of the Gemfile logic.
1424
+ def configure_gem_mirror(hosts)
1425
+ gem_source = ENV['GEM_SOURCE'] || 'https://rubygems.org'
1426
+
1427
+ Array(hosts).each do |host|
1428
+ gem = gem_command(host)
1429
+ on host, "#{gem} source --clear-all"
1430
+ on host, "#{gem} source --add #{gem_source}"
1431
+ end
1432
+ end
1356
1433
  end
1357
1434
  end
1358
1435
  end
@@ -1,3 +1,3 @@
1
1
  module BeakerPuppet
2
- VERSION = '0.10.0'
2
+ VERSION = '0.11.0'
3
3
  end
@@ -0,0 +1,50 @@
1
+ extend BeakerPuppet::Install::Puppet5
2
+ extend Beaker::DSL::InstallUtils::FOSSUtils
3
+
4
+ test_name "Install Packages"
5
+
6
+ dev_builds_url = ENV['DEV_BUILDS_URL'] || 'http://builds.delivery.puppetlabs.net'
7
+ nightly_builds_url = ENV['NIGHTLY_BUILDS_URL'] || "http://ravi.puppetlabs.com"
8
+
9
+ step "Install puppet-agent..." do
10
+ sha = ENV['SHA']
11
+ install_from_build_data_url('puppet-agent', "#{dev_builds_url}/puppet-agent/#{sha}/artifacts/#{sha}.yaml", hosts)
12
+ end
13
+
14
+ step "Install puppetserver..." do
15
+ if ENV['SERVER_VERSION'].nil? || ENV['SERVER_VERSION'] == 'latest'
16
+ install_puppetlabs_dev_repo(master, 'puppetserver', 'latest', nil, :dev_builds_url => nightly_builds_url)
17
+ master.install_package('puppetserver')
18
+ else
19
+ server_version = ENV['SERVER_VERSION']
20
+ install_from_build_data_url('puppetserver', "#{dev_builds_url}/puppetserver/#{server_version}/artifacts/#{server_version}.yaml", master)
21
+ end
22
+ end
23
+
24
+ # make sure install is sane, beaker has already added puppet and ruby
25
+ # to PATH in ~/.ssh/environment
26
+ agents.each do |agent|
27
+ on agent, puppet('--version')
28
+ ruby = ruby_command(agent)
29
+ on agent, "#{ruby} --version"
30
+ end
31
+
32
+ # Get a rough estimate of clock skew among hosts
33
+ times = []
34
+ hosts.each do |host|
35
+ ruby = ruby_command(host)
36
+ on(host, "#{ruby} -e 'puts Time.now.strftime(\"%Y-%m-%d %T.%L %z\")'") do |result|
37
+ times << result.stdout.chomp
38
+ end
39
+ end
40
+ times.map! do |time|
41
+ (Time.strptime(time, "%Y-%m-%d %T.%L %z").to_f * 1000.0).to_i
42
+ end
43
+ diff = times.max - times.min
44
+ if diff < 60000
45
+ logger.info "Host times vary #{diff} ms"
46
+ else
47
+ logger.warn "Host times vary #{diff} ms, tests may fail"
48
+ end
49
+
50
+ configure_gem_mirror(hosts)
@@ -0,0 +1,12 @@
1
+ platforms = hosts.map{|val| val[:platform]}
2
+ skip_test "No cumulus hosts present" unless platforms.any? { |val| /cumulus/ =~ val }
3
+ confine :to, {}, hosts.select { |host| host[:roles].include?('master') }
4
+
5
+ step 'install Cumulus Modules on masters' do
6
+ hosts.each do |node|
7
+ on(node, puppet('module','install','cumuluslinux-cumulus_license'))
8
+ on(node, puppet('module','install','cumuluslinux-cumulus_interfaces'))
9
+ on(node, puppet('module','install','cumuluslinux-cumulus_interface_policy'))
10
+ on(node, puppet('module','install','cumuluslinux-cumulus_ports'))
11
+ end
12
+ end
@@ -0,0 +1,20 @@
1
+ platforms = hosts.map{|val| val[:platform]}
2
+ skip_test "No arista hosts present" unless platforms.any? { |val| /^eos-/ =~ val }
3
+ test_name 'Arista Switch Pre-suite' do
4
+ masters = select_hosts({:roles => ['master', 'compile_master']})
5
+ switchs = select_hosts({:platform => ['eos-4-i386']})
6
+
7
+ step 'install Arista Module on masters' do
8
+ masters.each do |node|
9
+ on(node, puppet('module','install','aristanetworks-netdev_stdlib_eos'))
10
+ end
11
+ end
12
+
13
+ step 'add puppet user to switch' do
14
+ switchs.each do |switch|
15
+ on(switch, "useradd -U puppet")
16
+ on(switch, "/opt/puppetlabs/bin/puppet config --confdir /etc/puppetlabs/puppet set user root")
17
+ on(switch, "/opt/puppetlabs/bin/puppet config --confdir /etc/puppetlabs/puppet set group root")
18
+ end
19
+ end
20
+ end
@@ -0,0 +1 @@
1
+ on(master, puppet('resource', 'service', master['puppetservice'], "ensure=running"))
@@ -0,0 +1,11 @@
1
+ test_name "Expunge puppet bits if hypervisor is none"
2
+
3
+ # Ensure that the any previous installations of puppet
4
+ # are removed from the host if it is not managed by a
5
+ # provisioning hypervisor.
6
+
7
+ hosts.each do |host|
8
+ if host[:hypervisor] == "none"
9
+ remove_puppet_on(host)
10
+ end
11
+ end
@@ -0,0 +1,16 @@
1
+ test_name "Stop firewall" do
2
+ hosts.each do |host|
3
+ case host['platform']
4
+ when /debian/
5
+ on host, 'iptables -F'
6
+ when /fedora|el-7/
7
+ on host, puppet('resource', 'service', 'firewalld', 'ensure=stopped')
8
+ when /el-|centos/
9
+ on host, puppet('resource', 'service', 'iptables', 'ensure=stopped')
10
+ when /ubuntu/
11
+ on host, puppet('resource', 'service', 'ufw', 'ensure=stopped')
12
+ else
13
+ logger.notify("Not sure how to clear firewall on #{host['platform']}")
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,9 @@
1
+ test_name "Stop sssd" do
2
+ # The sssd service causes local users/groups to be cached,
3
+ # which can cause unexpected results when tests are trying
4
+ # to restore state. We ensure that it is not running to
5
+ # prevent such caching from occurring.
6
+ hosts.each do |host|
7
+ on(host, puppet('resource', 'service', 'sssd', 'ensure=stopped'), :accept_all_exit_codes => true)
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ test_name "Validate Sign Cert" do
2
+ hostname = on(master, 'facter hostname').stdout.strip
3
+ fqdn = on(master, 'facter fqdn').stdout.strip
4
+
5
+ if master.use_service_scripts?
6
+ step "Ensure puppet is stopped"
7
+ # Passenger, in particular, must be shutdown for the cert setup steps to work,
8
+ # but any running puppet master will interfere with webrick starting up and
9
+ # potentially ignore the puppet.conf changes.
10
+ on(master, puppet('resource', 'service', master['puppetservice'], "ensure=stopped"))
11
+ end
12
+
13
+ step "Clear SSL on all hosts"
14
+ hosts.each do |host|
15
+ ssldir = on(host, puppet('agent --configprint ssldir')).stdout.chomp
16
+ on(host, "rm -rf '#{ssldir}'")
17
+ end
18
+
19
+ step "Master: Start Puppet Master" do
20
+ master_opts = {
21
+ :main => {
22
+ :dns_alt_names => "puppet,#{hostname},#{fqdn}",
23
+ },
24
+ :__service_args__ => {
25
+ # apache2 service scripts can't restart if we've removed the ssl dir
26
+ :bypass_service_script => true,
27
+ },
28
+ }
29
+ with_puppet_running_on(master, master_opts) do
30
+
31
+ hosts.each do |host|
32
+ next if host['roles'].include? 'master'
33
+
34
+ step "Agents: Run agent --test first time to gen CSR"
35
+ on host, puppet("agent --test --server #{master}"), :acceptable_exit_codes => [1]
36
+ end
37
+
38
+ # Sign all waiting certs
39
+ step "Master: sign all certs"
40
+ on master, puppet("cert --sign --all"), :acceptable_exit_codes => [0,24]
41
+
42
+ step "Agents: Run agent --test second time to obtain signed cert"
43
+ on agents, puppet("agent --test --server #{master}"), :acceptable_exit_codes => [0,2]
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,40 @@
1
+ extend Beaker::DSL::InstallUtils::FOSSUtils
2
+
3
+ test_name "Install puppet gem"
4
+
5
+ agents.each do |agent|
6
+ sha = ENV['SHA']
7
+ base_url = "http://builds.delivery.puppetlabs.net/puppet/#{sha}/artifacts"
8
+
9
+ ruby_command = ruby_command(agent)
10
+ gem_command = gem_command(agent)
11
+
12
+ # retrieve the build data, since the gem version is based on the short git
13
+ # describe, not the full git SHA
14
+ on(agent, "curl -s -o build_data.yaml #{base_url}/#{sha}.yaml")
15
+ gem_version = on(agent, "#{ruby_command} -ryaml -e 'puts YAML.load_file(\"build_data.yaml\")[:gemversion]'").stdout.chomp
16
+
17
+ if agent['platform'] =~ /windows/
18
+ # wipe existing gems first
19
+ default_dir = on(agent, "#{ruby_command} -rrbconfig -e 'puts Gem.default_dir'").stdout.chomp
20
+ on(agent, "rm -rf '#{default_dir}'")
21
+
22
+ arch = agent[:ruby_arch] || 'x86'
23
+ gem_arch = arch == 'x64' ? 'x64-mingw32' : 'x86-mingw32'
24
+ url = "#{base_url}/puppet-#{gem_version}-#{gem_arch}.gem"
25
+ else
26
+ url = "#{base_url}/puppet-#{gem_version}.gem"
27
+ end
28
+
29
+ step "Download puppet gem from #{url}"
30
+ on(agent, "curl -s -o puppet.gem #{url}")
31
+
32
+ step "Install puppet.gem"
33
+ on(agent, "#{gem_command} install puppet.gem")
34
+
35
+ step "Verify it's sane"
36
+ on(agent, puppet('--version'))
37
+ on(agent, puppet('apply', "-e \"notify { 'hello': }\"")) do |result|
38
+ assert_match(/defined 'message' as 'hello'/, result.stdout)
39
+ end
40
+ end
@@ -0,0 +1,144 @@
1
+ test_name "Setup environment"
2
+
3
+ step "Ensure Git and Ruby"
4
+
5
+ extend Beaker::DSL::InstallUtils
6
+
7
+ PACKAGES = {
8
+ :redhat => [
9
+ 'git',
10
+ 'ruby',
11
+ 'rubygem-json', # invalid on RHEL6
12
+ 'rubygem-io-console', # required for Fedora25 to bundle install
13
+ 'rubygem-rdoc' # required for Fedora25 to install gems
14
+ ],
15
+ :debian => [
16
+ ['git', 'git-core'],
17
+ 'ruby',
18
+ ],
19
+ :debian_ruby18 => [
20
+ 'libjson-ruby',
21
+ ],
22
+ :solaris_11 => [
23
+ ['git', 'developer/versioning/git'],
24
+ ],
25
+ :solaris_10 => [
26
+ 'coreutils',
27
+ 'curl', # update curl to fix "CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!" issue
28
+ 'git',
29
+ 'ruby19',
30
+ 'ruby19_dev',
31
+ 'gcc4core',
32
+ ],
33
+ :windows => [
34
+ 'git',
35
+ # there isn't a need for json on windows because it is bundled in ruby 1.9
36
+ ],
37
+ }
38
+
39
+ # override incorrect FOSS (git) defaults from Beaker with AIO applicable ones
40
+ #
41
+ # Remove after PUP-4867 breaks distmoduledir and sitemoduledir into individual
42
+ # settings from modulepath and Beaker can properly introspect these settings
43
+ hosts.each do |host|
44
+ platform = host['platform'] =~ /windows/ ? 'windows' : 'unix'
45
+
46
+ host['puppetbindir'] = '/usr/bin' if platform == 'windows'
47
+
48
+ # Beakers add_aio_defaults_on helper is not appropriate here as it
49
+ # also alters puppetbindir / privatebindir to use package installed
50
+ # paths rather than git installed paths
51
+ host['distmoduledir'] = AIO_DEFAULTS[platform]['distmoduledir']
52
+ host['sitemoduledir'] = AIO_DEFAULTS[platform]['sitemoduledir']
53
+ end
54
+
55
+ hosts.each do |host|
56
+ case host['platform']
57
+ when /solaris-10/
58
+ on host, 'mkdir -p /var/lib'
59
+ on host, 'ln -sf /opt/csw/bin/pkgutil /usr/bin/pkgutil'
60
+ on host, 'ln -sf /opt/csw/bin/gem19 /usr/bin/gem'
61
+ on host, 'ln -sf /opt/csw/bin/git /usr/bin/git'
62
+ on host, 'ln -sf /opt/csw/bin/ruby19 /usr/bin/ruby'
63
+ on host, 'ln -sf /opt/csw/bin/gstat /usr/bin/stat'
64
+ on host, 'ln -sf /opt/csw/bin/greadlink /usr/bin/readlink'
65
+ when /solaris-11/
66
+ step "#{host} jump through hoops to install ruby19; switch back to runtime/ruby-19 after template upgrade to sol11.2"
67
+ create_remote_file host, "/root/shutupsolaris", <<END
68
+ mail=
69
+ # Overwrite already installed instances
70
+ instance=overwrite
71
+ # Do not bother checking for partially installed packages
72
+ partial=nocheck
73
+ # Do not bother checking the runlevel
74
+ runlevel=nocheck
75
+ # Do not bother checking package dependencies (We take care of this)
76
+ idepend=nocheck
77
+ rdepend=nocheck
78
+ # DO check for available free space and abort if there isn't enough
79
+ space=quit
80
+ # Do not check for setuid files.
81
+ setuid=nocheck
82
+ # Do not check if files conflict with other packages
83
+ conflict=nocheck
84
+ # We have no action scripts. Do not check for them.
85
+ action=nocheck
86
+ # Install to the default base directory.
87
+ basedir=default
88
+ END
89
+ on host, 'pkgadd -a /root/shutupsolaris -d http://get.opencsw.org/now all'
90
+ on host, '/opt/csw/bin/pkgutil -U all'
91
+ on host, '/opt/csw/bin/pkgutil -i -y ruby19_dev'
92
+ on host, '/opt/csw/bin/pkgutil -i -y ruby19'
93
+ on host, 'ln -sf /opt/csw/bin/gem19 /usr/bin/gem'
94
+ on host, 'ln -sf /opt/csw/bin/ruby19 /usr/bin/ruby'
95
+ end
96
+ end
97
+
98
+ install_packages_on(hosts, PACKAGES, :check_if_exists => true)
99
+
100
+ hosts.each do |host|
101
+ case host['platform']
102
+ when /windows/
103
+ arch = host[:ruby_arch] || 'x86'
104
+ step "#{host} Selected architecture #{arch}"
105
+
106
+ revision = if arch == 'x64'
107
+ '2.1.x-x64'
108
+ else
109
+ '2.1.x-x86'
110
+ end
111
+
112
+ step "#{host} Install ruby from git using revision #{revision}"
113
+ # TODO remove this step once we are installing puppet from msi packages
114
+ win_path = on(host, 'cygpath -m /opt/puppet-git-repos').stdout.chomp
115
+ install_from_git_on(host, win_path,
116
+ :name => 'puppet-win32-ruby',
117
+ :path => build_git_url('puppet-win32-ruby'),
118
+ :rev => revision)
119
+ on host, 'cd /opt/puppet-git-repos/puppet-win32-ruby; cp -r ruby/* /'
120
+ on host, 'cd /lib; icacls ruby /grant "Everyone:(OI)(CI)(RX)"'
121
+ on host, 'cd /lib; icacls ruby /reset /T'
122
+ on host, 'cd /; icacls bin /grant "Everyone:(OI)(CI)(RX)"'
123
+ on host, 'cd /; icacls bin /reset /T'
124
+ on host, 'ruby --version'
125
+ on host, 'cmd /c gem list'
126
+ end
127
+ end
128
+
129
+ # Only configure gem mirror after Ruby has been installed, but before any gems are installed.
130
+ configure_gem_mirror(hosts)
131
+
132
+ hosts.each do |host|
133
+ case host['platform']
134
+ when /solaris/
135
+ step "#{host} Install json from rubygems"
136
+ on host, 'gem install json_pure --no-ri --no-rdoc --version 1.8.3' # json_pure 2.0 requires ruby 2
137
+ on host, 'gem install bundler --no-ri --no-rdoc'
138
+ on host, "ln -sf /opt/csw/bin/bundle #{host['puppetbindir']}/bundle"
139
+ when /windows/
140
+ on host, 'cmd /c gem install bundler --no-ri --no-rdoc'
141
+ else
142
+ on host, 'gem install bundler --no-ri --no-rdoc'
143
+ end
144
+ end