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
This commit is contained in:
committed by
Vladimir Sharshov
parent
12de059d8a
commit
46c84c105f
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user