aboutsummaryrefslogtreecommitdiffstats
path: root/src/onaptests/steps/cloud
diff options
context:
space:
mode:
Diffstat (limited to 'src/onaptests/steps/cloud')
-rw-r--r--src/onaptests/steps/cloud/check_status.py62
-rw-r--r--src/onaptests/steps/cloud/complex_create.py2
-rw-r--r--src/onaptests/steps/cloud/customer_create.py2
-rw-r--r--src/onaptests/steps/cloud/expose_service_node_port.py29
-rw-r--r--src/onaptests/steps/cloud/k8s_connectivity_info_create.py9
-rw-r--r--src/onaptests/steps/cloud/register_cloud.py2
-rw-r--r--src/onaptests/steps/cloud/resources.py6
7 files changed, 72 insertions, 40 deletions
diff --git a/src/onaptests/steps/cloud/check_status.py b/src/onaptests/steps/cloud/check_status.py
index cbefa18..b3fab03 100644
--- a/src/onaptests/steps/cloud/check_status.py
+++ b/src/onaptests/steps/cloud/check_status.py
@@ -24,6 +24,7 @@ from .resources import (ConfigMap, Container, DaemonSet, Deployment, Ingress,
class CheckK8sResourcesStep(BaseStep):
+ """Base step for check of k8s resources in the selected namespace."""
__logger = logging.getLogger(__name__)
@@ -110,6 +111,7 @@ class CheckK8sResourcesStep(BaseStep):
class CheckBasicK8sResourcesStep(CheckK8sResourcesStep):
+ """Basic check of k8s resources in the selected namespace."""
def __init__(self, namespace: str, resource_type: str, k8s_res_class):
"""Init CheckBasicK8sResourcesStep."""
@@ -129,6 +131,7 @@ class CheckBasicK8sResourcesStep(CheckK8sResourcesStep):
class CheckK8sConfigMapsStep(CheckBasicK8sResourcesStep):
+ """Check of k8s configmap in the selected namespace."""
def __init__(self, namespace: str):
"""Init CheckK8sConfigMapsStep."""
@@ -140,6 +143,7 @@ class CheckK8sConfigMapsStep(CheckBasicK8sResourcesStep):
class CheckK8sSecretsStep(CheckBasicK8sResourcesStep):
+ """Check of k8s secrets in the selected namespace."""
def __init__(self, namespace: str):
"""Init CheckK8sSecretsStep."""
@@ -151,6 +155,7 @@ class CheckK8sSecretsStep(CheckBasicK8sResourcesStep):
class CheckK8sIngressesStep(CheckBasicK8sResourcesStep):
+ """Check of k8s ingress in the selected namespace."""
def __init__(self, namespace: str):
"""Init CheckK8sIngressesStep."""
@@ -162,6 +167,7 @@ class CheckK8sIngressesStep(CheckBasicK8sResourcesStep):
class CheckK8sPvcsStep(CheckK8sResourcesStep):
+ """Check of k8s pvcs in the selected namespace."""
def __init__(self, namespace: str):
"""Init CheckK8sPvcsStep."""
@@ -194,6 +200,7 @@ class CheckK8sPvcsStep(CheckK8sResourcesStep):
class CheckK8sResourcesUsingPodsStep(CheckK8sResourcesStep):
+ """Check of k8s respurces with pods in the selected namespace."""
def __init__(self, namespace: str, resource_type: str, pods_source):
"""Init CheckK8sResourcesUsingPodsStep."""
@@ -231,6 +238,7 @@ class CheckK8sResourcesUsingPodsStep(CheckK8sResourcesStep):
class CheckK8sJobsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s jobs in the selected namespace."""
__logger = logging.getLogger(__name__)
@@ -273,12 +281,13 @@ class CheckK8sJobsStep(CheckK8sResourcesUsingPodsStep):
if not any(waiver_elt in job.name for waiver_elt in settings.WAIVER_LIST):
self.all_resources.append(job)
else:
- self.__logger.warn(
+ self.__logger.warning(
"Waiver pattern found in job, exclude %s", job.name)
jobs_pods += job_pods
class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s pods in the selected namespace."""
__logger = logging.getLogger(__name__)
@@ -400,7 +409,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
self.jinja_env.get_template('pod.html.j2').stream(pod=pod).dump(
'{}/pod-{}.html'.format(self.res_dir, pod.name))
if any(waiver_elt in pod.name for waiver_elt in settings.WAIVER_LIST):
- self.__logger.warn("Waiver pattern found in pod, exclude %s", pod.name)
+ self.__logger.warning("Waiver pattern found in pod, exclude %s", pod.name)
else:
self.all_resources.append(pod)
@@ -412,7 +421,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
containers=containers).dump('{}/container_versions.html'.format(
self.res_dir))
# create a json file for version tracking
- with open(self.res_dir + "/onap_versions.json", "w") as write_file:
+ with open(self.res_dir + "/onap_versions.json", "w", encoding="utf-8") as write_file:
json.dump(pod_versions, write_file)
def _get_container_logs(self, pod, container, full=True, previous=False):
@@ -430,9 +439,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
)
except UnicodeDecodeError:
logs = "{0} has an unicode decode error...".format(pod.name)
- self.__logger.error(
- "{0} has an unicode decode error in the logs...", pod.name,
- )
+ self.__logger.error(logs)
return logs
def _parse_container(self, pod, k8s_container, init=False): # noqa
@@ -463,7 +470,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
with open(
"{}/pod-{}-{}.log".format(self.res_dir,
pod.name, container.name),
- 'w') as log_result:
+ 'w', encoding="utf-8") as log_result:
log_result.write(logs)
if (not container.ready) and container.restart_count > 0:
old_logs = self._get_container_logs(pod=pod, container=container,
@@ -472,16 +479,16 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
"{}/pod-{}-{}.old.log".format(self.res_dir,
pod.name,
container.name),
- 'w') as log_result:
+ 'w', encoding="utf-8") as log_result:
log_result.write(old_logs)
- if (container.name in settings.FULL_LOGS_CONTAINERS):
+ if container.name in settings.FULL_LOGS_CONTAINERS:
logs = self._get_container_logs(pod=pod, container=container)
with open(
"{}/pod-{}-{}.log".format(self.res_dir,
pod.name, container.name),
- 'w') as log_result:
+ 'w', encoding="utf-8") as log_result:
log_result.write(logs)
- if (container.name in settings.SPECIFIC_LOGS_CONTAINERS):
+ if container.name in settings.SPECIFIC_LOGS_CONTAINERS:
for log_file in settings.SPECIFIC_LOGS_CONTAINERS[container.name]:
exec_command = ['/bin/sh', '-c', "cat {}".format(log_file)]
log_files[log_file] = stream(
@@ -499,7 +506,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
"{}/pod-{}-{}-{}.log".format(
self.res_dir, pod.name,
container.name, log_file_slug),
- 'w') as log_result:
+ 'w', encoding="utf-8") as log_result:
log_result.write(log_files[log_file])
except client.rest.ApiException as exc:
self.__logger.warning("%scontainer %s of pod %s has an exception: %s",
@@ -512,7 +519,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
log_files=log_files).dump('{}/pod-{}-{}-logs.html'.format(
self.res_dir, pod.name, container.name))
if any(waiver_elt in container.name for waiver_elt in settings.WAIVER_LIST):
- self.__logger.warn(
+ self.__logger.warning(
"Waiver pattern found in container, exclude %s", container.name)
else:
containers_list.append(container)
@@ -522,6 +529,7 @@ class CheckK8sPodsStep(CheckK8sResourcesUsingPodsStep):
class CheckK8sServicesStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s services in the selected namespace."""
def __init__(self, namespace: str, pods):
"""Init CheckK8sServicesStep."""
@@ -547,6 +555,7 @@ class CheckK8sServicesStep(CheckK8sResourcesUsingPodsStep):
class CheckK8sDeploymentsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s deployments in the selected namespace."""
def __init__(self, namespace: str, pods):
"""Init CheckK8sDeploymentsStep."""
@@ -585,6 +594,7 @@ class CheckK8sDeploymentsStep(CheckK8sResourcesUsingPodsStep):
class CheckK8sReplicaSetsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s replicasets in the selected namespace."""
def __init__(self, namespace: str, pods):
"""Init CheckK8sReplicaSetsStep."""
@@ -625,6 +635,7 @@ class CheckK8sReplicaSetsStep(CheckK8sResourcesUsingPodsStep):
class CheckK8sStatefulSetsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s statefulsets in the selected namespace."""
def __init__(self, namespace: str, pods):
"""Init CheckK8sStatefulSetsStep."""
@@ -665,6 +676,7 @@ class CheckK8sStatefulSetsStep(CheckK8sResourcesUsingPodsStep):
class CheckK8sDaemonSetsStep(CheckK8sResourcesUsingPodsStep):
+ """Check of k8s daemonsets in the selected namespace."""
def __init__(self, namespace: str, pods):
"""Init CheckK8sDaemonSetsStep."""
@@ -694,7 +706,7 @@ class CheckK8sDaemonSetsStep(CheckK8sResourcesUsingPodsStep):
daemonset=daemonset).dump('{}/daemonset-{}.html'.format(
self.res_dir, daemonset.name))
- if (k8s.status.number_ready < k8s.status.desired_number_scheduled):
+ if k8s.status.number_ready < k8s.status.desired_number_scheduled:
self._add_failing_resource(daemonset)
self.all_resources.append(daemonset)
@@ -716,6 +728,24 @@ class CheckNamespaceStatusStep(CheckK8sResourcesStep):
for namespace in ([self.namespace] + settings.EXTRA_NAMESPACE_LIST):
self._init_namespace_steps(namespace)
+ self.pods = []
+ self.services = []
+ self.jobs = []
+ self.deployments = []
+ self.replicasets = []
+ self.statefulsets = []
+ self.daemonsets = []
+ self.pvcs = []
+ self.configmaps = []
+ self.secrets = []
+ self.ingresses = []
+ self.failing_statefulsets = []
+ self.failing_jobs = []
+ self.failing_deployments = []
+ self.failing_replicasets = []
+ self.failing_daemonsets = []
+ self.failing_pvcs = []
+
def _init_namespace_steps(self, namespace: str):
self.job_list_step = CheckK8sJobsStep(namespace)
self.pod_list_step = CheckK8sPodsStep(namespace, self.job_list_step)
@@ -820,10 +850,12 @@ class CheckNamespaceStatusStep(CheckK8sResourcesStep):
ns_details = ns_details[step.namespace]
store_results(ns_details, step)
- with (Path(self.res_dir).joinpath(settings.STATUS_DETAILS_JSON)).open('w') as file:
+ with (Path(self.res_dir).joinpath(settings.STATUS_DETAILS_JSON)
+ ).open('w', encoding="utf-8") as file:
json.dump(details, file, indent=4)
if self.failing:
raise StatusCheckException
def map_by_name(self, resources):
+ """Get resources' names."""
return list(map(lambda resource: resource.name, resources))
diff --git a/src/onaptests/steps/cloud/complex_create.py b/src/onaptests/steps/cloud/complex_create.py
index 96d8e7f..7afad16 100644
--- a/src/onaptests/steps/cloud/complex_create.py
+++ b/src/onaptests/steps/cloud/complex_create.py
@@ -38,4 +38,4 @@ class ComplexCreateStep(BaseStep):
data_center_code=settings.COMPLEX_DATA_CENTER_CODE,
name=settings.COMPLEX_PHYSICAL_LOCATION_ID)
except APIError:
- self._logger.warn("Try to update the complex failed.")
+ self._logger.warning("Try to update the complex failed.")
diff --git a/src/onaptests/steps/cloud/customer_create.py b/src/onaptests/steps/cloud/customer_create.py
index 96d192a..7bffb1a 100644
--- a/src/onaptests/steps/cloud/customer_create.py
+++ b/src/onaptests/steps/cloud/customer_create.py
@@ -33,4 +33,4 @@ class CustomerCreateStep(BaseStep):
try:
Customer.create(settings.GLOBAL_CUSTOMER_ID, settings.GLOBAL_CUSTOMER_ID, "INFRA")
except APIError:
- self._logger.warn("Try to update the Customer failed.")
+ self._logger.warning("Try to update the Customer failed.")
diff --git a/src/onaptests/steps/cloud/expose_service_node_port.py b/src/onaptests/steps/cloud/expose_service_node_port.py
index 1f43a65..4f6eecc 100644
--- a/src/onaptests/steps/cloud/expose_service_node_port.py
+++ b/src/onaptests/steps/cloud/expose_service_node_port.py
@@ -22,10 +22,6 @@ class ExposeServiceNodePortStep(BaseStep):
self.service_name = service_name
self.port = port
self.node_port = node_port
- if settings.IN_CLUSTER:
- config.load_incluster_config()
- else:
- config.load_kube_config(config_file=settings.K8S_CONFIG)
self.k8s_client: client.CoreV1Api = client.CoreV1Api()
@property
@@ -53,9 +49,9 @@ class ExposeServiceNodePortStep(BaseStep):
settings.K8S_ONAP_NAMESPACE
)
return service_data.spec.type == "NodePort"
- except ApiException:
+ except ApiException as exc:
self._logger.exception("Kubernetes API exception")
- raise OnapTestException
+ raise OnapTestException from exc
@BaseStep.store_state
def execute(self) -> None:
@@ -68,6 +64,10 @@ class ExposeServiceNodePortStep(BaseStep):
"""
super().execute()
+ if settings.IN_CLUSTER:
+ config.load_incluster_config()
+ else:
+ config.load_kube_config(config_file=settings.K8S_CONFIG)
if not self.is_service_node_port_type():
try:
self.k8s_client.patch_namespaced_service(
@@ -77,15 +77,16 @@ class ExposeServiceNodePortStep(BaseStep):
"nodePort": self.node_port}],
"type": "NodePort"}}
)
- except ApiException:
+ except ApiException as exc:
self._logger.exception("Kubernetes API exception")
- raise OnapTestException
- except urllib3.exceptions.HTTPError:
+ raise OnapTestException from exc
+ except urllib3.exceptions.HTTPError as exc:
self._logger.exception("Can't connect with k8s")
- raise OnapTestException
+ raise OnapTestException from exc
else:
self._logger.debug("Service already patched, skip")
+ @BaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
"""Step cleanup.
@@ -109,12 +110,12 @@ class ExposeServiceNodePortStep(BaseStep):
}
]
)
- except ApiException:
+ except ApiException as exc:
self._logger.exception("Kubernetes API exception")
- raise OnapTestException
- except urllib3.exceptions.HTTPError:
+ raise OnapTestException from exc
+ except urllib3.exceptions.HTTPError as exc:
self._logger.exception("Can't connect with k8s")
- raise OnapTestException
+ raise OnapTestException from exc
else:
self._logger.debug("Service is not 'NodePort' type, skip")
return super().cleanup()
diff --git a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py
index c22df47..410ac47 100644
--- a/src/onaptests/steps/cloud/k8s_connectivity_info_create.py
+++ b/src/onaptests/steps/cloud/k8s_connectivity_info_create.py
@@ -42,7 +42,7 @@ class K8SConnectivityInfoStep(BaseStep):
except APIError:
if settings.IN_CLUSTER:
token_file = "/var/run/secrets/kubernetes.io/serviceaccount/token"
- with open(token_file, "r") as file:
+ with open(token_file, "r", encoding="utf-8") as file:
user_token_value = file.read().strip()
jinja_env = Environment(autoescape=select_autoescape(['json.j2']),
loader=PackageLoader('onaptests.templates', 'kubeconfig'))
@@ -56,9 +56,10 @@ class K8SConnectivityInfoStep(BaseStep):
kubeconfig_data.encode('utf-8'))
else:
self._logger.info("Create the k8s connectivity information")
- ConnectivityInfo.create(settings.CLOUD_REGION_ID,
- settings.CLOUD_REGION_CLOUD_OWNER,
- open(settings.K8S_CONFIG, 'rb').read())
+ with open(settings.K8S_CONFIG, 'rb') as k8s_config:
+ ConnectivityInfo.create(settings.CLOUD_REGION_ID,
+ settings.CLOUD_REGION_CLOUD_OWNER,
+ k8s_config.read())
@BaseStep.store_state(cleanup=True)
def cleanup(self) -> None:
diff --git a/src/onaptests/steps/cloud/register_cloud.py b/src/onaptests/steps/cloud/register_cloud.py
index fbfb6f3..5035f86 100644
--- a/src/onaptests/steps/cloud/register_cloud.py
+++ b/src/onaptests/steps/cloud/register_cloud.py
@@ -5,9 +5,9 @@ from uuid import uuid4
from onapsdk.aai.cloud_infrastructure import CloudRegion
from onapsdk.configuration import settings
from onapsdk.exceptions import ResourceNotFound
+from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep
from ..base import BaseStep
-from onaptests.steps.cloud.cloud_region_create import CloudRegionCreateStep
class RegisterCloudRegionStep(BaseStep):
diff --git a/src/onaptests/steps/cloud/resources.py b/src/onaptests/steps/cloud/resources.py
index f00b60e..775d574 100644
--- a/src/onaptests/steps/cloud/resources.py
+++ b/src/onaptests/steps/cloud/resources.py
@@ -23,7 +23,6 @@ class K8sResource():
def specific_k8s_init(self):
"""Do the specific part for k8s resource when k8s object is present."""
- pass
def __repr__(self):
return self.name
@@ -32,10 +31,9 @@ class K8sResource():
return self.name
def __eq__(self, other):
- if (isinstance(other, K8sResource)):
+ if isinstance(other, K8sResource):
return self.name == other.name
- else:
- return False
+ return False
class K8sPodParentResource(K8sResource):