[jjo,gnuoy,r=thedac] jjo: only add neutron-server to HAProxyContext if neutron-api relation is not made, fixes lp#1476394. gnuoy: added unit tests

This commit is contained in:
Liam Young 2015-09-29 07:46:46 +01:00
commit 0af9078ed0
2 changed files with 50 additions and 7 deletions

View File

@ -11,6 +11,7 @@ from charmhelpers.core.hookenv import (
related_units,
relations_for_id,
relation_get,
is_relation_made,
unit_get,
)
from charmhelpers.fetch import (
@ -185,6 +186,7 @@ class HAProxyContext(context.HAProxyContext):
})
listen_ports['osapi_volume_listen_port'] = nvol_api
if not is_relation_made('neutron-api'):
if neutron.network_manager() in ['neutron', 'quantum']:
port_mapping.update({
'neutron-server': [

View File

@ -19,6 +19,7 @@ from charmhelpers.contrib.openstack import utils
from test_utils import CharmTestCase
from charmhelpers.contrib.openstack import neutron
TO_PATCH = [
'apt_install',
@ -30,6 +31,7 @@ TO_PATCH = [
'log',
'relations_for_id',
'https',
'is_relation_made',
]
@ -149,6 +151,45 @@ class NovaComputeContextTests(CharmTestCase):
self.related_units.return_value = ['unit/0']
self.assertFalse(context.use_local_neutron_api())
@mock.patch.object(neutron, 'network_manager')
@mock.patch('charmhelpers.contrib.hahelpers.cluster.https')
@mock.patch('charmhelpers.contrib.openstack.context.'
'get_address_in_network')
@mock.patch('charmhelpers.contrib.openstack.context.'
'get_netmask_for_address')
@mock.patch('charmhelpers.contrib.openstack.context.local_unit')
@mock.patch('charmhelpers.contrib.openstack.context.get_ipv6_addr')
@mock.patch('charmhelpers.contrib.openstack.context.relation_ids')
def test_haproxy_context(self, mock_relation_ids, mock_get_ipv6_addr,
mock_local_unit, mock_get_netmask_for_address,
mock_get_address_in_network, mock_https,
mock_network_manager):
mock_network_manager.return_value = 'neutron'
mock_https.return_value = False
self.is_relation_made.return_value = False
ctxt = context.HAProxyContext()()
self.assertEqual(ctxt['service_ports']['neutron-server'], [9696, 9686])
@mock.patch.object(neutron, 'network_manager')
@mock.patch('charmhelpers.contrib.hahelpers.cluster.https')
@mock.patch('charmhelpers.contrib.openstack.context.'
'get_address_in_network')
@mock.patch('charmhelpers.contrib.openstack.context.'
'get_netmask_for_address')
@mock.patch('charmhelpers.contrib.openstack.context.local_unit')
@mock.patch('charmhelpers.contrib.openstack.context.get_ipv6_addr')
@mock.patch('charmhelpers.contrib.openstack.context.relation_ids')
def test_haproxy_context_api_relation(self, mock_relation_ids,
mock_get_ipv6_addr, mock_local_unit,
mock_get_netmask_for_address,
mock_get_address_in_network,
mock_https, mock_network_manager):
mock_network_manager.return_value = 'neutron'
mock_https.return_value = False
self.is_relation_made.return_value = True
ctxt = context.HAProxyContext()()
self.assertEqual(ctxt['service_ports'].get('neutron-server'), None)
@mock.patch.object(context, 'config')
def test_console_ssl_disabled(self, mock_config):
config = {'console-ssl-cert': 'LS0tLS1CRUdJTiBDRV',