Fixes packstack failure when interface has no assigned ip address

In case we have unconfigured interfaces cidr_to_ifname() searches
its ipaddress and network mask and throws an exception.

Change-Id: I829a874ca44c2e4176bb1eeba28c3f49c44c72ca
Closes-bug: #1638549
This commit is contained in:
Olga Krishtal 2016-11-02 15:55:22 +03:00
parent eb2ab2ba53
commit f480c69d76
2 changed files with 10 additions and 6 deletions

View File

@ -77,12 +77,13 @@ def cidr_to_ifname(cidr, host, config):
for interface in info['interfaces'].split(','):
interface = interface.strip()
ipaddr = info['ipaddress_{}'.format(interface)]
netmask = info['netmask_{}'.format(interface)]
subnet_b = netaddr.IPNetwork('{ipaddr}/{netmask}'.format(**locals()))
if subnet_a == subnet_b:
translated.append(interface)
break
ipaddr = info.get('ipaddress_{}'.format(interface))
netmask = info.get('netmask_{}'.format(interface))
if ipaddr and netmask:
subnet_b = netaddr.IPNetwork('{ipaddr}/{netmask}'.format(**locals()))
if subnet_a == subnet_b:
translated.append(interface)
break
result.append(':'.join(translated))
return ','.join(result)

View File

@ -30,6 +30,9 @@ module Puppet::Parser::Functions
lookupvar('interfaces').split(',').each do |interface|
interface.strip!
ifaddr = lookupvar("ipaddress_#{interface}")
if ifaddr == nil
next
end
ifcidr = IPAddr.new ifaddr
if cidr.include?(ifcidr)
translated.push(interface)