X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=yardstick%2Fcommon%2Fkubernetes_utils.py;h=323f13abbff366a38cecd2b132270f1c9c776b26;hb=a562d505bf1549b41e93ecae4d8461f31851aa20;hp=f5b0443ea40d286182612affb3837c68ac524025;hpb=ead6f55e0cef44a601902f653f5c0f304a3dc01a;p=yardstick.git diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index f5b0443ea..323f13abb 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -121,8 +121,10 @@ def create_replication_controller(template, def delete_replication_controller(name, namespace='default', wait=False, - **kwargs): # pragma: no cover + skip_codes=None, + **kwargs): # pylint: disable=unused-argument + skip_codes = [] if not skip_codes else skip_codes core_v1_api = get_core_api() body = kwargs.get('body', client.V1DeleteOptions()) kwargs.pop('body', None) @@ -131,9 +133,12 @@ def delete_replication_controller(name, namespace, body, **kwargs) - except ApiException: - LOG.exception('Delete replication controller failed') - raise + except ApiException as e: + if e.status in skip_codes: + LOG.info(e.reason) + else: + raise exceptions.KubernetesApiException( + action='delete', resource='ReplicationController') def delete_pod(name, @@ -196,8 +201,10 @@ def create_config_map(name, def delete_config_map(name, namespace='default', wait=False, - **kwargs): # pragma: no cover + skip_codes=None, + **kwargs): # pylint: disable=unused-argument + skip_codes = [] if not skip_codes else skip_codes core_v1_api = get_core_api() body = kwargs.get('body', client.V1DeleteOptions()) kwargs.pop('body', None) @@ -206,9 +213,12 @@ def delete_config_map(name, namespace, body, **kwargs) - except ApiException: - LOG.exception('Delete config map failed') - raise + except ApiException as e: + if e.status in skip_codes: + LOG.info(e.reason) + else: + raise exceptions.KubernetesApiException( + action='delete', resource='ConfigMap') def create_custom_resource_definition(body): @@ -253,8 +263,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) @@ -266,7 +296,8 @@ def create_network(scope, group, version, plural, body, namespace='default'): action='create', resource='Custom Object: Network') -def delete_network(scope, group, version, plural, name, namespace='default'): +def delete_network(scope, group, version, plural, name, namespace='default', skip_codes=None): + skip_codes = [] if not skip_codes else skip_codes api = get_custom_objects_api() try: if scope == consts.SCOPE_CLUSTER: @@ -274,9 +305,12 @@ def delete_network(scope, group, version, plural, name, namespace='default'): else: api.delete_namespaced_custom_object( group, version, namespace, plural, name, {}) - except ApiException: - raise exceptions.KubernetesApiException( - action='delete', resource='Custom Object: Network') + except ApiException as e: + if e.status in skip_codes: + LOG.info(e.reason) + else: + raise exceptions.KubernetesApiException( + action='delete', resource='Custom Object: Network') def get_pod_list(namespace='default'): # pragma: no cover