diff options
author | Linda Wang <wangwulin@huawei.com> | 2017-11-21 16:02:53 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2017-11-21 16:02:53 +0000 |
commit | 185dbcfb6ed774cc2f0478b05041d9e3a4e2f303 (patch) | |
tree | 38ba2eb76be4b8ef6d43405412b49cb676d499b3 | |
parent | e627ff2e267c1c59461571d23b89b21199e49737 (diff) | |
parent | 8335acdf080e4d31fd1dd70f11aa456b4795833a (diff) |
Merge "Fix "Broken pipe" IOErrors of rally run"
-rw-r--r-- | functest/opnfv_tests/openstack/rally/rally.py | 44 | ||||
-rw-r--r-- | functest/tests/unit/openstack/rally/test_rally.py | 5 |
2 files changed, 22 insertions, 27 deletions
diff --git a/functest/opnfv_tests/openstack/rally/rally.py b/functest/opnfv_tests/openstack/rally/rally.py index a4970fc2b..32a855f0f 100644 --- a/functest/opnfv_tests/openstack/rally/rally.py +++ b/functest/opnfv_tests/openstack/rally/rally.py @@ -344,27 +344,24 @@ class RallyBase(testcase.TestCase): LOGGER.info('No tests for scenario "%s"', test_name) return - cmd_line = ("rally task start --abort-on-sla-failure " - "--task {0} " - "--task-args \"{1}\"" - .format(task_file, self._build_task_args(test_name))) - LOGGER.debug('running command line: %s', cmd_line) - - proc = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, shell=True) + cmd = (["rally", "task", "start", "--abort-on-sla-failure", "--task", + task_file, "--task-args", + str(self._build_task_args(test_name))]) + LOGGER.debug('running command: %s', cmd) + + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) output = self._get_output(proc, test_name) task_id = self.get_task_id(output) LOGGER.debug('task_id : %s', task_id) if task_id is None: LOGGER.error('Failed to retrieve task_id, validating task...') - cmd_line = ("rally task validate " - "--task {0} " - "--task-args \"{1}\"" - .format(task_file, self._build_task_args(test_name))) - LOGGER.debug('running command line: %s', cmd_line) - proc = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, - stderr=subprocess.STDOUT, shell=True) + cmd = (["rally", "task", "validate", "--task", task_file, + "--task-args", str(self._build_task_args(test_name))]) + LOGGER.debug('running command: %s', cmd) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) output = self.get_cmd_output(proc) LOGGER.error("Task validation result:" + "\n" + output) return @@ -378,17 +375,18 @@ class RallyBase(testcase.TestCase): # write html report file report_html_name = 'opnfv-{}.html'.format(test_name) report_html_dir = os.path.join(self.RESULTS_DIR, report_html_name) - cmd_line = "rally task report {} --out {}".format(task_id, - report_html_dir) + cmd = (["rally", "task", "report", task_id, "--out", report_html_dir]) - LOGGER.debug('running command line: %s', cmd_line) - os.popen(cmd_line) + LOGGER.debug('running command: %s', cmd) + subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) # get and save rally operation JSON result - cmd_line = "rally task results %s" % task_id - LOGGER.debug('running command line: %s', cmd_line) - cmd = os.popen(cmd_line) - json_results = cmd.read() + cmd = (["rally", "task", "results", task_id]) + LOGGER.debug('running command: %s', cmd) + proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, + stderr=subprocess.STDOUT) + json_results = self.get_cmd_output(proc) report_json_name = 'opnfv-{}.json'.format(test_name) report_json_dir = os.path.join(self.RESULTS_DIR, report_json_name) with open(report_json_dir, 'w') as r_file: diff --git a/functest/tests/unit/openstack/rally/test_rally.py b/functest/tests/unit/openstack/rally/test_rally.py index 83f0c86a3..450eb85bc 100644 --- a/functest/tests/unit/openstack/rally/test_rally.py +++ b/functest/tests/unit/openstack/rally/test_rally.py @@ -260,13 +260,10 @@ class OSRallyTesting(unittest.TestCase): return_value=True) @mock.patch('functest.opnfv_tests.openstack.rally.rally.subprocess.Popen') @mock.patch('functest.opnfv_tests.openstack.rally.rally.os.makedirs') - @mock.patch('functest.opnfv_tests.openstack.rally.rally.os.popen') @mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.info') @mock.patch('functest.opnfv_tests.openstack.rally.rally.LOGGER.error') def test_run_task_default(self, mock_logger_error, mock_logger_info, - mock_popen, *args): - attrs = {'read.return_value': 'json_result'} - mock_popen.return_value.configure_mock(**attrs) + *args): self.rally_base._run_task('test_name') text = 'Test scenario: "test_name" OK.\n' mock_logger_info.assert_any_call(text) |