Import NetNS from pyroute2
Since [1] (pyroute2>0.8.1), the class NetNS should be imported
from pyroute2 module.
Also remove usage of pyroute2.ipdb which also got removed.
[1]8b81ddffe6
Closes-Bug: #2092403
Change-Id: I92bf48cc616c0b2dadec4b74175338b3e9a3a6fe
This commit is contained in:
@@ -17,13 +17,13 @@ import socket
|
||||
import netaddr
|
||||
from neutron_lib import constants
|
||||
from oslo_log import log as logging
|
||||
import pyroute2
|
||||
from pyroute2 import iproute
|
||||
from pyroute2.netlink import exceptions as netlink_exceptions
|
||||
from pyroute2.netlink import rtnl
|
||||
from pyroute2.netlink.rtnl import ifinfmsg
|
||||
from pyroute2.netlink.rtnl import ndmsg
|
||||
from pyroute2 import netns
|
||||
from pyroute2.nslink import nslink
|
||||
import tenacity
|
||||
|
||||
from neutron._i18n import _
|
||||
@@ -146,14 +146,14 @@ def get_iproute(namespace):
|
||||
# `NetNS` -- RTNL API to another network namespace
|
||||
if namespace:
|
||||
# do not try and create the namespace
|
||||
return nslink.NetNS(namespace, flags=0, libc=priv_linux.get_cdll())
|
||||
return pyroute2.NetNS(namespace, flags=0, libc=priv_linux.get_cdll())
|
||||
return iproute.IPRoute()
|
||||
|
||||
|
||||
@privileged.default.entrypoint
|
||||
def open_namespace(namespace):
|
||||
"""Open namespace to test if the namespace is ready to be manipulated"""
|
||||
with nslink.NetNS(namespace, flags=0):
|
||||
with pyroute2.NetNS(namespace, flags=0):
|
||||
pass
|
||||
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ from unittest import mock
|
||||
import netaddr
|
||||
from neutron_lib import constants as n_cons
|
||||
from oslo_utils import uuidutils
|
||||
from pyroute2.ipdb import routes as ipdb_routes
|
||||
from pyroute2.iproute import linux as iproute_linux
|
||||
from pyroute2.netlink import exceptions as netlink_exc
|
||||
from pyroute2.netlink import rtnl
|
||||
@@ -551,7 +550,7 @@ class RouteTestCase(functional_base.BaseSudoTestCase):
|
||||
for cidr in cidrs:
|
||||
ip_version = common_utils.get_ip_version(cidr)
|
||||
if ip_version == n_cons.IP_VERSION_6 and not metric:
|
||||
metric = ipdb_routes.IP6_RT_PRIO_USER
|
||||
metric = rtnl.rtmsg.IP6_RT_PRIO_USER
|
||||
if ip_version == n_cons.IP_VERSION_6:
|
||||
scope = 0
|
||||
routes = priv_ip_lib.list_ip_routes(self.namespace, ip_version)
|
||||
@@ -578,7 +577,7 @@ class RouteTestCase(functional_base.BaseSudoTestCase):
|
||||
table = table or iproute_linux.DEFAULT_TABLE
|
||||
ip_version = common_utils.get_ip_version(gateway)
|
||||
if ip_version == n_cons.IP_VERSION_6 and not metric:
|
||||
metric = ipdb_routes.IP6_RT_PRIO_USER
|
||||
metric = rtnl.rtmsg.IP6_RT_PRIO_USER
|
||||
scope = 0
|
||||
routes = priv_ip_lib.list_ip_routes(self.namespace, ip_version)
|
||||
for route in routes:
|
||||
|
||||
@@ -23,11 +23,11 @@ from neutron_lib import constants
|
||||
from neutron_lib import exceptions
|
||||
from oslo_utils import netutils
|
||||
from oslo_utils import uuidutils
|
||||
import pyroute2
|
||||
from pyroute2.netlink import exceptions as netlink_exceptions
|
||||
from pyroute2.netlink.rtnl import ifinfmsg
|
||||
from pyroute2.netlink.rtnl import ndmsg
|
||||
from pyroute2 import netns
|
||||
from pyroute2.nslink import nslink
|
||||
import testtools
|
||||
|
||||
from neutron.agent.common import utils # noqa
|
||||
@@ -37,6 +37,7 @@ from neutron import privileged
|
||||
from neutron.privileged.agent.linux import ip_lib as priv_lib
|
||||
from neutron.tests import base
|
||||
|
||||
|
||||
NETNS_SAMPLE = [
|
||||
'12345678-1234-5678-abcd-1234567890ab',
|
||||
'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
||||
@@ -1003,7 +1004,7 @@ class TestIpNeighCommand(TestIPCmdBase):
|
||||
self.addCleanup(privileged.default.set_client_mode, True)
|
||||
privileged.default.set_client_mode(False)
|
||||
|
||||
@mock.patch.object(nslink, 'NetNS')
|
||||
@mock.patch.object(pyroute2, 'NetNS')
|
||||
def test_add_entry(self, mock_netns):
|
||||
mock_netns_instance = mock_netns.return_value
|
||||
mock_netns_enter = mock_netns_instance.__enter__.return_value
|
||||
@@ -1018,20 +1019,20 @@ class TestIpNeighCommand(TestIPCmdBase):
|
||||
ifindex=1,
|
||||
state=ndmsg.states['permanent'])
|
||||
|
||||
@mock.patch.object(nslink, 'NetNS')
|
||||
@mock.patch.object(pyroute2, 'NetNS')
|
||||
def test_add_entry_nonexistent_namespace(self, mock_netns):
|
||||
mock_netns.side_effect = OSError(errno.ENOENT, None)
|
||||
with testtools.ExpectedException(ip_lib.NetworkNamespaceNotFound):
|
||||
self.neigh_cmd.add('192.168.45.100', 'cc:dd:ee:ff:ab:cd')
|
||||
|
||||
@mock.patch.object(nslink, 'NetNS')
|
||||
@mock.patch.object(pyroute2, 'NetNS')
|
||||
def test_add_entry_other_error(self, mock_netns):
|
||||
expected_exception = OSError(errno.EACCES, None)
|
||||
mock_netns.side_effect = expected_exception
|
||||
with testtools.ExpectedException(expected_exception.__class__):
|
||||
self.neigh_cmd.add('192.168.45.100', 'cc:dd:ee:ff:ab:cd')
|
||||
|
||||
@mock.patch.object(nslink, 'NetNS')
|
||||
@mock.patch.object(pyroute2, 'NetNS')
|
||||
def test_delete_entry(self, mock_netns):
|
||||
mock_netns_instance = mock_netns.return_value
|
||||
mock_netns_enter = mock_netns_instance.__enter__.return_value
|
||||
@@ -1052,7 +1053,7 @@ class TestIpNeighCommand(TestIPCmdBase):
|
||||
errno.ENOENT, None)
|
||||
self.neigh_cmd.delete('192.168.45.100', 'cc:dd:ee:ff:ab:cd')
|
||||
|
||||
@mock.patch.object(nslink, 'NetNS')
|
||||
@mock.patch.object(pyroute2, 'NetNS')
|
||||
def test_dump_entries(self, mock_netns):
|
||||
mock_netns_instance = mock_netns.return_value
|
||||
mock_netns_enter = mock_netns_instance.__enter__.return_value
|
||||
|
||||
@@ -15,10 +15,10 @@
|
||||
import errno
|
||||
from unittest import mock
|
||||
|
||||
import pyroute2
|
||||
from pyroute2 import iproute
|
||||
from pyroute2 import netlink
|
||||
from pyroute2.netlink import exceptions as netlink_exceptions
|
||||
from pyroute2.nslink import nslink
|
||||
|
||||
from neutron.privileged.agent.linux import ip_lib as priv_lib
|
||||
from neutron.tests import base
|
||||
@@ -28,7 +28,7 @@ class IpLibTestCase(base.BaseTestCase):
|
||||
|
||||
def _test_run_iproute_link(self, namespace=None):
|
||||
ip_obj = "NetNS" if namespace else "IPRoute"
|
||||
_mod = nslink if namespace else iproute
|
||||
_mod = pyroute2 if namespace else iproute
|
||||
with mock.patch.object(_mod, ip_obj) as ip_mock_cls:
|
||||
ip_mock = ip_mock_cls()
|
||||
ip_mock.__enter__().link_lookup.return_value = [2]
|
||||
@@ -112,7 +112,7 @@ class IpLibTestCase(base.BaseTestCase):
|
||||
|
||||
def _test_run_iproute_neigh(self, namespace=None):
|
||||
ip_obj = "NetNS" if namespace else "IPRoute"
|
||||
_mod = nslink if namespace else iproute
|
||||
_mod = pyroute2 if namespace else iproute
|
||||
with mock.patch.object(_mod, ip_obj) as ip_mock_cls:
|
||||
ip_mock = ip_mock_cls()
|
||||
ip_mock.__enter__().link_lookup.return_value = [2]
|
||||
@@ -183,7 +183,7 @@ class IpLibTestCase(base.BaseTestCase):
|
||||
|
||||
def _test_run_iproute_addr(self, namespace=None):
|
||||
ip_obj = "NetNS" if namespace else "IPRoute"
|
||||
_mod = nslink if namespace else iproute
|
||||
_mod = pyroute2 if namespace else iproute
|
||||
with mock.patch.object(_mod, ip_obj) as ip_mock_cls:
|
||||
ip_mock = ip_mock_cls()
|
||||
ip_mock.__enter__().link_lookup.return_value = [2]
|
||||
|
||||
Reference in New Issue
Block a user