From 7be2ae2bd81f48641788d4de18cfeacbbe74a2ec Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Mon, 14 May 2018 12:52:09 +0200 Subject: [PATCH] Remove asn configuration option This configuration option is only used for CI testing and may be confusing for a unsuspecting end user. Change is coupled with PR on zaza that updates the dragent test to get information about configured asns by inspecting relation data on `neutron-dynamic-routing` and `quagga` units. Depends-On: I8b1508361fdc7541c0fc231e7e816651626596b7 Change-Id: I41360518ab2e65a207e238d95a39b763897d4fbc --- src/config.yaml | 9 ------- src/lib/charm/openstack/dragent.py | 11 +++++++++ src/reactive/dragent_handlers.py | 11 +++++---- .../bundles/bionic-queens-functional.yaml | 2 -- src/tests/bundles/xenial-pike-functional.yaml | 4 ++-- .../bundles/xenial-queens-functional.yaml | 3 +-- unit_tests/test_dragent_handlers.py | 24 ++++++++++++++----- .../test_lib_charm_openstack_dragent.py | 8 +++++++ 8 files changed, 47 insertions(+), 25 deletions(-) diff --git a/src/config.yaml b/src/config.yaml index 285922d..e69de29 100644 --- a/src/config.yaml +++ b/src/config.yaml @@ -1,9 +0,0 @@ -options: - asn: - default: - type: int - description: | - BGP Autonomous System Number for the OpenStack networks being advertised. - This setting is primarily used for testing. In production use ASNs are - configured post-deployment via the OpenStack client when creating bgp - speakers. diff --git a/src/lib/charm/openstack/dragent.py b/src/lib/charm/openstack/dragent.py index 457f9a7..85da16c 100644 --- a/src/lib/charm/openstack/dragent.py +++ b/src/lib/charm/openstack/dragent.py @@ -87,6 +87,17 @@ def bgp_speaker_bindings(): return [SPEAKER_BINDING] +def get_os_codename(): + """Return OpenStack Codename for installed application + + :returns: OpenStack Codename + :rtype: str + """ + return DRAgentCharm.singleton.get_os_codename_package( + DRAgentCharm.singleton.release_pkg, + DRAgentCharm.singleton.package_codenames) + + @os_adapters.config_property def provider_ip(cls): """Return the provider binding network IP diff --git a/src/reactive/dragent_handlers.py b/src/reactive/dragent_handlers.py index aa9b02f..595cf3f 100644 --- a/src/reactive/dragent_handlers.py +++ b/src/reactive/dragent_handlers.py @@ -16,7 +16,6 @@ from __future__ import absolute_import import charms.reactive as reactive -import charmhelpers.core.hookenv as hookenv import charms_openstack.charm as charm @@ -38,9 +37,13 @@ charm.use_defaults( def publish_bgp_info(endpoint): """Publish BGP information about this unit to interface-bgp peers """ - endpoint.publish_info(asn=hookenv.config('asn'), - passive=True, - bindings=dragent.bgp_speaker_bindings()) + if dragent.get_os_codename() == 'pike': + use_16bit_asn = True + else: + use_16bit_asn = False + endpoint.publish_info(passive=True, + bindings=dragent.bgp_speaker_bindings(), + use_16bit_asn=use_16bit_asn) dragent.assess_status() diff --git a/src/tests/bundles/bionic-queens-functional.yaml b/src/tests/bundles/bionic-queens-functional.yaml index 699aca4..d6e5fb2 100644 --- a/src/tests/bundles/bionic-queens-functional.yaml +++ b/src/tests/bundles/bionic-queens-functional.yaml @@ -28,7 +28,6 @@ applications: neutron-dynamic-routing: charm: ../../../neutron-dynamic-routing num_units: 1 - options: {asn: 12345} series: bionic rabbitmq-server: charm: cs:~openstack-charmers-next/bionic/rabbitmq-server @@ -38,6 +37,5 @@ applications: quagga: charm: cs:~openstack-charmers-next/bionic/quagga num_units: 1 - options: {asn: 10000} series: bionic diff --git a/src/tests/bundles/xenial-pike-functional.yaml b/src/tests/bundles/xenial-pike-functional.yaml index 9c857fe..705fbf3 100644 --- a/src/tests/bundles/xenial-pike-functional.yaml +++ b/src/tests/bundles/xenial-pike-functional.yaml @@ -30,7 +30,7 @@ applications: neutron-dynamic-routing: charm: ../../../neutron-dynamic-routing num_units: 1 - options: {asn: 12345, openstack-origin: 'cloud:xenial-pike/proposed'} + options: {openstack-origin: 'cloud:xenial-pike/proposed'} series: xenial rabbitmq-server: charm: cs:~openstack-charmers-next/xenial/rabbitmq-server @@ -41,6 +41,6 @@ applications: quagga: charm: cs:~openstack-charmers-next/xenial/quagga num_units: 1 - options: {asn: 10000} + options: {use-16bit-asn: True} series: xenial diff --git a/src/tests/bundles/xenial-queens-functional.yaml b/src/tests/bundles/xenial-queens-functional.yaml index 541ed5b..b32b1ba 100644 --- a/src/tests/bundles/xenial-queens-functional.yaml +++ b/src/tests/bundles/xenial-queens-functional.yaml @@ -29,7 +29,7 @@ applications: neutron-dynamic-routing: charm: ../../../neutron-dynamic-routing num_units: 1 - options: {asn: 12345, openstack-origin: 'cloud:xenial-queens/proposed'} + options: {openstack-origin: 'cloud:xenial-queens/proposed'} series: xenial rabbitmq-server: charm: cs:~openstack-charmers-next/xenial/rabbitmq-server @@ -40,6 +40,5 @@ applications: quagga: charm: cs:~openstack-charmers-next/xenial/quagga num_units: 1 - options: {asn: 10000} series: xenial diff --git a/unit_tests/test_dragent_handlers.py b/unit_tests/test_dragent_handlers.py index b6a1e38..2604488 100644 --- a/unit_tests/test_dragent_handlers.py +++ b/unit_tests/test_dragent_handlers.py @@ -122,16 +122,28 @@ class TestDRAgentHandlers(unittest.TestCase): "{}: incorrect state registration".format(f)) def test_publish_bgp_info(self): - _asn = 12345 _bindings = ['bgp-speaker'] self.patch(handlers.dragent, 'assess_status') - self.patch(handlers.hookenv, 'config') - self.config.return_value = _asn + self.patch(handlers.dragent, 'get_os_codename') bgp = mock.MagicMock() + self.get_os_codename.return_value = 'queens' handlers.publish_bgp_info(bgp) - bgp.publish_info.assert_called_once_with(asn=_asn, - passive=True, - bindings=_bindings) + self.get_os_codename.assert_called() + bgp.publish_info.assert_called_once_with(passive=True, + bindings=_bindings, + use_16bit_asn=False) + + def test_publish_bgp_info_pike(self): + _bindings = ['bgp-speaker'] + self.patch(handlers.dragent, 'assess_status') + self.patch(handlers.dragent, 'get_os_codename') + bgp = mock.MagicMock() + self.get_os_codename.return_value = 'pike' + handlers.publish_bgp_info(bgp) + self.get_os_codename.assert_called() + bgp.publish_info.assert_called_once_with(passive=True, + bindings=_bindings, + use_16bit_asn=True) def test_setup_amqp_req(self): self.patch(handlers.dragent, 'assess_status') diff --git a/unit_tests/test_lib_charm_openstack_dragent.py b/unit_tests/test_lib_charm_openstack_dragent.py index 9f802b8..41496aa 100644 --- a/unit_tests/test_lib_charm_openstack_dragent.py +++ b/unit_tests/test_lib_charm_openstack_dragent.py @@ -44,6 +44,14 @@ class TestOpenStackDRAgent(Helper): self.assertEqual(dragent.bgp_speaker_bindings(), [self.SPEAKER_BINDING]) + def get_os_codename(self): + self.patch_object(dragent.DRAgentCharm.singleton, + "get_os_codename_package") + dragent.get_os_codename() + self.get_os_codename_package.assert_called_once_with( + dragent.DRAgentCharm.singleton.release_pkg, + dragent.DRAgentCharm.singleton.package_codenames) + def test_speaker_ip(self): _ip = "10.0.0.10" self.patch_object(dragent.ch_ip, "get_relation_ip")