dop_common 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +176 -0
- data/Gemfile +11 -0
- data/LICENSE.txt +177 -0
- data/README.md +48 -0
- data/Rakefile +49 -0
- data/Vagrantfile +25 -0
- data/bin/dop-puppet-autosign +56 -0
- data/doc/examples/example_deploment_plan_v0.0.1.yaml +302 -0
- data/doc/plan_format_v0.0.1.md +919 -0
- data/doc/plan_format_v0.0.2_snippets.md +56 -0
- data/dop_common.gemspec +44 -0
- data/lib/dop_common/affinity_group.rb +57 -0
- data/lib/dop_common/cli/global_options.rb +37 -0
- data/lib/dop_common/cli/log.rb +51 -0
- data/lib/dop_common/cli/node_selection.rb +62 -0
- data/lib/dop_common/command.rb +125 -0
- data/lib/dop_common/config/helper.rb +39 -0
- data/lib/dop_common/config.rb +66 -0
- data/lib/dop_common/configuration.rb +37 -0
- data/lib/dop_common/credential.rb +152 -0
- data/lib/dop_common/data_disk.rb +62 -0
- data/lib/dop_common/dns.rb +55 -0
- data/lib/dop_common/hash_parser.rb +241 -0
- data/lib/dop_common/hooks.rb +81 -0
- data/lib/dop_common/infrastructure.rb +160 -0
- data/lib/dop_common/infrastructure_properties.rb +185 -0
- data/lib/dop_common/interface.rb +113 -0
- data/lib/dop_common/log.rb +78 -0
- data/lib/dop_common/network.rb +85 -0
- data/lib/dop_common/node/config.rb +159 -0
- data/lib/dop_common/node.rb +442 -0
- data/lib/dop_common/node_filter.rb +74 -0
- data/lib/dop_common/plan.rb +188 -0
- data/lib/dop_common/plan_cache.rb +83 -0
- data/lib/dop_common/plan_store.rb +263 -0
- data/lib/dop_common/pre_processor.rb +73 -0
- data/lib/dop_common/run_options.rb +56 -0
- data/lib/dop_common/signal_handler.rb +58 -0
- data/lib/dop_common/state_store.rb +95 -0
- data/lib/dop_common/step.rb +200 -0
- data/lib/dop_common/step_set.rb +41 -0
- data/lib/dop_common/thread_context_logger.rb +77 -0
- data/lib/dop_common/utils.rb +106 -0
- data/lib/dop_common/validator.rb +53 -0
- data/lib/dop_common/version.rb +3 -0
- data/lib/dop_common.rb +32 -0
- data/lib/hiera/backend/dop_backend.rb +94 -0
- data/lib/hiera/dop_logger.rb +20 -0
- data/spec/data/fake_hook_file_invalid +1 -0
- data/spec/data/fake_hook_file_valid +5 -0
- data/spec/data/fake_keyfile +1 -0
- data/spec/dop-puppet-autosign_spec_disable.rb +33 -0
- data/spec/dop_common/affinity_group_spec.rb +41 -0
- data/spec/dop_common/command_spec.rb +83 -0
- data/spec/dop_common/credential_spec.rb +73 -0
- data/spec/dop_common/data_disk_spec.rb +165 -0
- data/spec/dop_common/dns_spec.rb +33 -0
- data/spec/dop_common/hash_parser_spec.rb +181 -0
- data/spec/dop_common/hooks_spec.rb +33 -0
- data/spec/dop_common/infrastructure_properties_spec.rb +224 -0
- data/spec/dop_common/infrastructure_spec.rb +77 -0
- data/spec/dop_common/interface_spec.rb +192 -0
- data/spec/dop_common/network_spec.rb +92 -0
- data/spec/dop_common/node_filter_spec.rb +70 -0
- data/spec/dop_common/node_spec.rb +623 -0
- data/spec/dop_common/plan_cache_spec.rb +46 -0
- data/spec/dop_common/plan_spec.rb +136 -0
- data/spec/dop_common/plan_store_spec.rb +194 -0
- data/spec/dop_common/pre_processor_spec.rb +27 -0
- data/spec/dop_common/run_options_spec.rb +65 -0
- data/spec/dop_common/signal_handler_spec.rb +31 -0
- data/spec/dop_common/step_set_spec.rb +21 -0
- data/spec/dop_common/step_spec.rb +175 -0
- data/spec/dop_common/utils_spec.rb +27 -0
- data/spec/dop_common/validator_spec.rb +47 -0
- data/spec/example_plans_spec.rb +16 -0
- data/spec/fixtures/example_ssh_key +27 -0
- data/spec/fixtures/example_ssh_key.pub +1 -0
- data/spec/fixtures/incl/root_part.yaml +1 -0
- data/spec/fixtures/incl/some_list.yaml +2 -0
- data/spec/fixtures/other_plan_same_nodes.yaml +19 -0
- data/spec/fixtures/simple_include.yaml +6 -0
- data/spec/fixtures/simple_include_with_errors.yaml +4 -0
- data/spec/fixtures/simple_plan.yaml +19 -0
- data/spec/fixtures/simple_plan_invalid.yaml +18 -0
- data/spec/fixtures/simple_plan_modified.yaml +21 -0
- data/spec/spec_helper.rb +106 -0
- metadata +381 -0
@@ -0,0 +1,94 @@
|
|
1
|
+
#
|
2
|
+
# DOP Plan Hiera Backend
|
3
|
+
#
|
4
|
+
|
5
|
+
class Hiera
|
6
|
+
module Backend
|
7
|
+
|
8
|
+
class Dop_backend
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
Hiera.debug('Hiera DOP backend starting')
|
12
|
+
begin
|
13
|
+
require 'dop_common'
|
14
|
+
rescue
|
15
|
+
require 'rubygems'
|
16
|
+
require 'dop_common'
|
17
|
+
end
|
18
|
+
|
19
|
+
if Config[:dop].kind_of?(Hash)
|
20
|
+
@plan_store_dir ||= Config[:dop][:plan_store_dir]
|
21
|
+
end
|
22
|
+
@plan_store_dir ||= '/var/lib/dop/plans'
|
23
|
+
|
24
|
+
@plan_store = DopCommon::PlanStore.new(@plan_store_dir)
|
25
|
+
@plan_cache = DopCommon::PlanCache.new(@plan_store)
|
26
|
+
Hiera.debug('DOP Plan Cache Loaded')
|
27
|
+
end
|
28
|
+
|
29
|
+
def lookup(key, scope, order_override, resolution_type, context)
|
30
|
+
node_name = scope['::clientcert']
|
31
|
+
plan = @plan_cache.plan_by_node(node_name)
|
32
|
+
|
33
|
+
if plan.nil?
|
34
|
+
Hiera.debug("Node #{node_name} not found in any plan")
|
35
|
+
throw(:no_such_key)
|
36
|
+
else
|
37
|
+
Hiera.debug("Node #{node_name} found in plan #{plan.name}")
|
38
|
+
plan_lookup(plan, key, scope, order_override, resolution_type, context)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def plan_lookup(plan, key, scope, order_override, resolution_type, context)
|
43
|
+
answer = nil
|
44
|
+
found = false
|
45
|
+
extra_data = {}
|
46
|
+
context[:order_override] = order_override
|
47
|
+
Hiera::Backend.datasources(scope, order_override) do |source|
|
48
|
+
Hiera.debug("Looking for data source #{source}")
|
49
|
+
begin
|
50
|
+
data = plan.configuration.lookup(source, key, scope)
|
51
|
+
new_answer = Hiera::Backend.parse_answer(data, scope, extra_data, context)
|
52
|
+
found = true
|
53
|
+
|
54
|
+
case resolution_type.is_a?(Hash) ? :hash : resolution_type
|
55
|
+
when :array then answer = merge_array(answer, new_answer)
|
56
|
+
when :hash then answer = merge_hash(answer, new_answer, resolution_type)
|
57
|
+
else
|
58
|
+
answer = new_answer
|
59
|
+
break
|
60
|
+
end
|
61
|
+
|
62
|
+
rescue DopCommon::ConfigurationValueNotFound
|
63
|
+
next
|
64
|
+
end
|
65
|
+
end
|
66
|
+
throw(:no_such_key) unless found
|
67
|
+
return answer
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
|
72
|
+
def merge_array(answer, new_answer)
|
73
|
+
answer ||= []
|
74
|
+
case new_answer
|
75
|
+
when Array then answer += new_answer
|
76
|
+
when String then answer << new_answer
|
77
|
+
else
|
78
|
+
raise "Hiera type mismatch: expected Array or String and got #{new_answer.class}"
|
79
|
+
end
|
80
|
+
return answer
|
81
|
+
end
|
82
|
+
|
83
|
+
def merge_hash(answer, new_answer, resolution_type)
|
84
|
+
answer ||= {}
|
85
|
+
answer = Hiera::Backend.merge_answer(new_answer, answer, resolution_type)
|
86
|
+
unless new_answer.kind_of?(Hash)
|
87
|
+
raise "Hiera type mismatch: expected Hash and got #{new_answer.class}"
|
88
|
+
end
|
89
|
+
return answer
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#
|
2
|
+
# Route Hiera Log entries to DOPi Logger
|
3
|
+
#
|
4
|
+
require 'dop_common'
|
5
|
+
|
6
|
+
class Hiera
|
7
|
+
module Dop_logger
|
8
|
+
class << self
|
9
|
+
|
10
|
+
def warn(msg)
|
11
|
+
DopCommon.log.warn('Hiera: ' +msg)
|
12
|
+
end
|
13
|
+
|
14
|
+
def debug(msg)
|
15
|
+
DopCommon.log.debug('Hiera: ' + msg)
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
# A fake hook file that is invalid, i.e. without executable permissions.
|
@@ -0,0 +1 @@
|
|
1
|
+
# this is a fake keyfile for tests.
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
#
|
4
|
+
# This test does not run on ruby 1.8.7 because of the mixlib-shellout gem
|
5
|
+
# and is therefor deactivated for now.
|
6
|
+
#
|
7
|
+
|
8
|
+
describe 'dop-puppet-autosign' do
|
9
|
+
|
10
|
+
before :each do
|
11
|
+
@tmpdir = '/tmp/dop-puppet-autosign-test'
|
12
|
+
@plan_store = DopCommon::PlanStore.new(@tmpdir)
|
13
|
+
end
|
14
|
+
|
15
|
+
after :each do
|
16
|
+
FileUtils.remove_entry_secure(@tmpdir)
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:plan) { 'spec/fixtures/simple_plan.yaml' }
|
20
|
+
|
21
|
+
context 'There is no plan with the node in the plan store' do
|
22
|
+
command 'dop-puppet-autosign --plan_cache /tmp/dop-puppet-autosign-test linux01.example.com', :allow_error => true
|
23
|
+
its(:exitstatus) { is_expected.to_not eq 0 }
|
24
|
+
end
|
25
|
+
context 'The node is in one of the plans in the plan store' do
|
26
|
+
before do
|
27
|
+
@plan_store.add(plan)
|
28
|
+
end
|
29
|
+
command 'dop-puppet-autosign --plan_cache /tmp/dop-puppet-autosign-test linux01.example.com'
|
30
|
+
its(:exitstatus) { is_expected.to eq 0 }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DopCommon::AffinityGroup do
|
4
|
+
|
5
|
+
describe '#positive' do
|
6
|
+
it "will return 'true' if the affinity group is positive and 'false' if it is not" do
|
7
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {'positive' => true, 'enforce' => true, 'cluster' => 'cl'})
|
8
|
+
expect(affinity_group.positive).to eq(true)
|
9
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {'positive' => false, 'enforce' => true, 'cluster' => 'cl'})
|
10
|
+
expect(affinity_group.positive).to eq(false)
|
11
|
+
end
|
12
|
+
it 'will raise an error if the flag is not specified correctly' do
|
13
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {})
|
14
|
+
expect { affinity_group.positive }.to raise_error DopCommon::PlanParsingError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#enforce' do
|
19
|
+
it "will return 'true' if the affinity group should be enforced and 'false' if it shouldn't" do
|
20
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {'positive' => true, 'enforce' => true, 'cluster' => 'cl'})
|
21
|
+
expect(affinity_group.enforce).to eq(true)
|
22
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {'positive' => false, 'enforce' => false, 'cluster' => 'cl'})
|
23
|
+
expect(affinity_group.enforce).to eq(false)
|
24
|
+
end
|
25
|
+
it 'will raise an error if the flag is not specified correctly' do
|
26
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {})
|
27
|
+
expect { affinity_group.enforce }.to raise_error DopCommon::PlanParsingError
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#cluster' do
|
32
|
+
it 'will return the cluster name of the affinity group' do
|
33
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {'positive' => true, 'enforce' => true, 'cluster' => 'cl'})
|
34
|
+
expect(affinity_group.cluster).to eq('cl')
|
35
|
+
end
|
36
|
+
it 'will raise an error in case of invalid cluster specification' do
|
37
|
+
affinity_group = DopCommon::AffinityGroup.new('ag', {})
|
38
|
+
expect { affinity_group.cluster }.to raise_error DopCommon::PlanParsingError
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DopCommon::Command do
|
4
|
+
|
5
|
+
describe '#plugin' do
|
6
|
+
it 'returns the name of the plugin' do
|
7
|
+
command = DopCommon::Command.new({:plugin => 'dummy'})
|
8
|
+
expect(command.plugin).to eq 'dummy'
|
9
|
+
command = DopCommon::Command.new('dummy')
|
10
|
+
expect(command.plugin).to eq 'dummy'
|
11
|
+
end
|
12
|
+
it 'throws an exception if the the plugin name is not correctly specified' do
|
13
|
+
command = DopCommon::Command.new(1)
|
14
|
+
expect{command.plugin}.to raise_error DopCommon::PlanParsingError
|
15
|
+
command = DopCommon::Command.new('')
|
16
|
+
expect{command.plugin}.to raise_error DopCommon::PlanParsingError
|
17
|
+
command = DopCommon::Command.new({})
|
18
|
+
expect{command.plugin}.to raise_error DopCommon::PlanParsingError
|
19
|
+
command = DopCommon::Command.new({:plugin => 1})
|
20
|
+
expect{command.plugin}.to raise_error DopCommon::PlanParsingError
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#plugin_timeout' do
|
25
|
+
it 'returns the plugin timeout if specified' do
|
26
|
+
command = DopCommon::Command.new({:plugin_timeout => 200})
|
27
|
+
expect(command.plugin_timeout).to eq 200
|
28
|
+
end
|
29
|
+
it 'returns the default timeout if nothing is specified' do
|
30
|
+
command = DopCommon::Command.new({})
|
31
|
+
expect(command.plugin_timeout).to eq 300
|
32
|
+
end
|
33
|
+
it 'throws an exception if the value is not correctly specified' do
|
34
|
+
command = DopCommon::Command.new({:plugin_timeout => 'foo'})
|
35
|
+
expect{command.plugin_timeout}.to raise_error DopCommon::PlanParsingError
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe '#verify_command' do
|
40
|
+
it 'returns an array of command instances if specified right' do
|
41
|
+
command = DopCommon::Command.new({:verify_commands => 'dummy'})
|
42
|
+
expect(command.verify_commands).to be_an_instance_of Array
|
43
|
+
expect(command.verify_commands.length).to be 1
|
44
|
+
expect(command.verify_commands.all?{|x| x.class == DopCommon::Command}).to be true
|
45
|
+
command = DopCommon::Command.new({:verify_commands => {:plugin => 'dummy'}})
|
46
|
+
expect(command.verify_commands).to be_an_instance_of Array
|
47
|
+
expect(command.verify_commands.length).to be 1
|
48
|
+
expect(command.verify_commands.all?{|x| x.class == DopCommon::Command}).to be true
|
49
|
+
command = DopCommon::Command.new({:verify_commands => ['dummy', {:plugin => 'dummy'}]})
|
50
|
+
expect(command.verify_commands).to be_an_instance_of Array
|
51
|
+
expect(command.verify_commands.length).to be 2
|
52
|
+
expect(command.verify_commands.all?{|x| x.class == DopCommon::Command}).to be true
|
53
|
+
end
|
54
|
+
it 'returns an empty array if nothing is specified' do
|
55
|
+
command = DopCommon::Command.new({})
|
56
|
+
expect(command.verify_commands).to be_an_instance_of Array
|
57
|
+
expect(command.verify_commands.length).to be 0
|
58
|
+
end
|
59
|
+
it 'throws an exception if the value is not correctly specified' do
|
60
|
+
command = DopCommon::Command.new({:verify_commands => 1})
|
61
|
+
expect{command.verify_commands}.to raise_error DopCommon::PlanParsingError
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe '#verify_after_run' do
|
66
|
+
it 'returns false if verify_after_run is not defined' do
|
67
|
+
command = DopCommon::Command.new({})
|
68
|
+
expect(command.verify_after_run).to be false
|
69
|
+
end
|
70
|
+
it 'returns the correct value if set correctly' do
|
71
|
+
command = DopCommon::Command.new({:verify_after_run => true})
|
72
|
+
expect(command.verify_after_run).to be true
|
73
|
+
command = DopCommon::Command.new({:verify_after_run => false})
|
74
|
+
expect(command.verify_after_run).to be false
|
75
|
+
end
|
76
|
+
it 'raises an exeption if the value is not valid' do
|
77
|
+
command = DopCommon::Command.new({:verify_after_run => 2})
|
78
|
+
expect{command.verify_after_run}.to raise_error DopCommon::PlanParsingError
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'securerandom'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
describe DopCommon::Credential do
|
6
|
+
|
7
|
+
describe '#type' do
|
8
|
+
it 'returns the type if specified correctly (username_password)' do
|
9
|
+
credential = DopCommon::Credential.new('test', {:type => :username_password, :username => 'a', :password => 'b'})
|
10
|
+
expect(credential.type).to eq :username_password
|
11
|
+
end
|
12
|
+
it 'returns the type if specified correctly (kerberos)' do
|
13
|
+
credential = DopCommon::Credential.new('test', {:type => :kerberos, :realm => 'a',})
|
14
|
+
expect(credential.type).to eq :kerberos
|
15
|
+
end
|
16
|
+
it 'returns the type if specified correctly (ssh_key)' do
|
17
|
+
credential = DopCommon::Credential.new('test', {:type => :ssh_key, :username => 'a', :private_key => 'spec/data/fake_keyfile'})
|
18
|
+
expect(credential.type).to eq :ssh_key
|
19
|
+
end
|
20
|
+
it 'will raise an exception if the type is missing' do
|
21
|
+
credential = DopCommon::Credential.new('test', {})
|
22
|
+
expect{credential.type}.to raise_error DopCommon::PlanParsingError
|
23
|
+
end
|
24
|
+
it 'will raise an exception if the type is not valid' do
|
25
|
+
credential = DopCommon::Credential.new('test', {:type => :non_existing_type})
|
26
|
+
expect{credential.type}.to raise_error DopCommon::PlanParsingError
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
[:username, :realm, :service].each do |key|
|
31
|
+
describe '#' + key.to_s do
|
32
|
+
it "returns a #{key} if one is correctly specified" do
|
33
|
+
credential = DopCommon::Credential.new('test', {key => 'a'})
|
34
|
+
expect(credential.send(key)).to eq 'a'
|
35
|
+
end
|
36
|
+
it "returns nil if #{key} is not specified" do
|
37
|
+
credential = DopCommon::Credential.new('test', {})
|
38
|
+
expect(credential.send(key)).to be nil
|
39
|
+
end
|
40
|
+
it "raises an exception if #{key} is not a string" do
|
41
|
+
credential = DopCommon::Credential.new('test', {key => []})
|
42
|
+
expect{credential.send(key)}.to raise_error DopCommon::PlanParsingError
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
[:password, :keytab, :public_key, :private_key].each do |key|
|
48
|
+
describe '#' + key.to_s do
|
49
|
+
it "returns the content if correctly specified as a string" do
|
50
|
+
credential = DopCommon::Credential.new('test', {key => 'my secret'})
|
51
|
+
expect(credential.send(key)).to eq 'my secret'
|
52
|
+
end
|
53
|
+
it 'returns the content if correctly specified as a file' do
|
54
|
+
key_file = Tempfile.new('secret_file', ENV['HOME'])
|
55
|
+
key_file.write("my secret")
|
56
|
+
key_file.close
|
57
|
+
credential = DopCommon::Credential.new('test', {key => {'file' => key_file.path}})
|
58
|
+
expect(credential.send(key)).to eq 'my secret'
|
59
|
+
key_file.delete
|
60
|
+
end
|
61
|
+
it "returns nil if #{key} is not specified" do
|
62
|
+
credential = DopCommon::Credential.new('test', {})
|
63
|
+
expect(credential.send(key)).to be nil
|
64
|
+
end
|
65
|
+
it "raises an exception if the file does not exist" do
|
66
|
+
credential = DopCommon::Credential.new('test', {key => {'file' => 'spec/data/nonexisting_keyfile'}})
|
67
|
+
expect{credential.send(key)}.to raise_error DopCommon::PlanParsingError
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
@@ -0,0 +1,165 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DopCommon::DataDisk do
|
4
|
+
before(:all) do
|
5
|
+
@infrastructures = {
|
6
|
+
'rhev' => DopCommon::Infrastructure.new('rhev', {
|
7
|
+
'type' => 'rhev'
|
8
|
+
}),
|
9
|
+
'rhos' => DopCommon::Infrastructure.new('rhos', {
|
10
|
+
'type' => 'rhos'
|
11
|
+
}),
|
12
|
+
'baremetal' => DopCommon::Infrastructure.new('baremetal', {
|
13
|
+
'type' => 'baremetal'
|
14
|
+
}),
|
15
|
+
'vsphere' => DopCommon::Infrastructure.new('vsphere', {
|
16
|
+
'type' => 'vsphere'
|
17
|
+
}),
|
18
|
+
}
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#pool' do
|
22
|
+
%w(rhev vsphere rhos baremetal).each do |provider|
|
23
|
+
properties = case provider
|
24
|
+
when 'rhos'; { 'tenant' => 'foo' }
|
25
|
+
when 'baremetal'; {}
|
26
|
+
else { 'datacenter' => 'foo', 'cluster' => 'bar' }
|
27
|
+
end
|
28
|
+
it "will return pool's name if specified properly for provider #{provider}" do
|
29
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
30
|
+
{ 'pool' => 'foo' },
|
31
|
+
{
|
32
|
+
:parsed_infrastructure => @infrastructures[provider],
|
33
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
34
|
+
properties,
|
35
|
+
@infrastructures[provider]
|
36
|
+
)
|
37
|
+
}
|
38
|
+
)
|
39
|
+
expect(data_disk.pool).to eq 'foo'
|
40
|
+
end
|
41
|
+
it "will return default pool's if specified properly for provider #{provider} " do
|
42
|
+
data_disk = DopCommon::DataDisk.new('foo', {},
|
43
|
+
{
|
44
|
+
:parsed_infrastructure => @infrastructures[provider],
|
45
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
46
|
+
properties.merge('default_pool' => 'bar'),
|
47
|
+
@infrastructures[provider]
|
48
|
+
)
|
49
|
+
}
|
50
|
+
)
|
51
|
+
expect(data_disk.pool).to eq 'bar'
|
52
|
+
end
|
53
|
+
it %w(rhos baremetal).include?(provider) ?
|
54
|
+
"will return nil if unspecified because it is optional for provider #{provider}" :
|
55
|
+
"will raise an error if unspecified because it is required for provider #{provider}" do
|
56
|
+
data_disk = DopCommon::DataDisk.new('foo', {},
|
57
|
+
{
|
58
|
+
:parsed_infrastructure => @infrastructures[provider],
|
59
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
60
|
+
properties,
|
61
|
+
@infrastructures[provider]
|
62
|
+
)
|
63
|
+
}
|
64
|
+
)
|
65
|
+
%w(rhos baremetal).include?(provider) ?
|
66
|
+
(expect(data_disk.pool).to eq nil) :
|
67
|
+
(expect{data_disk.pool}.to raise_error DopCommon::PlanParsingError)
|
68
|
+
end
|
69
|
+
[[], {}, :invalid, 2].each do |pool_val|
|
70
|
+
it "will raise an error if not specified properly" do
|
71
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
72
|
+
{ 'pool' => pool_val},
|
73
|
+
{
|
74
|
+
:parsed_infrastructure => @infrastructures[provider],
|
75
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
76
|
+
properties,
|
77
|
+
@infrastructures[provider]
|
78
|
+
)
|
79
|
+
}
|
80
|
+
)
|
81
|
+
expect{data_disk.pool}.to raise_error DopCommon::PlanParsingError
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe '#size' do
|
88
|
+
['1000K', '1000M', '10G', '1000KB', '1000MB', '1000GB'].each do |size|
|
89
|
+
it 'will return DopCommon::Utils::DataSize object if specified properly' do
|
90
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
91
|
+
{ 'size' => size },
|
92
|
+
{
|
93
|
+
:parsed_infrastructure => @infrastructures['baremetal'],
|
94
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
95
|
+
{},
|
96
|
+
@infrastructures['baremetal']
|
97
|
+
)
|
98
|
+
}
|
99
|
+
)
|
100
|
+
expect(data_disk.size).to be_an_instance_of(DopCommon::Utils::DataSize)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
[nil, [], {}].each do |size|
|
104
|
+
it 'will raise an exception if not specified properly' do
|
105
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
106
|
+
{ 'size' => size },
|
107
|
+
{
|
108
|
+
:parsed_infrastructure => @infrastructures['baremetal'],
|
109
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
110
|
+
{},
|
111
|
+
@infrastructures['baremetal']
|
112
|
+
)
|
113
|
+
}
|
114
|
+
)
|
115
|
+
expect{data_disk.size}.to raise_error DopCommon::PlanParsingError
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe '#thin?' do
|
121
|
+
it 'will return true if not explicitly defined' do
|
122
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
123
|
+
{},
|
124
|
+
{
|
125
|
+
:parsed_infrastructure => @infrastructures['baremetal'],
|
126
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
127
|
+
{},
|
128
|
+
@infrastructures['baremetal']
|
129
|
+
)
|
130
|
+
}
|
131
|
+
)
|
132
|
+
expect(data_disk.thin?).to be true
|
133
|
+
end
|
134
|
+
[true, false].each do |thin_val|
|
135
|
+
it 'will return true or false if specified properly' do
|
136
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
137
|
+
{ 'thin' => thin_val },
|
138
|
+
{
|
139
|
+
:parsed_infrastructure => @infrastructures['baremetal'],
|
140
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
141
|
+
{},
|
142
|
+
@infrastructures['baremetal']
|
143
|
+
)
|
144
|
+
}
|
145
|
+
)
|
146
|
+
expect(data_disk.thin?).to be thin_val
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
['true', 'false', nil, [], {}, :true, :false].each do |thin_val|
|
151
|
+
it "will raise an error if isn't specified properly" do
|
152
|
+
data_disk = DopCommon::DataDisk.new('foo',
|
153
|
+
{ 'thin' => thin_val },
|
154
|
+
{
|
155
|
+
:parsed_infrastructure => @infrastructures['baremetal'],
|
156
|
+
:parsed_infrastructure_properties => DopCommon::InfrastructureProperties.new(
|
157
|
+
{},
|
158
|
+
@infrastructures['baremetal']
|
159
|
+
)
|
160
|
+
}
|
161
|
+
)
|
162
|
+
expect{data_disk.thin?}.to raise_error DopCommon::PlanParsingError
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DopCommon::DNS do
|
4
|
+
describe '#name_servers' do
|
5
|
+
it "will return list of name servers' IP addresses if specified correctly" do
|
6
|
+
dns = DopCommon::DNS.new(nil)
|
7
|
+
expect(dns.name_servers).to eq([])
|
8
|
+
dns = DopCommon::DNS.new({'name_servers' => ['10.0.1.1', '172.16.2.1']})
|
9
|
+
expect(dns.name_servers).to eq(['10.0.1.1', '172.16.2.1'])
|
10
|
+
end
|
11
|
+
it 'will raise an exception of not specified properly' do
|
12
|
+
[nil, {}, [], 'aaa.bbb.ccc', '1.2.3.300'].each do |val|
|
13
|
+
dns = DopCommon::DNS.new({'name_servers' => val})
|
14
|
+
expect { dns.name_servers }.to raise_error DopCommon::PlanParsingError
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#search_domains' do
|
20
|
+
it "will return list of search domains if specified correctly" do
|
21
|
+
dns = DopCommon::DNS.new(nil)
|
22
|
+
expect(dns.search_domains).to eq([])
|
23
|
+
dns = DopCommon::DNS.new({'search_domains' => ['foo', 'foo.bar']})
|
24
|
+
expect(dns.search_domains).to eq(['foo', 'foo.bar'])
|
25
|
+
end
|
26
|
+
it 'will raise an exception of not specified properly' do
|
27
|
+
[nil, [], {}, '-foo.bar.baz', 'foo.b.c', 'f', 1].each do |val|
|
28
|
+
dns = DopCommon::DNS.new({'search_domains' => val})
|
29
|
+
expect { dns.search_domains }.to raise_error DopCommon::PlanParsingError
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|