From 4f9988196aaf74fee8a7eff852d1c63724f9171f Mon Sep 17 00:00:00 2001 From: Liam Young Date: Tue, 30 Sep 2014 14:12:10 +0000 Subject: [PATCH] Add neutron-api-plugin relation and use it to dictate neutron settings liek l2_population --- config.yaml | 7 ------- hooks/neutron-plugin-api-relation-broken | 1 + hooks/neutron-plugin-api-relation-changed | 1 + hooks/neutron-plugin-api-relation-departed | 1 + hooks/neutron-plugin-api-relation-joined | 1 + hooks/quantum_contexts.py | 24 +++++++++++++++++++++- hooks/quantum_hooks.py | 3 ++- metadata.yaml | 2 ++ unit_tests/test_quantum_contexts.py | 21 +++++++++++++++++++ 9 files changed, 52 insertions(+), 9 deletions(-) create mode 120000 hooks/neutron-plugin-api-relation-broken create mode 120000 hooks/neutron-plugin-api-relation-changed create mode 120000 hooks/neutron-plugin-api-relation-departed create mode 120000 hooks/neutron-plugin-api-relation-joined diff --git a/config.yaml b/config.yaml index e19b551d..acc64c46 100644 --- a/config.yaml +++ b/config.yaml @@ -102,10 +102,3 @@ options: . This network will be used for tenant network traffic in overlay networks. - l2-population: - type: boolean - default: True - description: | - Populate the forwarding tables of virtual switches (LinuxBridge or OVS), - to decrease broadcast traffics inside the physical networks fabric while - using overlays networks (VXLan, GRE). diff --git a/hooks/neutron-plugin-api-relation-broken b/hooks/neutron-plugin-api-relation-broken new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-api-relation-broken @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-api-relation-changed b/hooks/neutron-plugin-api-relation-changed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-api-relation-changed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-api-relation-departed b/hooks/neutron-plugin-api-relation-departed new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-api-relation-departed @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/neutron-plugin-api-relation-joined b/hooks/neutron-plugin-api-relation-joined new file mode 120000 index 00000000..9a2da58e --- /dev/null +++ b/hooks/neutron-plugin-api-relation-joined @@ -0,0 +1 @@ +quantum_hooks.py \ No newline at end of file diff --git a/hooks/quantum_contexts.py b/hooks/quantum_contexts.py index 5bd6fba2..224cba29 100644 --- a/hooks/quantum_contexts.py +++ b/hooks/quantum_contexts.py @@ -100,6 +100,27 @@ def core_plugin(): return CORE_PLUGIN[networking_name()][plugin] +def _neutron_api_settings(): + ''' + Inspects current neutron-plugin-api relation for neutron settings. Return + defaults if it is not present + ''' + neutron_settings = { + 'l2_population': True, + + } + for rid in relation_ids('neutron-plugin-api'): + for unit in related_units(rid): + rdata = relation_get(rid=rid, unit=unit) + if 'l2-population' not in rdata: + continue + neutron_settings = { + 'l2_population': rdata['l2-population'], + } + return neutron_settings + return neutron_settings + + class NetworkServiceContext(OSContextGenerator): interfaces = ['quantum-network-service'] @@ -181,6 +202,7 @@ class ExternalPortContext(OSContextGenerator): class QuantumGatewayContext(OSContextGenerator): def __call__(self): + neutron_api_settings = _neutron_api_settings() ctxt = { 'shared_secret': get_shared_secret(), 'local_ip': @@ -191,7 +213,7 @@ class QuantumGatewayContext(OSContextGenerator): 'debug': config('debug'), 'verbose': config('verbose'), 'instance_mtu': config('instance-mtu'), - 'l2_population': config('l2-population'), + 'l2_population': neutron_api_settings['l2_population'], } return ctxt diff --git a/hooks/quantum_hooks.py b/hooks/quantum_hooks.py index af048362..62443d5b 100755 --- a/hooks/quantum_hooks.py +++ b/hooks/quantum_hooks.py @@ -162,7 +162,8 @@ def amqp_departed(): 'pgsql-db-relation-changed', 'amqp-relation-changed', 'cluster-relation-changed', - 'cluster-relation-joined') + 'cluster-relation-joined', + 'neutron-plugin-api-relation-changed') @restart_on_change(restart_map()) def db_amqp_changed(): CONFIGS.write_all() diff --git a/metadata.yaml b/metadata.yaml index c15d03fd..f24dde9f 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -27,6 +27,8 @@ requires: interface: rabbitmq amqp-nova: interface: rabbitmq + neutron-plugin-api: + interface: neutron-plugin-api peers: cluster: interface: quantum-gateway-ha diff --git a/unit_tests/test_quantum_contexts.py b/unit_tests/test_quantum_contexts.py index 7e9b87cf..a3ae7c73 100644 --- a/unit_tests/test_quantum_contexts.py +++ b/unit_tests/test_quantum_contexts.py @@ -353,3 +353,24 @@ class TestMisc(CharmTestCase): self.config.return_value = 'ovs' self.assertEquals(quantum_contexts.core_plugin(), quantum_contexts.NEUTRON_ML2_PLUGIN) + + def test_neutron_api_settings(self): + self.relation_ids.return_value = ['foo'] + self.related_units.return_value = ['bar'] + self.test_relation.set({'l2-population': True}) + self.relation_get.side_effect = self.test_relation.get + self.assertEquals(quantum_contexts._neutron_api_settings(), + {'l2_population': True}) + + def test_neutron_api_settings2(self): + self.relation_ids.return_value = ['foo'] + self.related_units.return_value = ['bar'] + self.test_relation.set({'l2-population': False}) + self.relation_get.side_effect = self.test_relation.get + self.assertEquals(quantum_contexts._neutron_api_settings(), + {'l2_population': False}) + + def test_neutron_api_settings_no_apiplugin(self): + self.relation_ids.return_value = [] + self.assertEquals(quantum_contexts._neutron_api_settings(), + {'l2_population': True})