beaker 0.0.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/.travis.yml +8 -0
- data/README.md +6 -6
- data/beaker.gemspec +6 -2
- data/lib/beaker.rb +1 -1
- data/lib/beaker/answers.rb +34 -7
- data/lib/beaker/answers/version20.rb +124 -0
- data/lib/beaker/answers/version28.rb +21 -0
- data/lib/beaker/answers/version30.rb +24 -5
- data/lib/beaker/cli.rb +55 -41
- data/lib/beaker/command.rb +2 -2
- data/lib/beaker/dsl/helpers.rb +320 -106
- data/lib/beaker/dsl/install_utils.rb +202 -81
- data/lib/beaker/dsl/roles.rb +40 -0
- data/lib/beaker/host.rb +28 -20
- data/lib/beaker/host/unix.rb +7 -4
- data/lib/beaker/host/unix/pkg.rb +42 -12
- data/lib/beaker/host/windows.rb +9 -5
- data/lib/beaker/host/windows/group.rb +1 -1
- data/lib/beaker/host/windows/pkg.rb +41 -8
- data/lib/beaker/hypervisor.rb +23 -10
- data/lib/beaker/hypervisor/aixer.rb +15 -19
- data/lib/beaker/hypervisor/blimper.rb +71 -72
- data/lib/beaker/hypervisor/fusion.rb +11 -10
- data/lib/beaker/hypervisor/solaris.rb +17 -23
- data/lib/beaker/hypervisor/vagrant.rb +27 -12
- data/lib/beaker/hypervisor/vcloud.rb +154 -138
- data/lib/beaker/hypervisor/vcloud_pooled.rb +97 -0
- data/lib/beaker/hypervisor/vsphere.rb +8 -5
- data/lib/beaker/hypervisor/vsphere_helper.rb +43 -33
- data/lib/beaker/network_manager.rb +16 -12
- data/lib/beaker/options/command_line_parser.rb +199 -0
- data/lib/beaker/options/hosts_file_parser.rb +39 -0
- data/lib/beaker/options/options_file_parser.rb +45 -0
- data/lib/beaker/options/options_hash.rb +294 -0
- data/lib/beaker/options/parser.rb +288 -0
- data/lib/beaker/options/pe_version_scraper.rb +35 -0
- data/lib/beaker/options/presets.rb +70 -0
- data/lib/beaker/shared.rb +2 -1
- data/lib/beaker/shared/host_handler.rb +7 -2
- data/lib/beaker/shared/repetition.rb +1 -0
- data/lib/beaker/shared/timed.rb +14 -0
- data/lib/beaker/test_case.rb +2 -38
- data/lib/beaker/test_suite.rb +11 -25
- data/lib/beaker/utils/repo_control.rb +6 -8
- data/lib/beaker/utils/setup_helper.rb +9 -20
- data/spec/beaker/answers_spec.rb +109 -0
- data/spec/beaker/command_spec.rb +2 -2
- data/spec/beaker/dsl/assertions_spec.rb +1 -3
- data/spec/beaker/dsl/helpers_spec.rb +519 -84
- data/spec/beaker/dsl/install_utils_spec.rb +265 -16
- data/spec/beaker/dsl/roles_spec.rb +31 -10
- data/spec/beaker/host/windows/group_spec.rb +55 -0
- data/spec/beaker/host_spec.rb +130 -40
- data/spec/beaker/hypervisor/aixer_spec.rb +34 -0
- data/spec/beaker/hypervisor/blimper_spec.rb +77 -0
- data/spec/beaker/hypervisor/fusion_spec.rb +26 -0
- data/spec/beaker/hypervisor/hypervisor_spec.rb +66 -0
- data/spec/beaker/hypervisor/solaris_spec.rb +39 -0
- data/spec/beaker/hypervisor/vagrant_spec.rb +105 -0
- data/spec/beaker/hypervisor/vcloud_pooled_spec.rb +60 -0
- data/spec/beaker/hypervisor/vcloud_spec.rb +70 -0
- data/spec/beaker/hypervisor/vsphere_helper_spec.rb +162 -0
- data/spec/beaker/hypervisor/vsphere_spec.rb +76 -0
- data/spec/beaker/options/command_line_parser_spec.rb +25 -0
- data/spec/beaker/options/data/LATEST +1 -0
- data/spec/beaker/options/data/badyaml.cfg +21 -0
- data/spec/beaker/options/data/hosts.cfg +21 -0
- data/spec/beaker/options/data/opts.txt +6 -0
- data/spec/beaker/options/hosts_file_parser_spec.rb +30 -0
- data/spec/beaker/options/options_file_parser_spec.rb +23 -0
- data/spec/beaker/options/options_hash_spec.rb +111 -0
- data/spec/beaker/options/parser_spec.rb +172 -0
- data/spec/beaker/options/pe_version_scaper_spec.rb +15 -0
- data/spec/beaker/options/presets_spec.rb +24 -0
- data/spec/beaker/puppet_command_spec.rb +54 -21
- data/spec/beaker/shared/error_handler_spec.rb +40 -0
- data/spec/beaker/shared/host_handler_spec.rb +104 -0
- data/spec/beaker/shared/repetition_spec.rb +72 -0
- data/spec/beaker/test_suite_spec.rb +3 -16
- data/spec/beaker/utils/ntp_control_spec.rb +42 -0
- data/spec/beaker/utils/repo_control_spec.rb +168 -0
- data/spec/beaker/utils/setup_helper_spec.rb +82 -0
- data/spec/beaker/utils/validator_spec.rb +58 -0
- data/spec/helpers.rb +97 -0
- data/spec/matchers.rb +39 -0
- data/spec/mock_blimpy.rb +48 -0
- data/spec/mock_fission.rb +60 -0
- data/spec/mock_vsphere.rb +310 -0
- data/spec/mock_vsphere_helper.rb +183 -0
- data/spec/mocks.rb +83 -0
- data/spec/spec_helper.rb +8 -1
- metadata +106 -13
- data/beaker.rb +0 -10
- data/lib/beaker/options_parsing.rb +0 -323
- data/lib/beaker/test_config.rb +0 -148
- data/spec/beaker/options_parsing_spec.rb +0 -37
- data/spec/mocks_and_helpers.rb +0 -34
@@ -0,0 +1,172 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
|
6
|
+
describe Parser do
|
7
|
+
let(:parser) { Parser.new }
|
8
|
+
let(:opts_path) { File.join(File.expand_path(File.dirname(__FILE__)), "data", "opts.txt") }
|
9
|
+
let(:hosts_path) { File.join(File.expand_path(File.dirname(__FILE__)), "data", "hosts.cfg") }
|
10
|
+
let(:badyaml_path) { File.join(File.expand_path(File.dirname(__FILE__)), "data", "badyaml.cfg") }
|
11
|
+
let(:home) {ENV['HOME']}
|
12
|
+
|
13
|
+
it "supports usage function" do
|
14
|
+
expect{parser.usage}.to_not raise_error
|
15
|
+
end
|
16
|
+
|
17
|
+
repo = 'git://github.com/puppetlabs'
|
18
|
+
|
19
|
+
it "has repo set to #{repo}" do
|
20
|
+
expect(parser.repo).to be === "#{repo}"
|
21
|
+
end
|
22
|
+
|
23
|
+
#test parse_install_options
|
24
|
+
it "can transform --install PUPPET/3.1 into #{repo}/puppet.git#3.1" do
|
25
|
+
opts = ["PUPPET/3.1"]
|
26
|
+
expect(parser.parse_git_repos(opts)).to be === ["#{repo}/puppet.git#3.1"]
|
27
|
+
end
|
28
|
+
it "can transform --install FACTER/v.1.0 into #{repo}/facter.git#v.1.0" do
|
29
|
+
opts = ["FACTER/v.1.0"]
|
30
|
+
expect(parser.parse_git_repos(opts)).to be === ["#{repo}/facter.git#v.1.0"]
|
31
|
+
end
|
32
|
+
it "can transform --install HIERA/xyz into #{repo}/hiera.git#xyz" do
|
33
|
+
opts = ["HIERA/xyz"]
|
34
|
+
expect(parser.parse_git_repos(opts)).to be === ["#{repo}/hiera.git#xyz"]
|
35
|
+
end
|
36
|
+
it "can transform --install HIERA-PUPPET/path/to/repo into #{repo}/hiera-puppet.git#path/to/repo" do
|
37
|
+
opts = ["HIERA-PUPPET/path/to/repo"]
|
38
|
+
expect(parser.parse_git_repos(opts)).to be === ["#{repo}/hiera-puppet.git#path/to/repo"]
|
39
|
+
end
|
40
|
+
it "can transform --install PUPPET/3.1,FACTER/v.1.0 into #{repo}/puppet.git#3.1,#{repo}/facter.git#v.1.0" do
|
41
|
+
opts = ["PUPPET/3.1", "FACTER/v.1.0"]
|
42
|
+
expect(parser.parse_git_repos(opts)).to be === ["#{repo}/puppet.git#3.1", "#{repo}/facter.git#v.1.0"]
|
43
|
+
end
|
44
|
+
it "can leave --install git://github.com/puppetlabs/puppet.git#my/full/path alone" do
|
45
|
+
opts = ["git://github.com/puppetlabs/puppet.git#my/full/path"]
|
46
|
+
expect(parser.parse_git_repos(opts)).to be === ["git://github.com/puppetlabs/puppet.git#my/full/path"]
|
47
|
+
end
|
48
|
+
|
49
|
+
#split_arg testing
|
50
|
+
it "can split comma separated list into an array" do
|
51
|
+
arg = "file1,file2,file3"
|
52
|
+
expect(parser.split_arg(arg)).to be === ["file1", "file2", "file3"]
|
53
|
+
end
|
54
|
+
it "can use an existing Array as an acceptable argument" do
|
55
|
+
arg = ["file1", "file2", "file3"]
|
56
|
+
expect(parser.split_arg(arg)).to be === ["file1", "file2", "file3"]
|
57
|
+
end
|
58
|
+
it "can generate an array from a single value" do
|
59
|
+
arg = "i'mjustastring"
|
60
|
+
expect(parser.split_arg(arg)).to be === ["i'mjustastring"]
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'testing path traversing', :use_fakefs => true do
|
64
|
+
let(:test_dir) { 'tmp/tests' }
|
65
|
+
|
66
|
+
let(:paths) { create_files(@files) }
|
67
|
+
let(:rb_test) { File.expand_path(test_dir + '/my_ruby_file.rb') }
|
68
|
+
let(:pl_test) { File.expand_path(test_dir + '/my_perl_file.pl') }
|
69
|
+
let(:sh_test) { File.expand_path(test_dir + '/my_shell_file.sh') }
|
70
|
+
let(:rb_other) { File.expand_path(test_dir + '/other/my_other_ruby_file.rb') }
|
71
|
+
|
72
|
+
it 'only collects ruby files as test files' do
|
73
|
+
@files = [ rb_test, pl_test, sh_test, rb_other ]
|
74
|
+
paths
|
75
|
+
expect(parser.file_list([File.expand_path(test_dir)])).to be === [rb_test, rb_other]
|
76
|
+
end
|
77
|
+
it 'raises an error when no ruby files are found' do
|
78
|
+
@files = [ pl_test, sh_test ]
|
79
|
+
paths
|
80
|
+
expect{parser.file_list([File.expand_path(test_dir)])}.to raise_error(ArgumentError)
|
81
|
+
end
|
82
|
+
it 'raises an error when no paths are specified for searching' do
|
83
|
+
@files = ''
|
84
|
+
expect{parser.file_list('')}.to raise_error(ArgumentError)
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
#test yaml file checking
|
90
|
+
it "raises error on improperly formatted yaml file" do
|
91
|
+
FakeFS.deactivate!
|
92
|
+
expect{parser.check_yaml_file(badyaml_path)}.to raise_error(ArgumentError)
|
93
|
+
end
|
94
|
+
it "raises an error when a yaml file is missing" do
|
95
|
+
FakeFS.deactivate!
|
96
|
+
expect{parser.check_yaml_file("not a path")}.to raise_error(ArgumentError)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "can correctly combine arguments from different sources" do
|
100
|
+
FakeFS.deactivate!
|
101
|
+
args = ["-h", hosts_path, "--debug", "--type", "git", "--install", "PUPPET/1.0,HIERA/hello"]
|
102
|
+
expect(parser.parse_args(args)).to be === {:hosts_file=>hosts_path, :options_file=>nil, :type=>"git", :provision=>true, :preserve_hosts=>false, :root_keys=>false, :quiet=>false, :xml=>false, :color=>true, :debug=>true, :dry_run=>false, :timeout=>300, :fail_mode=>nil, :timesync=>false, :repo_proxy=>false, :add_el_extras=>false, :consoleport=>443, :pe_dir=>"/opt/enterprise/dists", :pe_version_file=>"LATEST", :pe_version_file_win=>"LATEST-win", :dot_fog=>"#{home}/.fog", :help=>false, :ec2_yaml=>"config/image_templates/ec2.yaml", :ssh=>{:config=>false, :paranoid=>false, :timeout=>300, :auth_methods=>["publickey"], :port=>22, :forward_agent=>true, :keys=>["#{home}/.ssh/id_rsa"], :user_known_hosts_file=>"#{home}/.ssh/known_hosts"}, :install=>["git://github.com/puppetlabs/puppet.git#1.0", "git://github.com/puppetlabs/hiera.git#hello"], :HOSTS=>{:"pe-ubuntu-lucid"=>{:roles=>["agent", "dashboard", "database", "master"], :vmname=>"pe-ubuntu-lucid", :platform=>"ubuntu-10.04-i386", :snapshot=>"clean-w-keys", :hypervisor=>"fusion"}, :"pe-centos6"=>{:roles=>["agent"], :vmname=>"pe-centos6", :platform=>"el-6-i386", :hypervisor=>"fusion", :snapshot=>"clean-w-keys"}}, :nfs_server=>"none", :helper=>[], :load_path=>[], :tests=>[], :pre_suite=>[], :post_suite=>[], :modules=>[]}
|
103
|
+
end
|
104
|
+
|
105
|
+
it "ensures that file-mode is one of fast/stop" do
|
106
|
+
FakeFS.deactivate!
|
107
|
+
args = ["-h", hosts_path, "--debug", "--fail-mode", "slow"]
|
108
|
+
expect{parser.parse_args(args)}.to raise_error(ArgumentError)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "ensures that type is one of pe/git" do
|
112
|
+
FakeFS.deactivate!
|
113
|
+
args = ["-h", hosts_path, "--debug", "--type", "unkowns"]
|
114
|
+
expect{parser.parse_args(args)}.to raise_error(ArgumentError)
|
115
|
+
end
|
116
|
+
|
117
|
+
describe "normalize_args" do
|
118
|
+
let(:hosts) do
|
119
|
+
{
|
120
|
+
'HOSTS' => {
|
121
|
+
:master => {
|
122
|
+
:roles => ["master","agent"],
|
123
|
+
},
|
124
|
+
:agent => {
|
125
|
+
:roles => ["agent"],
|
126
|
+
},
|
127
|
+
}
|
128
|
+
}
|
129
|
+
end
|
130
|
+
|
131
|
+
def fake_hosts_file_for_platform(hosts, platform)
|
132
|
+
hosts['HOSTS'].values.each { |h| h[:platform] = platform }
|
133
|
+
filename = "hosts_file_#{platform}"
|
134
|
+
File.open(filename, "w") do |file|
|
135
|
+
YAML.dump(hosts, file)
|
136
|
+
end
|
137
|
+
filename
|
138
|
+
end
|
139
|
+
|
140
|
+
shared_examples_for(:a_platform_supporting_only_agents) do |platform,type|
|
141
|
+
let(:args) { ["--type", type] }
|
142
|
+
|
143
|
+
it "restricts #{platform} hosts to agent for #{type}" do
|
144
|
+
hosts_file = fake_hosts_file_for_platform(hosts, platform)
|
145
|
+
args << "--hosts" << hosts_file
|
146
|
+
expect { parser.parse_args(args) }.to raise_error(ArgumentError, /#{platform}.*can only have role 'agent'/)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
context "for pe" do
|
151
|
+
it_should_behave_like(:a_platform_supporting_only_agents, 'solaris', 'pe')
|
152
|
+
it_should_behave_like(:a_platform_supporting_only_agents, 'windows', 'pe')
|
153
|
+
it_should_behave_like(:a_platform_supporting_only_agents, 'el-4', 'pe')
|
154
|
+
end
|
155
|
+
|
156
|
+
context "for foss" do
|
157
|
+
it_should_behave_like(:a_platform_supporting_only_agents, 'windows', 'git')
|
158
|
+
it_should_behave_like(:a_platform_supporting_only_agents, 'el-4', 'git')
|
159
|
+
|
160
|
+
it "allows master role for solaris" do
|
161
|
+
hosts_file = fake_hosts_file_for_platform(hosts, 'solaris')
|
162
|
+
args = ["--type", "git", "--hosts", hosts_file]
|
163
|
+
options_hash = parser.parse_args(args)
|
164
|
+
expect(options_hash[:HOSTS][:master][:platform]).to match(/solaris/)
|
165
|
+
expect(options_hash[:HOSTS][:master][:roles]).to include('master')
|
166
|
+
expect(options_hash[:type]).to eq('git')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
describe PEVersionScraper do
|
6
|
+
it "can pull version from local LATEST file" do
|
7
|
+
expect(PEVersionScraper.load_pe_version(File.expand_path(File.dirname(__FILE__)), "data/LATEST")) === '3.0.0'
|
8
|
+
end
|
9
|
+
it "raises error when file doesn't exist" do
|
10
|
+
expect{PEVersionScraper.load_pe_version("not a valid path", "not a valid filename")}.to raise_error(ArgumentError)
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Options
|
5
|
+
|
6
|
+
describe Presets do
|
7
|
+
let(:presets) { Presets }
|
8
|
+
|
9
|
+
it "returns an env_vars OptionsHash" do
|
10
|
+
expect(presets.env_vars).to be_instance_of(Beaker::Options::OptionsHash)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "removes all empty/nil entries in env_vars" do
|
14
|
+
expect(presets.env_vars.has_value?(nil)).to be === false and expect(presets.env_vars.has_value?({})).to be === false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "returns a presets OptionsHash" do
|
18
|
+
expect(presets.presets).to be_instance_of(Beaker::Options::OptionsHash)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -5,13 +5,12 @@ module Beaker
|
|
5
5
|
describe PuppetCommand do
|
6
6
|
let(:command) { @command || '/bin/ls' }
|
7
7
|
let(:args) { @args || Array.new }
|
8
|
-
let(:options) { @options ||
|
8
|
+
let(:options) { @options || {} }
|
9
|
+
subject(:cmd) { PuppetCommand.new( command, args, options ) }
|
10
|
+
let(:host) { make_host( 'name', { :platform => @platform } ) }
|
9
11
|
|
10
|
-
|
11
|
-
let :
|
12
|
-
MockConfig.new({}, {'name' => {'platform' => @platform}}, @pe)
|
13
|
-
end
|
14
|
-
let(:host) { Host.create 'name', {}, config }
|
12
|
+
let( :nix_path ) { %q[PATH="/usr/bin:/opt/puppet-git-repos/hiera/bin:${PATH}"] }
|
13
|
+
let( :nix_lib ) { %q[RUBYLIB="/opt/puppet-git-repos/hiera/lib:/opt/puppet-git-repos/hiera-puppet/lib:${RUBYLIB}"] }
|
15
14
|
|
16
15
|
it 'creates a Windows env for a Windows host' do
|
17
16
|
@platform = 'windows'
|
@@ -20,13 +19,21 @@ module Beaker
|
|
20
19
|
@options = { :foo => 'bar' }
|
21
20
|
|
22
21
|
expect( host ).to be_a_kind_of Windows::Host
|
23
|
-
expect( cmd.options ).to be ==
|
24
|
-
expect( cmd.args ).to be == @args
|
22
|
+
expect( cmd.options ).to be == options
|
23
|
+
expect( cmd.args ).to be == [@args]
|
25
24
|
expect( cmd.command ).to be == "puppet " + @command
|
26
25
|
|
27
26
|
expect( cmd.args_string ).to be == 'to the baz'
|
28
27
|
expect( cmd.options_string ).to be == '--foo=bar'
|
29
|
-
|
28
|
+
|
29
|
+
win_path = %q[PATH="/opt/puppet-git-repos/hiera/bin:${PATH}"]
|
30
|
+
win_lib = %q[RUBYLIB="`cygpath -w /opt/puppet-git-repos/hiera/lib`;`cygpath -w /opt/puppet-git-repos/hiera-puppet/lib`;${RUBYLIB}"]
|
31
|
+
cmd_exe = %q[cmd.exe /c]
|
32
|
+
|
33
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
34
|
+
expect( command_line ).to include( win_path )
|
35
|
+
expect( command_line ).to include( win_lib )
|
36
|
+
expect( command_line ).to include( cmd_exe )
|
30
37
|
end
|
31
38
|
|
32
39
|
it 'creates a Unix env for a Unix host' do
|
@@ -37,12 +44,15 @@ module Beaker
|
|
37
44
|
|
38
45
|
expect( host ).to be_a_kind_of Unix::Host
|
39
46
|
expect( cmd.options ).to be == @options
|
40
|
-
expect( cmd.args ).to be == @args
|
47
|
+
expect( cmd.args ).to be == [@args]
|
41
48
|
expect( cmd.command ).to be == "puppet " + @command
|
42
49
|
|
43
50
|
expect( cmd.args_string ).to be == 'to the baz'
|
44
51
|
expect( cmd.options_string ).to be == '--foo=bar'
|
45
|
-
|
52
|
+
|
53
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
54
|
+
expect( command_line ).to include( nix_path )
|
55
|
+
expect( command_line ).to include( nix_lib )
|
46
56
|
end
|
47
57
|
|
48
58
|
it 'creates an AIX env for an AIX host' do
|
@@ -53,12 +63,15 @@ module Beaker
|
|
53
63
|
|
54
64
|
expect( host ).to be_a_kind_of Aix::Host
|
55
65
|
expect( cmd.options ).to be == @options
|
56
|
-
expect( cmd.args ).to be == @args
|
66
|
+
expect( cmd.args ).to be == [@args]
|
57
67
|
expect( cmd.command ).to be == "puppet " + @command
|
58
68
|
|
59
69
|
expect( cmd.args_string ).to be == 'to the baz'
|
60
70
|
expect( cmd.options_string ).to be == '--foo=bar'
|
61
|
-
|
71
|
+
|
72
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
73
|
+
expect( command_line ).to include( nix_path )
|
74
|
+
expect( command_line ).to include( nix_lib )
|
62
75
|
end
|
63
76
|
|
64
77
|
it 'correctly adds additional ENV to default ENV' do
|
@@ -69,12 +82,17 @@ module Beaker
|
|
69
82
|
|
70
83
|
expect( host ).to be_a_kind_of Unix::Host
|
71
84
|
expect( cmd.options ).to be == @options
|
72
|
-
expect( cmd.args ).to be == @args
|
85
|
+
expect( cmd.args ).to be == [@args]
|
73
86
|
expect( cmd.command ).to be == "puppet " + @command
|
74
87
|
|
75
88
|
expect( cmd.args_string ).to be == 'to the baz'
|
76
89
|
expect( cmd.options_string ).to be == '--foo=bar'
|
77
|
-
|
90
|
+
custom = %q[PATH="/STRING_ENV/bin"]
|
91
|
+
|
92
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
93
|
+
expect( command_line ).to include( nix_path )
|
94
|
+
expect( command_line ).to include( nix_lib )
|
95
|
+
expect( command_line ).to include( custom )
|
78
96
|
end
|
79
97
|
|
80
98
|
it 'correctly adds additional :ENV to default ENV' do
|
@@ -85,12 +103,17 @@ module Beaker
|
|
85
103
|
|
86
104
|
expect( host ).to be_a_kind_of Unix::Host
|
87
105
|
expect( cmd.options ).to be == @options
|
88
|
-
expect( cmd.args ).to be == @args
|
106
|
+
expect( cmd.args ).to be == [@args]
|
89
107
|
expect( cmd.command ).to be == "puppet " + @command
|
90
108
|
|
91
109
|
expect( cmd.args_string ).to be == 'to the baz'
|
92
110
|
expect( cmd.options_string ).to be == '--foo=bar'
|
93
|
-
|
111
|
+
|
112
|
+
custom = %q[PATH="/SYMBOL_ENV/bin"]
|
113
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
114
|
+
expect( command_line ).to include( nix_path )
|
115
|
+
expect( command_line ).to include( nix_lib )
|
116
|
+
expect( command_line ).to include( custom )
|
94
117
|
end
|
95
118
|
|
96
119
|
it 'correctly adds additional :environment to default ENV' do
|
@@ -101,12 +124,17 @@ module Beaker
|
|
101
124
|
|
102
125
|
expect( host ).to be_a_kind_of Unix::Host
|
103
126
|
expect( cmd.options ).to be == @options
|
104
|
-
expect( cmd.args ).to be == @args
|
127
|
+
expect( cmd.args ).to be == [@args]
|
105
128
|
expect( cmd.command ).to be == "puppet " + @command
|
106
129
|
|
107
130
|
expect( cmd.args_string ).to be == 'to the baz'
|
108
131
|
expect( cmd.options_string ).to be == '--foo=bar'
|
109
|
-
|
132
|
+
|
133
|
+
custom = %q[PATH="/SYMBOL_ENVIRONMENT/bin"]
|
134
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
135
|
+
expect( command_line ).to include( nix_path )
|
136
|
+
expect( command_line ).to include( nix_lib )
|
137
|
+
expect( command_line ).to include( custom )
|
110
138
|
end
|
111
139
|
|
112
140
|
it 'correctly adds additional environment to default ENV' do
|
@@ -117,12 +145,17 @@ module Beaker
|
|
117
145
|
|
118
146
|
expect( host ).to be_a_kind_of Unix::Host
|
119
147
|
expect( cmd.options ).to be == @options
|
120
|
-
expect( cmd.args ).to be == @args
|
148
|
+
expect( cmd.args ).to be == [@args]
|
121
149
|
expect( cmd.command ).to be == "puppet " + @command
|
122
150
|
|
123
151
|
expect( cmd.args_string ).to be == 'to the baz'
|
124
152
|
expect( cmd.options_string ).to be == '--foo=bar'
|
125
|
-
|
153
|
+
|
154
|
+
custom = %q[PATH="/STRING_ENVIRONMENT/bin"]
|
155
|
+
command_line = cmd.environment_string_for( host, cmd.environment )
|
156
|
+
expect( command_line ).to include( nix_path )
|
157
|
+
expect( command_line ).to include( nix_lib )
|
158
|
+
expect( command_line ).to include( custom )
|
126
159
|
end
|
127
160
|
end
|
128
161
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
module Shared
|
5
|
+
describe ErrorHandler do
|
6
|
+
|
7
|
+
let( :backtrace ) { "I'm the backtrace\nYes I am!\nI have important information" }
|
8
|
+
let( :logger ) { double( 'logger' ) }
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
logger.stub( :error ).and_return( true )
|
12
|
+
logger.stub( :pretty_backtrace ).and_return( backtrace )
|
13
|
+
|
14
|
+
end
|
15
|
+
|
16
|
+
context 'report_and_raise' do
|
17
|
+
|
18
|
+
it "records the backtrace of the exception to the logger" do
|
19
|
+
ex = Exception.new("ArgumentError")
|
20
|
+
ex.stub( :backtrace ).and_return(backtrace)
|
21
|
+
mesg = "I'm the extra message"
|
22
|
+
|
23
|
+
backtrace.each_line do |line|
|
24
|
+
logger.should_receive( :error ).with(line)
|
25
|
+
end
|
26
|
+
|
27
|
+
subject.should_receive( :raise ).once
|
28
|
+
|
29
|
+
subject.report_and_raise(logger, ex, mesg)
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,104 @@
|
|
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 '/g/{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
|