diff --git a/neutron/privileged/agent/linux/ip_lib.py b/neutron/privileged/agent/linux/ip_lib.py index 9e5ddfffa6e..28da4ac8068 100644 --- a/neutron/privileged/agent/linux/ip_lib.py +++ b/neutron/privileged/agent/linux/ip_lib.py @@ -152,12 +152,21 @@ def add_ip_address(ip_version, ip, prefixlen, device, namespace, scope, @privileged.default.entrypoint def delete_ip_address(ip_version, ip, prefixlen, device, namespace): family = _IP_VERSION_FAMILY_MAP[ip_version] - _run_iproute_addr("delete", - device, - namespace, - address=ip, - mask=prefixlen, - family=family) + try: + _run_iproute_addr("delete", + device, + namespace, + address=ip, + mask=prefixlen, + family=family) + except NetlinkError as e: + # when trying to delete a non-existent IP address, pyroute2 raises + # NetlinkError with code EADDRNOTAVAIL (99, 'Cannot assign requested + # address') + # this shouldn't raise an error + if e.code == errno.EADDRNOTAVAIL: + return + raise @privileged.default.entrypoint diff --git a/neutron/tests/functional/agent/linux/test_ip_lib.py b/neutron/tests/functional/agent/linux/test_ip_lib.py index 40b6b65515a..c8aa749b262 100644 --- a/neutron/tests/functional/agent/linux/test_ip_lib.py +++ b/neutron/tests/functional/agent/linux/test_ip_lib.py @@ -429,6 +429,10 @@ class IpLibTestCase(IpLibTestFramework): device_cidrs = [ip_info['cidr'] for ip_info in device.addr.list()] self.assertNotIn(cidr, device_cidrs) + # Try to delete not existing IP address, it should be just fine and + # finish without any error raised + device.addr.delete(cidr) + def test_flush_ip_addresses(self): ip_addresses = [ (netaddr.IPNetwork("10.10.10.10/30"), "global", '10.10.10.11'),