Merge "Don't raise error when removing not existing IP address"

This commit is contained in:
Zuul 2018-03-23 16:28:14 +00:00 committed by Gerrit Code Review
commit 0982729f56
2 changed files with 19 additions and 6 deletions

View File

@ -152,12 +152,21 @@ def add_ip_address(ip_version, ip, prefixlen, device, namespace, scope,
@privileged.default.entrypoint @privileged.default.entrypoint
def delete_ip_address(ip_version, ip, prefixlen, device, namespace): def delete_ip_address(ip_version, ip, prefixlen, device, namespace):
family = _IP_VERSION_FAMILY_MAP[ip_version] family = _IP_VERSION_FAMILY_MAP[ip_version]
_run_iproute_addr("delete", try:
device, _run_iproute_addr("delete",
namespace, device,
address=ip, namespace,
mask=prefixlen, address=ip,
family=family) 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 @privileged.default.entrypoint

View File

@ -429,6 +429,10 @@ class IpLibTestCase(IpLibTestFramework):
device_cidrs = [ip_info['cidr'] for ip_info in device.addr.list()] device_cidrs = [ip_info['cidr'] for ip_info in device.addr.list()]
self.assertNotIn(cidr, device_cidrs) 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): def test_flush_ip_addresses(self):
ip_addresses = [ ip_addresses = [
(netaddr.IPNetwork("10.10.10.10/30"), "global", '10.10.10.11'), (netaddr.IPNetwork("10.10.10.10/30"), "global", '10.10.10.11'),