Update k8s-ha-calico template and change conformance approach
Related-PROD: PROD-25978
Change-Id: Ie0e3ef34e5e82f09c845b7fa6befac060a95b805
diff --git a/tcp_tests/managers/k8smanager.py b/tcp_tests/managers/k8smanager.py
index 79974d3..3ae1a1b 100644
--- a/tcp_tests/managers/k8smanager.py
+++ b/tcp_tests/managers/k8smanager.py
@@ -41,6 +41,7 @@
self._api = None
self.kubectl = K8SKubectlCli(self)
self.virtlet = K8SVirtlet(self)
+ self.conformance_node = None
super(K8SManager, self).__init__(config=config, underlay=underlay)
def install(self, commands):
@@ -299,6 +300,61 @@
timeout_msg="Timeout for CNCF reached."
)
+ def start_conformance_inside_pod(self, cnf_type='k8s', timeout=60 * 60):
+ """
+ Create conformance pod and wait for results
+ :param cnf_type: k8s or virtlet. choose what conformance you want
+ :param timeout:
+ :return:
+ """
+ if cnf_type == 'k8s':
+ pod_mark = 'conformance'
+ elif cnf_type == 'virtlet':
+ pod_mark = 'virtlet-conformance'
+ else:
+ LOG.error("Unknown conformance type or it even not set")
+ raise RuntimeError("Unknown conformance type")
+ conformance_cmd = "kubectl apply -f /srv/kubernetes/{}.yml" \
+ "".format(pod_mark)
+ self.controller_check_call(conformance_cmd, timeout=900)
+
+ cnf_pod = self.api.pods.get(pod_mark, pod_mark)
+ cnf_pod.wait_running()
+
+ pod = cnf_pod.read()
+ target = "{}.".format(pod.spec.node_name)
+ self.conformance_node = self.__underlay.get_target_node_names(
+ target)[0]
+
+ def cnf_status():
+ pod = cnf_pod.read()
+ status = pod.status.phase
+ LOG.info("Conformance status: {}".format(status))
+ return status
+
+ LOG.info("Waiting for Conformance to complete")
+ helpers.wait(
+ lambda: cnf_status() == ('Succeeded' or 'Failed'),
+ interval=120, timeout=timeout,
+ timeout_msg="Timeout for Conformance reached."
+ )
+
+ pod = cnf_pod.read()
+ status = pod.status.phase
+ if status is 'Failed':
+ describe = "kubectl describe po {0} -n {0}".format(pod_mark)
+ LOG.info(self.controller_check_call(describe, timeout=30))
+ raise RuntimeError("Conformance failed")
+
+ def move_file_to_root_folder(self, filepath):
+ cmd = "mv {0} /root/".format(filepath)
+ if self.conformance_node:
+ self.__underlay.check_call(
+ cmd=cmd, node_name=self.conformance_node,
+ raise_on_err=False)
+ else:
+ LOG.info("Node is not properly set")
+
def extract_file_to_node(self, system='docker',
container='virtlet',
file_path='report.xml',
@@ -343,11 +399,16 @@
:param files:
:return:
"""
+ if self.conformance_node:
+ node = self.conformance_node
+ else:
+ node = self.controller_name
+ LOG.info("Trying to get logs at {}".format(node))
master_host = self.__config.salt.salt_master_host
with self.__underlay.remote(host=master_host) as r:
for log_file in files:
cmd = "rsync -r \"{0}:/root/{1}\" /root/".format(
- self.controller_name, log_file)
+ node, log_file)
r.check_call(cmd, raise_on_err=False)
LOG.info("Downloading the artifact {0}".format(log_file))
r.download(destination=log_file, target=os.getcwd())
@@ -362,7 +423,12 @@
:param output: Path to xml file where output will stored
:return:
"""
- with self.__underlay.remote(node_name=self.controller_name) as r:
+ if self.conformance_node:
+ node = self.conformance_node
+ else:
+ node = self.controller_name
+ LOG.info("Trying to combine xunit at {}".format(node))
+ with self.__underlay.remote(node_name=node) as r:
cmd = ("apt-get install python-setuptools -y; "
"pip install "
"https://github.com/mogaika/xunitmerge/archive/master.zip")