diff options
author | Rodolfo Alonso Hernandez <rodolfo.alonso.hernandez@intel.com> | 2018-07-06 09:00:09 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2018-07-06 09:00:09 +0000 |
commit | 093ab6a10558456c0cf61091d69648638e311143 (patch) | |
tree | ad7d05d6ebbddc9fa0e5e36f6f4d4532662bd3de /yardstick/common | |
parent | 1b8b08285fdf58e08ede154bc751cd7f66d76afd (diff) | |
parent | fa269e3789d19f1335ae9207817203c6ad58cf42 (diff) |
Merge "Add new Kubernetes resource kind: "CustomResourceDefinition""
Diffstat (limited to 'yardstick/common')
-rw-r--r-- | yardstick/common/constants.py | 4 | ||||
-rw-r--r-- | yardstick/common/exceptions.py | 16 | ||||
-rw-r--r-- | yardstick/common/kubernetes_utils.py | 39 |
3 files changed, 56 insertions, 3 deletions
diff --git a/yardstick/common/constants.py b/yardstick/common/constants.py index 1ebd32509..2f14d4bc4 100644 --- a/yardstick/common/constants.py +++ b/yardstick/common/constants.py @@ -171,3 +171,7 @@ TESTSUITE_PRE = 'opnfv_' # OpenStack cloud default config parameters OS_CLOUD_DEFAULT_CONFIG = {'verify': False} + +# Kubernetes +SCOPE_NAMESPACED = 'Namespaced' +SCOPE_CLUSTER = 'Cluster' diff --git a/yardstick/common/exceptions.py b/yardstick/common/exceptions.py index 935c77866..981e6f9d9 100644 --- a/yardstick/common/exceptions.py +++ b/yardstick/common/exceptions.py @@ -14,6 +14,8 @@ from oslo_utils import excutils +from yardstick.common import constants + class ProcessExecutionError(RuntimeError): def __init__(self, message, returncode): @@ -199,10 +201,24 @@ class WaitTimeout(YardstickException): message = 'Wait timeout while waiting for condition' +class KubernetesApiException(YardstickException): + message = ('Kubernetes API errors. Action: %(action)s, ' + 'resource: %(resource)s') + + +class KubernetesConfigFileNotFound(YardstickException): + message = 'Config file (%s) not found' % constants.K8S_CONF_FILE + + class KubernetesTemplateInvalidVolumeType(YardstickException): message = 'No valid "volume" types present in %(volume)s' +class KubernetesCRDObjectDefinitionError(YardstickException): + message = ('Kubernetes Custom Resource Definition Object error, missing ' + 'parameters: %(missing_parameters)s') + + class ScenarioCreateNetworkError(YardstickException): message = 'Create Neutron Network Scenario failed' diff --git a/yardstick/common/kubernetes_utils.py b/yardstick/common/kubernetes_utils.py index ee8e8edcd..a472b6de5 100644 --- a/yardstick/common/kubernetes_utils.py +++ b/yardstick/common/kubernetes_utils.py @@ -13,6 +13,8 @@ from kubernetes import config from kubernetes.client.rest import ApiException from yardstick.common import constants as consts +from yardstick.common import exceptions + LOG = logging.getLogger(__name__) LOG.setLevel(logging.DEBUG) @@ -22,12 +24,18 @@ def get_core_api(): # pragma: no cover try: config.load_kube_config(config_file=consts.K8S_CONF_FILE) except IOError: - LOG.exception('config file not found') - raise - + raise exceptions.KubernetesConfigFileNotFound() return client.CoreV1Api() +def get_extensions_v1beta_api(): + try: + config.load_kube_config(config_file=consts.K8S_CONF_FILE) + except IOError: + raise exceptions.KubernetesConfigFileNotFound() + return client.ApiextensionsV1beta1Api() + + def get_node_list(**kwargs): # pragma: no cover core_v1_api = get_core_api() try: @@ -187,6 +195,31 @@ def delete_config_map(name, raise +def create_custom_resource_definition(body): + api = get_extensions_v1beta_api() + body_obj = client.V1beta1CustomResourceDefinition( + spec=body['spec'], metadata=body['metadata']) + try: + api.create_custom_resource_definition(body_obj) + except ValueError: + # NOTE(ralonsoh): bug in kubernetes-client/python 6.0.0 + # https://github.com/kubernetes-client/python/issues/491 + pass + except ApiException: + raise exceptions.KubernetesApiException( + action='create', resource='CustomResourceDefinition') + + +def delete_custom_resource_definition(name): + api = get_extensions_v1beta_api() + body_obj = client.V1DeleteOptions() + try: + api.delete_custom_resource_definition(name, body_obj) + except ApiException: + raise exceptions.KubernetesApiException( + action='delete', resource='CustomResourceDefinition') + + def get_pod_list(namespace='default'): # pragma: no cover core_v1_api = get_core_api() try: |