From 059ebc5469200911b901fe41cab29447fa9a9705 Mon Sep 17 00:00:00 2001 From: Jack Lucas Date: Wed, 27 Feb 2019 11:38:13 -0500 Subject: [PATCH] Add k8sclient unit tests Change-Id: I4b664865618bf87822af325e2c2dd43e71c0bdac Issue-ID: DCAEGEN2-1261 Signed-off-by: Jack Lucas --- k8s/.coveragerc | 21 ++++++++ k8s/LICENSE.txt | 2 +- k8s/k8s-node-type.yaml | 8 +-- k8s/k8sclient/k8sclient.py | 6 +-- k8s/pom.xml | 4 +- k8s/setup.py | 2 +- k8s/tests/test_k8sclient.py | 125 ++++++++++++++++++++++++++++++++++++++++++-- 7 files changed, 154 insertions(+), 14 deletions(-) create mode 100644 k8s/.coveragerc diff --git a/k8s/.coveragerc b/k8s/.coveragerc new file mode 100644 index 0000000..088c2da --- /dev/null +++ b/k8s/.coveragerc @@ -0,0 +1,21 @@ +# .coveragerc to control coverage.py +[run] +branch = True + +[report] +# Regexes for lines to exclude from consideration +exclude_lines = + # Have to re-enable the standard pragma + pragma: no cover + + # Don't complain about missing debug-only code: + def __repr__ + if self\.debug + + # Don't complain if tests don't hit defensive assertion code: + raise AssertionError + raise NotImplementedError + + # Don't complain if non-runnable code isn't run: + if 0: + if __name__ == .__main__.: diff --git a/k8s/LICENSE.txt b/k8s/LICENSE.txt index e266d0a..43098d1 100644 --- a/k8s/LICENSE.txt +++ b/k8s/LICENSE.txt @@ -1,7 +1,7 @@ ============LICENSE_START======================================================= org.onap.dcae ================================================================================ -Copyright (c) 2017-2018 AT&T Intellectual Property. All rights reserved. +Copyright (c) 2017-2019 AT&T Intellectual Property. All rights reserved. ================================================================================ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/k8s/k8s-node-type.yaml b/k8s/k8s-node-type.yaml index f63f822..166e430 100644 --- a/k8s/k8s-node-type.yaml +++ b/k8s/k8s-node-type.yaml @@ -19,13 +19,13 @@ tosca_definitions_version: cloudify_dsl_1_3 imports: - - http://www.getcloudify.org/spec/cloudify/4.2/types.yaml + - http://www.getcloudify.org/spec/cloudify/3.4/types.yaml plugins: k8s: executor: 'central_deployment_agent' package_name: k8splugin - package_version: 1.4.6 + package_version: 1.4.7 data_types: @@ -123,9 +123,9 @@ node_types: default: {} description: > This is used to specify the cpu and memory request and limit for container. - Please specify "requests" property and/or a "limits" property, with subproproperties + Please specify "requests" property and/or a "limits" property, with subproproperties for cpu and memory. (https://kubernetes.io/docs/concepts/configuration/manage-compute-resources-container/) - + log_info: type: dcae.types.LoggingInfo diff --git a/k8s/k8sclient/k8sclient.py b/k8s/k8sclient/k8sclient.py index 84ca84f..31631ad 100644 --- a/k8s/k8sclient/k8sclient.py +++ b/k8s/k8sclient/k8sclient.py @@ -38,7 +38,7 @@ FACTORS = {None: 1, "s": 1, "m": 60, "h": 3600} # group 3: protocol # group 4: host port PORTS = re.compile("^([0-9]+)(/(udp|UDP|tcp|TCP))?:([0-9]+)$") - + def _create_deployment_name(component_name): return "dep-{0}".format(component_name) @@ -126,7 +126,7 @@ def _create_resources(resources=None): resources_obj = client.V1ResourceRequirements( limits = resources.get("limits"), requests = resources.get("requests") - ) + ) return resources_obj else: return None @@ -398,9 +398,9 @@ def deploy(namespace, component_name, image, replicas, always_pull, k8sconfig, r } try: - _configure_api() # Get API handles + _configure_api() core = client.CoreV1Api() ext = client.ExtensionsV1beta1Api() diff --git a/k8s/pom.xml b/k8s/pom.xml index 844f214..45c5a39 100644 --- a/k8s/pom.xml +++ b/k8s/pom.xml @@ -1,7 +1,7 @@