summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-03-04 03:20:15 +0000
committerGerrit Code Review <review@openstack.org>2017-03-04 03:20:15 +0000
commit895c4b4549a906392f6bba696912c6e65eb05346 (patch)
treed9019de8b629210ccd7ac901bba3bc5fdcbfe5da
parenta0d2e379a8c6c1e5667efc92fd32f168d2241268 (diff)
parente6ed9537845d4052d5374d10b2c65d43a2a18ae8 (diff)
Merge "Add unit test for veth binding driver"
-rw-r--r--kuryr/tests/unit/base.py8
-rw-r--r--kuryr/tests/unit/binding/drivers/test_veth.py (renamed from kuryr/tests/unit/binding/test_package.py)57
2 files changed, 38 insertions, 27 deletions
diff --git a/kuryr/tests/unit/base.py b/kuryr/tests/unit/base.py
index 500813b..ad2f994 100644
--- a/kuryr/tests/unit/base.py
+++ b/kuryr/tests/unit/base.py
@@ -89,7 +89,9 @@ class TestCase(base.BaseTestCase):
89 neutron_subnet_v4_id=None, 89 neutron_subnet_v4_id=None,
90 neutron_subnet_v6_id=None, 90 neutron_subnet_v6_id=None,
91 neutron_subnet_v4_address="192.168.1.2", 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 # The following fake response is retrieved from the Neutron doc: 95 # The following fake response is retrieved from the Neutron doc:
94 # http://developer.openstack.org/api-ref-networking-v2.html#createPort # noqa 96 # http://developer.openstack.org/api-ref-networking-v2.html#createPort # noqa
95 fake_port = { 97 fake_port = {
@@ -105,7 +107,9 @@ class TestCase(base.BaseTestCase):
105 "fixed_ips": [], 107 "fixed_ips": [],
106 "id": neutron_port_id, 108 "id": neutron_port_id,
107 "security_groups": [], 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
diff --git a/kuryr/tests/unit/binding/test_package.py b/kuryr/tests/unit/binding/drivers/test_veth.py
index a22f1df..46562f2 100644
--- a/kuryr/tests/unit/binding/test_package.py
+++ b/kuryr/tests/unit/binding/drivers/test_veth.py
@@ -1,31 +1,31 @@
1# Licensed under the Apache License, Version 2.0 (the "License"); you may 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 2# not use this file except in compliance with the License. You may obtain
3# a copy of the License at 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 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 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 9# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10# License for the specific language governing permissions and limitations 10# License for the specific language governing permissions and limitations
11# under the License. 11# under the License.
12import ddt 12
13
13import mock 14import mock
14from oslo_utils import uuidutils 15from oslo_utils import uuidutils
15 16
16from kuryr.lib import binding 17from kuryr.lib.binding.drivers import veth
17from kuryr.lib import constants 18from kuryr.lib import constants
18from kuryr.lib import utils 19from kuryr.lib import utils
19from kuryr.tests.unit import base 20from kuryr.tests.unit import base
20from mock import call 21
21 22
22mock_create = mock.MagicMock() 23mock_create = mock.MagicMock()
23mock_interface = mock.MagicMock() 24mock_interface = mock.MagicMock()
24 25
25 26
26@ddt.ddt 27class TestVethDriver(base.TestCase):
27class BindingTest(base.TestCase): 28 """Unit tests for veth driver"""
28 """Unit tests for binding."""
29 29
30 @mock.patch('os.path.exists', return_value=True) 30 @mock.patch('os.path.exists', return_value=True)
31 @mock.patch('oslo_concurrency.processutils.execute', 31 @mock.patch('oslo_concurrency.processutils.execute',
@@ -37,27 +37,31 @@ class BindingTest(base.TestCase):
37 def test_port_bind(self, mock_getitem, mock_getattribute, 37 def test_port_bind(self, mock_getitem, mock_getattribute,
38 mock_execute, mock_path_exists): 38 mock_execute, mock_path_exists):
39 fake_mtu = 1450 39 fake_mtu = 1450
40 fake_docker_network_id = utils.get_hash()
41 fake_docker_endpoint_id = utils.get_hash() 40 fake_docker_endpoint_id = utils.get_hash()
41 fake_docker_network_id = utils.get_hash()
42 fake_port_id = uuidutils.generate_uuid() 42 fake_port_id = uuidutils.generate_uuid()
43 fake_neutron_v4_subnet_id = uuidutils.generate_uuid() 43 fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
44 fake_neutron_v6_subnet_id = uuidutils.generate_uuid() 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 fake_port = self._get_fake_port( 47 fake_port = self._get_fake_port(
46 fake_docker_endpoint_id, fake_docker_network_id, 48 fake_docker_endpoint_id, fake_docker_network_id,
47 fake_port_id, constants.PORT_STATUS_ACTIVE, 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 fake_subnets = self._get_fake_subnets( 52 fake_subnets = self._get_fake_subnets(
50 fake_docker_endpoint_id, fake_docker_network_id, 53 fake_docker_endpoint_id, fake_docker_network_id,
51 fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id) 54 fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id)
52 fake_network = self._get_fake_networks(fake_docker_network_id) 55 fake_network = self._get_fake_networks(fake_docker_network_id)
53 fake_network['networks'][0]['mtu'] = fake_mtu 56 fake_network['networks'][0]['mtu'] = fake_mtu
54 57
55 binding.port_bind(fake_docker_endpoint_id, fake_port['port'], 58 veth.port_bind(fake_docker_endpoint_id,
56 fake_subnets['subnets'], 59 fake_port['port'],
57 fake_network['networks'][0]) 60 fake_subnets['subnets'],
61 fake_network['networks'][0])
58 62
59 expect_calls = [call.__enter__().set_mtu(fake_mtu), 63 expect_calls = [mock.call.__enter__().set_mtu(fake_mtu),
60 call.__enter__().up()] 64 mock.call.__enter__().up()]
61 mock_interface.assert_has_calls(expect_calls, any_order=True) 65 mock_interface.assert_has_calls(expect_calls, any_order=True)
62 mock_path_exists.assert_called_once() 66 mock_path_exists.assert_called_once()
63 mock_execute.assert_called_once() 67 mock_execute.assert_called_once()
@@ -66,15 +70,18 @@ class BindingTest(base.TestCase):
66 @mock.patch('oslo_concurrency.processutils.execute', 70 @mock.patch('oslo_concurrency.processutils.execute',
67 return_value=('fake_stdout', 'fake_stderr')) 71 return_value=('fake_stdout', 'fake_stderr'))
68 def test_port_unbind(self, mock_execute, mock_remove_device): 72 def test_port_unbind(self, mock_execute, mock_remove_device):
69 fake_docker_network_id = utils.get_hash()
70 fake_docker_endpoint_id = utils.get_hash() 73 fake_docker_endpoint_id = utils.get_hash()
74 fake_docker_network_id = utils.get_hash()
71 fake_port_id = uuidutils.generate_uuid() 75 fake_port_id = uuidutils.generate_uuid()
72 fake_neutron_v4_subnet_id = uuidutils.generate_uuid() 76 fake_neutron_v4_subnet_id = uuidutils.generate_uuid()
73 fake_neutron_v6_subnet_id = uuidutils.generate_uuid() 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 fake_port = self._get_fake_port( 80 fake_port = self._get_fake_port(
75 fake_docker_endpoint_id, fake_docker_network_id, 81 fake_docker_endpoint_id, fake_docker_network_id,
76 fake_port_id, constants.PORT_STATUS_ACTIVE, 82 fake_port_id, constants.PORT_STATUS_ACTIVE,
77 fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id) 83 fake_neutron_v4_subnet_id, fake_neutron_v6_subnet_id,
78 binding.port_unbind(fake_docker_endpoint_id, fake_port['port']) 84 vif_details=fake_vif_details, vif_type=fake_vif_type)
85 veth.port_unbind(fake_docker_endpoint_id, fake_port['port'])
79 mock_execute.assert_called_once() 86 mock_execute.assert_called_once()
80 mock_remove_device.assert_called_once() 87 mock_remove_device.assert_called_once()