Fix routable networks for role for nodes without public IP

Compute nodes don't need a public IP and therefore it isn't
possible to get a list of public networks on such hosts.
This commit fixes the logic so it returns an empty list,
instead of erroring on 'none' string.

Change-Id: I3cab92120b41794967c9affcbdeafb386c2ec9e0
Closes-Bug: #1520553
This commit is contained in:
Matthew Mosesohn 2015-11-30 16:54:19 +03:00
parent b9f8c28f0e
commit b97a053485
2 changed files with 64 additions and 2 deletions

View File

@ -16,7 +16,7 @@ EOS
e_point_name = net_scheme['roles'][net_role]
return [] if e_point_name.nil?
e_point = net_scheme['endpoints'][e_point_name]
return [] if e_point.nil? or !e_point.is_a?(Hash)
return [] if e_point.nil? or !e_point.is_a?(Hash) or e_point['IP'] == 'none'
#collect subnets for aliases
e_point['IP'].each do |cidr|
masklen = cidr.split('/')[-1]
@ -36,4 +36,4 @@ EOS
return rv
end
# vim: set ts=2 sw=2 et :
# vim: set ts=2 sw=2 et :

View File

@ -170,3 +170,65 @@ end
end
end
describe 'get_routable_networks_for_network_role for network_scheme without public IP' do
let(:network_scheme) do
"""
---
version: '1.1'
provider: lnx
transformations:
- action: add-br
name: section_not_used_in_this_trst
roles:
management: br-mgmt
mgmt/database: br-mgmt
neutron/mesh: br-mesh
storage: br-storage
ex: br-ex
neutron/floating: br-floating
fw-admin: br-fw-admin
interfaces:
eth1: {}
endpoints:
br-fw-admin:
IP:
- 10.144.0.13/24
br-mesh:
IP:
- 10.144.4.2/24
br-floating:
IP: none
br-storage:
IP:
- 10.144.3.2/24
br-mgmt:
IP:
- 10.144.2.4/24
br-ex:
IP: none
"""
end
let(:scope) { PuppetlabsSpec::PuppetInternals.scope }
before(:each) do
puppet_debug_override()
end
subject do
function_name = Puppet::Parser::Functions.function('get_routable_networks_for_network_role')
scope.method(function_name)
end
it 'should exist' do
expect(subject).to eq scope.method('function_get_routable_networks_for_network_role')
end
it 'should return empty list for public network' do
expect(scope.function_get_routable_networks_for_network_role([YAML.load(network_scheme), 'ex'])).to eq []
end
end