From: Juha Kosonen Date: Tue, 16 Jan 2018 14:45:46 +0000 (+0200) Subject: Fix Rally output retrieval X-Git-Tag: opnfv-6.0.0~232^2 X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F03%2F50703%2F1;p=functest.git Fix Rally output retrieval Read stdout until nothing left instead of stopping once the child process is terminated. Change-Id: I46a2eb93fd614e2e7ff676727eb9dc132c29d03f Signed-off-by: Juha Kosonen --- diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index eefd3eb46..103c3a7e2 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -219,8 +219,7 @@ class RallyBase(testcase.TestCase): def get_cmd_output(proc): """Get command stdout.""" result = "" - while proc.poll() is None: - line = proc.stdout.readline() + for line in proc.stdout: result += line return result @@ -410,8 +409,7 @@ class RallyBase(testcase.TestCase): success = 0.0 nb_totals = 0 - while proc.poll() is None: - line = proc.stdout.readline() + for line in proc.stdout: if ("Load duration" in line or "started" in line or "finished" in line or diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index 450eb85bc..6b50daead 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -27,7 +27,6 @@ class OSRallyTesting(unittest.TestCase): with mock.patch('snaps.openstack.tests.openstack_tests.' 'get_credentials', return_value=os_creds) as m: self.rally_base = rally.RallyBase() - self.polling_iter = 2 self.assertTrue(m.called) def test_build_task_args_missing_floating_network(self): @@ -102,19 +101,11 @@ class OSRallyTesting(unittest.TestCase): self.assertEqual(self.rally_base.task_succeed(json_raw), True) - def polling(self): - if self.polling_iter == 0: - return "something" - self.polling_iter -= 1 - return None - def test_get_cmd_output(self): proc = mock.Mock() - attrs = {'poll.side_effect': self.polling, - 'stdout.readline.return_value': 'line'} - proc.configure_mock(**attrs) + proc.stdout.__iter__ = mock.Mock(return_value=iter(['line1', 'line2'])) self.assertEqual(self.rally_base.get_cmd_output(proc), - 'lineline') + 'line1line2') @mock.patch('__builtin__.open', mock.mock_open()) @mock.patch('functest.opnfv_tests.openstack.rally.rally.yaml.safe_load',