From fec851381d9d34f1430f23efb0c92a235ff3e5f5 Mon Sep 17 00:00:00 2001 From: Mike Fedosin Date: Tue, 13 Jun 2017 19:09:54 +0300 Subject: [PATCH] Add Glare action pack This patch adds Glare action pack into Mistral. Change-Id: Icf4ce5a37f555d01cf9c0b865a6816e3f6801f3a Implements-blueprint: glare-action-pack --- mistral/actions/generator_factory.py | 1 + mistral/actions/openstack/actions.py | 29 +++++++++++++++++++ mistral/actions/openstack/mapping.json | 19 ++++++++++++ .../unit/actions/openstack/test_generator.py | 1 + .../openstack/test_openstack_actions.py | 13 +++++++++ requirements.txt | 1 + tools/get_action_list.py | 13 ++++++++- 7 files changed, 76 insertions(+), 1 deletion(-) diff --git a/mistral/actions/generator_factory.py b/mistral/actions/generator_factory.py index 150b32342..b7fd9358a 100644 --- a/mistral/actions/generator_factory.py +++ b/mistral/actions/generator_factory.py @@ -21,6 +21,7 @@ SUPPORTED_MODULES = [ 'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', 'Ceilometer', 'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'Zaqar', 'Barbican', 'Mistral', 'Designate', 'Magnum', 'Murano', 'Tacker', 'Aodh', 'Gnocchi', + 'Glare' ] diff --git a/mistral/actions/openstack/actions.py b/mistral/actions/openstack/actions.py index f519ab6df..ad4fe955f 100644 --- a/mistral/actions/openstack/actions.py +++ b/mistral/actions/openstack/actions.py @@ -53,6 +53,7 @@ ceilometerclient = _try_import('ceilometerclient.v2.client') cinderclient = _try_import('cinderclient.v2.client') designateclient = _try_import('designateclient.v1') glanceclient = _try_import('glanceclient.v2.client') +glareclient = _try_import('glareclient.v1.client') gnocchiclient = _try_import('gnocchiclient.v1.client') heatclient = _try_import('heatclient.v1.client') ironic_inspector_client = _try_import('ironic_inspector_client.v1') @@ -843,3 +844,31 @@ class GnocchiAction(base.OpenStackAction): @classmethod def _get_fake_client(cls): return cls._get_client_class()() + + +class GlareAction(base.OpenStackAction): + _service_name = 'glare' + + @classmethod + def _get_client_class(cls): + return glareclient.Client + + def _create_client(self, context): + + LOG.debug("Glare action security context: %s", context) + + glare_endpoint = self.get_service_endpoint() + + endpoint_url = keystone_utils.format_url( + glare_endpoint.url, + {'tenant_id': context.project_id} + ) + + return self._get_client_class()( + endpoint_url, + **self.get_session_and_auth(context) + ) + + @classmethod + def _get_fake_client(cls): + return cls._get_client_class()("http://127.0.0.1:9494/") diff --git a/mistral/actions/openstack/mapping.json b/mistral/actions/openstack/mapping.json index b0b3263e0..9a01df33c 100644 --- a/mistral/actions/openstack/mapping.json +++ b/mistral/actions/openstack/mapping.json @@ -1366,5 +1366,24 @@ "get_event": "get_event", "actions": "actions", "get_action": "get_action" + }, + "glare": { + "_comment": "It uses glareclient.v1.", + "artifacts_create": "artifacts.create", + "artifacts_delete": "artifacts.delete", + "artifacts_get": "artifacts.get", + "artifacts_list": "artifacts.list", + "artifacts_update": "artifacts.update", + "artifacts_activate": "artifacts.activate", + "artifacts_deactivate": "artifacts.deactivate", + "artifacts_reactivate": "artifacts.reactivate", + "artifacts_publish": "artifacts.publish", + "artifacts_add_tag": "artifacts.add_tag", + "artifacts_remove_tag": "artifacts.remove_tag", + "artifacts_get_type_list": "artifacts.get_type_list", + "artifacts_get_type_schema": "artifacts.get_type_schema", + "artifacts_upload_blob": "artifacts.upload_blob", + "artifacts_download_blob": "artifacts.download_blob", + "artifacts_add_external_location": "artifacts.add_external_location" } } diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 82fa94c1d..ae6453ccd 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -54,6 +54,7 @@ MODULE_MAPPING = { 'senlin': ['senlin.get_profile', actions.SenlinAction], 'aodh': ['aodh.alarm_list', actions.AodhAction], 'gnocchi': ['gnocchi.metric_list', actions.GnocchiAction], + 'glare': ['glare.artifacts_list', actions.GlareAction] } EXTRA_MODULES = ['neutron', 'swift', 'zaqar', 'tacker'] diff --git a/mistral/tests/unit/actions/openstack/test_openstack_actions.py b/mistral/tests/unit/actions/openstack/test_openstack_actions.py index a7fc3c001..0bb5b87a6 100644 --- a/mistral/tests/unit/actions/openstack/test_openstack_actions.py +++ b/mistral/tests/unit/actions/openstack/test_openstack_actions.py @@ -303,3 +303,16 @@ class OpenStackActionTest(base.BaseTestCase): self.assertTrue(mocked().metric.get.called) mocked().metric.get.assert_called_once_with(metric_id="1234-abcd") + + @mock.patch.object(actions.GlareAction, '_get_client') + def test_glare_action(self, mocked): + mock_ctx = mock.Mock() + method_name = "artifacts.get" + action_class = actions.GlareAction + action_class.client_method_name = method_name + params = {'artifact_id': '1234-abcd'} + action = action_class(**params) + action.run(mock_ctx) + + self.assertTrue(mocked().artifacts.get.called) + mocked().artifacts.get.assert_called_once_with(artifact_id="1234-abcd") diff --git a/requirements.txt b/requirements.txt index 2476fd350..888f36ef0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -35,6 +35,7 @@ python-ceilometerclient>=2.5.0 # Apache-2.0 python-cinderclient>=3.0.0 # Apache-2.0 python-designateclient>=1.5.0 # Apache-2.0 python-glanceclient>=2.7.0 # Apache-2.0 +python-glareclient>=0.3.0 # Apache-2.0 python-heatclient>=1.6.1 # Apache-2.0 python-keystoneclient>=3.8.0 # Apache-2.0 python-mistralclient>=3.1.0 # Apache-2.0 diff --git a/tools/get_action_list.py b/tools/get_action_list.py index d5c48dc16..ed1cd26f9 100644 --- a/tools/get_action_list.py +++ b/tools/get_action_list.py @@ -27,6 +27,7 @@ from cinderclient.apiclient import base as cinder_base from cinderclient.v2 import client as cinderclient from designateclient import client as designateclient from glanceclient.v2 import client as glanceclient +from glareclient.v1 import client as glareclient from gnocchiclient.v1 import base as gnocchi_base from gnocchiclient.v1 import client as gnocchiclient from heatclient.common import base as heat_base @@ -150,6 +151,9 @@ DESIGNATE_NAMESPACE_LIST = [ ] +GLARE_NAMESPACE_LIST = ['artifacts', 'versions'] + + def get_nova_client(**kwargs): return novaclient.Client(2) @@ -213,6 +217,10 @@ def get_gnocchi_client(**kwargs): return gnocchiclient.Client() +def get_glare_client(**kwargs): + return glareclient.Client('') + + CLIENTS = { 'nova': get_nova_client, 'heat': get_heat_client, @@ -229,6 +237,7 @@ CLIENTS = { 'murano': get_murano_client, 'aodh': get_aodh_client, 'gnocchi': get_gnocchi_client, + 'glare': get_glare_client, # 'neutron': get_nova_client # 'baremetal_introspection': ... # 'swift': ... @@ -250,6 +259,7 @@ BASE_MANAGERS = { 'murano': BASE_MURANO_MANAGER, 'aodh': BASE_AODH_MANAGER, 'gnocchi': BASE_GNOCCHI_MANAGER, + 'glare': None, # 'neutron': BASE_NOVA_MANAGER # 'baremetal_introspection': ... # 'swift': ... @@ -258,7 +268,8 @@ BASE_MANAGERS = { NAMESPACES = { 'glance': GLANCE_NAMESPACE_LIST, 'ceilometer': CEILOMETER_NAMESPACE_LIST, - 'designate': DESIGNATE_NAMESPACE_LIST + 'designate': DESIGNATE_NAMESPACE_LIST, + 'glare': GLARE_NAMESPACE_LIST } ALLOWED_ATTRS = ['service_catalog', 'catalog'] FORBIDDEN_METHODS = [