diff --git a/kuryr/tests/unit/binding/drivers/test_ipvlan.py b/kuryr/tests/unit/binding/drivers/test_ipvlan.py index b611d479..f23323e1 100644 --- a/kuryr/tests/unit/binding/drivers/test_ipvlan.py +++ b/kuryr/tests/unit/binding/drivers/test_ipvlan.py @@ -21,20 +21,12 @@ from kuryr.lib import utils from kuryr.tests.unit import base -mock_create = mock.MagicMock() -mock_interface = mock.MagicMock() - - class TestIpvlanDriver(base.TestCase): """Unit tests for nested IPVLAN driver""" @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface') - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getattribute__', - return_value=mock_create) - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getitem__', - return_value=mock_interface) - def test_port_bind(self, mock_getitem, mock_getattribute, - mock_configure_container_iface): + @mock.patch('kuryr.lib.binding.drivers.utils.get_ipdb', mock.MagicMock()) + def test_port_bind(self, mock_configure_container_iface): fake_mtu = 1450 fake_docker_endpoint_id = utils.get_hash() fake_docker_network_id = utils.get_hash() diff --git a/kuryr/tests/unit/binding/drivers/test_macvlan.py b/kuryr/tests/unit/binding/drivers/test_macvlan.py index 92126802..efd05d0e 100644 --- a/kuryr/tests/unit/binding/drivers/test_macvlan.py +++ b/kuryr/tests/unit/binding/drivers/test_macvlan.py @@ -21,20 +21,12 @@ from kuryr.lib import utils from kuryr.tests.unit import base -mock_create = mock.MagicMock() -mock_interface = mock.MagicMock() - - class TestMacvlanDriver(base.TestCase): """Unit tests for nested MACVLAN driver""" @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface') - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getattribute__', - return_value=mock_create) - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getitem__', - return_value=mock_interface) - def test_port_bind(self, mock_getitem, mock_getattribute, - mock_configure_container_iface): + @mock.patch('kuryr.lib.binding.drivers.utils.get_ipdb', mock.MagicMock()) + def test_port_bind(self, mock_configure_container_iface): fake_mtu = 1450 fake_docker_endpoint_id = utils.get_hash() fake_docker_network_id = utils.get_hash() diff --git a/kuryr/tests/unit/binding/drivers/test_veth.py b/kuryr/tests/unit/binding/drivers/test_veth.py index 79583c0d..8671a5f0 100644 --- a/kuryr/tests/unit/binding/drivers/test_veth.py +++ b/kuryr/tests/unit/binding/drivers/test_veth.py @@ -21,22 +21,19 @@ from kuryr.lib import utils from kuryr.tests.unit import base -mock_create = mock.MagicMock() -mock_interface = mock.MagicMock() - - class TestVethDriver(base.TestCase): """Unit tests for veth driver""" @mock.patch('os.path.exists', return_value=True) @mock.patch('oslo_concurrency.processutils.execute', return_value=('fake_stdout', 'fake_stderr')) - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getattribute__', - return_value=mock_create) - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getitem__', - return_value=mock_interface) - def test_port_bind(self, mock_getitem, mock_getattribute, - mock_execute, mock_path_exists): + @mock.patch('kuryr.lib.binding.drivers.utils.get_ipdb') + def test_port_bind(self, mock_ipdb, mock_execute, mock_path_exists): + mock_getitem = mock.MagicMock() + mock_ipdb.return_value = mock.MagicMock( + interfaces=mock.MagicMock(__getitem__=mock_getitem) + ) + fake_mtu = 1450 fake_docker_endpoint_id = utils.get_hash() fake_docker_network_id = utils.get_hash() @@ -63,7 +60,8 @@ class TestVethDriver(base.TestCase): expect_calls = [mock.call.__enter__().set_mtu(fake_mtu), mock.call.__enter__().up()] - mock_interface.assert_has_calls(expect_calls, any_order=True) + mock_getitem.return_value.assert_has_calls(expect_calls, + any_order=True) mock_path_exists.assert_called_once() mock_execute.assert_called_once() diff --git a/kuryr/tests/unit/binding/drivers/test_vlan.py b/kuryr/tests/unit/binding/drivers/test_vlan.py index ca2320ba..b921a338 100644 --- a/kuryr/tests/unit/binding/drivers/test_vlan.py +++ b/kuryr/tests/unit/binding/drivers/test_vlan.py @@ -21,20 +21,12 @@ from kuryr.lib import utils from kuryr.tests.unit import base -mock_create = mock.MagicMock() -mock_interface = mock.MagicMock() - - class TestVlanDriver(base.TestCase): """Unit tests for nested vlan driver""" @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface') - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getattribute__', - return_value=mock_create) - @mock.patch('pyroute2.ipdb.interfaces.InterfacesDict.__getitem__', - return_value=mock_interface) - def test_port_bind(self, mock_getitem, mock_getattribute, - mock_configure_container_iface): + @mock.patch('kuryr.lib.binding.drivers.utils.get_ipdb', mock.MagicMock()) + def test_port_bind(self, mock_configure_container_iface): fake_segmentation_id = 100 fake_docker_endpoint_id = utils.get_hash() fake_docker_network_id = utils.get_hash()