From e40ee23abab92f863f53f6ba4041e3e04cf2a89f Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Thu, 12 Jan 2012 11:13:42 -0800 Subject: Updates linux_net to ignore some shell errors * Allows exit 254 from ip add and ip del * Allows exit 7 from route add and route del * These exit codes means the ip/route already existed or was already removed * Fixes bug 915556 Change-Id: Ib71da2351372f3c7e3558cf5b3e9f55e10681875 --- nova/network/linux_net.py | 29 +++++++++++++++-------------- nova/network/manager.py | 3 +-- 2 files changed, 16 insertions(+), 16 deletions(-) (limited to 'nova') diff --git a/nova/network/linux_net.py b/nova/network/linux_net.py index 5b0c80eec..cf35c4510 100755 --- a/nova/network/linux_net.py +++ b/nova/network/linux_net.py @@ -433,11 +433,11 @@ def init_host(ip_range=None): iptables_manager.apply() -def bind_floating_ip(floating_ip, device, check_exit_code=True): +def bind_floating_ip(floating_ip, device): """Bind ip to public interface.""" _execute('ip', 'addr', 'add', str(floating_ip) + '/32', 'dev', device, - run_as_root=True, check_exit_code=check_exit_code) + run_as_root=True, check_exit_code=[0, 254]) if FLAGS.send_arp_for_ha: _execute('arping', '-U', floating_ip, '-A', '-I', device, @@ -447,14 +447,15 @@ def bind_floating_ip(floating_ip, device, check_exit_code=True): def unbind_floating_ip(floating_ip, device): """Unbind a public ip from public interface.""" _execute('ip', 'addr', 'del', str(floating_ip) + '/32', - 'dev', device, run_as_root=True) + 'dev', device, + run_as_root=True, check_exit_code=[0, 254]) def ensure_metadata_ip(): """Sets up local metadata ip.""" _execute('ip', 'addr', 'add', '169.254.169.254/32', 'scope', 'link', 'dev', 'lo', - run_as_root=True, check_exit_code=False) + run_as_root=True, check_exit_code=[0, 254]) def ensure_vpn_forward(public_ip, port, private_ip): @@ -523,17 +524,17 @@ def initialize_gateway_device(dev, network_ref): fields[-1] == dev: gateway = fields[1] _execute('route', 'del', 'default', 'gw', gateway, - 'dev', dev, check_exit_code=False, - run_as_root=True) + 'dev', dev, run_as_root=True, + check_exit_code=[0, 7]) for ip_params in old_ip_params: _execute(*_ip_bridge_cmd('del', ip_params, dev), - run_as_root=True) + run_as_root=True, check_exit_code=[0, 254]) for ip_params in new_ip_params: _execute(*_ip_bridge_cmd('add', ip_params, dev), - run_as_root=True) + run_as_root=True, check_exit_code=[0, 254]) if gateway: _execute('route', 'add', 'default', 'gw', gateway, - run_as_root=True) + run_as_root=True, check_exit_code=[0, 7]) if FLAGS.send_arp_for_ha: _execute('arping', '-U', network_ref['dhcp_server'], '-A', '-I', dev, @@ -991,8 +992,8 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver): fields[-1] == interface: old_gateway = fields[1] _execute('route', 'del', 'default', 'gw', old_gateway, - 'dev', interface, check_exit_code=False, - run_as_root=True) + 'dev', interface, run_as_root=True, + check_exit_code=[0, 7]) out, err = _execute('ip', 'addr', 'show', 'dev', interface, 'scope', 'global', run_as_root=True) for line in out.split('\n'): @@ -1000,12 +1001,12 @@ class LinuxBridgeInterfaceDriver(LinuxNetInterfaceDriver): if fields and fields[0] == 'inet': params = fields[1:-1] _execute(*_ip_bridge_cmd('del', params, fields[-1]), - run_as_root=True) + run_as_root=True, check_exit_code=[0, 254]) _execute(*_ip_bridge_cmd('add', params, bridge), - run_as_root=True) + run_as_root=True, check_exit_code=[0, 254]) if old_gateway: _execute('route', 'add', 'default', 'gw', old_gateway, - run_as_root=True) + run_as_root=True, check_exit_code=[0, 7]) if (err and err != "device %s is already a member of a bridge;" "can't enslave it to bridge %s.\n" % (interface, bridge)): diff --git a/nova/network/manager.py b/nova/network/manager.py index 038b1d964..564ccac05 100644 --- a/nova/network/manager.py +++ b/nova/network/manager.py @@ -205,8 +205,7 @@ class FloatingIP(object): # NOTE(vish): The False here is because we ignore the case # that the ip is already bound. self.driver.bind_floating_ip(floating_ip['address'], - floating_ip['interface'], - False) + floating_ip['interface']) self.driver.ensure_floating_forward(floating_ip['address'], fixed_address) -- cgit