Revert to use of charms.openstack transport_url
Drop charm specific code to build the oslo.messaging transport_url; this is now provided as part of charms.openstack. Change-Id: I1a9bcf7bc57b99326cae618df06930ae3990fab0 Closes-Bug: 1817672
This commit is contained in:
parent
af65fc44ce
commit
3bedb660d4
|
@ -142,51 +142,13 @@ def speaker_ip(cls):
|
||||||
return ch_ip.get_relation_ip(SPEAKER_BINDING)
|
return ch_ip.get_relation_ip(SPEAKER_BINDING)
|
||||||
|
|
||||||
|
|
||||||
class TransportURLAdapter(os_adapters.RabbitMQRelationAdapter):
|
|
||||||
"""Add Transport URL to RabbitMQRelationAdapter
|
|
||||||
TODO: Move to charms.openstack.adapters
|
|
||||||
"""
|
|
||||||
|
|
||||||
DEFAULT_PORT = '5672'
|
|
||||||
|
|
||||||
def __init__(self, relation):
|
|
||||||
super(TransportURLAdapter, self).__init__(relation)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def transport_url(self):
|
|
||||||
"""Return the transport URL for communicating with rabbitmq
|
|
||||||
|
|
||||||
:returns: string transport URL
|
|
||||||
"""
|
|
||||||
if self.hosts:
|
|
||||||
hosts = self.hosts.split(',')
|
|
||||||
else:
|
|
||||||
hosts = [self.host]
|
|
||||||
if hosts:
|
|
||||||
transport_url_hosts = ','.join([
|
|
||||||
"{}:{}@{}:{}".format(self.username,
|
|
||||||
self.password,
|
|
||||||
host_,
|
|
||||||
self.port)
|
|
||||||
for host_ in hosts])
|
|
||||||
return "rabbit://{}/{}".format(transport_url_hosts, self.vhost)
|
|
||||||
|
|
||||||
@property
|
|
||||||
def port(self):
|
|
||||||
"""Return the port for commuicating with rabbitmq
|
|
||||||
|
|
||||||
:returns: int port number
|
|
||||||
"""
|
|
||||||
return self.ssl_port or self.DEFAULT_PORT
|
|
||||||
|
|
||||||
|
|
||||||
class DRAgentRelationAdapters(os_adapters.OpenStackRelationAdapters):
|
class DRAgentRelationAdapters(os_adapters.OpenStackRelationAdapters):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Adapters collection to append specific adapters for Neutron Dynamic Routing
|
Adapters collection to append specific adapters for Neutron Dynamic Routing
|
||||||
"""
|
"""
|
||||||
relation_adapters = {
|
relation_adapters = {
|
||||||
'amqp': TransportURLAdapter,
|
'amqp': os_adapters.RabbitMQRelationAdapter,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,8 +15,6 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
from __future__ import print_function
|
from __future__ import print_function
|
||||||
|
|
||||||
import mock
|
|
||||||
|
|
||||||
import charm.openstack.dragent as dragent
|
import charm.openstack.dragent as dragent
|
||||||
|
|
||||||
import charms_openstack.test_utils as test_utils
|
import charms_openstack.test_utils as test_utils
|
||||||
|
@ -69,42 +67,6 @@ class TestOpenStackDRAgent(Helper):
|
||||||
self.get_relation_ip.assert_called_once_with(self.PROVIDER_BINDING)
|
self.get_relation_ip.assert_called_once_with(self.PROVIDER_BINDING)
|
||||||
|
|
||||||
|
|
||||||
class TestTransportURLAdapter(Helper):
|
|
||||||
|
|
||||||
def test_transport_url(self):
|
|
||||||
_expected = "rabbit://user:pass@10.0.0.50:5672/vhost"
|
|
||||||
amqp = mock.MagicMock()
|
|
||||||
amqp.relation_name = "amqp"
|
|
||||||
amqp.username.return_value = "user"
|
|
||||||
amqp.vhost.return_value = "vhost"
|
|
||||||
tua = dragent.TransportURLAdapter(amqp)
|
|
||||||
tua.vip = None
|
|
||||||
tua.password = "pass"
|
|
||||||
tua.ssl_port = None
|
|
||||||
|
|
||||||
# Single
|
|
||||||
tua.private_address = "10.0.0.50"
|
|
||||||
self.assertEqual(tua.transport_url, _expected)
|
|
||||||
|
|
||||||
# Multiple
|
|
||||||
_expected = ("rabbit://user:pass@10.200.0.20:5672,"
|
|
||||||
"user:pass@10.200.0.30:5672/vhost")
|
|
||||||
amqp.rabbitmq_hosts.return_value = ["10.200.0.20", "10.200.0.30"]
|
|
||||||
self.assertEqual(tua.transport_url, _expected)
|
|
||||||
|
|
||||||
def test_port(self):
|
|
||||||
_ssl_port = '2765'
|
|
||||||
_port = '5672'
|
|
||||||
amqp = mock.MagicMock()
|
|
||||||
tua = dragent.TransportURLAdapter(amqp)
|
|
||||||
# Default Port
|
|
||||||
tua.ssl_port = None
|
|
||||||
self.assertEqual(tua.port, _port)
|
|
||||||
# SSL port
|
|
||||||
tua.ssl_port = _ssl_port
|
|
||||||
self.assertEqual(tua.port, _ssl_port)
|
|
||||||
|
|
||||||
|
|
||||||
class TestDRAgentCharm(Helper):
|
class TestDRAgentCharm(Helper):
|
||||||
|
|
||||||
def test_install(self):
|
def test_install(self):
|
||||||
|
|
Loading…
Reference in New Issue