Create DRAgentRelationAdapters

Override the amqp adapter the correct way by creating a new relation
adapters class. Use the newer transport_url rather than the older
rabbit_* settings for amqp messaging.

Change-Id: I22b81e25d0e9fc227de4e000540d350c2a635765
This commit is contained in:
David Ames 2018-05-18 15:31:37 -07:00
parent ae26c6f642
commit dc79712d49
8 changed files with 49 additions and 21 deletions

4
.gitreview Normal file
View File

@ -0,0 +1,4 @@
[gerrit]
host=review.openstack.org
port=29418
project=openstack/charm-neutron-dynamic-routing.git

View File

@ -118,6 +118,11 @@ class TransportURLAdapter(os_adapters.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
@ -143,7 +148,17 @@ class TransportURLAdapter(os_adapters.RabbitMQRelationAdapter):
:returns: int port number
"""
return self.ssl_port or 5672
return self.ssl_port or self.DEFAULT_PORT
class DRAgentRelationAdapters(os_adapters.OpenStackRelationAdapters):
"""
Adapters collection to append specific adapters for Neutron Dynamic Routing
"""
relation_adapters = {
'amqp': TransportURLAdapter,
}
class DRAgentCharm(charms_openstack.charm.OpenStackCharm):
@ -157,11 +172,7 @@ class DRAgentCharm(charms_openstack.charm.OpenStackCharm):
default_service = 'neutron-bgp-dragent'
services = [default_service]
required_relations = ['amqp']
adapters_class = os_adapters.OpenStackRelationAdapters
adapters_class.relation_adapters = {
'amqp': TransportURLAdapter,
}
adapters_class = DRAgentRelationAdapters
restart_map = {
NEUTRON_CONF: services,

View File

@ -6,12 +6,12 @@
verbose = {{ options.verbose }}
debug = {{ options.debug }}
{% if amqp.transport_url -%}
transport_url = {{ amqp.transport_url }}
{% endif -%}
[agent]
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
{% include "parts/section-rabbitmq-oslo" %}
{% include "parts/section-oslo-notifications" %}
[oslo_concurrency]
lock_path = /var/lock/neutron

View File

@ -4,9 +4,9 @@ tests:
configure:
- zaza.charm_tests.dragent.configure.setup
gate_bundles:
- xenial-queens-functional
- xenial-pike-functional
smoke_bundles:
- xenial-queens-functional
dev_bundles:
- bionic-queens-functional
- xenial-pike-functional
- xenial-queens-functional
smoke_bundles:
- bionic-queens-functional
dev_bundles:

View File

@ -6,7 +6,9 @@ skipsdist = True
setenv = VIRTUAL_ENV={envdir}
PYTHONHASHSEED=0
whitelist_externals = juju
passenv = HOME TERM CS_API_*
passenv =
HOME TERM CS_API_* FIP_RANGE AMULET_* MOJO_* NET_ID GATEWAY NAME_SERVER
CIDR_EXT FIP_RANGE VIP_RANGE
deps = -r{toxinidir}/test-requirements.txt
install_command =
pip install {opts} {packages}

View File

@ -3,7 +3,7 @@
# within individual charm repos.
[tox]
skipsdist = True
envlist = pep8,py3
envlist = pep8,py35
skip_missing_interpreters = True
[testenv]
@ -32,13 +32,13 @@ basepython = python2.7
whitelist_externals = true
commands = true
[testenv:py3]
[testenv:py35]
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = ostestr {posargs}
[testenv:pep8]
basepython = python3.5
basepython = python3
deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs} src unit_tests

View File

@ -20,3 +20,14 @@ sys.path.append('src/lib')
# Mock out charmhelpers so that we can test without it.
import charms_openstack.test_mocks # noqa
charms_openstack.test_mocks.mock_charmhelpers()
def mock_more_stuff():
charmhelpers = charms_openstack.test_mocks.charmhelpers
sys.modules['charmhelpers.core.hookenv.charm_dir'] = (
charmhelpers.core.hookenv.charm_dir
)
charmhelpers.core.hookenv.charm_dir.return_value = "/tmp"
mock_more_stuff()

View File

@ -85,8 +85,8 @@ class TestTransportURLAdapter(Helper):
self.assertEqual(tua.transport_url, _expected)
def test_port(self):
_ssl_port = 2765
_port = 5672
_ssl_port = '2765'
_port = '5672'
amqp = mock.MagicMock()
tua = dragent.TransportURLAdapter(amqp)
# Default Port