Merge "changes code to pass config in sender class"
This commit is contained in:
commit
9fdcdf29b4
|
@ -30,7 +30,7 @@ class Notifier(object):
|
||||||
def __init__(self, meters, config):
|
def __init__(self, meters, config):
|
||||||
"""Initialize Notifier."""
|
"""Initialize Notifier."""
|
||||||
self._meters = meters
|
self._meters = meters
|
||||||
self._sender = aodh_sender.Sender()
|
self._sender = aodh_sender.Sender(config)
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
def notify(self, vl, data):
|
def notify(self, vl, data):
|
||||||
|
|
|
@ -39,12 +39,12 @@ HTTP_NOT_FOUND = 404
|
||||||
class Sender(common_sender.Sender):
|
class Sender(common_sender.Sender):
|
||||||
"""Sends the JSON serialized data to Aodh."""
|
"""Sends the JSON serialized data to Aodh."""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
"""Create the Sender instance.
|
"""Create the Sender instance.
|
||||||
|
|
||||||
The configuration must be initialized before the object is created.
|
The configuration must be initialized before the object is created.
|
||||||
"""
|
"""
|
||||||
super(Sender, self).__init__()
|
super(Sender, self).__init__(config)
|
||||||
|
|
||||||
self._alarm_ids = {}
|
self._alarm_ids = {}
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,7 @@ class Sender(object):
|
||||||
HTTP_UNAUTHORIZED = requests.codes['UNAUTHORIZED']
|
HTTP_UNAUTHORIZED = requests.codes['UNAUTHORIZED']
|
||||||
HTTP_NOT_FOUND = requests.codes['NOT_FOUND']
|
HTTP_NOT_FOUND = requests.codes['NOT_FOUND']
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, config):
|
||||||
"""Create the Sender instance
|
"""Create the Sender instance
|
||||||
|
|
||||||
The configuration must be initialized before the object is created.
|
The configuration must be initialized before the object is created.
|
||||||
|
@ -60,6 +60,7 @@ class Sender(object):
|
||||||
self._auth_token = None
|
self._auth_token = None
|
||||||
self._auth_lock = threading.Lock()
|
self._auth_lock = threading.Lock()
|
||||||
self._failed_auth = False
|
self._failed_auth = False
|
||||||
|
self._config = config
|
||||||
|
|
||||||
def _on_authenticated(self):
|
def _on_authenticated(self):
|
||||||
"""Defines an action to be taken after auth_token acquired.
|
"""Defines an action to be taken after auth_token acquired.
|
||||||
|
@ -96,12 +97,11 @@ class Sender(object):
|
||||||
try:
|
try:
|
||||||
# create a keystone client if it doesn't exist
|
# create a keystone client if it doesn't exist
|
||||||
if self._keystone is None:
|
if self._keystone is None:
|
||||||
cfg = Config.instance()
|
|
||||||
self._keystone = ClientV3(
|
self._keystone = ClientV3(
|
||||||
auth_url=cfg.OS_AUTH_URL,
|
auth_url=self._config.OS_AUTH_URL,
|
||||||
username=cfg.OS_USERNAME,
|
username=self._config.OS_USERNAME,
|
||||||
password=cfg.OS_PASSWORD,
|
password=self._config.OS_PASSWORD,
|
||||||
tenant_name=cfg.OS_TENANT_NAME
|
tenant_name=self._config.OS_TENANT_NAME
|
||||||
)
|
)
|
||||||
# store the authentication token
|
# store the authentication token
|
||||||
self._auth_token = self._keystone.auth_token
|
self._auth_token = self._keystone.auth_token
|
||||||
|
|
|
@ -35,7 +35,7 @@ class Sender(common_sender.Sender):
|
||||||
|
|
||||||
The cofinguration must be initialized before the object is created.
|
The cofinguration must be initialized before the object is created.
|
||||||
"""
|
"""
|
||||||
super(Sender, self).__init__()
|
super(Sender, self).__init__(config)
|
||||||
self._meter_ids = {}
|
self._meter_ids = {}
|
||||||
self._config = config
|
self._config = config
|
||||||
|
|
||||||
|
|
|
@ -75,11 +75,12 @@ class MockedCollectd(object):
|
||||||
"""Get notification severity."""
|
"""Get notification severity."""
|
||||||
|
|
||||||
|
|
||||||
def mock_config(**kwargs):
|
def mock_config(OS_AUTH_URL=None, OS_USERNAME=None, OS_PASSWORD=None, **kwargs):
|
||||||
"""Return collectd module with collectd logging hooks."""
|
"""Return collectd module with collectd logging hooks."""
|
||||||
return mock.patch(
|
return mock.patch(
|
||||||
__name__ + '.' + MockedConfig.__name__, specs=True,
|
__name__ + '.' + MockedConfig.__name__, specs=True,
|
||||||
**kwargs)
|
OS_AUTH_URL=OS_AUTH_URL, OS_USERNAME=OS_USERNAME,
|
||||||
|
OS_PASSWORD=OS_PASSWORD, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def config_module(
|
def config_module(
|
||||||
|
|
|
@ -22,6 +22,7 @@ import requests
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from collectd_openstack.aodh import sender as aodh_sender
|
from collectd_openstack.aodh import sender as aodh_sender
|
||||||
|
from collectd_openstack.common.settings import Config
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
|
|
||||||
from collectd_openstack.common.meters import base
|
from collectd_openstack.common.meters import base
|
||||||
|
@ -56,7 +57,8 @@ class TestSender(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSender, self).setUp()
|
super(TestSender, self).setUp()
|
||||||
self.sender = aodh_sender.Sender()
|
self._config = Config._decorated()
|
||||||
|
self.sender = aodh_sender.Sender(self._config)
|
||||||
|
|
||||||
@mock.patch.object(aodh_sender.Sender, "_get_remote_alarm_id",
|
@mock.patch.object(aodh_sender.Sender, "_get_remote_alarm_id",
|
||||||
autospec=True)
|
autospec=True)
|
||||||
|
|
|
@ -22,6 +22,7 @@ import requests
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from collectd_openstack.common import sender as common_sender
|
from collectd_openstack.common import sender as common_sender
|
||||||
|
from collectd_openstack.common.settings import Config
|
||||||
|
|
||||||
|
|
||||||
class TestSender(unittest.TestCase):
|
class TestSender(unittest.TestCase):
|
||||||
|
@ -29,7 +30,8 @@ class TestSender(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super(TestSender, self).setUp()
|
super(TestSender, self).setUp()
|
||||||
self.sender = common_sender.Sender()
|
self._config = Config._decorated()
|
||||||
|
self.sender = common_sender.Sender(self._config)
|
||||||
|
|
||||||
self.sender._url_base = \
|
self.sender._url_base = \
|
||||||
"http://my-gnocchi-endpoint/v1/action"
|
"http://my-gnocchi-endpoint/v1/action"
|
||||||
|
|
|
@ -70,17 +70,22 @@ class MockedCollectd(object):
|
||||||
"Gets a dataset."
|
"Gets a dataset."
|
||||||
|
|
||||||
|
|
||||||
def mock_config(BATCH_SIZE=1, **kwargs):
|
def mock_config(BATCH_SIZE=1, OS_AUTH_URL=None, OS_USERNAME=None,
|
||||||
|
OS_PASSWORD=None, **kwargs):
|
||||||
"Returns collectd module with collectd logging hooks."
|
"Returns collectd module with collectd logging hooks."
|
||||||
return mock.patch(
|
return mock.patch(
|
||||||
__name__ + '.' + MockedConfig.__name__, specs=True,
|
__name__ + '.' + MockedConfig.__name__, specs=True,
|
||||||
BATCH_SIZE=BATCH_SIZE, **kwargs)
|
BATCH_SIZE=BATCH_SIZE, OS_AUTH_URL=OS_AUTH_URL, OS_USERNAME=OS_USERNAME,
|
||||||
|
OS_PASSWORD=OS_PASSWORD, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class MockedConfig(object):
|
class MockedConfig(object):
|
||||||
"Mocked config class."
|
"Mocked config class."
|
||||||
|
|
||||||
BATCH_SIZE = 1
|
BATCH_SIZE = 1
|
||||||
|
OS_AUTH_URL = ''
|
||||||
|
OS_USERNAME = 'test'
|
||||||
|
OS_PASSWORD = 'test'
|
||||||
|
|
||||||
|
|
||||||
def mock_value(
|
def mock_value(
|
||||||
|
|
|
@ -21,6 +21,7 @@ import mock
|
||||||
import requests
|
import requests
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
|
from collectd_openstack.common.settings import Config
|
||||||
from collectd_openstack.gnocchi import sender as gnocchi_sender
|
from collectd_openstack.gnocchi import sender as gnocchi_sender
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,7 +33,8 @@ class TestGnocchiSender(unittest.TestCase):
|
||||||
"""Test the sender class."""
|
"""Test the sender class."""
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.sender = gnocchi_sender.Sender(config=MockedConfig)
|
self._config = Config._decorated()
|
||||||
|
self.sender = gnocchi_sender.Sender(self._config)
|
||||||
self.sender._url_base = \
|
self.sender._url_base = \
|
||||||
"http://my-endpoint/v1/metric/%s/measures"
|
"http://my-endpoint/v1/metric/%s/measures"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue