Remove oslo.context dependency
oslo.context is only used to generate a request id, something we can easily do since it's just about generating a random string. There's no reason to depends on this library just for that, especially since we're never going to use the rest of it. Change-Id: I6b8618bdc32264f9f5e66a4697d1886e4f292dc8
This commit is contained in:
parent
121f83200a
commit
73cb32238a
@ -14,8 +14,9 @@
|
|||||||
# under the License.
|
# under the License.
|
||||||
"""Rest alarm notifier."""
|
"""Rest alarm notifier."""
|
||||||
|
|
||||||
|
import uuid
|
||||||
|
|
||||||
from oslo_config import cfg
|
from oslo_config import cfg
|
||||||
from oslo_context import context
|
|
||||||
from oslo_log import log
|
from oslo_log import log
|
||||||
from oslo_serialization import jsonutils
|
from oslo_serialization import jsonutils
|
||||||
import requests
|
import requests
|
||||||
@ -58,8 +59,9 @@ class RestAlarmNotifier(notifier.AlarmNotifier):
|
|||||||
def notify(self, action, alarm_id, alarm_name, severity, previous,
|
def notify(self, action, alarm_id, alarm_name, severity, previous,
|
||||||
current, reason, reason_data, headers=None):
|
current, reason, reason_data, headers=None):
|
||||||
headers = headers or {}
|
headers = headers or {}
|
||||||
if not headers.get('x-openstack-request-id'):
|
if 'x-openstack-request-id' not in headers:
|
||||||
headers['x-openstack-request-id'] = context.generate_request_id()
|
headers['x-openstack-request-id'] = b'req-' + str(
|
||||||
|
uuid.uuid4()).encode('ascii')
|
||||||
|
|
||||||
LOG.info(_(
|
LOG.info(_(
|
||||||
"Notifying alarm %(alarm_name)s %(alarm_id)s with severity"
|
"Notifying alarm %(alarm_name)s %(alarm_id)s with severity"
|
||||||
|
@ -66,9 +66,6 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
'aodh.notifier.zaqar.ZaqarAlarmNotifier.get_zaqar_client',
|
'aodh.notifier.zaqar.ZaqarAlarmNotifier.get_zaqar_client',
|
||||||
return_value=self.zaqar))
|
return_value=self.zaqar))
|
||||||
self.service = notifier.AlarmNotifierService(self.CONF)
|
self.service = notifier.AlarmNotifierService(self.CONF)
|
||||||
self.useFixture(mockpatch.Patch(
|
|
||||||
'oslo_context.context.generate_request_id',
|
|
||||||
self._fake_generate_request_id))
|
|
||||||
|
|
||||||
def test_notify_alarm(self):
|
def test_notify_alarm(self):
|
||||||
data = {
|
data = {
|
||||||
@ -111,12 +108,6 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
notification['actions'] = [action]
|
notification['actions'] = [action]
|
||||||
return notification
|
return notification
|
||||||
|
|
||||||
HTTP_HEADERS = {'x-openstack-request-id': 'fake_request_id',
|
|
||||||
'content-type': 'application/json'}
|
|
||||||
|
|
||||||
def _fake_generate_request_id(self):
|
|
||||||
return self.HTTP_HEADERS['x-openstack-request-id']
|
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_ok(self):
|
def test_notify_alarm_rest_action_ok(self):
|
||||||
action = 'http://host/action'
|
action = 'http://host/action'
|
||||||
|
|
||||||
@ -126,7 +117,13 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
poster.assert_called_with(action, data=mock.ANY,
|
poster.assert_called_with(action, data=mock.ANY,
|
||||||
headers=mock.ANY)
|
headers=mock.ANY)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_with_ssl_client_cert(self):
|
def test_notify_alarm_rest_action_with_ssl_client_cert(self):
|
||||||
@ -142,7 +139,13 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
cert=certificate, verify=True)
|
cert=certificate, verify=True)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_with_ssl_client_cert_and_key(self):
|
def test_notify_alarm_rest_action_with_ssl_client_cert_and_key(self):
|
||||||
@ -160,7 +163,12 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
cert=(certificate, key), verify=True)
|
cert=(certificate, key), verify=True)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_with_ssl_verify_disable_by_cfg(self):
|
def test_notify_alarm_rest_action_with_ssl_verify_disable_by_cfg(self):
|
||||||
@ -175,7 +183,13 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
verify=False)
|
verify=False)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_with_ssl_verify_disable(self):
|
def test_notify_alarm_rest_action_with_ssl_verify_disable(self):
|
||||||
@ -188,7 +202,13 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
verify=False)
|
verify=False)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_notify_alarm_rest_action_with_ssl_verify_enable_by_user(self):
|
def test_notify_alarm_rest_action_with_ssl_verify_enable_by_user(self):
|
||||||
@ -203,7 +223,13 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
headers=mock.ANY,
|
headers=mock.ANY,
|
||||||
verify=True)
|
verify=True)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(self.HTTP_HEADERS, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -242,8 +268,6 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
|
|
||||||
client = mock.MagicMock()
|
client = mock.MagicMock()
|
||||||
client.session.auth.get_access.return_value.auth_token = 'token_1234'
|
client.session.auth.get_access.return_value.auth_token = 'token_1234'
|
||||||
headers = {'X-Auth-Token': 'token_1234'}
|
|
||||||
headers.update(self.HTTP_HEADERS)
|
|
||||||
|
|
||||||
self.useFixture(mockpatch.Patch('keystoneclient.v3.client.Client',
|
self.useFixture(mockpatch.Patch('keystoneclient.v3.client.Client',
|
||||||
lambda **kwargs: client))
|
lambda **kwargs: client))
|
||||||
@ -251,12 +275,18 @@ class TestAlarmNotifier(tests_base.BaseTestCase):
|
|||||||
with mock.patch.object(requests.Session, 'post') as poster:
|
with mock.patch.object(requests.Session, 'post') as poster:
|
||||||
self.service.notify_alarm({},
|
self.service.notify_alarm({},
|
||||||
self._notification(action))
|
self._notification(action))
|
||||||
headers = {'X-Auth-Token': 'token_1234'}
|
|
||||||
headers.update(self.HTTP_HEADERS)
|
|
||||||
poster.assert_called_with(
|
poster.assert_called_with(
|
||||||
url, data=mock.ANY, headers=mock.ANY)
|
url, data=mock.ANY, headers=mock.ANY)
|
||||||
args, kwargs = poster.call_args
|
args, kwargs = poster.call_args
|
||||||
self.assertEqual(headers, kwargs['headers'])
|
self.assertEqual(
|
||||||
|
{
|
||||||
|
'X-Auth-Token': 'token_1234',
|
||||||
|
'x-openstack-request-id':
|
||||||
|
kwargs['headers']['x-openstack-request-id'],
|
||||||
|
'content-type': 'application/json'
|
||||||
|
},
|
||||||
|
kwargs['headers'])
|
||||||
|
|
||||||
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
self.assertEqual(DATA_JSON, jsonutils.loads(kwargs['data']))
|
||||||
|
|
||||||
def test_zaqar_notifier_action(self):
|
def test_zaqar_notifier_action(self):
|
||||||
|
@ -8,7 +8,6 @@ jsonschema!=2.5.0,<3.0.0,>=2.0.0
|
|||||||
keystonemiddleware>=2.2.0
|
keystonemiddleware>=2.2.0
|
||||||
gnocchiclient>=2.1.0 # Apache-2.0
|
gnocchiclient>=2.1.0 # Apache-2.0
|
||||||
lxml>=2.3
|
lxml>=2.3
|
||||||
oslo.context>=0.2.0 # Apache-2.0
|
|
||||||
oslo.db>=1.12.0 # Apache-2.0
|
oslo.db>=1.12.0 # Apache-2.0
|
||||||
oslo.config>=2.6.0 # Apache-2.0
|
oslo.config>=2.6.0 # Apache-2.0
|
||||||
oslo.i18n>=1.5.0 # Apache-2.0
|
oslo.i18n>=1.5.0 # Apache-2.0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user