From 66d31e7d65638cd7c04af43c719140d0199576e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Dulko?= Date: Wed, 15 Sep 2021 12:15:40 +0200 Subject: [PATCH] Fix unit tests pyroute2 changed structure of the modules a bit and the unit tests were assuming it. This commit makes sure tests work with new pyroute2. Change-Id: I013f2750ca1371d3b4d5e2f618067cd9b70e76e4 --- .../tests/unit/binding/drivers/test_ipvlan.py | 12 ++--------- .../unit/binding/drivers/test_macvlan.py | 12 ++--------- kuryr/tests/unit/binding/drivers/test_veth.py | 20 +++++++++---------- kuryr/tests/unit/binding/drivers/test_vlan.py | 12 ++--------- 4 files changed, 15 insertions(+), 41 deletions(-) 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()