Removed 'watcher_messaging' to use oslo.messaging
The old 'watcher_messaging' section of the Watcher configuration file has now been replaced by the more standard oslo.configuration one. DocImpact Change-Id: Ie027df023e6133f3188e57b42846083f28c282bd
This commit is contained in:
@@ -15,63 +15,74 @@
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
import mock
|
||||
from oslo_config import cfg
|
||||
from mock import patch
|
||||
|
||||
from watcher.common.messaging.messaging_core import MessagingCore
|
||||
from watcher.common.messaging.messaging_handler import MessagingHandler
|
||||
from watcher.common.rpc import RequestContextSerializer
|
||||
from watcher.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
from watcher.tests.base import TestCase
|
||||
|
||||
|
||||
class TestMessagingCore(base.TestCase):
|
||||
messaging = MessagingCore("", "", "")
|
||||
class TestMessagingCore(TestCase):
|
||||
|
||||
def fake_topic_name(self):
|
||||
topic_name = "MyTopic"
|
||||
return topic_name
|
||||
def setUp(self):
|
||||
super(TestMessagingCore, self).setUp()
|
||||
|
||||
def test_build_topic(self):
|
||||
topic_name = self.fake_topic_name()
|
||||
messaging_handler = self.messaging.build_topic(topic_name)
|
||||
topic_name = "MyTopic"
|
||||
messaging = MessagingCore("", "", "")
|
||||
messaging_handler = messaging.build_topic(topic_name)
|
||||
self.assertIsNotNone(messaging_handler)
|
||||
|
||||
def test_init_messaging_core(self):
|
||||
self.assertIsInstance(self.messaging.serializer,
|
||||
messaging = MessagingCore("", "", "")
|
||||
self.assertIsInstance(messaging.serializer,
|
||||
RequestContextSerializer)
|
||||
self.assertIsInstance(self.messaging.topic_control, MessagingHandler)
|
||||
self.assertIsInstance(self.messaging.topic_status, MessagingHandler)
|
||||
self.assertIsInstance(messaging.topic_control, MessagingHandler)
|
||||
self.assertIsInstance(messaging.topic_status, MessagingHandler)
|
||||
|
||||
def test_publish_control(self):
|
||||
with mock.patch.object(MessagingCore, 'publish_control') as mock_call:
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "MyEvent"
|
||||
self.messaging.publish_control(event, payload)
|
||||
mock_call.assert_called_once_with(event, payload)
|
||||
@patch.object(MessagingCore, 'publish_control')
|
||||
def test_publish_control(self, mock_call):
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "MyEvent"
|
||||
messaging = MessagingCore("", "", "")
|
||||
messaging.publish_control(event, payload)
|
||||
mock_call.assert_called_once_with(event, payload)
|
||||
|
||||
def test_publish_status(self):
|
||||
with mock.patch.object(MessagingCore, 'publish_status') as mock_call:
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "MyEvent"
|
||||
self.messaging.publish_status(event, payload)
|
||||
mock_call.assert_called_once_with(event, payload)
|
||||
@patch.object(MessagingCore, 'publish_status')
|
||||
def test_publish_status(self, mock_call):
|
||||
payload = {
|
||||
"name": "value",
|
||||
}
|
||||
event = "MyEvent"
|
||||
messaging = MessagingCore("", "", "")
|
||||
messaging.publish_status(event, payload)
|
||||
mock_call.assert_called_once_with(event, payload)
|
||||
|
||||
def test_response(self):
|
||||
with mock.patch.object(MessagingCore, 'publish_status') as mock_call:
|
||||
event = "My event"
|
||||
context = {'request_id': 12}
|
||||
message = "My Message"
|
||||
@patch.object(MessagingCore, 'publish_status')
|
||||
def test_response(self, mock_call):
|
||||
event = "My event"
|
||||
context = {'request_id': 12}
|
||||
message = "My Message"
|
||||
|
||||
self.messaging.response(event, context, message)
|
||||
messaging = MessagingCore("", "", "")
|
||||
messaging.response(event, context, message)
|
||||
|
||||
expected_payload = {
|
||||
'request_id': context['request_id'],
|
||||
'msg': message
|
||||
}
|
||||
mock_call.assert_called_once_with(event, expected_payload)
|
||||
expected_payload = {
|
||||
'request_id': context['request_id'],
|
||||
'msg': message
|
||||
}
|
||||
mock_call.assert_called_once_with(event, expected_payload)
|
||||
|
||||
def test_messaging_build_topic(self):
|
||||
messaging = MessagingCore("pub_id", "test_topic", "does not matter")
|
||||
topic = messaging.build_topic("test_topic")
|
||||
|
||||
self.assertIsInstance(topic, MessagingHandler)
|
||||
self.assertEqual(messaging.publisher_id, "pub_id")
|
||||
self.assertEqual(topic.publisher_id, "pub_id")
|
||||
|
||||
self.assertEqual(messaging.topic_control.topic_watcher, "test_topic")
|
||||
self.assertEqual(topic.topic_watcher, "test_topic")
|
||||
|
||||
78
watcher/tests/common/messaging/test_messaging_handler.py
Normal file
78
watcher/tests/common/messaging/test_messaging_handler.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from mock import Mock
|
||||
from mock import patch
|
||||
from oslo_config import cfg
|
||||
import oslo_messaging as messaging
|
||||
from watcher.common.messaging.messaging_handler import MessagingHandler
|
||||
from watcher.tests.base import TestCase
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestMessagingHandler(TestCase):
|
||||
|
||||
PUBLISHER_ID = 'TEST_API'
|
||||
TOPIC_WATCHER = 'TEST_TOPIC_WATCHER'
|
||||
ENDPOINT = 'http://fake-fqdn:1337'
|
||||
VERSION = "1.0"
|
||||
|
||||
def setUp(self):
|
||||
super(TestMessagingHandler, self).setUp()
|
||||
CONF.set_default('host', 'fake-fqdn')
|
||||
|
||||
@patch.object(messaging, "get_rpc_server")
|
||||
@patch.object(messaging, "Target")
|
||||
def test_setup_messaging_handler(self, m_target_cls, m_get_rpc_server):
|
||||
m_target = Mock()
|
||||
m_target_cls.return_value = m_target
|
||||
messaging_handler = MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_watcher=self.TOPIC_WATCHER,
|
||||
endpoint=self.ENDPOINT,
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
messaging_handler.run()
|
||||
|
||||
m_target_cls.assert_called_once_with(
|
||||
server="fake-fqdn",
|
||||
topic="TEST_TOPIC_WATCHER",
|
||||
version="1.0",
|
||||
)
|
||||
m_get_rpc_server.assert_called_once_with(
|
||||
messaging_handler.transport,
|
||||
m_target,
|
||||
[self.ENDPOINT],
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
def test_messaging_handler_remove_endpoint(self):
|
||||
messaging_handler = MessagingHandler(
|
||||
publisher_id=self.PUBLISHER_ID,
|
||||
topic_watcher=self.TOPIC_WATCHER,
|
||||
endpoint=self.ENDPOINT,
|
||||
version=self.VERSION,
|
||||
serializer=None,
|
||||
)
|
||||
|
||||
self.assertEqual(messaging_handler.endpoints, [self.ENDPOINT])
|
||||
|
||||
messaging_handler.remove_endpoint(self.ENDPOINT)
|
||||
|
||||
self.assertEqual(messaging_handler.endpoints, [])
|
||||
@@ -1,46 +0,0 @@
|
||||
# -*- encoding: utf-8 -*-
|
||||
# Copyright (c) 2015 b<>com
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
# implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
|
||||
from oslo_config import cfg
|
||||
import re
|
||||
from watcher.common.messaging.utils.transport_url_builder import \
|
||||
TransportUrlBuilder
|
||||
from watcher.tests import base
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestTransportUrlBuilder(base.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestTransportUrlBuilder, self).setUp()
|
||||
|
||||
def test_transport_url_not_none(self):
|
||||
url = TransportUrlBuilder().url
|
||||
self.assertIsNotNone(url, "The transport url must not be none")
|
||||
|
||||
def test_transport_url_valid_pattern(self):
|
||||
url = TransportUrlBuilder().url
|
||||
url_pattern = r'(\D+)://(\D+):(\D+)@(\D+):(\d+)'
|
||||
pattern = re.compile(url_pattern)
|
||||
match = re.search(url_pattern, url)
|
||||
self.assertEqual('rabbit', match.group(1))
|
||||
self.assertEqual('guest', match.group(2))
|
||||
self.assertEqual('guest', match.group(3))
|
||||
self.assertEqual('localhost', match.group(4))
|
||||
self.assertEqual('5672', match.group(5))
|
||||
self.assertIsNotNone(pattern.match(url))
|
||||
@@ -34,7 +34,6 @@ class ConfFixture(fixtures.Fixture):
|
||||
def setUp(self):
|
||||
super(ConfFixture, self).setUp()
|
||||
|
||||
self.conf.set_default('host', 'fake-mini')
|
||||
self.conf.set_default('connection', "sqlite://", group='database')
|
||||
self.conf.set_default('sqlite_synchronous', False, group='database')
|
||||
self.conf.set_default('verbose', True)
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestDecisionEngineAPI(base.TestCase):
|
||||
mock_call.assert_called_once_with(
|
||||
expected_context.to_dict(),
|
||||
'check_api_version',
|
||||
api_version=DecisionEngineAPI().API_VERSION)
|
||||
api_version=DecisionEngineAPI().api_version)
|
||||
|
||||
def test_execute_audit_throw_exception(self):
|
||||
audit_uuid = "uuid"
|
||||
|
||||
Reference in New Issue
Block a user