From f25fb43177767ef968d8ac6a7849ea3b028f3b5c Mon Sep 17 00:00:00 2001 From: Jaewook Oh Date: Mon, 23 Apr 2018 21:56:16 +0900 Subject: [PATCH] Added Vitrage actions into Mistral Implements: blueprint mistral-vitrage-actions Change-Id: I11068c1f1a0d7ee6973e7c736ba92c475f7d0902 --- lower-constraints.txt | 1 + mistral/actions/generator_factory.py | 2 +- mistral/actions/openstack/actions.py | 31 +++++++++++++++++++ mistral/actions/openstack/mapping.json | 21 +++++++++++++ .../unit/actions/openstack/test_generator.py | 3 +- .../openstack/test_openstack_actions.py | 13 ++++++++ ...tral-vitrage-actions-a205b8ea82b43cab.yaml | 3 ++ requirements.txt | 1 + 8 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 releasenotes/notes/mistral-vitrage-actions-a205b8ea82b43cab.yaml diff --git a/lower-constraints.txt b/lower-constraints.txt index 6be274f00..f4796606d 100644 --- a/lower-constraints.txt +++ b/lower-constraints.txt @@ -127,6 +127,7 @@ python-subunit==1.0.0 python-swiftclient==3.2.0 python-tackerclient==0.8.0 python-troveclient==2.2.0 +python-vitrageclient==2.0.0 python-zaqarclient==1.0.0 pytz==2013.6 PyYAML==3.12 diff --git a/mistral/actions/generator_factory.py b/mistral/actions/generator_factory.py index f73bfc0e8..af823f7b9 100644 --- a/mistral/actions/generator_factory.py +++ b/mistral/actions/generator_factory.py @@ -21,7 +21,7 @@ SUPPORTED_MODULES = [ 'Nova', 'Glance', 'Keystone', 'Heat', 'Neutron', 'Cinder', 'Trove', 'Ironic', 'Baremetal Introspection', 'Swift', 'SwiftService', 'Zaqar', 'Barbican', 'Mistral', 'Designate', 'Magnum', 'Murano', 'Tacker', - 'Aodh', 'Gnocchi', 'Glare' + 'Aodh', 'Gnocchi', 'Glare', 'Vitrage' ] diff --git a/mistral/actions/openstack/actions.py b/mistral/actions/openstack/actions.py index e8713e0f3..f2d225072 100644 --- a/mistral/actions/openstack/actions.py +++ b/mistral/actions/openstack/actions.py @@ -70,6 +70,7 @@ swift_client = _try_import('swiftclient.client') swiftservice = _try_import('swiftclient.service') tackerclient = _try_import('tackerclient.v1_0.client') troveclient = _try_import('troveclient.v1.client') +vitrageclient = _try_import('vitrageclient.v1.client') zaqarclient = _try_import('zaqarclient.queues.client') @@ -908,3 +909,33 @@ class GlareAction(base.OpenStackAction): @classmethod def _get_fake_client(cls): return cls._get_client_class()("http://127.0.0.1:9494/") + + +class VitrageAction(base.OpenStackAction): + _service_type = 'rca' + + @classmethod + def _get_client_class(cls): + return vitrageclient.Client + + def _create_client(self, context): + + LOG.debug("Vitrage action security context: %s", context) + + vitrage_endpoint = self.get_service_endpoint() + + endpoint_url = keystone_utils.format_url( + vitrage_endpoint.url, + {'tenant_id': context.project_id} + ) + + session_and_auth = self.get_session_and_auth(context) + + return vitrageclient.Client( + session=session_and_auth['session'], + endpoint_override=endpoint_url + ) + + @classmethod + def _get_fake_client(cls): + return cls._get_client_class()() diff --git a/mistral/actions/openstack/mapping.json b/mistral/actions/openstack/mapping.json index 6e7c50699..a6d02ed6e 100644 --- a/mistral/actions/openstack/mapping.json +++ b/mistral/actions/openstack/mapping.json @@ -1247,5 +1247,26 @@ "artifacts_upload_blob": "artifacts.upload_blob", "artifacts_download_blob": "artifacts.download_blob", "artifacts_add_external_location": "artifacts.add_external_location" + }, + "vitrage": { + "_comment": "It uses vitrageclient.v1.", + "alarm_list": "alarm.list", + "alarm_get": "alarm.get", + "alarm_count": "alarm.count", + "event_post": "event.post", + "healthcheck_get": "healthcheck.get", + "rca_get": "rca.get", + "resource_list": "resource.list", + "resource_get": "resource.get", + "template_list": "template.list", + "template_show": "template.show", + "template_add": "template.add", + "template_delete": "template.delete", + "template_validate": "template.validate", + "topology_get": "topology.get", + "webhook_list": "webhook.list", + "webhook_show": "webhook.show", + "webhook_add": "webhook.add", + "webhook_delete": "webhook.delete" } } diff --git a/mistral/tests/unit/actions/openstack/test_generator.py b/mistral/tests/unit/actions/openstack/test_generator.py index 5bd46a84a..c70ce9526 100644 --- a/mistral/tests/unit/actions/openstack/test_generator.py +++ b/mistral/tests/unit/actions/openstack/test_generator.py @@ -54,7 +54,8 @@ 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] + 'glare': ['glare.artifacts_list', actions.GlareAction], + 'vitrage': ['vitrage.alarm_get', actions.VitrageAction] } 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 80e089604..44d4da136 100644 --- a/mistral/tests/unit/actions/openstack/test_openstack_actions.py +++ b/mistral/tests/unit/actions/openstack/test_openstack_actions.py @@ -346,3 +346,16 @@ class OpenStackActionTest(base.BaseTestCase): self.assertTrue(mocked().artifacts.get.called) mocked().artifacts.get.assert_called_once_with(artifact_id="1234-abcd") + + @mock.patch.object(actions.VitrageAction, '_get_client') + def test_vitrage_action(self, mocked): + mock_ctx = mock.Mock() + method_name = "alarm.get" + action_class = actions.VitrageAction + action_class.client_method_name = method_name + params = {'vitrage_id': '1234-abcd'} + action = action_class(**params) + action.run(mock_ctx) + + self.assertTrue(mocked().alarm.get.called) + mocked().alarm.get.assert_called_once_with(vitrage_id="1234-abcd") diff --git a/releasenotes/notes/mistral-vitrage-actions-a205b8ea82b43cab.yaml b/releasenotes/notes/mistral-vitrage-actions-a205b8ea82b43cab.yaml new file mode 100644 index 000000000..e20bbceb7 --- /dev/null +++ b/releasenotes/notes/mistral-vitrage-actions-a205b8ea82b43cab.yaml @@ -0,0 +1,3 @@ +--- +features: + - Add Mistral actions for OpenStack Vitrage, the RCA service diff --git a/requirements.txt b/requirements.txt index b4906ff82..bb5b281f2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -48,6 +48,7 @@ python-tackerclient>=0.8.0 # Apache-2.0 python-troveclient>=2.2.0 # Apache-2.0 python-ironicclient>=2.3.0 # Apache-2.0 python-ironic-inspector-client>=1.5.0 # Apache-2.0 +python-vitrageclient>=2.0.0 # Apache-2.0 python-zaqarclient>=1.0.0 # Apache-2.0 PyJWT>=1.0.1 # MIT PyYAML>=3.12 # MIT