summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShu Yingya <yingya.shu@easystack.cn>2016-09-25 23:58:38 +0800
committerShu Yingya <yingya.shu@easystack.cn>2016-10-02 04:55:01 +0800
commit82cabbd3c9e3fe7b310a086a03a4c0730ccd148d (patch)
tree30e1b455446361f459f7a14f06e76ab34f6b2615
parent559fa06ddcefcadae54b025f2a0abd5095e7a21d (diff)
downloadpython-saharaclient-82cabbd3c9e3fe7b310a086a03a4c0730ccd148d.tar.gz
Raise exception in command "plugin configs get"
In this patch, there are three changes. 1. Raise Exception if the config file already exists. 2. Avoid overriding the file of different version of a plugin. 3. stdout message should end with '\n' to start a newline. 4. execute remote API call only when file not exists. Change-Id: I0c9eb2cb7fd1cafe4bea05c73811d6dea6b3e9a8 Closes-Bug: 1625990
-rw-r--r--saharaclient/osc/v1/plugins.py25
-rw-r--r--saharaclient/tests/unit/osc/v1/test_plugins.py2
2 files changed, 16 insertions, 11 deletions
diff --git a/saharaclient/osc/v1/plugins.py b/saharaclient/osc/v1/plugins.py
index 8d2a2fe..497ec04 100644
--- a/saharaclient/osc/v1/plugins.py
+++ b/saharaclient/osc/v1/plugins.py
@@ -154,7 +154,8 @@ class GetPluginConfigs(command.Command):
parser.add_argument(
'--file',
metavar="<file>",
- help='Destination file (defaults to plugin name)',
+ help="Destination file (defaults to a combination of "
+ "plugin name and plugin version)",
)
return parser
@@ -163,21 +164,25 @@ class GetPluginConfigs(command.Command):
client = self.app.client_manager.data_processing
if not parsed_args.file:
- parsed_args.file = parsed_args.plugin
-
- data = client.plugins.get_version_details(
- parsed_args.plugin, parsed_args.plugin_version).to_dict()
+ parsed_args.file = (parsed_args.plugin + '-' +
+ parsed_args.plugin_version)
if path.exists(parsed_args.file):
- self.log.error('File "%s" already exists. Chose another one with '
- '--file argument.' % parsed_args.file)
+ msg = ('File "%s" already exists. Choose another one with '
+ '--file argument.' % parsed_args.file)
+ raise exceptions.CommandError(msg)
else:
+ data = client.plugins.get_version_details(
+ parsed_args.plugin, parsed_args.plugin_version).to_dict()
+
with open(parsed_args.file, 'w') as f:
jsonutils.dump(data, f, indent=4)
sys.stdout.write(
- '"%(plugin)s" plugin configs was saved in "%(file)s"'
- 'file' % {'plugin': parsed_args.plugin,
- 'file': parsed_args.file})
+ '"%(plugin)s" plugin "%(version)s" version configs '
+ 'was saved in "%(file)s" file\n' % {
+ 'plugin': parsed_args.plugin,
+ 'version': parsed_args.plugin_version,
+ 'file': parsed_args.file})
class UpdatePlugin(command.ShowOne):
diff --git a/saharaclient/tests/unit/osc/v1/test_plugins.py b/saharaclient/tests/unit/osc/v1/test_plugins.py
index 1096087..0a07ff2 100644
--- a/saharaclient/tests/unit/osc/v1/test_plugins.py
+++ b/saharaclient/tests/unit/osc/v1/test_plugins.py
@@ -171,7 +171,7 @@ class TestGetPluginConfigs(TestPlugins):
self.assertEqual(PLUGIN_INFO, args_to_dump[0])
# Check that data will be saved to the right file
- self.assertEqual('fake', m_open.call_args[0][0])
+ self.assertEqual('fake-0.1', m_open.call_args[0][0])
@mock.patch('oslo_serialization.jsonutils.dump')
def test_get_plugin_configs_specified_file(self, p_dump):