From 42f601844447ebd5de1354f323e24326c55cf080 Mon Sep 17 00:00:00 2001 From: Konrad Djimeli Date: Thu, 26 Apr 2018 08:40:17 +0100 Subject: Update logging to log Errors, when they occur Enable logging of errors which can occur due to incorrect configfile, wrong KUBE_MASTER_URL or KUBE_MASTER_IP etc. Change-Id: I352ed0ab0376e9392d205decdc569bac6304ba27 Signed-off-by: Konrad Djimeli (cherry picked from commit 9f8e105025763e75273f430448518fea77a49d34) --- functest_kubernetes/k8stest.py | 2 ++ functest_kubernetes/test_k8stest.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+) (limited to 'functest_kubernetes') diff --git a/functest_kubernetes/k8stest.py b/functest_kubernetes/k8stest.py index 7d9400ed..2977bb81 100644 --- a/functest_kubernetes/k8stest.py +++ b/functest_kubernetes/k8stest.py @@ -51,6 +51,8 @@ class K8sTesting(testcase.TestCase): lines = output.split('\n') i = 0 while i < len(lines): + if 'Error' in lines[i]: + self.__logger.error(lines[i]) if '[k8s.io]' in lines[i]: if i != 0 and 'seconds' in lines[i - 1]: self.__logger.debug(lines[i - 1]) diff --git a/functest_kubernetes/test_k8stest.py b/functest_kubernetes/test_k8stest.py index 05f40e12..9db14d5a 100644 --- a/functest_kubernetes/test_k8stest.py +++ b/functest_kubernetes/test_k8stest.py @@ -66,6 +66,20 @@ class K8sTests(unittest.TestCase): with self.assertRaises(TypeError): self.k8stesting.run_kubetest() + @mock.patch('functest_kubernetes.k8stest.os.path.isfile') + def test_error_logging(self, mock_isfile): + # pylint: disable=unused-argument + with mock.patch('functest_kubernetes.k8stest.' + 'subprocess.Popen') as mock_popen, \ + mock.patch.object(self.k8stesting, + '_K8sTesting__logger') as mock_logger: + mock_stdout = mock.Mock() + attrs = {'stdout.read.return_value': 'Error loading client'} + mock_stdout.configure_mock(**attrs) + mock_popen.return_value = mock_stdout + self.k8stesting.run_kubetest() + mock_logger.error.assert_called_with("Error loading client") + @mock.patch('functest_kubernetes.k8stest.os.path.isfile') @mock.patch('functest_kubernetes.k8stest.subprocess.Popen') def test_run(self, mock_open, mock_isfile): -- cgit 1.2.3-korg