beaker 1.16.0 → 1.17.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/CONTRIBUTING.md +90 -0
- data/HISTORY.md +654 -2
- data/beaker.gemspec +1 -0
- data/lib/beaker/answers/version34.rb +4 -0
- data/lib/beaker/cli.rb +49 -2
- data/lib/beaker/dsl/helpers.rb +356 -196
- data/lib/beaker/dsl/install_utils.rb +135 -16
- data/lib/beaker/dsl/patterns.rb +37 -0
- data/lib/beaker/dsl/roles.rb +29 -0
- data/lib/beaker/dsl.rb +2 -1
- data/lib/beaker/host/unix.rb +14 -10
- data/lib/beaker/host/windows.rb +2 -0
- data/lib/beaker/host.rb +96 -1
- data/lib/beaker/host_prebuilt_steps.rb +41 -51
- data/lib/beaker/hypervisor/aws_sdk.rb +80 -16
- data/lib/beaker/hypervisor/ec2_helper.rb +1 -1
- data/lib/beaker/logger.rb +17 -0
- data/lib/beaker/options/command_line_parser.rb +3 -0
- data/lib/beaker/options/hosts_file_parser.rb +7 -4
- data/lib/beaker/options/options_hash.rb +2 -2
- data/lib/beaker/options/parser.rb +1 -1
- data/lib/beaker/options/presets.rb +128 -83
- data/lib/beaker/perf.rb +58 -0
- data/lib/beaker/shared/host_manager.rb +81 -0
- data/lib/beaker/shared.rb +2 -2
- data/lib/beaker/ssh_connection.rb +14 -7
- data/lib/beaker/test_case.rb +13 -0
- data/lib/beaker/test_suite.rb +23 -5
- data/lib/beaker/version.rb +1 -1
- data/lib/beaker.rb +1 -1
- data/spec/beaker/answers_spec.rb +13 -8
- data/spec/beaker/dsl/ezbake_utils_spec.rb +8 -9
- data/spec/beaker/dsl/helpers_spec.rb +299 -51
- data/spec/beaker/dsl/install_utils_spec.rb +75 -10
- data/spec/beaker/dsl/roles_spec.rb +36 -1
- data/spec/beaker/host_prebuilt_steps_spec.rb +21 -5
- data/spec/beaker/host_spec.rb +187 -23
- data/spec/beaker/hypervisor/ec2_helper_spec.rb +4 -4
- data/spec/beaker/hypervisor/vagrant_spec.rb +1 -1
- data/spec/beaker/options/hosts_file_parser_spec.rb +5 -0
- data/spec/beaker/options/options_hash_spec.rb +2 -2
- data/spec/beaker/options/parser_spec.rb +6 -0
- data/spec/beaker/options/presets_spec.rb +18 -2
- data/spec/beaker/perf_spec.rb +87 -0
- data/spec/beaker/shared/{host_role_parser_spec.rb → host_manager_spec.rb} +36 -5
- data/spec/beaker/test_suite_spec.rb +4 -3
- data/spec/matchers.rb +31 -3
- data/spec/mocks.rb +31 -25
- metadata +24 -5
- data/lib/beaker/shared/host_role_parser.rb +0 -36
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Beaker
|
4
|
+
describe Perf do
|
5
|
+
|
6
|
+
context "When a Perf object is created" do
|
7
|
+
it 'creates a new Perf object' do
|
8
|
+
hosts = Array.new
|
9
|
+
options = Hash.new
|
10
|
+
options[:log_level] = :debug
|
11
|
+
my_logger = Beaker::Logger.new(options)
|
12
|
+
options[:logger] = my_logger
|
13
|
+
perf = Perf.new( hosts, options )
|
14
|
+
expect( perf ).to be_a_kind_of Perf
|
15
|
+
end
|
16
|
+
|
17
|
+
before(:each) do
|
18
|
+
@options = make_opts
|
19
|
+
@options[:collect_perf_data] = true
|
20
|
+
@options[:log_level] = :debug
|
21
|
+
@options[:color] = false
|
22
|
+
@my_io = StringIO.new
|
23
|
+
@my_logger = Beaker::Logger.new(@options)
|
24
|
+
@my_logger.add_destination(@my_io)
|
25
|
+
@options[:logger] = @my_logger
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'creates a new Perf object with a single host, :collect_perf_data = true' do
|
29
|
+
hosts = [ make_host("myHost", @options) ]
|
30
|
+
@my_logger.remove_destination(STDOUT)
|
31
|
+
perf = Perf.new( hosts, @options )
|
32
|
+
expect( perf ).to be_a_kind_of Perf
|
33
|
+
expect(@my_io.string).to match(/Setup perf on host: myHost/)
|
34
|
+
end
|
35
|
+
|
36
|
+
it 'creates a new Perf object with multiple hosts, :collect_perf_data = true' do
|
37
|
+
hosts = [ make_host("myHost", @options), make_host("myOtherHost", @options) ]
|
38
|
+
@my_logger.remove_destination(STDOUT)
|
39
|
+
perf = Perf.new( hosts, @options )
|
40
|
+
expect( perf ).to be_a_kind_of Perf
|
41
|
+
expect(@my_io.string).to match(/Setup perf on host: myHost*Setup perf on host: myOtherHost/)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'creates a new Perf object with multiple hosts, :collect_perf_data = true, SLES' do
|
45
|
+
hosts = [ make_host("myHost", @options), make_host("myOtherHost", @options) ]
|
46
|
+
hosts[0]['platform'] = "SLES"
|
47
|
+
@my_logger.remove_destination(STDOUT)
|
48
|
+
perf = Perf.new( hosts, @options )
|
49
|
+
expect( perf ).to be_a_kind_of Perf
|
50
|
+
expect(@my_io.string).to match(/Setup perf on host: myHostSetup perf on host: myOtherHost/)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "When testing is finished, :collect_perf_data = true" do
|
55
|
+
before(:each) do
|
56
|
+
@options = make_opts
|
57
|
+
@options[:collect_perf_data] = true
|
58
|
+
@options[:log_level] = :debug
|
59
|
+
@options[:color] = false
|
60
|
+
@hosts = [ make_host("myHost", @options), make_host("myOtherHost", @options) ]
|
61
|
+
@my_io = StringIO.new
|
62
|
+
@my_logger = Beaker::Logger.new(@options)
|
63
|
+
@my_logger.add_destination(@my_io)
|
64
|
+
@options[:logger] = @my_logger
|
65
|
+
end
|
66
|
+
|
67
|
+
it "Does the Right Thing on Linux hosts" do
|
68
|
+
@hosts[0]['platform'] = "centos"
|
69
|
+
@my_logger.remove_destination(STDOUT)
|
70
|
+
perf = Perf.new( @hosts, @options )
|
71
|
+
expect( perf ).to be_a_kind_of Perf
|
72
|
+
perf.print_perf_info
|
73
|
+
expect(@my_io.string).to match(/Setup perf on host: myHostSetup perf on host: myOtherHostGetting perf data for host: myHostGetting perf data for host: myOtherHost/)
|
74
|
+
end
|
75
|
+
|
76
|
+
it "Does the Right Thing on non-Linux hosts" do
|
77
|
+
@hosts[0]['platform'] = "windows"
|
78
|
+
@my_logger.remove_destination(STDOUT)
|
79
|
+
perf = Perf.new( @hosts, @options )
|
80
|
+
expect( perf ).to be_a_kind_of Perf
|
81
|
+
perf.print_perf_info
|
82
|
+
expect(@my_io.string).to match(/Setup perf on host: myHostSetup perf on host: myOtherHostGetting perf data for host: myHostGetting perf data for host: myOtherHost/)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
end
|
@@ -2,13 +2,17 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Beaker
|
4
4
|
module Shared
|
5
|
-
describe
|
6
|
-
let( :host_handler ) { Beaker::Shared::
|
5
|
+
describe HostManager do
|
6
|
+
let( :host_handler ) { Beaker::Shared::HostManager }
|
7
|
+
let( :spec_block ) { Proc.new { |arr| arr } }
|
7
8
|
let( :platform ) { @platform || 'unix' }
|
9
|
+
let( :role0 ) { "role0" }
|
10
|
+
let( :role1 ) { :role1 }
|
11
|
+
let( :role2 ) { :role2 }
|
8
12
|
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']
|
13
|
+
hosts[0][:roles] = ['agent', role0]
|
14
|
+
hosts[1][:roles] = ['master', 'dashboard', 'agent', 'database', role1]
|
15
|
+
hosts[2][:roles] = ['agent', role2]
|
12
16
|
hosts }
|
13
17
|
|
14
18
|
context "hosts_with_role" do
|
@@ -52,6 +56,33 @@ module Beaker
|
|
52
56
|
end
|
53
57
|
end
|
54
58
|
|
59
|
+
context "run_block_on" do
|
60
|
+
it "can execute a block against hosts identified by a string" do
|
61
|
+
myhosts = host_handler.run_block_on( hosts, role0 ) do |hosts|
|
62
|
+
hosts
|
63
|
+
end
|
64
|
+
expect( myhosts ).to be === hosts[0]
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
it "can execute a block against hosts identified by a hostname" do
|
69
|
+
myhosts = host_handler.run_block_on( hosts, hosts[0].name ) do |hosts|
|
70
|
+
hosts
|
71
|
+
end
|
72
|
+
expect( myhosts ).to be === hosts[0]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
it "can execute a block against an array of hosts" do
|
77
|
+
myhosts = host_handler.run_block_on( hosts ) do |hosts|
|
78
|
+
hosts
|
79
|
+
end
|
80
|
+
expect( myhosts ).to be === hosts
|
81
|
+
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
|
55
86
|
end
|
56
87
|
|
57
88
|
end
|
@@ -35,6 +35,7 @@ module Beaker
|
|
35
35
|
let(:rb_test) { 'my_ruby_file.rb' }
|
36
36
|
let(:pl_test) { '/my_perl_file.pl' }
|
37
37
|
let(:sh_test) { '/my_shell_file.sh' }
|
38
|
+
let(:hosts) { make_hosts() }
|
38
39
|
|
39
40
|
it 'fails fast if fail_mode != :slow and runtime error is raised' do
|
40
41
|
Logger.stub('new')
|
@@ -43,7 +44,7 @@ module Beaker
|
|
43
44
|
File.open(pl_test, 'w') { |file| file.write(okay_script) }
|
44
45
|
File.open(sh_test, 'w') { |file| file.write(okay_script) }
|
45
46
|
|
46
|
-
ts = Beaker::TestSuite.new( 'name',
|
47
|
+
ts = Beaker::TestSuite.new( 'name', hosts, options, Time.now, :stop )
|
47
48
|
tsr = ts.instance_variable_get( :@test_suite_results )
|
48
49
|
tsr.stub(:write_junit_xml).and_return( true )
|
49
50
|
tsr.stub(:summarize).and_return( true )
|
@@ -63,7 +64,7 @@ module Beaker
|
|
63
64
|
File.open(pl_test, 'w') { |file| file.write(okay_script) }
|
64
65
|
File.open(sh_test, 'w') { |file| file.write(okay_script) }
|
65
66
|
|
66
|
-
ts = Beaker::TestSuite.new( 'name',
|
67
|
+
ts = Beaker::TestSuite.new( 'name', hosts, options, Time.now, :stop )
|
67
68
|
tsr = ts.instance_variable_get( :@test_suite_results )
|
68
69
|
tsr.stub(:write_junit_xml).and_return( true )
|
69
70
|
tsr.stub(:summarize).and_return( true )
|
@@ -83,7 +84,7 @@ module Beaker
|
|
83
84
|
File.open(pl_test, 'w') { |file| file.write(fail_script) }
|
84
85
|
File.open(sh_test, 'w') { |file| file.write(okay_script) }
|
85
86
|
|
86
|
-
ts = Beaker::TestSuite.new( 'name',
|
87
|
+
ts = Beaker::TestSuite.new( 'name', hosts, options, Time.now, :slow )
|
87
88
|
tsr = ts.instance_variable_get( :@test_suite_results )
|
88
89
|
tsr.stub(:write_junit_xml).and_return( true )
|
89
90
|
tsr.stub(:summarize).and_return( true )
|
data/spec/matchers.rb
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
RSpec::Matchers.define :execute_commands_matching do |pattern|
|
2
|
-
|
3
2
|
match do |actual|
|
4
|
-
raise(RuntimeError, "Expected #{actual} to be a FakeHost") unless actual.kind_of?(FakeHost)
|
3
|
+
raise(RuntimeError, "Expected #{actual} to be a FakeHost") unless actual.kind_of?(FakeHost::MockedExec)
|
5
4
|
@found_count = actual.command_strings.grep(pattern).size
|
6
5
|
@times.nil? ?
|
7
6
|
@found_count > 0 :
|
@@ -18,7 +17,6 @@ RSpec::Matchers.define :execute_commands_matching do |pattern|
|
|
18
17
|
|
19
18
|
chain :once do
|
20
19
|
@times = 1
|
21
|
-
# clarity only
|
22
20
|
end
|
23
21
|
|
24
22
|
def message(actual, pattern, times, found_count)
|
@@ -37,3 +35,33 @@ RSpec::Matchers.define :execute_commands_matching do |pattern|
|
|
37
35
|
"Unexpectedly found #{message(actual, pattern, @times, @found_count)}"
|
38
36
|
end
|
39
37
|
end
|
38
|
+
|
39
|
+
RSpec::Matchers.define :execute_commands_matching_in_order do |*patterns|
|
40
|
+
match do |actual|
|
41
|
+
raise(RuntimeError, "Expected #{actual} to be a FakeHost") unless actual.kind_of?(FakeHost::MockedExec)
|
42
|
+
|
43
|
+
remaining_patterns = patterns.clone
|
44
|
+
actual.command_strings.each do |line|
|
45
|
+
if remaining_patterns.empty?
|
46
|
+
break
|
47
|
+
elsif remaining_patterns.first.match(line)
|
48
|
+
remaining_patterns.shift
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
remaining_patterns.empty?
|
53
|
+
end
|
54
|
+
|
55
|
+
def message(actual, patterns)
|
56
|
+
msg = "#{patterns.join(', ')} in order" +
|
57
|
+
" in:\n #{actual.command_strings.pretty_inspect}"
|
58
|
+
end
|
59
|
+
|
60
|
+
failure_message_for_should do |actual|
|
61
|
+
"Expected to find #{message(actual, patterns)}"
|
62
|
+
end
|
63
|
+
|
64
|
+
failure_message_for_should_not do |actual|
|
65
|
+
"Unexpectedly found #{message(actual, patterns)}"
|
66
|
+
end
|
67
|
+
end
|
data/spec/mocks.rb
CHANGED
@@ -43,7 +43,7 @@ module MockNet
|
|
43
43
|
@uri = uri
|
44
44
|
end
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
def initialize host, port
|
48
48
|
@host = host
|
49
49
|
@port = port
|
@@ -56,37 +56,43 @@ module MockNet
|
|
56
56
|
|
57
57
|
end
|
58
58
|
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
59
|
+
module FakeHost
|
60
|
+
def self.create(name = 'fakevm', platform = 'redhat-version-arch', options = {})
|
61
|
+
options_hash = Beaker::Options::OptionsHash.new.merge(options)
|
62
|
+
options_hash['HOSTS'] = { name => { 'platform' => Beaker::Platform.new(platform) } }
|
63
|
+
host = Beaker::Host.create(name, options_hash)
|
64
|
+
host.extend(MockedExec)
|
65
|
+
host
|
66
66
|
end
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
68
|
+
module MockedExec
|
69
|
+
def self.extended(other)
|
70
|
+
other.instance_eval do
|
71
|
+
send(:instance_variable_set, :@commands, [])
|
72
|
+
end
|
73
|
+
end
|
71
74
|
|
72
|
-
|
73
|
-
@pe
|
74
|
-
end
|
75
|
+
attr_accessor :commands
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
77
|
+
def port_open?(port)
|
78
|
+
true
|
79
|
+
end
|
79
80
|
|
80
|
-
|
81
|
-
|
82
|
-
|
81
|
+
def any_exec_result
|
82
|
+
RSpec::Mocks::Mock.new('exec-result').as_null_object
|
83
|
+
end
|
83
84
|
|
84
|
-
|
85
|
-
|
86
|
-
|
85
|
+
def exec(command, options = {})
|
86
|
+
commands << command
|
87
|
+
any_exec_result
|
88
|
+
end
|
89
|
+
|
90
|
+
def command_strings
|
91
|
+
commands.map { |c| [c.command, c.args].join(' ') }
|
92
|
+
end
|
87
93
|
end
|
88
94
|
|
89
|
-
def
|
90
|
-
|
95
|
+
def log_prefix
|
96
|
+
"FakeHost"
|
91
97
|
end
|
92
98
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: beaker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.17.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Puppetlabs
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: minitest
|
@@ -164,6 +164,20 @@ dependencies:
|
|
164
164
|
- - ~>
|
165
165
|
- !ruby/object:Gem::Version
|
166
166
|
version: '1.8'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: hocon
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ~>
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: 0.0.4
|
174
|
+
type: :runtime
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ~>
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: 0.0.4
|
167
181
|
- !ruby/object:Gem::Dependency
|
168
182
|
name: net-ssh
|
169
183
|
requirement: !ruby/object:Gem::Requirement
|
@@ -344,6 +358,7 @@ files:
|
|
344
358
|
- .rspec
|
345
359
|
- .simplecov
|
346
360
|
- .travis.yml
|
361
|
+
- CONTRIBUTING.md
|
347
362
|
- DOCUMENTING.md
|
348
363
|
- Gemfile
|
349
364
|
- HISTORY.md
|
@@ -369,6 +384,7 @@ files:
|
|
369
384
|
- lib/beaker/dsl/helpers.rb
|
370
385
|
- lib/beaker/dsl/install_utils.rb
|
371
386
|
- lib/beaker/dsl/outcomes.rb
|
387
|
+
- lib/beaker/dsl/patterns.rb
|
372
388
|
- lib/beaker/dsl/roles.rb
|
373
389
|
- lib/beaker/dsl/structure.rb
|
374
390
|
- lib/beaker/dsl/wrappers.rb
|
@@ -417,11 +433,12 @@ files:
|
|
417
433
|
- lib/beaker/options/parser.rb
|
418
434
|
- lib/beaker/options/pe_version_scraper.rb
|
419
435
|
- lib/beaker/options/presets.rb
|
436
|
+
- lib/beaker/perf.rb
|
420
437
|
- lib/beaker/platform.rb
|
421
438
|
- lib/beaker/result.rb
|
422
439
|
- lib/beaker/shared.rb
|
423
440
|
- lib/beaker/shared/error_handler.rb
|
424
|
-
- lib/beaker/shared/
|
441
|
+
- lib/beaker/shared/host_manager.rb
|
425
442
|
- lib/beaker/shared/repetition.rb
|
426
443
|
- lib/beaker/shared/timed.rb
|
427
444
|
- lib/beaker/ssh_connection.rb
|
@@ -470,10 +487,11 @@ files:
|
|
470
487
|
- spec/beaker/options/parser_spec.rb
|
471
488
|
- spec/beaker/options/pe_version_scaper_spec.rb
|
472
489
|
- spec/beaker/options/presets_spec.rb
|
490
|
+
- spec/beaker/perf_spec.rb
|
473
491
|
- spec/beaker/platform_spec.rb
|
474
492
|
- spec/beaker/puppet_command_spec.rb
|
475
493
|
- spec/beaker/shared/error_handler_spec.rb
|
476
|
-
- spec/beaker/shared/
|
494
|
+
- spec/beaker/shared/host_manager_spec.rb
|
477
495
|
- spec/beaker/shared/repetition_spec.rb
|
478
496
|
- spec/beaker/ssh_connection_spec.rb
|
479
497
|
- spec/beaker/test_case_spec.rb
|
@@ -551,10 +569,11 @@ test_files:
|
|
551
569
|
- spec/beaker/options/parser_spec.rb
|
552
570
|
- spec/beaker/options/pe_version_scaper_spec.rb
|
553
571
|
- spec/beaker/options/presets_spec.rb
|
572
|
+
- spec/beaker/perf_spec.rb
|
554
573
|
- spec/beaker/platform_spec.rb
|
555
574
|
- spec/beaker/puppet_command_spec.rb
|
556
575
|
- spec/beaker/shared/error_handler_spec.rb
|
557
|
-
- spec/beaker/shared/
|
576
|
+
- spec/beaker/shared/host_manager_spec.rb
|
558
577
|
- spec/beaker/shared/repetition_spec.rb
|
559
578
|
- spec/beaker/ssh_connection_spec.rb
|
560
579
|
- spec/beaker/test_case_spec.rb
|
@@ -1,36 +0,0 @@
|
|
1
|
-
module Beaker
|
2
|
-
module Shared
|
3
|
-
#Methods for selecting host or hosts that match roles.
|
4
|
-
module HostRoleParser
|
5
|
-
|
6
|
-
#Find hosts from a given array of hosts that all have the desired role.
|
7
|
-
#@param [Array<Host>] hosts The hosts to examine
|
8
|
-
#@param [String] desired_role The hosts returned will have this role in their roles list
|
9
|
-
#@return [Array<Host>] The hosts that have the desired role in their roles list
|
10
|
-
def hosts_with_role(hosts, desired_role = nil)
|
11
|
-
hosts.select do |host|
|
12
|
-
desired_role.nil? or host['roles'].include?(desired_role.to_s)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
#Find a single host with the role provided. Raise an error if more than one host is found to have the
|
17
|
-
#provided role.
|
18
|
-
#@param [Array<Host>] hosts The hosts to examine
|
19
|
-
#@param [String] role The host returned will have this role in its role list
|
20
|
-
#@return [Host] The single host with the desired role in its roles list
|
21
|
-
#@raise [ArgumentError] Raised if more than one host has the given role defined, or if no host has the
|
22
|
-
# role defined.
|
23
|
-
def only_host_with_role(hosts, role)
|
24
|
-
a_host = hosts_with_role(hosts, role)
|
25
|
-
case
|
26
|
-
when a_host.length == 0
|
27
|
-
raise ArgumentError, "There should be one host with #{role} defined!"
|
28
|
-
when a_host.length > 1
|
29
|
-
host_string = ( a_host.map { |host| host.name } ).join( ', ')
|
30
|
-
raise ArgumentError, "There should be only one host with #{role} defined, but I found #{a_host.length} (#{host_string})"
|
31
|
-
end
|
32
|
-
a_host.first
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|