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(','): for interface in info['interfaces'].split(','):
interface = interface.strip() interface = interface.strip()
ipaddr = info['ipaddress_{}'.format(interface)] ipaddr = info.get('ipaddress_{}'.format(interface))
netmask = info['netmask_{}'.format(interface)] netmask = info.get('netmask_{}'.format(interface))
subnet_b = netaddr.IPNetwork('{ipaddr}/{netmask}'.format(**locals())) if ipaddr and netmask:
if subnet_a == subnet_b: subnet_b = netaddr.IPNetwork('{ipaddr}/{netmask}'.format(**locals()))
translated.append(interface) if subnet_a == subnet_b:
break translated.append(interface)
break
result.append(':'.join(translated)) result.append(':'.join(translated))
return ','.join(result) return ','.join(result)

View File

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