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 <bdiaz@whitestack.com>
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 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 @@
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 @@
@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 @@
'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 @@
'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 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 @@
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 @@
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 @@
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 @@
"""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 @@
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 @@
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__)