Merge "Adding ability to get plugin processes via CLI"
This commit is contained in:
commit
a109193fa7
|
@ -78,6 +78,10 @@ class ShowPlugin(show.ShowOne):
|
|||
metavar="<plugin>",
|
||||
help="Name of the plugin to display",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--version",
|
||||
help='Version of the plugin to display'
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
|
@ -85,10 +89,30 @@ class ShowPlugin(show.ShowOne):
|
|||
self.log.debug("take_action(%s)" % parsed_args)
|
||||
client = self.app.client_manager.data_processing
|
||||
|
||||
data = client.plugins.get(parsed_args.plugin).to_dict()
|
||||
data['versions'] = osc_utils.format_list(data['versions'])
|
||||
if parsed_args.version:
|
||||
data = client.plugins.get_version_details(
|
||||
parsed_args.plugin, parsed_args.version).to_dict()
|
||||
|
||||
return self.dict2columns(data)
|
||||
processes = data.pop('node_processes')
|
||||
for k, v in processes.items():
|
||||
processes[k] = osc_utils.format_list(v)
|
||||
data['required_image_tags'] = osc_utils.format_list(
|
||||
data['required_image_tags'])
|
||||
|
||||
data = utils.prepare_data(
|
||||
data, ['required_image_tags', 'name', 'description', 'title'])
|
||||
|
||||
data = zip(*sorted(data.items()) + [('', ''), (
|
||||
'Service:', 'Available processes:'), ('', '')] + sorted(
|
||||
processes.items()))
|
||||
else:
|
||||
data = client.plugins.get(parsed_args.plugin).to_dict()
|
||||
data['versions'] = osc_utils.format_list(data['versions'])
|
||||
data = utils.prepare_data(
|
||||
data, ['versions', 'name', 'description', 'title'])
|
||||
data = self.dict2columns(data)
|
||||
|
||||
return data
|
||||
|
||||
|
||||
class GetPluginConfigs(command.Command):
|
||||
|
|
|
@ -23,7 +23,12 @@ from saharaclient.tests.unit.osc.v1 import fakes
|
|||
PLUGIN_INFO = {'name': 'fake',
|
||||
'title': 'Fake Plugin',
|
||||
'versions': ['0.1', '0.2'],
|
||||
'description': 'Plugin for tests'}
|
||||
'description': 'Plugin for tests',
|
||||
'required_image_tags': ['fake', '0.1'],
|
||||
'node_processes': {
|
||||
'HDFS': ['datanode', 'namenode'],
|
||||
'MapReduce': ['jobtracker', 'tasktracker']
|
||||
}}
|
||||
|
||||
|
||||
class TestPlugins(fakes.TestDataProcessing):
|
||||
|
@ -81,29 +86,54 @@ class TestShowPlugin(TestPlugins):
|
|||
super(TestShowPlugin, self).setUp()
|
||||
self.plugins_mock.get.return_value = api_plugins.Plugin(
|
||||
None, PLUGIN_INFO)
|
||||
self.plugins_mock.get_version_details.return_value = (
|
||||
api_plugins.Plugin(None, PLUGIN_INFO))
|
||||
|
||||
# Command to test
|
||||
self.cmd = osc_plugins.ShowPlugin(self.app, None)
|
||||
|
||||
def test_plugin_show(self):
|
||||
arglist = ['fake']
|
||||
verifylist = []
|
||||
verifylist = [('plugin', 'fake')]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that correct arguments was passed
|
||||
# Check that correct arguments were passed
|
||||
self.plugins_mock.get.assert_called_once_with('fake')
|
||||
|
||||
# Check that columns are correct
|
||||
expected_columns = ('description', 'name', 'title', 'versions')
|
||||
expected_columns = ('Description', 'Name', 'Title', 'Versions')
|
||||
self.assertEqual(expected_columns, columns)
|
||||
|
||||
# Check that data is correct
|
||||
expected_data = ('Plugin for tests', 'fake', 'Fake Plugin', '0.1, 0.2')
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
def test_plugin_version_show(self):
|
||||
arglist = ['fake', '--version', '0.1']
|
||||
verifylist = [('plugin', 'fake'), ('version', '0.1')]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
columns, data = self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that correct arguments were passed
|
||||
self.plugins_mock.get_version_details.assert_called_once_with(
|
||||
'fake', '0.1')
|
||||
|
||||
# Check that columns are correct
|
||||
expected_columns = ('Description', 'Name', 'Required image tags',
|
||||
'Title', '', 'Service:', '', 'HDFS', 'MapReduce')
|
||||
self.assertEqual(expected_columns, columns)
|
||||
|
||||
# Check that data is correct
|
||||
expected_data = ('Plugin for tests', 'fake', '0.1, fake',
|
||||
'Fake Plugin', '', 'Available processes:', '',
|
||||
'datanode, namenode', 'jobtracker, tasktracker')
|
||||
self.assertEqual(expected_data, data)
|
||||
|
||||
|
||||
class TestGetPluginConfigs(TestPlugins):
|
||||
def setUp(self):
|
||||
|
@ -125,7 +155,7 @@ class TestGetPluginConfigs(TestPlugins):
|
|||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that correct arguments was passed
|
||||
# Check that correct arguments were passed
|
||||
self.plugins_mock.get_version_details.assert_called_once_with(
|
||||
'fake', '0.1')
|
||||
|
||||
|
@ -148,7 +178,7 @@ class TestGetPluginConfigs(TestPlugins):
|
|||
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
# Check that correct arguments was passed
|
||||
# Check that correct arguments were passed
|
||||
self.plugins_mock.get_version_details.assert_called_once_with(
|
||||
'fake', '0.1')
|
||||
|
||||
|
|
Loading…
Reference in New Issue