diff options
author | John O Loughlin <john.oloughlin@intel.com> | 2018-07-13 10:41:15 +0100 |
---|---|---|
committer | Emma Foley <emma.l.foley@intel.com> | 2018-07-20 11:17:49 +0000 |
commit | d0c9fc59e53cace276093f8785fbdcd16fb1d2aa (patch) | |
tree | e4acfb114b5bbcd9e4a981fb3cd55f0e46be5a63 /yardstick/tests | |
parent | 438f7b5100e05ed668a0ea90674008a391eb5784 (diff) |
Check for network already created k8
When creating a network the host should be checked to see if the network
is already created. If the required network is already there it should be used.
JIRA: YARDSTICK-1315
Change-Id: I09b114a728364ee56397af70cc48f1b7904f06cc
Signed-off-by: John O Loughlin <john.oloughlin@intel.com>
Diffstat (limited to 'yardstick/tests')
-rw-r--r-- | yardstick/tests/unit/common/test_kubernetes_utils.py | 78 | ||||
-rw-r--r-- | yardstick/tests/unit/orchestrator/test_kubernetes.py | 3 |
2 files changed, 75 insertions, 6 deletions
diff --git a/yardstick/tests/unit/common/test_kubernetes_utils.py b/yardstick/tests/unit/common/test_kubernetes_utils.py index bf9992b57..5da32a7cc 100644 --- a/yardstick/tests/unit/common/test_kubernetes_utils.py +++ b/yardstick/tests/unit/common/test_kubernetes_utils.py @@ -159,7 +159,7 @@ class GetCustomResourceDefinitionTestCase(base.BaseUnitTestCase): kubernetes_utils.get_custom_resource_definition('kind') -class CreateNetworkTestCase(base.BaseUnitTestCase): +class GetNetworkTestCase(base.BaseUnitTestCase): @mock.patch.object(kubernetes_utils, 'get_custom_objects_api') def test_execute_correct(self, mock_get_api): mock_api = mock.Mock() @@ -167,29 +167,97 @@ class CreateNetworkTestCase(base.BaseUnitTestCase): group = 'group.com' version = mock.Mock() plural = 'networks' + name = 'net_one' + + kubernetes_utils.get_network( + constants.SCOPE_CLUSTER, group, version, plural, name) + mock_api.get_cluster_custom_object.assert_called_once_with( + group, version, plural, name) + + mock_api.reset_mock() + kubernetes_utils.get_network( + constants.SCOPE_NAMESPACED, group, version, plural, name) + mock_api.get_namespaced_custom_object.assert_called_once_with( + group, version, 'default', plural, name) + + @mock.patch.object(kubernetes_utils, 'get_custom_objects_api') + def test_execute_exception(self, mock_get_api): + mock_api = mock.Mock() + mock_api.get_cluster_custom_object.side_effect = rest.ApiException(404) + mock_api.get_namespaced_custom_object.side_effect = rest.ApiException(404) + mock_get_api.return_value = mock_api + group = 'group.com' + version = mock.Mock() + plural = 'networks' + name = 'net_one' + + network_obj = kubernetes_utils.get_network( + constants.SCOPE_CLUSTER, group, version, plural, name) + self.assertIsNone(network_obj) + + mock_api.reset_mock() + network_obj = kubernetes_utils.get_network( + constants.SCOPE_NAMESPACED, group, version, plural, name) + self.assertIsNone(network_obj) + + +class CreateNetworkTestCase(base.BaseUnitTestCase): + @mock.patch.object(kubernetes_utils, 'get_custom_objects_api') + @mock.patch.object(kubernetes_utils, 'get_network') + def test_execute_correct(self, mock_get_net, mock_get_api): + mock_get_net.return_value = None + mock_api = mock.Mock() + mock_get_api.return_value = mock_api + group = 'group.com' + version = mock.Mock() + plural = 'networks' body = mock.Mock() + name = 'net_one' kubernetes_utils.create_network( - constants.SCOPE_CLUSTER, group, version, plural, body) + constants.SCOPE_CLUSTER, group, version, plural, body, name) mock_api.create_cluster_custom_object.assert_called_once_with( group, version, plural, body) mock_api.reset_mock() kubernetes_utils.create_network( - constants.SCOPE_NAMESPACED, group, version, plural, body) + constants.SCOPE_NAMESPACED, group, version, plural, body, name) mock_api.create_namespaced_custom_object.assert_called_once_with( group, version, 'default', plural, body) + @mock.patch.object(kubernetes_utils, 'get_custom_objects_api') + @mock.patch.object(kubernetes_utils, 'get_network') + def test_network_already_created(self, mock_get_net, mock_get_api): + mock_get_net.return_value = mock.Mock + mock_api = mock.Mock() + mock_get_api.return_value = mock_api + group = 'group.com' + version = mock.Mock() + plural = 'networks' + body = mock.Mock() + name = 'net_one' + + mock_api.reset_mock() + kubernetes_utils.create_network( + constants.SCOPE_CLUSTER, group, version, plural, body, name) + mock_api.create_cluster_custom_object.assert_not_called() + + mock_api.reset_mock() + kubernetes_utils.create_network( + constants.SCOPE_NAMESPACED, group, version, plural, body, name) + mock_api.create_namespaced_custom_object.assert_not_called() @mock.patch.object(kubernetes_utils, 'get_custom_objects_api') - def test_execute_exception(self, mock_get_api): + @mock.patch.object(kubernetes_utils, 'get_network') + def test_execute_exception(self, mock_get_net, mock_get_api): + mock_get_net.return_value = None mock_api = mock.Mock() mock_api.create_cluster_custom_object.side_effect = rest.ApiException mock_get_api.return_value = mock_api with self.assertRaises(exceptions.KubernetesApiException): kubernetes_utils.create_network( constants.SCOPE_CLUSTER, mock.ANY, mock.ANY, mock.ANY, - mock.ANY) + mock.ANY, mock.ANY) class DeleteNetworkTestCase(base.BaseUnitTestCase): diff --git a/yardstick/tests/unit/orchestrator/test_kubernetes.py b/yardstick/tests/unit/orchestrator/test_kubernetes.py index f248338ee..5a48fe573 100644 --- a/yardstick/tests/unit/orchestrator/test_kubernetes.py +++ b/yardstick/tests/unit/orchestrator/test_kubernetes.py @@ -491,9 +491,10 @@ class NetworkObjectTestCase(base.BaseUnitTestCase): net_obj._version = 'version' net_obj._plural = 'plural' net_obj._template = 'template' + net_obj._name = 'fake_name' net_obj.create() mock_create_network.assert_called_once_with( - 'scope', 'group', 'version', 'plural', 'template') + 'scope', 'group', 'version', 'plural', 'template', 'fake_name') @mock.patch.object(kubernetes_utils, 'delete_network') def test_delete(self, mock_delete_network): |