Added below tests for calicoctl-utility pod

- test_verify_readonly_rootfs
 - test_verify_calicoctl_pod_logs

Also added _get_pod_logs method to get logs of any utility pod.

Change-Id: I6b1294cda8c515d17eefef1f38e2250caf0aa690
This commit is contained in:
Geet Jain 2020-07-24 14:47:10 +05:30 committed by diwakar thyagaraj
parent 436e79e923
commit 44d77e9450
2 changed files with 45 additions and 0 deletions

View File

@ -186,6 +186,17 @@ class UtilityContainerClient(object):
'namespace'.format(
deployment_name, deployment_selectors, self.NAMESPACE))
def _get_pod_logs(self, deployment_name):
"""Method to get logs for a specific utility pod
:param deployment_name: if specified the deployment name of the utility pod
where the utilscli command is to be executed
:return: pod logs for specific pod
"""
pod = self._get_utility_container(deployment_name)
return self._corev1api_api_client.read_namespaced_pod_log(
pod.metadata.name, self.NAMESPACE)
def _get_exec_cmd_output(self, utility_container, ex_cmd, default=1):
"""Exec into a specific utility container, then execute the utilscli
command and return the output of the command

View File

@ -30,3 +30,37 @@ class TestCalicoUtilityContainer(TestBase):
self.assertIn(
expected, result_set, 'Unexpected value for command: {}, '
'Command Output: {}'.format(exec_cmd, result_set))
def test_verify_readonly_rootfs(self):
"""To verify calico-utility readonly rootfs configuration"""
failures = []
expected = "False"
calico_utility_pod = \
self.client._get_utility_container(self.deployment_name)
for container in calico_utility_pod.spec.containers:
if expected != \
str(container.security_context.read_only_root_filesystem):
failures.append(
f"container {container.name} is not having expected"
f" value {expected} set for read_only_root_filesystem"
f" in pod {calico_utility_pod.metadata.name}")
self.assertEqual(0, len(failures), failures)
def test_verify_calico_utility_pod_logs(self):
"""To verify calico-utility pod logs"""
date_1 = (self.client.exec_cmd(
self.deployment_name,
['date', '+%Y-%m-%d %H'])).replace('\n','')
date_2 = (self.client.exec_cmd(
self.deployment_name,
['date', '+%b %d %H'])).replace('\n','')
exec_cmd = ['utilscli', 'calicoctl', 'version']
self.client.exec_cmd(self.deployment_name, exec_cmd)
pod_logs = (self.client._get_pod_logs(self.deployment_name)). \
replace('\n','')
if date_1 in pod_logs:
latest_pod_logs = (pod_logs.split(date_1))[1:]
else:
latest_pod_logs = (pod_logs.split(date_2))[1:]
self.assertNotEqual(
0, len(latest_pod_logs), "Not able to get the latest logs")