Add ability to pass deployment successfully
if required namespace already exists.
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index 7d9b142..d84fd73 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -21,7 +21,7 @@
from tcp_tests import logger
from tcp_tests.managers.execute_commands import ExecuteCommandsMixin
from tcp_tests.managers.k8s import cluster
-
+from k8sclient.client.rest import ApiException
LOG = logger.logger
@@ -275,12 +275,20 @@
:param name: str
:rtype: K8sNamespace object
"""
- LOG.info("Creating Namespace in k8s cluster")
- ns = self.api.namespaces.create(body={'metadata': {'name': name}})
- LOG.info("Namespace '{0}' is created".format(ns.name))
- # wait 10 seconds until a token for new service account is created
- time.sleep(10)
- return self.api.namespaces.get(name=ns.name)
+ try:
+ ns = self.api.namespaces.get(name=name)
+ LOG.info("Namespace '{0}' is already exists".format(ns.name))
+ except ApiException as e:
+ if hasattr(e,"status") and 404 == e.status:
+ LOG.info("Creating Namespace in k8s cluster")
+ ns = self.api.namespaces.create(body={'metadata': {'name': name}})
+ LOG.info("Namespace '{0}' is created".format(ns.name))
+ # wait 10 seconds until a token for new service account is created
+ time.sleep(10)
+ ns = self.api.namespaces.get(name=ns.name)
+ else:
+ raise
+ return ns
def create_objects(self, path):
if isinstance(path, str):