From 757bdd3b48b2b447d1e25a6a14bffb30ce2d9a29 Mon Sep 17 00:00:00 2001 From: Bulat Gaifullin Date: Mon, 7 Sep 2015 09:56:17 +0300 Subject: [PATCH] Plugin sync added to new CLI CLI examples: fuel2 plugins sync fuel2 plugins sync 1 2 cmd line entry points are sorted in alphabetical order DocImpact Closes-Bug: #1472982 Change-Id: I894b05ff1cfa36e1be63fa9d5476c5e534baf773 --- fuelclient/__init__.py | 1 + fuelclient/commands/plugins.py | 39 ++++++++++++++ fuelclient/objects/__init__.py | 1 + fuelclient/objects/plugins.py | 2 +- fuelclient/tests/unit/v2/cli/test_plugins.py | 41 +++++++++++++++ fuelclient/tests/unit/v2/lib/test_plugins.py | 55 ++++++++++++++++++++ fuelclient/v1/__init__.py | 5 +- fuelclient/v1/plugins.py | 34 ++++++++++++ setup.cfg | 41 ++++++++------- 9 files changed, 196 insertions(+), 23 deletions(-) create mode 100644 fuelclient/commands/plugins.py create mode 100644 fuelclient/tests/unit/v2/cli/test_plugins.py create mode 100644 fuelclient/tests/unit/v2/lib/test_plugins.py create mode 100644 fuelclient/v1/plugins.py diff --git a/fuelclient/__init__.py b/fuelclient/__init__.py index ccebfc1..ba6dbfd 100644 --- a/fuelclient/__init__.py +++ b/fuelclient/__init__.py @@ -52,6 +52,7 @@ def get_client(resource, version='v1'): 'fuel-version': v1.fuelversion, 'network-group': v1.network_group, 'node': v1.node, + 'plugins': v1.plugins, 'task': v1.task, } } diff --git a/fuelclient/commands/plugins.py b/fuelclient/commands/plugins.py new file mode 100644 index 0000000..9cc8465 --- /dev/null +++ b/fuelclient/commands/plugins.py @@ -0,0 +1,39 @@ +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from fuelclient.commands import base + + +class PluginsMixIn(object): + entity_name = 'plugins' + + +class PluginsSync(PluginsMixIn, base.BaseCommand): + """Synchronise plugins on file system with plugins in API service.""" + + def get_parser(self, prog_name): + parser = super(PluginsSync, self).get_parser(prog_name) + parser.add_argument( + 'ids', + type=int, + nargs='*', + metavar='plugin-id', + help='Synchronise only plugins with specified ids') + + return parser + + def take_action(self, parsed_args): + ids = parsed_args.ids if len(parsed_args.ids) > 0 else None + self.client.sync(ids=ids) + self.app.stdout.write("Plugins were successfully synchronized.") diff --git a/fuelclient/objects/__init__.py b/fuelclient/objects/__init__.py index e69b7e4..6b3e6c4 100644 --- a/fuelclient/objects/__init__.py +++ b/fuelclient/objects/__init__.py @@ -26,3 +26,4 @@ from fuelclient.objects.task import SnapshotTask from fuelclient.objects.task import Task from fuelclient.objects.fuelversion import FuelVersion from fuelclient.objects.network_group import NetworkGroup +from fuelclient.objects.plugins import Plugins diff --git a/fuelclient/objects/plugins.py b/fuelclient/objects/plugins.py index 21d2124..921b18a 100644 --- a/fuelclient/objects/plugins.py +++ b/fuelclient/objects/plugins.py @@ -290,7 +290,7 @@ class Plugins(base.BaseObject): :returns: None """ post_data = None - if plugin_ids: + if plugin_ids is not None: post_data = {'ids': plugin_ids} cls.connection.post_request( diff --git a/fuelclient/tests/unit/v2/cli/test_plugins.py b/fuelclient/tests/unit/v2/cli/test_plugins.py new file mode 100644 index 0000000..75756e1 --- /dev/null +++ b/fuelclient/tests/unit/v2/cli/test_plugins.py @@ -0,0 +1,41 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import mock + +from fuelclient.tests.unit.v2.cli import test_engine + + +class TestPluginsCommand(test_engine.BaseCLITest): + """Tests for fuel2 node * commands.""" + + def setUp(self): + super(TestPluginsCommand, self).setUp() + + def test_plugins_sync_all(self): + args = 'plugins sync' + self.exec_command(args) + + self.m_get_client.assert_called_once_with('plugins', mock.ANY) + self.m_client.sync.assert_called_once_with(ids=None) + + def test_plugins_sync_specified_plugins(self): + ids = [1, 2] + args = 'plugins sync {ids}'.format(ids=' '.join(map(str, ids))) + self.exec_command(args) + + self.m_get_client.assert_called_once_with('plugins', mock.ANY) + self.m_client.sync.assert_called_once_with(ids=ids) diff --git a/fuelclient/tests/unit/v2/lib/test_plugins.py b/fuelclient/tests/unit/v2/lib/test_plugins.py new file mode 100644 index 0000000..885d2ad --- /dev/null +++ b/fuelclient/tests/unit/v2/lib/test_plugins.py @@ -0,0 +1,55 @@ +# -*- coding: utf-8 -*- +# +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +import fuelclient +from fuelclient.tests.unit.v2.lib import test_api + + +class TestPluginsFacade(test_api.BaseLibTest): + + def setUp(self): + super(TestPluginsFacade, self).setUp() + + self.version = 'v1' + self.client = fuelclient.get_client('plugins', self.version) + + def test_sync_plugins(self): + expected_uri = '/api/{version}/plugins/sync/'.format( + version=self.version + ) + matcher = self.m_request.post(expected_uri, json={}) + self.client.sync(None) + self.assertTrue(matcher.called) + self.assertIsNone(matcher.last_request.body) + + def test_sync_plugins_empty_ids(self): + expected_uri = '/api/{version}/plugins/sync/'.format( + version=self.version + ) + matcher = self.m_request.post(expected_uri, json={}) + self.client.sync([]) + self.assertTrue(matcher.called) + self.assertEqual([], matcher.last_request.json()['ids']) + + def test_sync_specified_plugins(self): + expected_uri = '/api/{version}/plugins/sync/'.format( + version=self.version + ) + ids = [1, 2] + matcher = self.m_request.post(expected_uri, json={}) + self.client.sync(ids=ids) + self.assertTrue(matcher.called) + self.assertEqual(ids, matcher.last_request.json()['ids']) diff --git a/fuelclient/v1/__init__.py b/fuelclient/v1/__init__.py index 352e372..93e1736 100644 --- a/fuelclient/v1/__init__.py +++ b/fuelclient/v1/__init__.py @@ -17,11 +17,12 @@ from fuelclient.v1 import fuelversion from fuelclient.v1 import network_group from fuelclient.v1 import node from fuelclient.v1 import task - +from fuelclient.v1 import plugins # Please keeps the list in alphabetical order __all__ = ('environment', 'fuelversion', 'network_group', 'node', - 'task') + 'plugins', + 'task',) diff --git a/fuelclient/v1/plugins.py b/fuelclient/v1/plugins.py new file mode 100644 index 0000000..b7d7565 --- /dev/null +++ b/fuelclient/v1/plugins.py @@ -0,0 +1,34 @@ +# Copyright 2015 Mirantis, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from fuelclient import objects +from fuelclient.v1 import base_v1 + + +class PluginsClient(base_v1.BaseV1Client): + + _entity_wrapper = objects.Plugins + + def sync(self, ids): + """Synchronise plugins on file system with plugins in API service. + + :param ids: List of ids for filtering plugins + :type ids: list + """ + + self._entity_wrapper.sync(plugin_ids=ids) + + +def get_client(): + return PluginsClient() diff --git a/setup.cfg b/setup.cfg index 5e50645..db97de6 100644 --- a/setup.cfg +++ b/setup.cfg @@ -28,34 +28,35 @@ console_scripts = fuel2=fuelclient.main:main fuelclient = - env_list=fuelclient.commands.environment:EnvList + env_add_nodes=fuelclient.commands.environment:EnvAddNodes env_create=fuelclient.commands.environment:EnvCreate - env_show=fuelclient.commands.environment:EnvShow env_delete=fuelclient.commands.environment:EnvDelete + env_deploy=fuelclient.commands.environment:EnvDeploy + env_list=fuelclient.commands.environment:EnvList + env_show=fuelclient.commands.environment:EnvShow + env_spawn-vms=fuelclient.commands.environment:EnvSpawnVms env_update=fuelclient.commands.environment:EnvUpdate env_upgrade=fuelclient.commands.environment:EnvUpgrade - env_deploy=fuelclient.commands.environment:EnvDeploy - env_add_nodes=fuelclient.commands.environment:EnvAddNodes - env_spawn-vms=fuelclient.commands.environment:EnvSpawnVms - node_list=fuelclient.commands.node:NodeList - node_show=fuelclient.commands.node:NodeShow - node_list-vms-conf=fuelclient.commands.node:NodeVmsList - node_create-vms-conf=fuelclient.commands.node:NodeCreateVMsConf - node_update=fuelclient.commands.node:NodeUpdate - node_label_list=fuelclient.commands.node:NodeLabelList - node_label_set=fuelclient.commands.node:NodeLabelSet - node_label_delete=fuelclient.commands.node:NodeLabelDelete - task_list=fuelclient.commands.task:TaskList - task_show=fuelclient.commands.task:TaskShow fuel-version=fuelclient.commands.fuelversion:FuelVersion - network-template_upload=fuelclient.commands.network_template:NetworkTemplateUpload - network-template_download=fuelclient.commands.network_template:NetworkTemplateDownload - network-template_delete=fuelclient.commands.network_template:NetworkTemplateDelete + network-group_create=fuelclient.commands.network_group:NetworkGroupCreate + network-group_delete=fuelclient.commands.network_group:NetworkGroupDelete network-group_list=fuelclient.commands.network_group:NetworkGroupList network-group_show=fuelclient.commands.network_group:NetworkGroupShow - network-group_create=fuelclient.commands.network_group:NetworkGroupCreate network-group_update=fuelclient.commands.network_group:NetworkGroupUpdate - network-group_delete=fuelclient.commands.network_group:NetworkGroupDelete + network-template_delete=fuelclient.commands.network_template:NetworkTemplateDelete + network-template_download=fuelclient.commands.network_template:NetworkTemplateDownload + network-template_upload=fuelclient.commands.network_template:NetworkTemplateUpload + node_create-vms-conf=fuelclient.commands.node:NodeCreateVMsConf + node_label_delete=fuelclient.commands.node:NodeLabelDelete + node_label_list=fuelclient.commands.node:NodeLabelList + node_label_set=fuelclient.commands.node:NodeLabelSet + node_list-vms-conf=fuelclient.commands.node:NodeVmsList + node_list=fuelclient.commands.node:NodeList + node_show=fuelclient.commands.node:NodeShow + node_update=fuelclient.commands.node:NodeUpdate + plugins_sync=fuelclient.commands.plugins:PluginsSync + task_list=fuelclient.commands.task:TaskList + task_show=fuelclient.commands.task:TaskShow [global] setup-hooks =