Browse Source

Add unit tests for nested binding driver

Add unit test for binding drivers: IPVLAN, MACVLAN,
and VLAN.

Change-Id: I8d25630b1543f9760cc34f331711804c7a1dde0f
Closes-Bug: #1644403
tags/0.4.0
Dongcan Ye 2 years ago
parent
commit
d4e71a3794

+ 61
- 0
kuryr/tests/unit/binding/drivers/test_ipvlan.py View File

@@ -0,0 +1,61 @@
1
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+# not use this file except in compliance with the License. You may obtain
3
+# a copy of the License at
4
+#
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+# Unless required by applicable law or agreed to in writing, software
8
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+# License for the specific language governing permissions and limitations
11
+# under the License.
12
+
13
+
14
+import mock
15
+from oslo_utils import uuidutils
16
+
17
+from kuryr.lib.binding.drivers import ipvlan
18
+from kuryr.lib import constants
19
+from kuryr.lib import utils
20
+from kuryr.tests.unit import base
21
+
22
+
23
+mock_create = mock.MagicMock()
24
+mock_interface = mock.MagicMock()
25
+
26
+
27
+class TestIpvlanDriver(base.TestCase):
28
+    """Unit tests for nested IPVLAN driver"""
29
+
30
+    @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface')
31
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getattribute__',
32
+                return_value=mock_create)
33
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getitem__',
34
+                return_value=mock_interface)
35
+    def test_port_bind(self, mock_getitem, mock_getattribute,
36
+                       mock_configure_container_iface):
37
+        fake_mtu = 1450
38
+        fake_docker_endpoint_id = utils.get_hash()
39
+        fake_docker_network_id = utils.get_hash()
40
+        fake_port_id = uuidutils.generate_uuid()
41
+        fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
42
+        fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
43
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
44
+        fake_vif_type = "ovs"
45
+        fake_port = self._get_fake_port(
46
+            fake_docker_endpoint_id, fake_docker_network_id,
47
+            fake_port_id, constants.PORT_STATUS_ACTIVE,
48
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
49
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
50
+        fake_subnets = self._get_fake_subnets(
51
+            fake_docker_endpoint_id, fake_docker_network_id,
52
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
53
+        fake_network = self._get_fake_networks(fake_docker_network_id)
54
+        fake_network['networks'][0]['mtu'] = fake_mtu
55
+
56
+        ipvlan.port_bind(fake_docker_endpoint_id,
57
+                         fake_port['port'],
58
+                         fake_subnets['subnets'],
59
+                         fake_network['networks'][0])
60
+
61
+        mock_configure_container_iface.assert_called_once()

+ 69
- 0
kuryr/tests/unit/binding/drivers/test_macvlan.py View File

@@ -0,0 +1,69 @@
1
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+# not use this file except in compliance with the License. You may obtain
3
+# a copy of the License at
4
+#
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+# Unless required by applicable law or agreed to in writing, software
8
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+# License for the specific language governing permissions and limitations
11
+# under the License.
12
+
13
+
14
+import mock
15
+from oslo_utils import uuidutils
16
+
17
+from kuryr.lib.binding.drivers import macvlan
18
+from kuryr.lib import constants
19
+from kuryr.lib import utils
20
+from kuryr.tests.unit import base
21
+
22
+
23
+mock_create = mock.MagicMock()
24
+mock_interface = mock.MagicMock()
25
+
26
+
27
+class TestMacvlanDriver(base.TestCase):
28
+    """Unit tests for nested MACVLAN driver"""
29
+
30
+    @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface')
31
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getattribute__',
32
+                return_value=mock_create)
33
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getitem__',
34
+                return_value=mock_interface)
35
+    def test_port_bind(self, mock_getitem, mock_getattribute,
36
+                       mock_configure_container_iface):
37
+        fake_mtu = 1450
38
+        fake_docker_endpoint_id = utils.get_hash()
39
+        fake_docker_network_id = utils.get_hash()
40
+        fake_port_id = uuidutils.generate_uuid()
41
+        fake_nova_instance_port_id = uuidutils.generate_uuid()
42
+        fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
43
+        fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
44
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
45
+        fake_vif_type = "ovs"
46
+        fake_neutron_port = self._get_fake_port(
47
+            fake_docker_endpoint_id, fake_docker_network_id,
48
+            fake_port_id, constants.PORT_STATUS_ACTIVE,
49
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
50
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
51
+        fake_nova_instance_port = self._get_fake_port(
52
+            "nova-port", fake_docker_network_id,
53
+            fake_nova_instance_port_id, constants.PORT_STATUS_ACTIVE,
54
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
55
+            "192.168.1.3", "fe80::f816:3eff:fe20:57c5",
56
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
57
+        fake_subnets = self._get_fake_subnets(
58
+            fake_docker_endpoint_id, fake_docker_network_id,
59
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
60
+        fake_network = self._get_fake_networks(fake_docker_network_id)
61
+        fake_network['networks'][0]['mtu'] = fake_mtu
62
+
63
+        macvlan.port_bind(fake_docker_endpoint_id,
64
+                          fake_neutron_port['port'],
65
+                          fake_subnets['subnets'],
66
+                          fake_network['networks'][0],
67
+                          fake_nova_instance_port['port'])
68
+
69
+        mock_configure_container_iface.assert_called_once()

+ 41
- 0
kuryr/tests/unit/binding/drivers/test_nested.py View File

@@ -0,0 +1,41 @@
1
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+# not use this file except in compliance with the License. You may obtain
3
+# a copy of the License at
4
+#
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+# Unless required by applicable law or agreed to in writing, software
8
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+# License for the specific language governing permissions and limitations
11
+# under the License.
12
+
13
+
14
+import mock
15
+from oslo_utils import uuidutils
16
+
17
+from kuryr.lib.binding.drivers import nested
18
+from kuryr.lib import constants
19
+from kuryr.lib import utils
20
+from kuryr.tests.unit import base
21
+
22
+
23
+class TestNestedDriver(base.TestCase):
24
+    """Unit tests for nested driver"""
25
+
26
+    @mock.patch('kuryr.lib.binding.drivers.utils.remove_device')
27
+    def test_port_unbind(self, mock_remove_device):
28
+        fake_docker_endpoint_id = utils.get_hash()
29
+        fake_docker_network_id = utils.get_hash()
30
+        fake_port_id = uuidutils.generate_uuid()
31
+        fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
32
+        fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
33
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
34
+        fake_vif_type = "ovs"
35
+        fake_port = self._get_fake_port(
36
+            fake_docker_endpoint_id, fake_docker_network_id,
37
+            fake_port_id, constants.PORT_STATUS_ACTIVE,
38
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
39
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
40
+        nested.port_unbind(fake_docker_endpoint_id, fake_port['port'])
41
+        mock_remove_device.assert_called_once()

+ 59
- 0
kuryr/tests/unit/binding/drivers/test_vlan.py View File

@@ -0,0 +1,59 @@
1
+# Licensed under the Apache License, Version 2.0 (the "License"); you may
2
+# not use this file except in compliance with the License. You may obtain
3
+# a copy of the License at
4
+#
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6
+#
7
+# Unless required by applicable law or agreed to in writing, software
8
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10
+# License for the specific language governing permissions and limitations
11
+# under the License.
12
+
13
+
14
+import mock
15
+from oslo_utils import uuidutils
16
+
17
+from kuryr.lib.binding.drivers import vlan
18
+from kuryr.lib import constants
19
+from kuryr.lib import utils
20
+from kuryr.tests.unit import base
21
+
22
+
23
+mock_create = mock.MagicMock()
24
+mock_interface = mock.MagicMock()
25
+
26
+
27
+class TestVlanDriver(base.TestCase):
28
+    """Unit tests for nested vlan driver"""
29
+
30
+    @mock.patch('kuryr.lib.binding.drivers.utils._configure_container_iface')
31
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getattribute__',
32
+                return_value=mock_create)
33
+    @mock.patch('pyroute2.ipdb.interface.InterfacesDict.__getitem__',
34
+                return_value=mock_interface)
35
+    def test_port_bind(self, mock_getitem, mock_getattribute,
36
+                       mock_configure_container_iface):
37
+        fake_segmentation_id = 100
38
+        fake_docker_endpoint_id = utils.get_hash()
39
+        fake_docker_network_id = utils.get_hash()
40
+        fake_port_id = uuidutils.generate_uuid()
41
+        fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
42
+        fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
43
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
44
+        fake_vif_type = "ovs"
45
+        fake_port = self._get_fake_port(
46
+            fake_docker_endpoint_id, fake_docker_network_id,
47
+            fake_port_id, constants.PORT_STATUS_ACTIVE,
48
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
49
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
50
+        fake_subnets = self._get_fake_subnets(
51
+            fake_docker_endpoint_id, fake_docker_network_id,
52
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
53
+
54
+        vlan.port_bind(fake_docker_endpoint_id,
55
+                       fake_port['port'],
56
+                       fake_subnets['subnets'],
57
+                       fake_segmentation_id)
58
+
59
+        mock_configure_container_iface.assert_called_once()

Loading…
Cancel
Save