From b669145ffded2932d1d4068d1f92a2f97142cd2c Mon Sep 17 00:00:00 2001 From: "Vladimir Sharshov (warpc)" Date: Tue, 19 Apr 2016 15:58:36 +0300 Subject: [PATCH] Fix problem with explitly file path for deployment info actions Also this patch fix problem with extra .yaml for file name if we save content to non-default path. For example, call fuel2 task settings download 15 -f /tmp/networks.yaml save info to /tmp/networks.yaml.yaml instead of /tmp/networks.yaml without this patch. Change-Id: I6beda8b47007a77f0e29abfda30e423b71af277b Closes-Bug: #1572098 (cherry picked from commit 46c84c105f726795daf83e16e240f10d9061e03b) --- fuelclient/commands/task.py | 27 ++++++++++++++--------- fuelclient/tests/unit/v2/cli/test_task.py | 14 +++++++++--- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/fuelclient/commands/task.py b/fuelclient/commands/task.py index fa5405b..329f46d 100644 --- a/fuelclient/commands/task.py +++ b/fuelclient/commands/task.py @@ -50,10 +50,17 @@ class TaskMixIn(object): :return: path to resulting file :rtype: str """ - return (serializer or Serializer()).write_to_path( - (file_path or cls.get_default_info_path(info_type, - transaction_id)), - data) + serializer = serializer or Serializer() + if file_path: + return serializer.write_to_full_path( + file_path, + data + ) + else: + return serializer.write_to_path( + cls.get_default_info_path(info_type, transaction_id), + data + ) @staticmethod def get_default_info_path(info_type, transaction_id): @@ -88,12 +95,12 @@ class TaskMixIn(object): :rtype: str """ data = self.client.download(transaction_id=transaction_id) - data_file_path = TaskMixIn.write_info_to_file( - info_type, - data, - transaction_id, - file_path) - return data_file_path + return self.write_info_to_file( + info_type=info_type, + data=data, + transaction_id=transaction_id, + serializer=Serializer(), + file_path=file_path) class TaskInfoFileMixIn(TaskMixIn): diff --git a/fuelclient/tests/unit/v2/cli/test_task.py b/fuelclient/tests/unit/v2/cli/test_task.py index c54d3cd..73653b6 100644 --- a/fuelclient/tests/unit/v2/cli/test_task.py +++ b/fuelclient/tests/unit/v2/cli/test_task.py @@ -15,6 +15,7 @@ # under the License. import mock +import os import yaml from fuelclient.tests.unit.v2.cli import test_engine @@ -29,6 +30,7 @@ class TestTaskCommand(test_engine.BaseCLITest): self.m_client.get_all.return_value = [utils.get_fake_task() for i in range(10)] self.m_client.get_by_id.return_value = utils.get_fake_task() + self.current_path = os.path.join(os.path.abspath(os.curdir)) def test_task_list(self): args = 'task list' @@ -61,7 +63,7 @@ class TestTaskCommand(test_engine.BaseCLITest): statuses=None) def _test_cmd(self, cmd, method, cmd_line, client, - return_data, expected_kwargs): + return_data, expected_file_path, expected_kwargs): self.m_get_client.reset_mock() self.m_client.get_filtered.reset_mock() self.m_client.__getattr__(method).return_value =\ @@ -72,6 +74,7 @@ class TestTaskCommand(test_engine.BaseCLITest): self.exec_command('task {0} {1} {2}'.format(cmd, method, cmd_line)) + m_open.assert_called_once_with(expected_file_path, 'w') written_yaml = yaml.safe_load(m_open().write.mock_calls[0][1][0]) expected_yaml = yaml.safe_load(return_data) self.assertEqual(written_yaml, expected_yaml) @@ -81,19 +84,24 @@ class TestTaskCommand(test_engine.BaseCLITest): **expected_kwargs) def test_task_deployment_info_download(self): - self._test_cmd('deployment-info', 'download', '1', + self._test_cmd('deployment-info', 'download', '1 ', 'deployment-info', utils.get_fake_yaml_deployment_info(), + "{0}/deployment_info_1.yaml".format( + self.current_path), dict(transaction_id=1)) def test_task_cluster_settings_download(self): - self._test_cmd('settings', 'download', '1', + self._test_cmd('settings', 'download', '1 --file settings.yaml', 'cluster-settings', utils.get_fake_yaml_cluster_settings(), + 'settings.yaml', dict(transaction_id=1)) def test_task_network_configuration_download(self): self._test_cmd('network-configuration', 'download', '1', 'network-configuration', utils.get_fake_yaml_network_conf(), + "{0}/network_configuration_1.yaml".format( + self.current_path), dict(transaction_id=1))