From 23a411413fbad6e96ed6b3c3ec3876cba3d8f4fd Mon Sep 17 00:00:00 2001 From: Michael Johnson Date: Thu, 28 Mar 2019 11:33:14 -0700 Subject: [PATCH] Fix ifup failures on member interfaces with IPv6 When an older version of ifup is used, there are cases where bringing up an IPv6 address on an interface will fail with "RTNETLINK answers: File exists" This patch corrects this issue by bringing the interface up and flushing the existing addresses prior to the ifup. This returns a previous behavior of the ifdown/ifup commands. Change-Id: I0dbb145ab9a0bb8f831c1db28cabd262f9394e7e Story: 2005320 Task: 30248 --- .../backends/agent/api_server/osutils.py | 19 ++++++++++++++++-- .../backend/agent/api_server/test_server.py | 20 +++++++++---------- ...fup-on-member-create-5b405d98eb036718.yaml | 4 ++++ 3 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 releasenotes/notes/Fix-ifup-on-member-create-5b405d98eb036718.yaml diff --git a/octavia/amphorae/backends/agent/api_server/osutils.py b/octavia/amphorae/backends/agent/api_server/osutils.py index d5746baf13..102297d3a7 100644 --- a/octavia/amphorae/backends/agent/api_server/osutils.py +++ b/octavia/amphorae/backends/agent/api_server/osutils.py @@ -202,10 +202,25 @@ class BaseOS(object): def _bring_if_up(cls, interface, what): # Note, we are not using pyroute2 for this as it is not /etc/netns # aware. - cmd = ("ip netns exec {ns} ifup {params}".format( + # Work around for bug: + # https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=845121 + int_up = "ip netns exec {ns} ip link set {int} up".format( + ns=consts.AMPHORA_NAMESPACE, int=interface) + addr_flush = "ip netns exec {ns} ip addr flush {int}".format( + ns=consts.AMPHORA_NAMESPACE, int=interface) + + cmd = ("ip netns exec {ns} ifup -v {params}".format( ns=consts.AMPHORA_NAMESPACE, params=interface)) try: - subprocess.check_output(cmd.split(), stderr=subprocess.STDOUT) + out = subprocess.check_output(int_up.split(), + stderr=subprocess.STDOUT) + LOG.debug(out) + out = subprocess.check_output(addr_flush.split(), + stderr=subprocess.STDOUT) + LOG.debug(out) + out = subprocess.check_output(cmd.split(), + stderr=subprocess.STDOUT) + LOG.debug(out) except subprocess.CalledProcessError as e: LOG.error('Failed to ifup %s due to error: %s %s', interface, e, e.output) diff --git a/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py b/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py index 837b28ea99..8d4f0e7587 100644 --- a/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py +++ b/octavia/tests/functional/amphorae/backend/agent/api_server/test_server.py @@ -1185,7 +1185,7 @@ class TestServerTestCase(base.TestCase): 'PERSISTENT_DHCLIENT="1"\n'.format(int=test_int_num)) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', 'eth' + test_int_num], stderr=-2) + 'ifup', '-v', 'eth' + test_int_num], stderr=-2) # fixed IPs happy path port_info = {'mac_address': '123', 'mtu': 1450, 'fixed_ips': [ @@ -1263,7 +1263,7 @@ class TestServerTestCase(base.TestCase): 'NETMASK="255.255.255.0"\n'.format(int=test_int_num)) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', 'eth' + test_int_num], stderr=-2) + 'ifup', '-v', 'eth' + test_int_num], stderr=-2) # fixed IPs happy path IPv6 port_info = {'mac_address': '123', 'mtu': 1450, 'fixed_ips': [ @@ -1337,7 +1337,7 @@ class TestServerTestCase(base.TestCase): '0000:0002"\n'.format(int=test_int_num)) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', 'eth' + test_int_num], stderr=-2) + 'ifup', '-v', 'eth' + test_int_num], stderr=-2) # fixed IPs, bogus IP port_info = {'mac_address': '123', 'fixed_ips': [ @@ -1539,7 +1539,7 @@ class TestServerTestCase(base.TestCase): mock_os_chmod.assert_has_calls(calls) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', consts.NETNS_PRIMARY_INTERFACE], stderr=-2) + 'ifup', '-v', consts.NETNS_PRIMARY_INTERFACE], stderr=-2) def test_ubuntu_plug_VIP4(self): self._test_plug_VIP4(consts.UBUNTU) @@ -1800,7 +1800,7 @@ class TestServerTestCase(base.TestCase): mock_os_chmod.assert_has_calls(calls) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}:0'.format( + 'ifup', '-v', '{netns_int}:0'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) # Verify sysctl was loaded @@ -1903,7 +1903,7 @@ class TestServerTestCase(base.TestCase): netns_int=consts.NETNS_PRIMARY_INTERFACE)) mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}:0'.format( + 'ifup', '-v', '{netns_int}:0'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) mock_interfaces.side_effect = [['blah']] @@ -2167,12 +2167,12 @@ class TestServerTestCase(base.TestCase): if distro == consts.UBUNTU: mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}:0'.format( + 'ifup', '-v', '{netns_int}:0'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) elif distro == consts.CENTOS: mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}'.format( + 'ifup', '-v', '{netns_int}'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) # Verify sysctl was loaded @@ -2277,12 +2277,12 @@ class TestServerTestCase(base.TestCase): if distro == consts.UBUNTU: mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}:0'.format( + 'ifup', '-v', '{netns_int}:0'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) elif distro == consts.CENTOS: mock_check_output.assert_called_with( ['ip', 'netns', 'exec', consts.AMPHORA_NAMESPACE, - 'ifup', '{netns_int}'.format( + 'ifup', '-v', '{netns_int}'.format( netns_int=consts.NETNS_PRIMARY_INTERFACE)], stderr=-2) mock_interfaces.side_effect = [['blah']] diff --git a/releasenotes/notes/Fix-ifup-on-member-create-5b405d98eb036718.yaml b/releasenotes/notes/Fix-ifup-on-member-create-5b405d98eb036718.yaml new file mode 100644 index 0000000000..1304dd94bd --- /dev/null +++ b/releasenotes/notes/Fix-ifup-on-member-create-5b405d98eb036718.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + Fixed an issue creating members on networks with IPv6 subnets.