From 75512477988ae5e287433c6c859c61de1bc82318 Mon Sep 17 00:00:00 2001 From: Benjamin Diaz Date: Fri, 27 Apr 2018 14:32:31 -0300 Subject: [PATCH] Adds granularity support in OpenStack vim config Adds global config class in core Reorders common_consumer conditional blocks Adds support for OS_DEFAULT_GRANULARITY env var Modifies tests to support changes Change-Id: I873b8d24814825bff6e628092942bf16fa5e2a03 Signed-off-by: Benjamin Diaz --- osm_mon/core/auth.py | 10 +- osm_mon/core/database.py | 4 +- osm_mon/core/message_bus/common_consumer.py | 85 +++++---------- .../{plugins/OpenStack => core}/settings.py | 6 +- osm_mon/plugins/OpenStack/Aodh/alarming.py | 103 ++++++++++-------- osm_mon/plugins/OpenStack/Aodh/notifier.py | 4 +- osm_mon/plugins/OpenStack/Gnocchi/metrics.py | 4 +- osm_mon/test/OpenStack/test_alarm_req.py | 32 +++++- osm_mon/test/OpenStack/test_alarming.py | 14 +-- osm_mon/test/OpenStack/test_common.py | 10 +- osm_mon/test/OpenStack/test_notifier.py | 5 +- osm_mon/test/OpenStack/test_settings.py | 6 +- osm_mon/test/integration/test_notify_alarm.py | 14 +-- 13 files changed, 139 insertions(+), 158 deletions(-) rename osm_mon/{plugins/OpenStack => core}/settings.py (91%) diff --git a/osm_mon/core/auth.py b/osm_mon/core/auth.py index 947175a..3a88a50 100644 --- a/osm_mon/core/auth.py +++ b/osm_mon/core/auth.py @@ -40,12 +40,16 @@ class AuthManager: credentials.user = creds_dict['vim_user'] credentials.password = creds_dict['vim_password'] credentials.tenant_name = creds_dict['vim_tenant_name'] - if 'config' in creds_dict: - credentials.config = json.dumps(creds_dict['config']) + if 'config' not in creds_dict: + creds_dict['config'] = {} + credentials.config = json.dumps(creds_dict['config']) self.database_manager.save_credentials(credentials) def get_credentials(self, vim_uuid): - return self.database_manager.get_credentials(vim_uuid) + creds = self.database_manager.get_credentials(vim_uuid) + if creds.config is None: + creds.config = {} + return creds def delete_auth_credentials(self, creds_dict): credentials = self.get_credentials(creds_dict['_id']) diff --git a/osm_mon/core/database.py b/osm_mon/core/database.py index 1d66264..eab4bed 100644 --- a/osm_mon/core/database.py +++ b/osm_mon/core/database.py @@ -27,7 +27,7 @@ import logging from peewee import * from playhouse.sqlite_ext import SqliteExtDatabase -from osm_mon.plugins.OpenStack.settings import Config +from osm_mon.core.settings import Config log = logging.getLogger(__name__) cfg = Config.instance() @@ -48,7 +48,7 @@ class VimCredentials(BaseModel): user = CharField() password = CharField() tenant_name = CharField() - config = TextField(null=True) + config = TextField(default='{}') class Alarm(BaseModel): diff --git a/osm_mon/core/message_bus/common_consumer.py b/osm_mon/core/message_bus/common_consumer.py index 8f595b0..10cd3d5 100755 --- a/osm_mon/core/message_bus/common_consumer.py +++ b/osm_mon/core/message_bus/common_consumer.py @@ -26,13 +26,14 @@ import sys import yaml +from osm_mon.core.settings import Config + logging.basicConfig(stream=sys.stdout, format='%(asctime)s %(message)s', datefmt='%m/%d/%Y %I:%M:%S %p', level=logging.INFO) log = logging.getLogger(__name__) - sys.path.append(os.path.abspath(os.path.join(os.path.realpath(__file__), '..', '..', '..', '..'))) from kafka import KafkaConsumer @@ -50,14 +51,11 @@ from osm_mon.plugins.vRealiseOps import plugin_receiver from osm_mon.core.auth import AuthManager from osm_mon.core.database import DatabaseManager -# Initialize servers -if "BROKER_URI" in os.environ: - server = {'server': os.getenv("BROKER_URI")} -else: - server = {'server': 'localhost:9092'} +cfg = Config.instance() +cfg.read_environ() # Initialize consumers for alarms and metrics -common_consumer = KafkaConsumer(bootstrap_servers=server['server'], +common_consumer = KafkaConsumer(bootstrap_servers=cfg.BROKER_URI, key_deserializer=bytes.decode, value_deserializer=bytes.decode, group_id="mon-consumer") @@ -85,7 +83,7 @@ def get_vim_type(vim_uuid): try: credentials = database_manager.get_credentials(vim_uuid) return credentials.type - except Exception as exc: + except Exception: log.exception("Error getting vim_type: ") return None @@ -103,73 +101,40 @@ for message in common_consumer: values = json.loads(message.value) except ValueError: values = yaml.safe_load(message.value) - # Check the message topic - if message.topic == "metric_request": - # Check the vim desired by the message - vim_type = get_vim_type(values['vim_uuid']) - - if vim_type == "openstack": - log.info("This message is for the OpenStack plugin.") - openstack_metrics.metric_calls(message) - elif vim_type == "aws": - log.info("This message is for the CloudWatch plugin.") - aws_conn = aws_connection.setEnvironment() - cloudwatch_metrics.metric_calls(message, aws_conn) - - elif vim_type == "vmware": - log.info("This metric_request message is for the vROPs plugin.") - vrops_rcvr.consume(message) - else: - log.debug("vim_type is misconfigured or unsupported; %s", - vim_type) - - elif message.topic == "alarm_request": - # Check the vim desired by the message - vim_type = get_vim_type(values['vim_uuid']) - if vim_type == "openstack": - log.info("This message is for the OpenStack plugin.") - openstack_alarms.alarming(message) - - elif vim_type == "aws": - log.info("This message is for the CloudWatch plugin.") - aws_conn = aws_connection.setEnvironment() - cloudwatch_alarms.alarm_calls(message, aws_conn) - - elif vim_type == "vmware": - log.info("This alarm_request message is for the vROPs plugin.") - vrops_rcvr.consume(message) - - else: - log.debug("vim_type is misconfigured or unsupported; %s", - vim_type) - - elif message.topic == "vim_account": + if message.topic == "vim_account": if message.key == "create" or message.key == "edit": auth_manager.store_auth_credentials(values) if message.key == "delete": auth_manager.delete_auth_credentials(values) - # TODO: Remove in the near future when all plugins support vim_uuid. Modify tests accordingly. - elif message.topic == "access_credentials": + else: # Check the vim desired by the message vim_type = get_vim_type(values['vim_uuid']) + if vim_type == "openstack": + log.info("This message is for the OpenStack plugin.") + if message.topic == "metric_request": + openstack_metrics.metric_calls(message) + if message.topic == "alarm_request": + openstack_alarms.alarming(message) - if vim_type == "aws": + elif vim_type == "aws": log.info("This message is for the CloudWatch plugin.") - aws_access_credentials.access_credential_calls(message) + aws_conn = aws_connection.setEnvironment() + if message.topic == "metric_request": + cloudwatch_metrics.metric_calls(message, aws_conn) + if message.topic == "alarm_request": + cloudwatch_alarms.alarm_calls(message, aws_conn) + if message.topic == "access_credentials": + aws_access_credentials.access_credential_calls(message) elif vim_type == "vmware": - log.info("This access_credentials message is for the vROPs plugin.") + log.info("This metric_request message is for the vROPs plugin.") vrops_rcvr.consume(message) else: log.debug("vim_type is misconfigured or unsupported; %s", vim_type) - else: - log.info("This topic is not relevant to any of the MON plugins.") - - - except Exception as exc: - log.exception("Exception: %s") + except Exception: + log.exception("Exception processing message: ") diff --git a/osm_mon/plugins/OpenStack/settings.py b/osm_mon/core/settings.py similarity index 91% rename from osm_mon/plugins/OpenStack/settings.py rename to osm_mon/core/settings.py index f0d19bf..e40fecd 100644 --- a/osm_mon/plugins/OpenStack/settings.py +++ b/osm_mon/core/settings.py @@ -19,7 +19,7 @@ # For those usages not covered by the Apache License, Version 2.0 please # contact: helena.mcgough@intel.com or adrian.hoban@intel.com ## -"""Configurations for the OpenStack plugins.""" +"""Global configuration managed by environment variables.""" import logging import os @@ -56,10 +56,12 @@ class CfgParam(namedtuple('CfgParam', ['key', 'default', 'data_type'])): @Singleton class Config(object): - """Plugin confguration.""" + """Configuration object.""" _configuration = [ + CfgParam('BROKER_URI', "localhost:9092", six.text_type), CfgParam('OS_NOTIFIER_URI', "http://localhost:8662", six.text_type), + CfgParam('OS_DEFAULT_GRANULARITY', "300", six.text_type), ] _config_dict = {cfg.key: cfg for cfg in _configuration} diff --git a/osm_mon/plugins/OpenStack/Aodh/alarming.py b/osm_mon/plugins/OpenStack/Aodh/alarming.py index b0602bd..09dc5f6 100644 --- a/osm_mon/plugins/OpenStack/Aodh/alarming.py +++ b/osm_mon/plugins/OpenStack/Aodh/alarming.py @@ -27,11 +27,12 @@ import logging import six import yaml +from osm_mon.core.auth import AuthManager from osm_mon.core.database import DatabaseManager from osm_mon.core.message_bus.producer import KafkaProducer +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.common import Common from osm_mon.plugins.OpenStack.response import OpenStack_Response -from osm_mon.plugins.OpenStack.settings import Config log = logging.getLogger(__name__) @@ -83,6 +84,7 @@ class Alarming(object): config.read_environ() self._database_manager = DatabaseManager() + self._auth_manager = AuthManager() # Use the Response class to generate valid json response messages self._response = OpenStack_Response() @@ -90,6 +92,40 @@ class Alarming(object): # Initializer a producer to send responses back to SO self._producer = KafkaProducer("alarm_response") + def configure_alarm(self, alarm_endpoint, metric_endpoint, auth_token, values, vim_config): + """Create requested alarm in Aodh.""" + url = "{}/v2/alarms/".format(alarm_endpoint) + + # Check if the desired alarm is supported + alarm_name = values['alarm_name'].lower() + metric_name = values['metric_name'].lower() + resource_id = values['resource_uuid'] + + if metric_name not in METRIC_MAPPINGS.keys(): + log.warn("This metric is not supported.") + return None, False + + # Check for the required metric + metric_id = self.check_for_metric(auth_token, metric_endpoint, metric_name, resource_id) + + try: + if metric_id is not None: + # Create the alarm if metric is available + if 'granularity' in vim_config and 'granularity' not in values: + values['granularity'] = vim_config['granularity'] + payload = self.check_payload(values, metric_name, resource_id, + alarm_name) + new_alarm = Common.perform_request( + url, auth_token, req_type="post", payload=payload) + return json.loads(new_alarm.text)['alarm_id'], True + else: + log.warn("The required Gnocchi metric does not exist.") + return None, False + + except Exception as exc: + log.warn("Failed to create the alarm: %s", exc) + return None, False + def alarming(self, message): """Consume info from the message bus to manage alarms.""" try: @@ -105,12 +141,15 @@ class Alarming(object): alarm_endpoint = Common.get_endpoint("alarming", vim_uuid) metric_endpoint = Common.get_endpoint("metric", vim_uuid) + vim_account = self._auth_manager.get_credentials(vim_uuid) + vim_config = json.loads(vim_account.config) + if message.key == "create_alarm_request": # Configure/Update an alarm alarm_details = values['alarm_create_request'] alarm_id, alarm_status = self.configure_alarm( - alarm_endpoint, metric_endpoint, auth_token, alarm_details) + alarm_endpoint, metric_endpoint, auth_token, alarm_details, vim_config) # Generate a valid response message, send via producer try: @@ -126,7 +165,7 @@ class Alarming(object): self._producer.create_alarm_response( 'create_alarm_response', resp_message, 'alarm_response') - except Exception as exc: + except Exception: log.exception("Response creation failed:") elif message.key == "list_alarm_request": @@ -146,7 +185,7 @@ class Alarming(object): self._producer.list_alarm_response( 'list_alarm_response', resp_message, 'alarm_response') - except Exception as exc: + except Exception: log.exception("Failed to send a valid response back.") elif message.key == "delete_alarm_request": @@ -166,8 +205,8 @@ class Alarming(object): self._producer.delete_alarm_response( 'delete_alarm_response', resp_message, 'alarm_response') - except Exception as exc: - log.warn("Failed to create delete response:%s", exc) + except Exception: + log.exception("Failed to create delete response: ") elif message.key == "acknowledge_alarm": # Acknowledge that an alarm has been dealt with by the SO @@ -187,7 +226,7 @@ class Alarming(object): alarm_details = values['alarm_update_request'] alarm_id, status = self.update_alarm( - alarm_endpoint, auth_token, alarm_details) + alarm_endpoint, auth_token, alarm_details, vim_config) # Generate a response for an update request try: @@ -199,46 +238,14 @@ class Alarming(object): self._producer.update_alarm_response( 'update_alarm_response', resp_message, 'alarm_response') - except Exception as exc: - log.warn("Failed to send an update response:%s", exc) + except Exception: + log.exception("Failed to send an update response: ") else: log.debug("Unknown key, no action will be performed") return - def configure_alarm(self, alarm_endpoint, metric_endpoint, auth_token, values): - """Create requested alarm in Aodh.""" - url = "{}/v2/alarms/".format(alarm_endpoint) - - # Check if the desired alarm is supported - alarm_name = values['alarm_name'].lower() - metric_name = values['metric_name'].lower() - resource_id = values['resource_uuid'] - - if metric_name not in METRIC_MAPPINGS.keys(): - log.warn("This metric is not supported.") - return None, False - - # Check for the required metric - metric_id = self.check_for_metric(auth_token, metric_endpoint, metric_name, resource_id) - - try: - if metric_id is not None: - # Create the alarm if metric is available - payload = self.check_payload(values, metric_name, resource_id, - alarm_name) - new_alarm = Common.perform_request( - url, auth_token, req_type="post", payload=payload) - return json.loads(new_alarm.text)['alarm_id'], True - else: - log.warn("The required Gnocchi metric does not exist.") - return None, False - - except Exception as exc: - log.warn("Failed to create the alarm: %s", exc) - return None, False - def delete_alarm(self, endpoint, auth_token, alarm_id): """Delete alarm function.""" url = "{}/v2/alarms/%s".format(endpoint) % alarm_id @@ -253,8 +260,8 @@ class Alarming(object): else: return True - except Exception as exc: - log.warn("Failed to delete alarm: %s because %s.", alarm_id, exc) + except Exception: + log.exception("Failed to delete alarm %s :", alarm_id) return False def list_alarms(self, endpoint, auth_token, list_details): @@ -347,11 +354,11 @@ class Alarming(object): Common.perform_request( url, auth_token, req_type="put", payload=payload) return True - except Exception as exc: - log.warn("Unable to update alarm state: %s", exc) + except Exception: + log.exception("Unable to update alarm state: ") return False - def update_alarm(self, endpoint, auth_token, values): + def update_alarm(self, endpoint, auth_token, values, vim_config): """Get alarm name for an alarm configuration update.""" # Get already existing alarm details url = "{}/v2/alarms/%s".format(endpoint) % values['alarm_uuid'] @@ -371,6 +378,8 @@ class Alarming(object): return None, False # Generates and check payload configuration for alarm update + if 'granularity' in vim_config and 'granularity' not in values: + values['granularity'] = vim_config['granularity'] payload = self.check_payload(values, metric_name, resource_id, alarm_name, alarm_state=alarm_state) @@ -404,7 +413,7 @@ class Alarming(object): statistic = values['statistic'].lower() - granularity = '300' + granularity = cfg.OS_DEFAULT_GRANULARITY if 'granularity' in values: granularity = values['granularity'] diff --git a/osm_mon/plugins/OpenStack/Aodh/notifier.py b/osm_mon/plugins/OpenStack/Aodh/notifier.py index 314548f..c09ad9e 100644 --- a/osm_mon/plugins/OpenStack/Aodh/notifier.py +++ b/osm_mon/plugins/OpenStack/Aodh/notifier.py @@ -24,10 +24,10 @@ """A Webserver to send alarm notifications from Aodh to the SO.""" import json import logging +import os import sys import time -import os from six.moves.BaseHTTPServer import BaseHTTPRequestHandler from six.moves.BaseHTTPServer import HTTPServer @@ -46,7 +46,7 @@ from osm_mon.core.message_bus.producer import KafkaProducer from osm_mon.plugins.OpenStack.common import Common from osm_mon.plugins.OpenStack.response import OpenStack_Response -from osm_mon.plugins.OpenStack.settings import Config +from osm_mon.core.settings import Config class NotifierHandler(BaseHTTPRequestHandler): diff --git a/osm_mon/plugins/OpenStack/Gnocchi/metrics.py b/osm_mon/plugins/OpenStack/Gnocchi/metrics.py index 47bc7d9..b41b5c0 100644 --- a/osm_mon/plugins/OpenStack/Gnocchi/metrics.py +++ b/osm_mon/plugins/OpenStack/Gnocchi/metrics.py @@ -24,17 +24,15 @@ import datetime import json import logging - import time import six import yaml from osm_mon.core.message_bus.producer import KafkaProducer +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.common import Common - from osm_mon.plugins.OpenStack.response import OpenStack_Response -from osm_mon.plugins.OpenStack.settings import Config log = logging.getLogger(__name__) diff --git a/osm_mon/test/OpenStack/test_alarm_req.py b/osm_mon/test/OpenStack/test_alarm_req.py index 023b31a..15cf63b 100644 --- a/osm_mon/test/OpenStack/test_alarm_req.py +++ b/osm_mon/test/OpenStack/test_alarm_req.py @@ -29,11 +29,16 @@ import unittest import mock +from osm_mon.core.auth import AuthManager +from osm_mon.core.database import VimCredentials from osm_mon.plugins.OpenStack.Aodh import alarming as alarm_req from osm_mon.plugins.OpenStack.common import Common log = logging.getLogger(__name__) +mock_creds = VimCredentials() +mock_creds.config = '{}' + class Message(object): """A class to mock a message object value for alarm requests.""" @@ -54,13 +59,16 @@ class TestAlarmKeys(unittest.TestCase): self.alarming = alarm_req.Alarming() self.alarming.common = Common() + @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(Common, 'get_endpoint') @mock.patch.object(Common, 'get_auth_token') - def test_alarming_authentication(self, get_token, get_endpoint): + def test_alarming_authentication(self, get_token, get_endpoint, get_creds): """Test getting an auth_token and endpoint for alarm requests.""" # if auth_token is None environment variables are used to authenticate message = Message() + get_creds.return_value = mock_creds + self.alarming.alarming(message) get_token.assert_called_with('test_id') @@ -68,8 +76,9 @@ class TestAlarmKeys(unittest.TestCase): @mock.patch.object(Common, 'get_endpoint', mock.Mock()) @mock.patch.object(Common, 'get_auth_token', mock.Mock()) + @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(alarm_req.Alarming, 'delete_alarm') - def test_delete_alarm_key(self, del_alarm): + def test_delete_alarm_key(self, del_alarm, get_creds): """Test the functionality for a create alarm request.""" # Mock a message value and key message = Message() @@ -78,28 +87,34 @@ class TestAlarmKeys(unittest.TestCase): 'alarm_delete_request': {'alarm_uuid': 'my_alarm_id'}}) + get_creds.return_value = mock_creds + # Call the alarming functionality and check delete request self.alarming.alarming(message) del_alarm.assert_called_with(mock.ANY, mock.ANY, 'my_alarm_id') @mock.patch.object(Common, 'get_endpoint', mock.Mock()) @mock.patch.object(Common, 'get_auth_token', mock.Mock()) + @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(alarm_req.Alarming, 'list_alarms') - def test_list_alarm_key(self, list_alarm): + def test_list_alarm_key(self, list_alarm, get_creds): """Test the functionality for a list alarm request.""" # Mock a message with list alarm key and value message = Message() message.key = 'list_alarm_request' message.value = json.dumps({'vim_uuid': 'test_id', 'alarm_list_request': 'my_alarm_details'}) + get_creds.return_value = mock_creds + # Call the alarming functionality and check list functionality self.alarming.alarming(message) list_alarm.assert_called_with(mock.ANY, mock.ANY, 'my_alarm_details') @mock.patch.object(Common, 'get_auth_token', mock.Mock()) @mock.patch.object(Common, 'get_endpoint', mock.Mock()) + @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(alarm_req.Alarming, 'update_alarm_state') - def test_ack_alarm_key(self, ack_alarm): + def test_ack_alarm_key(self, ack_alarm, get_creds): """Test the functionality for an acknowledge alarm request.""" # Mock a message with acknowledge alarm key and value message = Message() @@ -108,21 +123,26 @@ class TestAlarmKeys(unittest.TestCase): 'ack_details': {'alarm_uuid': 'my_alarm_id'}}) + get_creds.return_value = mock_creds + # Call alarming functionality and check acknowledge functionality self.alarming.alarming(message) ack_alarm.assert_called_with(mock.ANY, mock.ANY, 'my_alarm_id') @mock.patch.object(Common, 'get_auth_token', mock.Mock()) @mock.patch.object(Common, 'get_endpoint', mock.Mock()) + @mock.patch.object(AuthManager, 'get_credentials') @mock.patch.object(alarm_req.Alarming, 'configure_alarm') - def test_config_alarm_key(self, config_alarm): + def test_config_alarm_key(self, config_alarm, get_creds): """Test the functionality for a create alarm request.""" # Mock a message with config alarm key and value message = Message() message.key = 'create_alarm_request' message.value = json.dumps({'vim_uuid': 'test_id', 'alarm_create_request': 'alarm_details'}) + get_creds.return_value = mock_creds + # Call alarming functionality and check config alarm call config_alarm.return_value = 'my_alarm_id', True self.alarming.alarming(message) - config_alarm.assert_called_with(mock.ANY, mock.ANY, mock.ANY, 'alarm_details') + config_alarm.assert_called_with(mock.ANY, mock.ANY, mock.ANY, 'alarm_details', {}) diff --git a/osm_mon/test/OpenStack/test_alarming.py b/osm_mon/test/OpenStack/test_alarming.py index 598ef2b..5726f69 100644 --- a/osm_mon/test/OpenStack/test_alarming.py +++ b/osm_mon/test/OpenStack/test_alarming.py @@ -27,9 +27,9 @@ import unittest import mock +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.Aodh import alarming as alarm_req from osm_mon.plugins.OpenStack.common import Common -from osm_mon.plugins.OpenStack.settings import Config log = logging.getLogger(__name__) @@ -66,7 +66,7 @@ class TestAlarming(unittest.TestCase): values = {"alarm_name": "my_alarm", "metric_name": "my_metric", "resource_uuid": "my_r_id"} - self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values) + self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values, {}) perf_req.assert_not_called() perf_req.reset_mock() @@ -78,7 +78,7 @@ class TestAlarming(unittest.TestCase): check_metric.return_value = None - self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values) + self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values, {}) perf_req.assert_not_called() @mock.patch.object(alarm_req.Alarming, "check_payload") @@ -95,7 +95,7 @@ class TestAlarming(unittest.TestCase): check_metric.return_value = "my_metric_id" check_pay.return_value = "my_payload" - self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values) + self.alarming.configure_alarm(alarm_endpoint, metric_endpoint, auth_token, values, {}) perf_req.assert_called_with( "alarm_endpoint/v2/alarms/", auth_token, req_type="post", payload="my_payload") @@ -152,7 +152,7 @@ class TestAlarming(unittest.TestCase): """Test update alarm with invalid get response.""" values = {"alarm_uuid": "my_alarm_id"} - self.alarming.update_alarm(alarm_endpoint, auth_token, values) + self.alarming.update_alarm(alarm_endpoint, auth_token, values, {}) perf_req.assert_called_with(mock.ANY, auth_token, req_type="get") check_pay.assert_not_called() @@ -170,7 +170,7 @@ class TestAlarming(unittest.TestCase): check_pay.return_value = None values = {"alarm_uuid": "my_alarm_id"} - self.alarming.update_alarm(alarm_endpoint, auth_token, values) + self.alarming.update_alarm(alarm_endpoint, auth_token, values, {}) perf_req.assert_called_with(mock.ANY, auth_token, req_type="get") self.assertEqual(perf_req.call_count, 1) @@ -187,7 +187,7 @@ class TestAlarming(unittest.TestCase): perf_req.return_value = resp values = {"alarm_uuid": "my_alarm_id"} - self.alarming.update_alarm(alarm_endpoint, auth_token, values) + self.alarming.update_alarm(alarm_endpoint, auth_token, values, {}) check_pay.assert_called_with(values, "disk_write_ops", "my_resource_id", "my_alarm", alarm_state="alarm") diff --git a/osm_mon/test/OpenStack/test_common.py b/osm_mon/test/OpenStack/test_common.py index 9853d15..042d15b 100644 --- a/osm_mon/test/OpenStack/test_common.py +++ b/osm_mon/test/OpenStack/test_common.py @@ -22,21 +22,17 @@ """Tests for all common OpenStack methods.""" import json - import logging - import unittest -from keystoneclient.v3 import client - import mock +import requests +from keystoneclient.v3 import client from osm_mon.core.auth import AuthManager from osm_mon.core.database import VimCredentials +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.common import Common -from osm_mon.plugins.OpenStack.settings import Config - -import requests __author__ = "Helena McGough" diff --git a/osm_mon/test/OpenStack/test_notifier.py b/osm_mon/test/OpenStack/test_notifier.py index 81ef2e8..0f96e71 100644 --- a/osm_mon/test/OpenStack/test_notifier.py +++ b/osm_mon/test/OpenStack/test_notifier.py @@ -22,19 +22,16 @@ """Tests for all common OpenStack methods.""" import json - import unittest - from BaseHTTPServer import BaseHTTPRequestHandler import mock from osm_mon.core.message_bus.producer import KafkaProducer - +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.Aodh.alarming import Alarming from osm_mon.plugins.OpenStack.common import Common from osm_mon.plugins.OpenStack.response import OpenStack_Response -from osm_mon.plugins.OpenStack.settings import Config # Mock data from post request post_data = json.dumps({"severity": "critical", diff --git a/osm_mon/test/OpenStack/test_settings.py b/osm_mon/test/OpenStack/test_settings.py index 0f924ce..42619f8 100644 --- a/osm_mon/test/OpenStack/test_settings.py +++ b/osm_mon/test/OpenStack/test_settings.py @@ -22,14 +22,10 @@ """Tests for settings for OpenStack plugins configurations.""" import logging - import os - import unittest -import mock - -from osm_mon.plugins.OpenStack.settings import Config +from osm_mon.core.settings import Config log = logging.getLogger(__name__) diff --git a/osm_mon/test/integration/test_notify_alarm.py b/osm_mon/test/integration/test_notify_alarm.py index db21c4e..4f44572 100644 --- a/osm_mon/test/integration/test_notify_alarm.py +++ b/osm_mon/test/integration/test_notify_alarm.py @@ -22,27 +22,21 @@ """Tests for all common OpenStack methods.""" import json - import logging - import socket import unittest +from threading import Thread +import mock +import requests from six.moves.BaseHTTPServer import BaseHTTPRequestHandler from six.moves.BaseHTTPServer import HTTPServer -from threading import Thread - from osm_mon.core.message_bus.producer import KafkaProducer - -import mock - +from osm_mon.core.settings import Config from osm_mon.plugins.OpenStack.Aodh.alarming import Alarming from osm_mon.plugins.OpenStack.common import Common from osm_mon.plugins.OpenStack.response import OpenStack_Response -from osm_mon.plugins.OpenStack.settings import Config - -import requests log = logging.getLogger(__name__) -- 2.25.1