Browse Source

Merge "Add unit test for veth binding driver"

tags/0.4.0
Jenkins 2 years ago
parent
commit
895c4b4549
2 changed files with 38 additions and 27 deletions
  1. 6
    2
      kuryr/tests/unit/base.py
  2. 32
    25
      kuryr/tests/unit/binding/drivers/test_veth.py

+ 6
- 2
kuryr/tests/unit/base.py View File

@@ -89,7 +89,9 @@ class TestCase(base.BaseTestCase):
89 89
                        neutron_subnet_v4_id=None,
90 90
                        neutron_subnet_v6_id=None,
91 91
                        neutron_subnet_v4_address="192.168.1.2",
92
-                       neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4"):
92
+                       neutron_subnet_v6_address="fe80::f816:3eff:fe20:57c4",
93
+                       vif_details=None,
94
+                       vif_type=None):
93 95
         # The following fake response is retrieved from the Neutron doc:
94 96
         #   http://developer.openstack.org/api-ref-networking-v2.html#createPort  # noqa
95 97
         fake_port = {
@@ -105,7 +107,9 @@ class TestCase(base.BaseTestCase):
105 107
                 "fixed_ips": [],
106 108
                 "id": neutron_port_id,
107 109
                 "security_groups": [],
108
-                "device_id": ""
110
+                "device_id": "",
111
+                "binding:vif_details": vif_details,
112
+                "binding:vif_type": vif_type
109 113
             }
110 114
         }
111 115
 

kuryr/tests/unit/binding/test_package.py → kuryr/tests/unit/binding/drivers/test_veth.py View File

@@ -1,31 +1,31 @@
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
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 4
 #
5
-#         http://www.apache.org/licenses/LICENSE-2.0
5
+#      http://www.apache.org/licenses/LICENSE-2.0
6 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
-import ddt
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
+
13 14
 import mock
14 15
 from oslo_utils import uuidutils
15 16
 
16
-from kuryr.lib import binding
17
+from kuryr.lib.binding.drivers import veth
17 18
 from kuryr.lib import constants
18 19
 from kuryr.lib import utils
19 20
 from kuryr.tests.unit import base
20
-from mock import call
21
+
21 22
 
22 23
 mock_create = mock.MagicMock()
23 24
 mock_interface = mock.MagicMock()
24 25
 
25 26
 
26
-@ddt.ddt
27
-class BindingTest(base.TestCase):
28
-    """Unit tests for binding."""
27
+class TestVethDriver(base.TestCase):
28
+    """Unit tests for veth driver"""
29 29
 
30 30
     @mock.patch('os.path.exists', return_value=True)
31 31
     @mock.patch('oslo_concurrency.processutils.execute',
@@ -37,27 +37,31 @@ class BindingTest(base.TestCase):
37 37
     def test_port_bind(self, mock_getitem, mock_getattribute,
38 38
                        mock_execute, mock_path_exists):
39 39
         fake_mtu = 1450
40
-        fake_docker_network_id = utils.get_hash()
41 40
         fake_docker_endpoint_id = utils.get_hash()
41
+        fake_docker_network_id = utils.get_hash()
42 42
         fake_port_id = uuidutils.generate_uuid()
43 43
         fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
44 44
         fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
45
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
46
+        fake_vif_type = "ovs"
45 47
         fake_port = self._get_fake_port(
46 48
             fake_docker_endpoint_id, fake_docker_network_id,
47 49
             fake_port_id, constants.PORT_STATUS_ACTIVE,
48
-            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
50
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
51
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
49 52
         fake_subnets = self._get_fake_subnets(
50 53
             fake_docker_endpoint_id, fake_docker_network_id,
51 54
             fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
52 55
         fake_network = self._get_fake_networks(fake_docker_network_id)
53 56
         fake_network['networks'][0]['mtu'] = fake_mtu
54 57
 
55
-        binding.port_bind(fake_docker_endpoint_id, fake_port['port'],
56
-                          fake_subnets['subnets'],
57
-                          fake_network['networks'][0])
58
+        veth.port_bind(fake_docker_endpoint_id,
59
+                       fake_port['port'],
60
+                       fake_subnets['subnets'],
61
+                       fake_network['networks'][0])
58 62
 
59
-        expect_calls = [call.__enter__().set_mtu(fake_mtu),
60
-                        call.__enter__().up()]
63
+        expect_calls = [mock.call.__enter__().set_mtu(fake_mtu),
64
+                        mock.call.__enter__().up()]
61 65
         mock_interface.assert_has_calls(expect_calls, any_order=True)
62 66
         mock_path_exists.assert_called_once()
63 67
         mock_execute.assert_called_once()
@@ -66,15 +70,18 @@ class BindingTest(base.TestCase):
66 70
     @mock.patch('oslo_concurrency.processutils.execute',
67 71
                 return_value=('fake_stdout', 'fake_stderr'))
68 72
     def test_port_unbind(self, mock_execute, mock_remove_device):
69
-        fake_docker_network_id = utils.get_hash()
70 73
         fake_docker_endpoint_id = utils.get_hash()
74
+        fake_docker_network_id = utils.get_hash()
71 75
         fake_port_id = uuidutils.generate_uuid()
72 76
         fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
73 77
         fake_neutron_v6_subnet_id = uuidutils.generate_uuid()
78
+        fake_vif_details = {"port_filter": True, "ovs_hybrid_plug": False}
79
+        fake_vif_type = "ovs"
74 80
         fake_port = self._get_fake_port(
75 81
             fake_docker_endpoint_id, fake_docker_network_id,
76 82
             fake_port_id, constants.PORT_STATUS_ACTIVE,
77
-            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
78
-        binding.port_unbind(fake_docker_endpoint_id, fake_port['port'])
83
+            fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
84
+            vif_details=fake_vif_details, vif_type=fake_vif_type)
85
+        veth.port_unbind(fake_docker_endpoint_id, fake_port['port'])
79 86
         mock_execute.assert_called_once()
80 87
         mock_remove_device.assert_called_once()

Loading…
Cancel
Save