beaker-puppet 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (52) hide show
  1. checksums.yaml +15 -0
  2. data/.gitignore +25 -0
  3. data/.simplecov +9 -0
  4. data/Gemfile +25 -0
  5. data/HISTORY.md +8 -0
  6. data/LICENSE +202 -0
  7. data/README.md +55 -0
  8. data/Rakefile +299 -0
  9. data/acceptance/config/acceptance-options.rb +6 -0
  10. data/acceptance/config/gem/acceptance-options.rb +9 -0
  11. data/acceptance/config/git/acceptance-options.rb +9 -0
  12. data/acceptance/config/nodes/vagrant-ubuntu-1404.yml +8 -0
  13. data/acceptance/config/pkg/acceptance-options.rb +8 -0
  14. data/acceptance/lib/beaker/acceptance/install_utils.rb +58 -0
  15. data/acceptance/pre_suite/gem/install.rb +8 -0
  16. data/acceptance/pre_suite/git/install.rb +97 -0
  17. data/acceptance/pre_suite/pkg/install.rb +9 -0
  18. data/acceptance/tests/README.md +3 -0
  19. data/acceptance/tests/backwards_compatible.rb +19 -0
  20. data/acceptance/tests/install_smoke_test.rb +21 -0
  21. data/acceptance/tests/stub_host.rb +47 -0
  22. data/acceptance/tests/web_helpers_test.rb +54 -0
  23. data/acceptance/tests/with_puppet_running_on.rb +26 -0
  24. data/beaker-puppet.gemspec +38 -0
  25. data/bin/beaker-puppet +32 -0
  26. data/lib/beaker-puppet.rb +46 -0
  27. data/lib/beaker-puppet/helpers/facter_helpers.rb +57 -0
  28. data/lib/beaker-puppet/helpers/puppet_helpers.rb +865 -0
  29. data/lib/beaker-puppet/helpers/tk_helpers.rb +89 -0
  30. data/lib/beaker-puppet/install_utils/aio_defaults.rb +93 -0
  31. data/lib/beaker-puppet/install_utils/ezbake_utils.rb +256 -0
  32. data/lib/beaker-puppet/install_utils/foss_defaults.rb +211 -0
  33. data/lib/beaker-puppet/install_utils/foss_utils.rb +1309 -0
  34. data/lib/beaker-puppet/install_utils/module_utils.rb +244 -0
  35. data/lib/beaker-puppet/install_utils/puppet_utils.rb +157 -0
  36. data/lib/beaker-puppet/version.rb +3 -0
  37. data/lib/beaker-puppet/wrappers.rb +93 -0
  38. data/lib/beaker/dsl/helpers/facter_helpers.rb +1 -0
  39. data/lib/beaker/dsl/helpers/puppet_helpers.rb +1 -0
  40. data/lib/beaker/dsl/helpers/tk_helpers.rb +1 -0
  41. data/lib/beaker/dsl/install_utils/aio_defaults.rb +1 -0
  42. data/lib/beaker/dsl/install_utils/ezbake_utils.rb +1 -0
  43. data/lib/beaker/dsl/install_utils/foss_defaults.rb +1 -0
  44. data/lib/beaker/dsl/install_utils/foss_utils.rb +1 -0
  45. data/lib/beaker/dsl/install_utils/module_utils.rb +1 -0
  46. data/lib/beaker/dsl/install_utils/puppet_utils.rb +1 -0
  47. data/spec/beaker-puppet/helpers/facter_helpers_spec.rb +64 -0
  48. data/spec/beaker-puppet/helpers/puppet_helpers_spec.rb +1287 -0
  49. data/spec/beaker-puppet/helpers/tk_helpers_spec.rb +86 -0
  50. data/spec/helpers.rb +109 -0
  51. data/spec/spec_helper.rb +23 -0
  52. metadata +249 -0
@@ -0,0 +1,6 @@
1
+ {
2
+ :load_path => File.join('acceptance', 'lib'),
3
+ :ssh => {
4
+ :keys => ["id_rsa_acceptance", "#{ENV['HOME']}/.ssh/id_rsa-acceptance"],
5
+ },
6
+ }
@@ -0,0 +1,9 @@
1
+ {
2
+ :type => 'foss',
3
+ :add_el_extras => 'true',
4
+ :is_puppetserver => false,
5
+ :puppetservice => 'puppet.service',
6
+ :pre_suite => 'acceptance/pre_suite/gem/install.rb',
7
+ :tests => 'acceptance/tests',
8
+ :'master-start-curl-retries' => 30,
9
+ }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -0,0 +1,9 @@
1
+ {
2
+ :type => 'foss',
3
+ :add_el_extras => 'true',
4
+ :is_puppetserver => false,
5
+ :puppetservice => 'puppet.service',
6
+ :pre_suite => 'acceptance/pre_suite/git/install.rb',
7
+ :tests => 'acceptance/tests',
8
+ :'master-start-curl-retries' => 30,
9
+ }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -0,0 +1,8 @@
1
+ HOSTS:
2
+ ubuntu-server-1404-x64:
3
+ roles:
4
+ - master
5
+ platform: ubuntu-14.04-amd64
6
+ box: puppetlabs/ubuntu-14.04-64-nocm
7
+ box_url: https://vagrantcloud.com/puppetlabs/boxes/ubuntu-14.04-64-nocm
8
+ hypervisor: vagrant
@@ -0,0 +1,8 @@
1
+ {
2
+ :type => 'foss',
3
+ :is_puppetserver => false,
4
+ :puppetservice => 'puppet.service',
5
+ :pre_suite => 'acceptance/pre_suite/pkg/install.rb',
6
+ :tests => 'acceptance/tests',
7
+ :'master-start-curl-retries' => 30,
8
+ }.merge(eval File.read('acceptance/config/acceptance-options.rb'))
@@ -0,0 +1,58 @@
1
+ module Beaker
2
+ module Acceptance
3
+ module InstallUtils
4
+
5
+ PLATFORM_PATTERNS = {
6
+ :redhat => /fedora|el|centos/,
7
+ :debian => /debian|ubuntu/,
8
+ :debian_ruby18 => /debian|ubuntu-lucid|ubuntu-precise/,
9
+ :solaris_10 => /solaris-10/,
10
+ :solaris_11 => /solaris-11/,
11
+ :windows => /windows/,
12
+ :sles => /sles/,
13
+ }.freeze
14
+
15
+ # Installs packages on the hosts.
16
+ #
17
+ # @param hosts [Array<Host>] Array of hosts to install packages to.
18
+ # @param package_hash [Hash{Symbol=>Array<String,Array<String,String>>}]
19
+ # Keys should be a symbol for a platform in PLATFORM_PATTERNS. Values
20
+ # should be an array of package names to install, or of two element
21
+ # arrays where a[0] is the command we expect to find on the platform
22
+ # and a[1] is the package name (when they are different).
23
+ # @param options [Hash{Symbol=>Boolean}]
24
+ # @option options [Boolean] :check_if_exists First check to see if
25
+ # command is present before installing package. (Default false)
26
+ # @return true
27
+ def install_packages_on(hosts, package_hash, options = {})
28
+ return true if hosts == nil
29
+ check_if_exists = options[:check_if_exists]
30
+ hosts = [hosts] unless hosts.kind_of?(Array)
31
+ hosts.each do |host|
32
+ package_hash.each do |platform_key,package_list|
33
+ if pattern = PLATFORM_PATTERNS[platform_key]
34
+ if pattern.match(host['platform'])
35
+ package_list.each do |cmd_pkg|
36
+ if cmd_pkg.kind_of?(Array)
37
+ command, package = cmd_pkg
38
+ else
39
+ command = package = cmd_pkg
40
+ end
41
+ if !check_if_exists || !host.check_for_package(command)
42
+ host.logger.notify("Installing #{package}")
43
+ additional_switches = '--allow-unauthenticated' if platform_key == :debian
44
+ host.install_package(package, additional_switches)
45
+ end
46
+ end
47
+ end
48
+ else
49
+ raise("Unknown platform '#{platform_key}' in package_hash")
50
+ end
51
+ end
52
+ end
53
+ return true
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ hosts.each do |host|
2
+ install_puppet_from_gem(host, {:version => '3.8.7'})
3
+ unless host['platform'] =~ /windows/
4
+ on(host, "touch #{File.join(host.puppet['confdir'],'puppet.conf')}")
5
+ on(host, puppet('resource user puppet ensure=present'))
6
+ on(host, puppet('resource group puppet ensure=present'))
7
+ end
8
+ end
@@ -0,0 +1,97 @@
1
+ begin
2
+ require 'beaker/acceptance/install_utils'
3
+ extend Beaker::Acceptance::InstallUtils
4
+ end
5
+ test_name 'Puppet git pre-suite'
6
+
7
+ install = [
8
+ 'facter#2.1.0',
9
+ 'hiera#1.3.4',
10
+ 'puppet#3.8.7'
11
+ ]
12
+
13
+ SourcePath = Beaker::DSL::InstallUtils::SourcePath
14
+
15
+ PACKAGES = {
16
+ :redhat => [
17
+ 'git',
18
+ 'ruby',
19
+ 'rubygem-json', # :add_el_extras is required to find this package
20
+ ],
21
+ :debian => [
22
+ ['git', 'git-core'],
23
+ 'ruby',
24
+ ],
25
+ :debian_ruby18 => [
26
+ 'libjson-ruby',
27
+ ],
28
+ :solaris_11 => [
29
+ ['git', 'developer/versioning/git'],
30
+ ['ruby', 'runtime/ruby-18'],
31
+ ],
32
+ :solaris_10 => [
33
+ 'coreutils',
34
+ 'curl', # update curl to fix "CURLOPT_SSL_VERIFYHOST no longer supports 1 as value!" issue
35
+ 'git',
36
+ 'ruby19',
37
+ 'ruby19_dev',
38
+ 'gcc4core',
39
+ ],
40
+ :windows => [
41
+ 'git',
42
+ # there isn't a need for json on windows because it is bundled in ruby 1.9
43
+ ],
44
+ :sles => [
45
+ 'git-core',
46
+ ]
47
+ }
48
+
49
+ install_packages_on(hosts, PACKAGES, :check_if_exists => true)
50
+
51
+ hosts.each do |host|
52
+ case host['platform']
53
+ when /windows/
54
+ arch = host[:ruby_arch] || 'x86'
55
+ step "#{host} Selected architecture #{arch}"
56
+
57
+ revision = if arch == 'x64'
58
+ '2.1.x-x64'
59
+ else
60
+ '2.1.x-x86'
61
+ end
62
+
63
+ step "#{host} Install ruby from git using revision #{revision}"
64
+ # TODO remove this step once we are installing puppet from msi packages
65
+ install_from_git(host, "/opt/puppet-git-repos",
66
+ :name => 'puppet-win32-ruby',
67
+ :path => build_giturl('puppet-win32-ruby'),
68
+ :rev => revision)
69
+ on host, 'cd /opt/puppet-git-repos/puppet-win32-ruby; cp -r ruby/* /'
70
+ on host, 'cd /lib; icacls ruby /grant "Everyone:(OI)(CI)(RX)"'
71
+ on host, 'cd /lib; icacls ruby /reset /T'
72
+ on host, 'cd /; icacls bin /grant "Everyone:(OI)(CI)(RX)"'
73
+ on host, 'cd /; icacls bin /reset /T'
74
+ on host, 'ruby --version'
75
+ on host, 'cmd /c gem list'
76
+ when /solaris/
77
+ on host, 'gem install json'
78
+ end
79
+ end
80
+
81
+ tmp_repos = []
82
+ install.each do |reponame|
83
+ tmp_repos << extract_repo_info_from("https://github.com/puppetlabs/#{reponame}")
84
+ end
85
+
86
+ repos = order_packages(tmp_repos)
87
+
88
+ hosts.each do |host|
89
+ repos.each do |repo|
90
+ install_from_git(host, SourcePath, repo)
91
+ end
92
+ unless host['platform'] =~ /windows/
93
+ on(host, "touch #{File.join(host.puppet['confdir'],'puppet.conf')}")
94
+ on(host, puppet('resource user puppet ensure=present'))
95
+ on(host, puppet('resource group puppet ensure=present'))
96
+ end
97
+ end
@@ -0,0 +1,9 @@
1
+ # the version is required on windows
2
+ # all versions are required for osx
3
+ install_puppet({
4
+ :version => ENV['BEAKER_PUPPET_VERSION'] || '4.8.0',
5
+ :puppet_agent_version => ENV['BEAKER_PUPPET_AGENT_VERSION'] || '1.8.0'
6
+ })
7
+
8
+ on(master, puppet('resource user puppet ensure=present'))
9
+ on(master, puppet('resource group puppet ensure=present'))
@@ -0,0 +1,3 @@
1
+ # Beaker Acceptance Tests: puppet
2
+
3
+ Tests that depend upon Puppet being installed on the SUTs.
@@ -0,0 +1,19 @@
1
+ test_name 'backwards compatible test' do
2
+
3
+ step 'calls the new FOSSUtils even if I require & include the old path' do
4
+ require 'beaker/dsl/install_utils/foss_utils'
5
+ assert( !Beaker::DSL::InstallUtils::FOSSUtils::SourcePath.nil? )
6
+ assert( Beaker::DSL::InstallUtils::FOSSUtils.method_defined?(:lookup_in_env) )
7
+ end
8
+
9
+ step 'require old Helpers path, get helpers from new location' do
10
+ require 'beaker/dsl/helpers/puppet_helpers'
11
+ assert( Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:puppet_user) )
12
+ assert( Beaker::DSL::Helpers::PuppetHelpers.method_defined?(:resolve_hostname_on) )
13
+ end
14
+
15
+ step 'require old Helpers module, get from new location' do
16
+ require 'beaker/dsl/helpers'
17
+ assert( Beaker::DSL::Helpers.is_a?( Module ) )
18
+ end
19
+ end
@@ -0,0 +1,21 @@
1
+ test_name "puppet install smoketest"
2
+
3
+ step 'puppet install smoketest: verify \'facter --help\' can be successfully called on all hosts'
4
+ hosts.each do |host|
5
+ on host, facter('--help')
6
+ end
7
+
8
+ step 'puppet install smoketest: verify \'hiera --help\' can be successfully called on all hosts'
9
+ hosts.each do |host|
10
+ on host, hiera('--help')
11
+ end
12
+
13
+ step 'puppet install smoketest: verify \'puppet help\' can be successfully called on all hosts'
14
+ hosts.each do |host|
15
+ on host, puppet('help')
16
+ end
17
+
18
+ step "puppet install smoketest: can get a configprint of the puppet server setting on all hosts"
19
+ hosts.each do |host|
20
+ assert(!host.puppet['server'].empty?, "can get a configprint of the puppet server setting")
21
+ end
@@ -0,0 +1,47 @@
1
+ test_name "validate host stubbing behavior"
2
+
3
+ def get_hosts_file(host)
4
+ if host['platform'] =~ /win/
5
+ hosts_file = "C:\\\\Windows\\\\System32\\\\Drivers\\\\etc\\\\hosts"
6
+ else
7
+ hosts_file = '/etc/hosts'
8
+ end
9
+ return hosts_file
10
+ end
11
+
12
+ step 'verify stub_host_on' do
13
+ step 'should add entry to hosts file' do
14
+ hosts.each do |host|
15
+ stub_hosts_on(host, { 'foo' => '1.1.1.1' }, { 'foo' => [ 'bar', 'baz' ] })
16
+ hosts_file = get_hosts_file(host)
17
+ result = on host, "cat #{hosts_file}"
18
+ assert_match %r{foo}, result.stdout
19
+ end
20
+ end
21
+
22
+ step 'stubbed value should be available for other steps in the test' do
23
+ hosts.each do |host|
24
+ hosts_file = get_hosts_file(host)
25
+ result = on host, "cat #{hosts_file}"
26
+ assert_match %r{foo}, result.stdout
27
+ end
28
+ end
29
+ end
30
+
31
+ step 'verify with_stub_host_on' do
32
+ step 'should add entry to hosts file' do
33
+ hosts.each do |host|
34
+ hosts_file = get_hosts_file(host)
35
+ result = with_host_stubbed_on(host, { 'sleepy' => '1.1.1.2' }, { 'sleepy' => [ 'grumpy', 'dopey' ] }) { on host, "cat #{hosts_file}" }
36
+ assert_match %r{sleepy}, result.stdout
37
+ end
38
+ end
39
+
40
+ step 'stubbed value should be reverted after the execution of the block' do
41
+ hosts.each do |host|
42
+ hosts_file = get_hosts_file(host)
43
+ result = on host, "cat #{hosts_file}"
44
+ assert_no_match %r{sleepy}, result.stdout
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,54 @@
1
+ require 'webrick'
2
+ require 'webrick/https'
3
+
4
+ test_name 'dsl::helpers::web_helpers #link_exists?' do
5
+ cert_name = [
6
+ %w[CN localhost],
7
+ ]
8
+ http_cmd = "ruby -rwebrick -e'WEBrick::HTTPServer.new(:Port => 80, :DocumentRoot => \"/tmp\").start' > /tmp/mylogfile 2>&1 &"
9
+ https_cmd = "ruby -rwebrick/https -e'WEBrick::HTTPServer.new(:SSLEnable => true, :SSLCertName => #{cert_name}, :Port => 555,:DocumentRoot => \"/tmp\").start' > /tmp/mylogfile 2>&1 &"
10
+ on(default, http_cmd)
11
+ on(default, https_cmd)
12
+ #allow web servers to start up
13
+ sleep(3)
14
+ dir = default.tmpdir('test_dir')
15
+ file = default.tmpfile('test_file')
16
+ dir.slice! "/tmp"
17
+ file.slice! "/tmp"
18
+ dst_dir = 'web_helpers'
19
+
20
+ step '#port_open_within? can tell if a port is open' do
21
+ assert port_open_within?(default,80)
22
+ end
23
+
24
+ step '#link_exists? can tell if a basic link exists' do
25
+ assert link_exists?("http://#{default}")
26
+ end
27
+
28
+ step '#link_exists? can tell if a basic link does not exist' do
29
+ assert !link_exists?("http://#{default}/test")
30
+ end
31
+
32
+ step '#link_exists? can use an ssl link' do
33
+ assert link_exists?("https://#{default}:555")
34
+ end
35
+
36
+ step '#fetch_http_dir can fetch a dir' do
37
+ assert_equal "#{dst_dir}#{dir}", fetch_http_dir("http://#{default}/#{dir}", dst_dir)
38
+ end
39
+
40
+ step '#fetch_http_dir will raise an error if unable fetch a dir' do
41
+ exception = assert_raises(RuntimeError) { fetch_http_dir("http://#{default}/tmps", dst_dir) }
42
+ assert_match /Failed to fetch_remote_dir.*/, exception.message, "#fetch_http_dir raised an unexpected RuntimeError"
43
+ end
44
+
45
+ step '#fetch_http_file can fetch a file' do
46
+ assert_equal "#{dst_dir}#{file}", fetch_http_file("http://#{default}", file, dst_dir)
47
+ end
48
+
49
+ step '#fetch_http_file will raise an error if unable to fetch a file' do
50
+ exception = assert_raises(RuntimeError) { fetch_http_file("http://#{default}", "test2.txt", dst_dir) }
51
+ assert_match /Failed to fetch_remote_file.*/, exception.message, "#fetch_http_dir raised an unexpected RuntimeError"
52
+ end
53
+
54
+ end
@@ -0,0 +1,26 @@
1
+ test_name 'skip_test in with_puppet_running_on' do
2
+ assert_raises SkipTest do
3
+ with_puppet_running_on(master, {}) do
4
+ skip_test 'skip rest'
5
+ assert(false)
6
+ end
7
+ end
8
+ end
9
+
10
+ test_name 'pending_test in with_puppet_running_on' do
11
+ assert_raises PendingTest do
12
+ with_puppet_running_on(master, {}) do
13
+ pending_test 'pending appendix prepended'
14
+ assert(false)
15
+ end
16
+ end
17
+ end
18
+
19
+ test_name 'fail_test in with_puppet_running_on' do
20
+ assert_raises FailTest do
21
+ with_puppet_running_on(master, {}) do
22
+ fail_test 'fail_test message'
23
+ assert(false)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,38 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
3
+ require 'beaker-puppet/version'
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "beaker-puppet"
7
+ s.version = BeakerPuppet::VERSION
8
+ s.authors = ["Puppet"]
9
+ s.email = ["delivery@puppet.com"]
10
+ s.homepage = "https://github.com/puppetlabs/beaker-puppet"
11
+ s.summary = %q{Beaker's Puppet DSL Extension Helpers!}
12
+ s.description = %q{For use for the Beaker acceptance testing tool}
13
+ s.license = 'Apache2'
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ # Testing dependencies
21
+ s.add_development_dependency 'rspec', '~> 3.0'
22
+ s.add_development_dependency 'rspec-its'
23
+ s.add_development_dependency 'fakefs', '~> 0.6'
24
+ s.add_development_dependency 'rake', '~> 10.1'
25
+ s.add_development_dependency 'simplecov'
26
+ s.add_development_dependency 'pry', '~> 0.10'
27
+
28
+ # Documentation dependencies
29
+ s.add_development_dependency 'yard'
30
+ s.add_development_dependency 'markdown'
31
+ s.add_development_dependency 'thin'
32
+
33
+ # Run time dependencies
34
+ s.add_runtime_dependency 'stringify-hash', '~> 0.0.0'
35
+ s.add_runtime_dependency 'in-parallel', '~> 0.1'
36
+
37
+ end
38
+