Implement prefixed hostnames support

in the network_metadata_to_hosts() parser function.

This functional required for separation nova live migration
and RMQ-server to dedicated networks.

Change-Id: I9813fa8c20d47e0ef1e251fe5ac8d01d08fe7703
Related-bug: 1528707
This commit is contained in:
Sergey Vasilenko 2015-12-30 15:56:29 +03:00 committed by Kyrylo Galanov
parent ec3b588f2c
commit 68bcee4af6
2 changed files with 32 additions and 6 deletions

View File

@ -6,16 +6,26 @@ module Puppet::Parser::Functions
newfunction(:network_metadata_to_hosts, :type => :rvalue, :doc => <<-EOS
convert network_metadata hash to
hash for puppet `host` create_resources call
Call network_metadata_to_hosts(network_metadata, 'network/role', 'optional_prefix')
EOS
) do |args|
hosts=Hash.new
nodes=args[0].fetch('nodes', {})
unless args.size == 1 or args.size == 3
raise(Puppet::ParseError, 'network_metadata_to_hosts(): Wrong number of arguments, need one or three')
end
hosts = Hash.new
nodes = args[0].fetch('nodes', {})
network_role = (args[1].to_s == '' ? 'mgmt/vip' : args[1].to_s)
prefix = args[2].to_s
nodes.each do |name, props|
hosts[props['fqdn']]={:ip=>props['network_roles']['mgmt/vip'],:host_aliases=>[name]}
notice("Generating host entry #{name} #{props['network_roles']['mgmt/vip']} #{props['fqdn']}")
fqdn = "#{prefix}#{props['fqdn']}"
hosts[fqdn]={:ip=>props['network_roles'][network_role],:host_aliases=>["#{prefix}#{name}"]}
notice("Generating host entry #{name} #{props['network_roles'][network_role]} #{props['fqdn']}")
end
return hosts
end
end
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :

View File

@ -17,6 +17,7 @@ let(:network_metadata) {"""
mgmt/database: 10.88.0.6
mgmt/vip: 10.88.0.6
sahara/api: 10.88.0.6
nova/migration: 10.77.0.6
user_node_name: CO22
node_roles:
- compute
@ -33,6 +34,7 @@ let(:network_metadata) {"""
sahara/api: 10.88.0.7
heat/api: 10.88.0.7
ceilometer/api: 10.88.0.7
nova/migration: 10.77.0.7
ex: 10.88.1.132
user_node_name: CNT21
node_roles:
@ -49,6 +51,7 @@ let(:network_metadata) {"""
sahara/api: 10.88.0.8
ceilometer/api: 10.88.0.8
mgmt/vip: 10.88.0.8
nova/migration: 10.77.0.8
user_node_name: CO23
node_roles:
- compute
@ -100,7 +103,7 @@ let(:network_metadata) {"""
expect(subject).to eq scope.method('function_network_metadata_to_hosts')
end
it 'should return hash for creating set of "host" puppet resources by create_resources()' do
it 'should return hash for creating ordinary set of "host" puppet resources by create_resources()' do
expect(scope.function_network_metadata_to_hosts([YAML.load(network_metadata)])).to eq({
'node-6.domain.local' => {:ip => '10.88.0.8', :host_aliases => ['node-6']},
'node-5.domain.local' => {:ip => '10.88.0.6', :host_aliases => ['node-5']},
@ -108,4 +111,17 @@ let(:network_metadata) {"""
})
end
it 'should return hash for creating prefixed set of "host" puppet resources by create_resources()' do
expect(scope.function_network_metadata_to_hosts([YAML.load(network_metadata), 'nova/migration', 'xxx-'])).to eq({
'xxx-node-6.domain.local' => {:ip => '10.77.0.8', :host_aliases => ['xxx-node-6']},
'xxx-node-5.domain.local' => {:ip => '10.77.0.6', :host_aliases => ['xxx-node-5']},
'xxx-node-4.domain.local' => {:ip => '10.77.0.7', :host_aliases => ['xxx-node-4']},
})
end
it 'should throw exception on wrong number of parameters' do
expect{scope.function_network_metadata_to_hosts([YAML.load(network_metadata), 'nova/migration'])}.to \
raise_error(Puppet::ParseError, /Wrong number of arg/)
end
end