From 9fe633745359ca87b7e97b9d6ee3fbff448288d5 Mon Sep 17 00:00:00 2001 From: Hongbin Lu Date: Sun, 11 Feb 2018 18:20:26 +0000 Subject: [PATCH] Add test case for attaching to attached network Related-Bug: #1748335 Change-Id: Ia34983988bdf33b71c3217299f94d8e64d4bae46 --- .../unit/container/docker/test_docker_driver.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/zun/tests/unit/container/docker/test_docker_driver.py b/zun/tests/unit/container/docker/test_docker_driver.py index b825aa66f..88d9546de 100644 --- a/zun/tests/unit/container/docker/test_docker_driver.py +++ b/zun/tests/unit/container/docker/test_docker_driver.py @@ -16,6 +16,7 @@ import mock from oslo_utils import units from zun.common import consts +from zun.common import exception from zun import conf from zun.container.docker.driver import DockerDriver from zun.container.docker import utils as docker_utils @@ -578,8 +579,9 @@ class TestDockerDriver(base.DriverTestCase): @mock.patch('zun.network.kuryr_network.KuryrNetwork' '.list_networks') def test_network_attach(self, mock_list, mock_disconnect, mock_connect): - mock_container = mock.MagicMock() + mock_container = mock.Mock() mock_container.security_groups = None + mock_container.addresses = {} mock_list.return_value = {'network': 'network'} requested_network = [{'network': 'network', 'port': '', @@ -592,6 +594,14 @@ class TestDockerDriver(base.DriverTestCase): requested_network[0], security_groups=None) + def test_network_attach_error(self): + mock_container = mock.Mock() + mock_container.security_groups = None + mock_container.addresses = {'already-attached-net': []} + self.assertRaises(exception.ZunException, + self.driver.network_attach, + self.context, mock_container, 'already-attached-net') + @mock.patch('zun.common.utils.get_security_group_ids') @mock.patch('zun.network.kuryr_network.KuryrNetwork' '.connect_container_to_network') @@ -601,8 +611,9 @@ class TestDockerDriver(base.DriverTestCase): mock_connect, mock_get_sec_group_id): test_sec_group_id = '84e3a4c1-c8cd-46b1-a0d9-c8c35f6a32a4' - mock_container = mock.MagicMock() + mock_container = mock.Mock() mock_container.security_groups = ['test_sec_group'] + mock_container.addresses = {} mock_list.return_value = {'network': 'network'} mock_get_sec_group_id.return_value = test_sec_group_id requested_network = [{'network': 'network',