From dcae559e53f86c708ddd8f6922836fe7137ddb25 Mon Sep 17 00:00:00 2001 From: "dt241s@att.com" Date: Mon, 17 Aug 2020 21:33:43 +0000 Subject: [PATCH] Add Below test Cases to Postgres Utility Container 1) verify readonly. 2) verify postgresql utility Pod Logs Change-Id: Ib786b0561c6713bba0f1f62fae9739b629bea503 --- .../test_postgresql_utility_container.py | 35 ++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/kube_utility_container/tests/utility/postgresql/test_postgresql_utility_container.py b/kube_utility_container/tests/utility/postgresql/test_postgresql_utility_container.py index b080fa39..dbb7cddb 100644 --- a/kube_utility_container/tests/utility/postgresql/test_postgresql_utility_container.py +++ b/kube_utility_container/tests/utility/postgresql/test_postgresql_utility_container.py @@ -16,13 +16,46 @@ import unittest from kube_utility_container.tests.utility.base import TestBase - class TestPostgresqlUtilityContainer(TestBase): @classmethod def setUpClass(cls): cls.deployment_name = 'postgresql-utility' super(TestPostgresqlUtilityContainer, cls).setUpClass() + def test_verify_readonly_rootfs(self): + """To verify postgresql-utility readonly rootfs configuration""" + failures = [] + expected = "False" + postgresql_utility_pod = \ + self.client._get_utility_container(self.deployment_name) + for container in postgresql_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 {postgresql_utility_pod.metadata.name}") + self.assertEqual(0, len(failures), failures) + + def test_verify_postgresql_utility_pod_logs(self): + """To verify postgresql-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', 'psql', '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") + def test_verify_postgresql_client_psql_is_present(self): """To verify psql-client is present""" exec_cmd = ['utilscli', 'psql' , '-V']