beaker 1.8.1 → 1.8.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +8 -8
  2. data/bin/beaker +1 -1
  3. data/lib/beaker.rb +1 -1
  4. data/lib/beaker/cli.rb +15 -35
  5. data/lib/beaker/host_prebuilt_steps.rb +335 -0
  6. data/lib/beaker/hypervisor.rb +53 -4
  7. data/lib/beaker/hypervisor/aixer.rb +2 -2
  8. data/lib/beaker/hypervisor/blimper.rb +5 -5
  9. data/lib/beaker/hypervisor/fusion.rb +3 -3
  10. data/lib/beaker/hypervisor/solaris.rb +2 -2
  11. data/lib/beaker/hypervisor/vagrant.rb +6 -16
  12. data/lib/beaker/hypervisor/vcloud.rb +6 -6
  13. data/lib/beaker/hypervisor/vcloud_pooled.rb +4 -4
  14. data/lib/beaker/hypervisor/vsphere.rb +3 -3
  15. data/lib/beaker/network_manager.rb +51 -37
  16. data/lib/beaker/options/presets.rb +1 -0
  17. data/lib/beaker/shared.rb +2 -2
  18. data/lib/beaker/shared/host_role_parser.rb +36 -0
  19. data/lib/beaker/version.rb +1 -1
  20. data/spec/beaker/host_prebuilt_steps_spec.rb +421 -0
  21. data/spec/beaker/hypervisor/google_compute.rb +23 -0
  22. data/spec/beaker/hypervisor/vagrant_spec.rb +5 -4
  23. data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +2 -2
  24. data/spec/beaker/hypervisor/vcloud_spec.rb +2 -2
  25. data/spec/beaker/hypervisor/vsphere_spec.rb +2 -2
  26. data/spec/beaker/options/parser_spec.rb +1 -1
  27. data/spec/beaker/shared/host_role_parser_spec.rb +58 -0
  28. metadata +10 -18
  29. data/lib/beaker/shared/host_handler.rb +0 -51
  30. data/lib/beaker/utils.rb +0 -7
  31. data/lib/beaker/utils/ntp_control.rb +0 -57
  32. data/lib/beaker/utils/repo_control.rb +0 -90
  33. data/lib/beaker/utils/setup_helper.rb +0 -66
  34. data/lib/beaker/utils/validator.rb +0 -36
  35. data/spec/beaker/shared/host_handler_spec.rb +0 -104
  36. data/spec/beaker/utils/ntp_control_spec.rb +0 -70
  37. data/spec/beaker/utils/repo_control_spec.rb +0 -168
  38. data/spec/beaker/utils/setup_helper_spec.rb +0 -82
  39. data/spec/beaker/utils/validator_spec.rb +0 -91
@@ -1,66 +0,0 @@
1
- module Beaker
2
- module Utils
3
- class SetupHelper
4
- ETC_HOSTS_PATH = "/etc/hosts"
5
- ETC_HOSTS_PATH_SOLARIS = "/etc/inet/hosts"
6
- ROOT_KEYS_SCRIPT = "https://raw.github.com/puppetlabs/puppetlabs-sshkeys/master/templates/scripts/manage_root_authorized_keys"
7
- ROOT_KEYS_SYNC_CMD = "curl -k -o - #{ROOT_KEYS_SCRIPT} | %s"
8
-
9
- def initialize(options, hosts)
10
- @options = options.dup
11
- @hosts = hosts
12
- @logger = options[:logger]
13
- end
14
-
15
- def add_master_entry
16
- @logger.notify "Add Master entry to /etc/hosts"
17
- master = only_host_with_role(@hosts, :master)
18
- if master["hypervisor"] and master["hypervisor"] =~ /vagrant/
19
- @logger.debug "Don't update master entry on vagrant masters"
20
- return
21
- end
22
- @logger.debug "Get ip address of Master #{master}"
23
- if master['platform'].include? 'solaris'
24
- stdout = master.exec(Command.new("ifconfig -a inet| awk '/broadcast/ {print $2}' | cut -d/ -f1 | head -1")).stdout
25
- else
26
- stdout = master.exec(Command.new("ip a|awk '/global/{print$2}' | cut -d/ -f1 | head -1")).stdout
27
- end
28
- ip=stdout.chomp
29
-
30
- path = ETC_HOSTS_PATH
31
- if master['platform'].include? 'solaris'
32
- path = ETC_HOSTS_PATH_SOLARIS
33
- end
34
-
35
- @logger.debug "Update %s on #{master}" % path
36
- # Preserve the mode the easy way...
37
- master.exec(Command.new("cp %s %s.old" % [path, path]))
38
- master.exec(Command.new("cp %s %s.new" % [path, path]))
39
- master.exec(Command.new("grep -v '#{ip} #{master}' %s > %s.new" % [path, path]))
40
- master.exec(Command.new("echo '#{ip} #{master}' >> %s.new" % path))
41
- master.exec(Command.new("mv %s.new %s" % [path, path]))
42
- rescue => e
43
- report_and_raise(@logger, e, "add_master_entry")
44
- end
45
-
46
- def sync_root_keys
47
- # JJM This step runs on every system under test right now. We're anticipating
48
- # issues on Windows and maybe Solaris. We will likely need to filter this step
49
- # but we're deliberately taking the approach of "assume it will work, fix it
50
- # when reality dictates otherwise"
51
- @logger.notify "Sync root authorized_keys from github"
52
- @hosts.each do |host|
53
- # Allow all exit code, as this operation is unlikely to cause problems if it fails.
54
- if host['platform'].include? 'solaris'
55
- host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "bash"), :acceptable_exit_codes => (0..255))
56
- else
57
- host.exec(Command.new(ROOT_KEYS_SYNC_CMD % "env PATH=/usr/gnu/bin:$PATH bash"), :acceptable_exit_codes => (0..255))
58
- end
59
- end
60
- rescue => e
61
- report_and_raise(@logger, e, "sync_root_keys")
62
- end
63
-
64
- end
65
- end
66
- end
@@ -1,36 +0,0 @@
1
- module Beaker
2
- module Utils
3
- module Validator
4
- PACKAGES = ['curl']
5
- UNIX_PACKAGES = ['ntpdate']
6
- SLES_PACKAGES = ['ntp']
7
-
8
- def self.validate(hosts, logger)
9
- hosts.each do |host|
10
- PACKAGES.each do |pkg|
11
- if not host.check_for_package pkg
12
- host.install_package pkg
13
- end
14
- end
15
- case
16
- when host['platform'] =~ /sles-/
17
- SLES_PACKAGES.each do |pkg|
18
- if not host.check_for_package pkg
19
- host.install_package pkg
20
- end
21
- end
22
-
23
- when host['platform'] !~ /(windows)|(aix)|(solaris)/
24
- UNIX_PACKAGES.each do |pkg|
25
- if not host.check_for_package pkg
26
- host.install_package pkg
27
- end
28
- end
29
- end
30
- end
31
- rescue => e
32
- report_and_raise(logger, e, "validate")
33
- end
34
- end
35
- end
36
- end
@@ -1,104 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Beaker
4
- module Shared
5
- describe HostHandler do
6
- let( :host_handler ) { Beaker::Shared::HostHandler }
7
- let( :platform ) { @platform || 'unix' }
8
- let( :hosts ) { hosts = make_hosts( { :platform => platform } )
9
- hosts[0][:roles] = ['agent']
10
- hosts[1][:roles] = ['master', 'dashboard', 'agent', 'database']
11
- hosts[2][:roles] = ['agent']
12
- hosts }
13
-
14
- context 'get_domain_name' do
15
-
16
- it "can find the domain for a host" do
17
- host = make_host('name', { :stdout => "domain labs.lan d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" } )
18
-
19
- Command.should_receive( :new ).with( "cat /etc/resolv.conf" ).once
20
-
21
- expect( host_handler.get_domain_name( host ) ).to be === "labs.lan"
22
-
23
- end
24
-
25
- it "can find the search for a host" do
26
- host = make_host('name', { :stdout => "search labs.lan d.labs.net dc1.labs.net labs.com\nnameserver 10.16.22.10\nnameserver 10.16.22.11" } )
27
-
28
- Command.should_receive( :new ).with( "cat /etc/resolv.conf" ).once
29
-
30
- expect( host_handler.get_domain_name( host ) ).to be === "labs.lan"
31
-
32
- end
33
- end
34
-
35
- context "get_ip" do
36
- it "can exec the get_ip command" do
37
- host = make_host('name', { :stdout => "192.168.2.130\n" } )
38
-
39
- Command.should_receive( :new ).with( "ip a|awk '/global/{print$2}' | cut -d/ -f1 | head -1" ).once
40
-
41
- expect( host_handler.get_ip( host ) ).to be === "192.168.2.130"
42
-
43
- end
44
-
45
- end
46
-
47
- context "set_etc_hosts" do
48
- it "can set the /etc/hosts string on a host" do
49
- host = make_host('name', {})
50
- etc_hosts = "127.0.0.1 localhost\n192.168.2.130 pe-ubuntu-lucid\n192.168.2.128 pe-centos6\n192.168.2.131 pe-debian6"
51
-
52
- Command.should_receive( :new ).with( "echo '#{etc_hosts}' > /etc/hosts" ).once
53
- host.should_receive( :exec ).once
54
-
55
- host_handler.set_etc_hosts(host, etc_hosts)
56
- end
57
-
58
- end
59
-
60
- context "hosts_with_role" do
61
- it "can find the master in a set of hosts" do
62
-
63
- expect( host_handler.hosts_with_role( hosts, 'master' ) ).to be === [hosts[1]]
64
-
65
- end
66
-
67
- it "can find all agents in a set of hosts" do
68
-
69
- expect( host_handler.hosts_with_role( hosts, 'agent' ) ).to be === hosts
70
-
71
- end
72
-
73
- it "returns [] when no match is found in a set of hosts" do
74
-
75
- expect( host_handler.hosts_with_role( hosts, 'surprise' ) ).to be === []
76
-
77
- end
78
-
79
- end
80
-
81
- context "only_host_with_role" do
82
- it "can find the single master in a set of hosts" do
83
-
84
- expect( host_handler.only_host_with_role( hosts, 'master' ) ).to be === hosts[1]
85
-
86
- end
87
-
88
- it "throws an error when more than one host with matching role is found" do
89
-
90
- expect{ host_handler.only_host_with_role( hosts, 'agent' ) }.to raise_error(ArgumentError)
91
-
92
- end
93
-
94
- it "throws an error when no host is found matching the role" do
95
-
96
- expect{ host_handler.only_host_with_role( hosts, 'surprise' ) }.to raise_error(ArgumentError)
97
-
98
- end
99
- end
100
-
101
- end
102
-
103
- end
104
- end
@@ -1,70 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Beaker
4
- module Utils
5
- describe NTPControl do
6
- let( :ntpserver ) { Beaker::Utils::NTPControl::NTPSERVER }
7
- let( :ntp_control ) { Beaker::Utils::NTPControl.new( make_opts, @hosts) }
8
-
9
- it "can sync time on unix hosts" do
10
- @hosts = make_hosts( { :platform => 'unix' } )
11
-
12
- Command.should_receive( :new ).with("ntpdate -t 20 #{ntpserver}").exactly( 3 ).times
13
-
14
- ntp_control.timesync
15
-
16
- end
17
-
18
- it "can retry on failure on unix hosts" do
19
- @hosts = make_hosts( { :platform => 'unix', :exit_code => [1, 0] } )
20
- ntp_control.stub( :sleep ).and_return(true)
21
-
22
- Command.should_receive( :new ).with("ntpdate -t 20 #{ntpserver}").exactly( 6 ).times
23
-
24
- ntp_control.timesync
25
- end
26
-
27
- it "eventually gives up and raises an error when unix hosts can't be synched" do
28
- @hosts = make_hosts( { :platform => 'unix', :exit_code => 1 } )
29
- ntp_control.stub( :sleep ).and_return(true)
30
-
31
- Command.should_receive( :new ).with("ntpdate -t 20 #{ntpserver}").exactly( 5 ).times
32
-
33
- expect{ ntp_control.timesync }.to raise_error
34
- end
35
-
36
- it "can sync time on solaris-10 hosts" do
37
- @hosts = make_hosts( { :platform => 'solaris-10' } )
38
-
39
- Command.should_receive( :new ).with("sleep 10 && ntpdate -w #{ntpserver}").exactly( 3 ).times
40
-
41
- ntp_control.timesync
42
-
43
- end
44
-
45
- it "can sync time on windows hosts" do
46
- @hosts = make_hosts( { :platform => 'windows' } )
47
-
48
- Command.should_receive( :new ).with("w32tm /register").exactly( 3 ).times
49
- Command.should_receive( :new ).with("net start w32time").exactly( 3 ).times
50
- Command.should_receive( :new ).with("w32tm /config /manualpeerlist:#{ntpserver} /syncfromflags:manual /update").exactly( 3 ).times
51
- Command.should_receive( :new ).with("w32tm /resync").exactly( 3 ).times
52
-
53
- ntp_control.timesync
54
-
55
- end
56
-
57
- it "can sync time on Sles hosts" do
58
- @hosts = make_hosts( { :platform => 'sles-13.1-x64' } )
59
-
60
- Command.should_receive( :new ).with("sntp #{ntpserver}").exactly( 3 ).times
61
-
62
- ntp_control.timesync
63
-
64
- end
65
-
66
-
67
- end
68
-
69
- end
70
- end
@@ -1,168 +0,0 @@
1
- require 'spec_helper'
2
-
3
- module Beaker
4
- module Utils
5
- describe RepoControl do
6
- let( :apt_cfg ) { Beaker::Utils::RepoControl::APT_CFG }
7
- let( :ips_pkg_repo ) { Beaker::Utils::RepoControl::IPS_PKG_REPO }
8
- let( :repo_control ) { Beaker::Utils::RepoControl.new( make_opts, @hosts) }
9
-
10
- context "epel_info_for!" do
11
-
12
- it "can return the correct url for an el-6 host" do
13
- host = make_host( 'testhost', { :platform => 'el-6-platform' } )
14
-
15
- expect( repo_control.epel_info_for!( host )).to be === "http://mirror.itc.virginia.edu/fedora-epel/6/i386/epel-release-6-8.noarch.rpm"
16
- end
17
-
18
- it "can return the correct url for an el-5 host" do
19
- host = make_host( 'testhost', { :platform => 'el-5-platform' } )
20
-
21
- expect( repo_control.epel_info_for!( host )).to be === "http://archive.linux.duke.edu/pub/epel/5/i386/epel-release-5-4.noarch.rpm"
22
-
23
- end
24
-
25
- it "raises an error on non el-5/6 host" do
26
- host = make_host( 'testhost', { :platform => 'el-4-platform' } )
27
-
28
- expect{ repo_control.epel_info_for!( host )}.to raise_error
29
-
30
- end
31
-
32
- end
33
-
34
- context "apt_get_update" do
35
-
36
- it "can perform apt-get on ubuntu hosts" do
37
- host = make_host( 'testhost', { :platform => 'ubuntu' } )
38
-
39
- Command.should_receive( :new ).with("apt-get -y -f -m update").once
40
-
41
- repo_control.apt_get_update( host )
42
-
43
- end
44
-
45
- it "can perform apt-get on debian hosts" do
46
- host = make_host( 'testhost', { :platform => 'debian' } )
47
-
48
- Command.should_receive( :new ).with("apt-get -y -f -m update").once
49
-
50
- repo_control.apt_get_update( host )
51
-
52
- end
53
-
54
- it "does nothing on non debian/ubuntu hosts" do
55
- host = make_host( 'testhost', { :platform => 'windows' } )
56
-
57
- Command.should_receive( :new ).never
58
-
59
- repo_control.apt_get_update( host )
60
-
61
- end
62
-
63
- end
64
-
65
- context "copy_file_to_remote" do
66
-
67
- it "can copy a file to a remote host" do
68
- content = "this is the content"
69
- tempfilepath = "/path/to/tempfile"
70
- filepath = "/path/to/file"
71
- host = make_host( 'testhost', { :platform => 'windows' })
72
- tempfile = double( 'tempfile' )
73
- tempfile.stub( :path ).and_return( tempfilepath )
74
- Tempfile.stub( :open ).and_yield( tempfile )
75
- file = double( 'file' )
76
- File.stub( :open ).and_yield( file )
77
-
78
- file.should_receive( :puts ).with( content ).once
79
- host.should_receive( :do_scp_to ).with( tempfilepath, filepath, repo_control.instance_variable_get( :@options ) ).once
80
-
81
- repo_control.copy_file_to_remote(host, filepath, content)
82
-
83
- end
84
-
85
-
86
- end
87
-
88
- context "proxy_config" do
89
-
90
- it "correctly configures ubuntu hosts" do
91
- @hosts = make_hosts( { :platform => 'ubuntu', :exit_code => 1 } )
92
-
93
- Command.should_receive( :new ).with( "if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi" ).exactly( 3 )
94
- @hosts.each do |host|
95
- repo_control.should_receive( :copy_file_to_remote ).with( host, '/etc/apt/apt.conf', apt_cfg ).once
96
- repo_control.should_receive( :apt_get_update ).with( host ).once
97
- end
98
-
99
- repo_control.proxy_config
100
-
101
- end
102
-
103
- it "correctly configures debian hosts" do
104
- @hosts = make_hosts( { :platform => 'debian' } )
105
-
106
- Command.should_receive( :new ).with( "if test -f /etc/apt/apt.conf; then mv /etc/apt/apt.conf /etc/apt/apt.conf.bk; fi" ).exactly( 3 ).times
107
- @hosts.each do |host|
108
- repo_control.should_receive( :copy_file_to_remote ).with( host, '/etc/apt/apt.conf', apt_cfg ).once
109
- repo_control.should_receive( :apt_get_update ).with( host ).once
110
- end
111
-
112
- repo_control.proxy_config
113
-
114
- end
115
-
116
- it "correctly configures solaris-11 hosts" do
117
- @hosts = make_hosts( { :platform => 'solaris-11' } )
118
-
119
- Command.should_receive( :new ).with( "/usr/bin/pkg unset-publisher solaris || :" ).exactly( 3 ).times
120
- @hosts.each do |host|
121
- Command.should_receive( :new ).with( "/usr/bin/pkg set-publisher -g %s solaris" % ips_pkg_repo ).once
122
- end
123
-
124
- repo_control.proxy_config
125
-
126
- end
127
-
128
- it "does nothing for non ubuntu/debian/solaris-11 hosts" do
129
- @hosts = make_hosts( { :platform => 'windows' } )
130
-
131
- Command.should_receive( :new ).never
132
-
133
- repo_control.proxy_config
134
-
135
- end
136
- end
137
-
138
- context "add_el_extras" do
139
-
140
- it "add extras for el-5/6 hosts" do
141
- @hosts = make_hosts( { :platform => 'el-5', :exit_code => 1 } )
142
- @hosts[0][:platform] = 'el-6'
143
- url = "http://el_extras_url"
144
-
145
- repo_control.stub( :epel_info_for! ).and_return( url )
146
-
147
- Command.should_receive( :new ).with("rpm -qa | grep epel-release").exactly( 3 ).times
148
- Command.should_receive( :new ).with("rpm -i #{url}").exactly( 3 ).times
149
- Command.should_receive( :new ).with("yum clean all && yum makecache").exactly( 3 ).times
150
-
151
- repo_control.add_el_extras
152
-
153
- end
154
-
155
- it "should do nothing for non el-5/6 hosts" do
156
- @hosts = make_hosts( { :platform => 'windows' } )
157
-
158
- Command.should_receive( :new ).never
159
-
160
- repo_control.add_el_extras
161
-
162
- end
163
- end
164
-
165
- end
166
-
167
- end
168
- end