summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDongcan Ye <hellochosen@gmail.com>2017-03-06 13:15:54 +0800
committerDongcan Ye <hellochosen@gmail.com>2017-03-06 13:27:03 +0800
commitd4e71a37947a15229991cee610d1c678b77969f1 (patch)
treecafc53dc05aa5efe6b254a9d816f6691857c4157
parent895c4b4549a906392f6bba696912c6e65eb05346 (diff)
Add unit tests for nested binding driver
Add unit test for binding drivers: IPVLAN, MACVLAN, and VLAN. Change-Id: I8d25630b1543f9760cc34f331711804c7a1dde0f Closes-Bug: #1644403
Notes
Notes (review): Code-Review+1: Jaivish Kothari(janonymous) <jaivish.kothari@nectechnologies.in> Code-Review+2: Liping Mao <limao@cisco.com> Code-Review+2: Berezovsky Irena <irenab.dev@gmail.com> Code-Review+1: Luis Tomas Bolivar <ltomasbo@redhat.com> Workflow+1: Antoni Segura Puimedon <celebdor@gmail.com> Verified+2: Jenkins Submitted-by: Jenkins Submitted-at: Wed, 08 Mar 2017 11:44:50 +0000 Reviewed-on: https://review.openstack.org/441743 Project: openstack/kuryr Branch: refs/heads/master
-rw-r--r--kuryr/tests/unit/binding/drivers/test_ipvlan.py61
-rw-r--r--kuryr/tests/unit/binding/drivers/test_macvlan.py69
-rw-r--r--kuryr/tests/unit/binding/drivers/test_nested.py41
-rw-r--r--kuryr/tests/unit/binding/drivers/test_vlan.py59
4 files changed, 230 insertions, 0 deletions
diff --git a/kuryr/tests/unit/binding/drivers/test_ipvlan.py b/kuryr/tests/unit/binding/drivers/test_ipvlan.py
new file mode 100644
index 0000000..b668cc1
--- /dev/null
+++ b/kuryr/tests/unit/binding/drivers/test_ipvlan.py
@@ -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
14import mock
15from oslo_utils import uuidutils
16
17from kuryr.lib.binding.drivers import ipvlan
18from kuryr.lib import constants
19from kuryr.lib import utils
20from kuryr.tests.unit import base
21
22
23mock_create = mock.MagicMock()
24mock_interface = mock.MagicMock()
25
26
27class 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()
diff --git a/kuryr/tests/unit/binding/drivers/test_macvlan.py b/kuryr/tests/unit/binding/drivers/test_macvlan.py
new file mode 100644
index 0000000..11ad409
--- /dev/null
+++ b/kuryr/tests/unit/binding/drivers/test_macvlan.py
@@ -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
14import mock
15from oslo_utils import uuidutils
16
17from kuryr.lib.binding.drivers import macvlan
18from kuryr.lib import constants
19from kuryr.lib import utils
20from kuryr.tests.unit import base
21
22
23mock_create = mock.MagicMock()
24mock_interface = mock.MagicMock()
25
26
27class 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()
diff --git a/kuryr/tests/unit/binding/drivers/test_nested.py b/kuryr/tests/unit/binding/drivers/test_nested.py
new file mode 100644
index 0000000..bdd3b82
--- /dev/null
+++ b/kuryr/tests/unit/binding/drivers/test_nested.py
@@ -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
14import mock
15from oslo_utils import uuidutils
16
17from kuryr.lib.binding.drivers import nested
18from kuryr.lib import constants
19from kuryr.lib import utils
20from kuryr.tests.unit import base
21
22
23class 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()
diff --git a/kuryr/tests/unit/binding/drivers/test_vlan.py b/kuryr/tests/unit/binding/drivers/test_vlan.py
new file mode 100644
index 0000000..d2a5ac1
--- /dev/null
+++ b/kuryr/tests/unit/binding/drivers/test_vlan.py
@@ -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
14import mock
15from oslo_utils import uuidutils
16
17from kuryr.lib.binding.drivers import vlan
18from kuryr.lib import constants
19from kuryr.lib import utils
20from kuryr.tests.unit import base
21
22
23mock_create = mock.MagicMock()
24mock_interface = mock.MagicMock()
25
26
27class 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()