From d0c9fc59e53cace276093f8785fbdcd16fb1d2aa Mon Sep 17 00:00:00 2001 From: John O Loughlin Date: Fri, 13 Jul 2018 10:41:15 +0100 Subject: 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 --- yardstick/common/kubernetes_utils.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'yardstick/common') diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index 42267fc41..d1dd42173 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -241,8 +241,28 @@ def get_custom_resource_definition(kind): action='delete', resource='CustomResourceDefinition') -def create_network(scope, group, version, plural, body, namespace='default'): +def get_network(scope, group, version, plural, name, namespace='default'): api = get_custom_objects_api() + try: + if scope == consts.SCOPE_CLUSTER: + network = api.get_cluster_custom_object(group, version, plural, name) + else: + network = api.get_namespaced_custom_object( + group, version, namespace, plural, name) + except ApiException as e: + if e.status in [404]: + return + else: + raise exceptions.KubernetesApiException( + action='get', resource='Custom Object: Network') + return network + + +def create_network(scope, group, version, plural, body, name, namespace='default'): + api = get_custom_objects_api() + if get_network(scope, group, version, plural, name, namespace): + logging.info('Network %s already exists', name) + return try: if scope == consts.SCOPE_CLUSTER: api.create_cluster_custom_object(group, version, plural, body) -- cgit 1.2.3-korg