From a9b5cc401bc1b91fd28ff44eb93b0b103e126db5 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam Date: Thu, 3 Dec 2015 15:40:49 +0530 Subject: [PATCH] Makes monasca plugin as supported Adds python-monascaclient into requirments.txt and makes the monasca plugin as supported. Closes-bug: #1581379 Change-Id: I3793b06cab25d7a108bb140791f3f672fd9154a1 --- heat/engine/clients/os/monasca.py | 11 +++----- .../openstack/monasca/alarm_definition.py | 20 ++++++--------- .../openstack/monasca/notification.py | 21 ++++++---------- heat/tests/clients/test_monasca_client.py | 10 -------- .../monasca/test_alarm_definition.py | 25 +------------------ .../openstack/monasca/test_notification.py | 25 +------------------ requirements.txt | 1 + 7 files changed, 22 insertions(+), 91 deletions(-) diff --git a/heat/engine/clients/os/monasca.py b/heat/engine/clients/os/monasca.py index 609e4a99dc..af13c64e15 100644 --- a/heat/engine/clients/os/monasca.py +++ b/heat/engine/clients/os/monasca.py @@ -11,28 +11,23 @@ # License for the specific language governing permissions and limitations # under the License. -from oslo_utils import importutils +from monascaclient import client +from monascaclient import exc as monasca_exc from heat.common import exception as heat_exc from heat.engine.clients import client_plugin from heat.engine import constraints -client = importutils.try_import('monascaclient.client') -monasca_exc = importutils.try_import('monascaclient.exc') - CLIENT_NAME = 'monasca' class MonascaClientPlugin(client_plugin.ClientPlugin): exceptions_module = [monasca_exc] + service_types = [MONITORING] = ['monitoring'] VERSION = '2_0' - @staticmethod - def is_available(): - return client is not None - def _create(self): args = self._get_client_args(service_name=CLIENT_NAME, service_type=self.MONITORING) diff --git a/heat/engine/resources/openstack/monasca/alarm_definition.py b/heat/engine/resources/openstack/monasca/alarm_definition.py index c97bd62432..6c820fae98 100644 --- a/heat/engine/resources/openstack/monasca/alarm_definition.py +++ b/heat/engine/resources/openstack/monasca/alarm_definition.py @@ -12,7 +12,6 @@ # under the License. from heat.common.i18n import _ -from heat.engine import clients from heat.engine import constraints from heat.engine import properties from heat.engine import resource @@ -22,8 +21,9 @@ from heat.engine import support class MonascaAlarmDefinition(resource.Resource): """Heat Template Resource for Monasca Alarm definition. - This plug-in requires python-monascaclient>=1.0.22. So to enable this - plug-in, install this client library and restart the heat-engine. + Monasca Alarm definition helps to define the required expression for + a given alarm situation. This plugin helps to create, update and + delete the alarm definition. Alarm definitions is necessary to describe and manage alarms in a one-to-many relationship in order to avoid having to manually declare each @@ -32,8 +32,11 @@ class MonascaAlarmDefinition(resource.Resource): """ support_status = support.SupportStatus( - version='5.0.0', - status=support.UNSUPPORTED) + version='7.0.0', + previous_status=support.SupportStatus( + version='5.0.0', + status=support.UNSUPPORTED + )) default_client_name = 'monasca' @@ -201,10 +204,3 @@ def resource_mapping(): return { 'OS::Monasca::AlarmDefinition': MonascaAlarmDefinition } - - -def available_resource_mapping(): - if not clients.has_client(MonascaAlarmDefinition.default_client_name): - return {} - - return resource_mapping() diff --git a/heat/engine/resources/openstack/monasca/notification.py b/heat/engine/resources/openstack/monasca/notification.py index c87cadd256..2430bd43e6 100644 --- a/heat/engine/resources/openstack/monasca/notification.py +++ b/heat/engine/resources/openstack/monasca/notification.py @@ -12,7 +12,6 @@ # under the License. from heat.common.i18n import _ -from heat.engine import clients from heat.engine import constraints from heat.engine import properties from heat.engine import resource @@ -22,15 +21,18 @@ from heat.engine import support class MonascaNotification(resource.Resource): """Heat Template Resource for Monasca Notification. - This plug-in requires python-monascaclient>=1.0.22. So to enable this - plug-in, install this client library and restart the heat-engine. - A resource which is used to notificate if there is some alarm. + Monasca Notification helps to declare the hook points, which will be + invoked once alarm is generated. This plugin helps to create, update and + delete the notification. """ support_status = support.SupportStatus( - version='5.0.0', - status=support.UNSUPPORTED) + version='7.0.0', + previous_status=support.SupportStatus( + version='5.0.0', + status=support.UNSUPPORTED + )) default_client_name = 'monasca' @@ -114,10 +116,3 @@ def resource_mapping(): return { 'OS::Monasca::Notification': MonascaNotification } - - -def available_resource_mapping(): - if not clients.has_client(MonascaNotification.default_client_name): - return {} - - return resource_mapping() diff --git a/heat/tests/clients/test_monasca_client.py b/heat/tests/clients/test_monasca_client.py index 16fa4b0ee2..8c751fb098 100644 --- a/heat/tests/clients/test_monasca_client.py +++ b/heat/tests/clients/test_monasca_client.py @@ -90,12 +90,6 @@ class MonascaClientPluginTest(common.HeatTestCase): ) -# TODO(skraynev): remove it when monasca client will be -# merged in global requirements -class NotFound(Exception): - pass - - class MonascaClientPluginNotificationTest(common.HeatTestCase): sample_uuid = '477e8273-60a7-4c41-b683-fdb0bc7cd152' @@ -110,10 +104,6 @@ class MonascaClientPluginNotificationTest(common.HeatTestCase): def setUp(self): super(MonascaClientPluginNotificationTest, self).setUp() self._client = mock.MagicMock() - client_plugin.monasca_exc = mock.Mock() - # TODO(skraynev): remove it when monasca client will be - # merged in global requirements - client_plugin.monasca_exc.NotFound = NotFound self.client_plugin = client_plugin.MonascaClientPlugin( context=mock.MagicMock() ) diff --git a/heat/tests/openstack/monasca/test_alarm_definition.py b/heat/tests/openstack/monasca/test_alarm_definition.py index 32115fe884..5c1dba6c73 100644 --- a/heat/tests/openstack/monasca/test_alarm_definition.py +++ b/heat/tests/openstack/monasca/test_alarm_definition.py @@ -14,7 +14,6 @@ import mock from heat.engine.clients.os import monasca as client_plugin -from heat.engine import resource from heat.engine.resources.openstack.monasca import alarm_definition from heat.engine import stack from heat.engine import template @@ -45,27 +44,13 @@ sample_template = { RESOURCE_TYPE = 'OS::Monasca::AlarmDefinition' -class MonascaAlarmDefinition(alarm_definition.MonascaAlarmDefinition): - """This class overrides the is_service_available to return True. - - Monasca service is not available by default. So, this class overrides - the is_service_available to return True. - """ - @classmethod - def is_service_available(cls, context): - return True - - class MonascaAlarmDefinitionTest(common.HeatTestCase): def setUp(self): super(MonascaAlarmDefinitionTest, self).setUp() self.ctx = utils.dummy_context() - # As monascaclient is not part of requirements.txt, RESOURCE_TYPE is - # not registered by default. For testing, its registered here - resource._register_class(RESOURCE_TYPE, - MonascaAlarmDefinition) + self.stack = stack.Stack( self.ctx, 'test_stack', template.Template(sample_template) @@ -209,14 +194,6 @@ class MonascaAlarmDefinitionTest(common.HeatTestCase): self.assertIsNone(self.test_resource.handle_delete()) def test_resource_handle_delete_not_found(self): - # TODO(skraynev): remove it when monasca client will be - # merged in global requirements - class NotFound(Exception): - pass - - client_plugin.monasca_exc = mock.Mock() - client_plugin.monasca_exc.NotFound = NotFound - self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151' mock_alarm_delete = self.test_client.alarm_definitions.delete mock_alarm_delete.side_effect = client_plugin.monasca_exc.NotFound diff --git a/heat/tests/openstack/monasca/test_notification.py b/heat/tests/openstack/monasca/test_notification.py index 5b94b9dca6..be54c2fbd3 100644 --- a/heat/tests/openstack/monasca/test_notification.py +++ b/heat/tests/openstack/monasca/test_notification.py @@ -14,7 +14,6 @@ import mock from heat.engine.clients.os import monasca as client_plugin -from heat.engine import resource from heat.engine.resources.openstack.monasca import notification from heat.engine import stack from heat.engine import template @@ -39,27 +38,13 @@ sample_template = { RESOURCE_TYPE = 'OS::Monasca::Notification' -class MonascaNotification(notification.MonascaNotification): - """This class overrides the is_service_available to return True. - - Monasca service is not available by default. So, this class overrides - the is_service_available to return True. - """ - @classmethod - def is_service_available(cls, context): - return True - - class MonascaNotificationTest(common.HeatTestCase): def setUp(self): super(MonascaNotificationTest, self).setUp() self.ctx = utils.dummy_context() - # As monascaclient is not part of requirements.txt, RESOURCE_TYPE is - # not registered by default. For testing, its registered here - resource._register_class(RESOURCE_TYPE, - MonascaNotification) + self.stack = stack.Stack( self.ctx, 'test_stack', template.Template(sample_template) @@ -153,14 +138,6 @@ class MonascaNotificationTest(common.HeatTestCase): self.assertIsNone(self.test_resource.handle_delete()) def test_resource_handle_delete_not_found(self): - # TODO(skraynev): remove it when monasca client will be - # merged in global requirements - class NotFound(Exception): - pass - - client_plugin.monasca_exc = mock.Mock() - client_plugin.monasca_exc.NotFound = NotFound - self.test_resource.resource_id = '477e8273-60a7-4c41-b683-fdb0bc7cd151' mock_notification_delete = self.test_client.notifications.delete mock_notification_delete.side_effect = ( diff --git a/requirements.txt b/requirements.txt index 1e679cff9c..3b197106a0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -40,6 +40,7 @@ python-keystoneclient!=1.8.0,!=2.1.0,>=1.6.0 # Apache-2.0 python-magnumclient>=2.0.0 # Apache-2.0 python-manilaclient>=1.3.0 # Apache-2.0 python-mistralclient>=1.0.0 # Apache-2.0 +python-monascaclient>=1.0.30 # Apache-2.0 python-neutronclient>=4.2.0 # Apache-2.0 python-novaclient!=2.33.0,>=2.29.0 # Apache-2.0 python-openstackclient>=2.1.0 # Apache-2.0