From f480c69d76e15c76a5f01dee0b981b000efa7cb3 Mon Sep 17 00:00:00 2001 From: Olga Krishtal Date: Wed, 2 Nov 2016 15:55:22 +0300 Subject: [PATCH] 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 --- packstack/modules/common.py | 13 +++++++------ .../lib/puppet/parser/functions/force_interface.rb | 3 +++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/packstack/modules/common.py b/packstack/modules/common.py index 0a95cbbba..a608a4045 100644 --- a/packstack/modules/common.py +++ b/packstack/modules/common.py @@ -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) diff --git a/packstack/puppet/modules/packstack/lib/puppet/parser/functions/force_interface.rb b/packstack/puppet/modules/packstack/lib/puppet/parser/functions/force_interface.rb index a52556b3a..a958b9dbb 100644 --- a/packstack/puppet/modules/packstack/lib/puppet/parser/functions/force_interface.rb +++ b/packstack/puppet/modules/packstack/lib/puppet/parser/functions/force_interface.rb @@ -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)