Create iproute.IPRoute() inside a context
IPRoute() object must be closed once is no longer used. This is done automatically calling it inside its own context. If IPRoute() object is not closed, the following error is raised after many calls: OSError: [Errno 24] Too many open files Change-Id: I37ee291c22c2c3933ee229bfc939a4481898626c Closes-Bug: #1807949
This commit is contained in:
parent
5fa14f8372
commit
db5216357b
@ -40,7 +40,7 @@ class PyRoute2(ip_command.IpCommand):
|
||||
def set(self, device, check_exit_code=None, state=None, mtu=None,
|
||||
address=None, promisc=None):
|
||||
check_exit_code = check_exit_code or []
|
||||
ip = iproute.IPRoute()
|
||||
with iproute.IPRoute() as ip:
|
||||
idx = ip.link_lookup(ifname=device)
|
||||
if not idx:
|
||||
raise exception.NetworkInterfaceNotFound(interface=device)
|
||||
@ -67,7 +67,7 @@ class PyRoute2(ip_command.IpCommand):
|
||||
def add(self, device, dev_type, check_exit_code=None, peer=None, link=None,
|
||||
vlan_id=None):
|
||||
check_exit_code = check_exit_code or []
|
||||
ip = iproute.IPRoute()
|
||||
with iproute.IPRoute() as ip:
|
||||
args = {'ifname': device,
|
||||
'kind': dev_type}
|
||||
if self.TYPE_VLAN == dev_type:
|
||||
@ -85,7 +85,7 @@ class PyRoute2(ip_command.IpCommand):
|
||||
|
||||
def delete(self, device, check_exit_code=None):
|
||||
check_exit_code = check_exit_code or []
|
||||
ip = iproute.IPRoute()
|
||||
with iproute.IPRoute() as ip:
|
||||
idx = ip.link_lookup(ifname=device)
|
||||
if len(idx) == 0:
|
||||
raise exception.NetworkInterfaceNotFound(interface=device)
|
||||
@ -95,6 +95,6 @@ class PyRoute2(ip_command.IpCommand):
|
||||
|
||||
def exists(self, device):
|
||||
"""Return True if the device exists."""
|
||||
ip = iproute.IPRoute()
|
||||
with iproute.IPRoute() as ip:
|
||||
idx = ip.link_lookup(ifname=device)
|
||||
return True if idx else False
|
||||
|
@ -181,3 +181,13 @@ class TestIpCommand(ShellIpCommands, base.BaseFunctionalTestCase):
|
||||
self.assertTrue(self.exist_device(device))
|
||||
_ip_cmd_delete(device)
|
||||
self.assertFalse(self.exist_device(device))
|
||||
|
||||
def test_iproute_object_closes_correctly(self):
|
||||
# NOTE(ralonsoh): check https://bugs.launchpad.net/os-vif/+bug/1807949
|
||||
device = "test_dev_9"
|
||||
link = "test_devlink_2"
|
||||
self.add_device(link, 'dummy')
|
||||
self.addCleanup(self.del_device, 'dummy')
|
||||
for _ in range(300):
|
||||
_ip_cmd_add(device, 'vlan', link=link, vlan_id=100)
|
||||
_ip_cmd_delete(device)
|
||||
|
Loading…
x
Reference in New Issue
Block a user