From 6f33e03ab86de19a75bae2444e97f2d0d0cd9d4e Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 12 Feb 2015 16:27:40 +0000 Subject: [PATCH] _neutron_api_settings should return booleans for things which are supposed to be booleans rather than strings. this avoids confusion in the template --- hooks/neutron_ovs_context.py | 11 ++++++++--- unit_tests/test_neutron_ovs_context.py | 8 ++++---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/hooks/neutron_ovs_context.py b/hooks/neutron_ovs_context.py index 7dbf5211..e4aa2587 100644 --- a/hooks/neutron_ovs_context.py +++ b/hooks/neutron_ovs_context.py @@ -11,13 +11,18 @@ from charmhelpers.core.host import service_running, service_start from charmhelpers.contrib.network.ovs import add_bridge, add_bridge_port from charmhelpers.contrib.openstack.utils import get_host_ip from charmhelpers.contrib.network.ip import get_address_in_network - +import ast import re OVS_BRIDGE = 'br-int' DATA_BRIDGE = 'br-data' +def to_boolean(option): + if option is None: + return False + return ast.literal_eval(option) + def _neutron_api_settings(): ''' Inspects current neutron-plugin relation @@ -33,9 +38,9 @@ def _neutron_api_settings(): if 'l2-population' not in rdata: continue neutron_settings = { - 'l2_population': rdata['l2-population'], - 'neutron_security_groups': rdata['neutron-security-groups'], + 'l2_population': to_boolean(rdata['l2-population']), 'overlay_network_type': rdata['overlay-network-type'], + 'neutron_security_groups': to_boolean(rdata['neutron-security-groups']), } # Override with configuration if set to true if config('disable-security-groups'): diff --git a/unit_tests/test_neutron_ovs_context.py b/unit_tests/test_neutron_ovs_context.py index 3e2ee906..ec51d54a 100644 --- a/unit_tests/test_neutron_ovs_context.py +++ b/unit_tests/test_neutron_ovs_context.py @@ -88,8 +88,8 @@ class OVSPluginContextTest(CharmTestCase): _is_clus.return_value = False self.related_units.return_value = ['unit1'] self.relation_ids.return_value = ['rid2'] - self.test_relation.set({'neutron-security-groups': True, - 'l2-population': True, + self.test_relation.set({'neutron-security-groups': 'True', + 'l2-population': 'True', 'overlay-network-type': 'gre', }) self.get_host_ip.return_value = '127.0.0.15' @@ -141,8 +141,8 @@ class OVSPluginContextTest(CharmTestCase): self.test_config.set('disable-security-groups', True) self.related_units.return_value = ['unit1'] self.relation_ids.return_value = ['rid2'] - self.test_relation.set({'neutron-security-groups': True, - 'l2-population': True, + self.test_relation.set({'neutron-security-groups': 'True', + 'l2-population': 'True', 'overlay-network-type': 'gre', }) self.get_host_ip.return_value = '127.0.0.15'