From 981fcccf8313157e7d78fda542ea18fc2547a17a Mon Sep 17 00:00:00 2001 From: Bartosz Woronicz Date: Wed, 15 Mar 2023 13:50:59 +0000 Subject: [PATCH] add support for availability zone in OVN cms options LP#2002449 That fix enables AZ support in OVN via external-ids:ovn-cms-options It relies on JUJU_AVAILABILITY_ZONE env variable. --- config.yaml | 10 ++++++++++ lib/charms/ovn_charm.py | 4 ++++ unit_tests/test_lib_charms_ovn_charm.py | 10 ++++++++++ 3 files changed, 24 insertions(+) diff --git a/config.yaml b/config.yaml index 4d116cc..de9f28e 100644 --- a/config.yaml +++ b/config.yaml @@ -297,6 +297,16 @@ options: . NOTE: It is also possible to enable this option on several OVN chassis applications at the same time, e.g. on 2 out of 3. + customize-failure-domain: + type: boolean + default: false + description: | + Juju propagates availability zone information to charms from the + underlying machine provider such as MAAS and this option allows the + charm to use JUJU_AVAILABILITY_ZONE to set default_availability_zone for + Nova nodes. This option overrides the default-availability-zone charm + config setting only when the Juju provider sets JUJU_AVAILABILITY_ZONE. + More details: https://docs.openstack.org/neutron/latest/admin/ovn/availability_zones.html nagios_context: default: "juju" type: string diff --git a/lib/charms/ovn_charm.py b/lib/charms/ovn_charm.py index 3d58036..c6fa3bb 100644 --- a/lib/charms/ovn_charm.py +++ b/lib/charms/ovn_charm.py @@ -1341,6 +1341,10 @@ def _get_ovn_cms_options(self): if self.options.card_serial_number: cms_opts.append( f'card-serial-number={self.options.card_serial_number}') + if self.options.customize_failure_domain and \ + 'JUJU_AVAILABILITY_ZONE' in os.environ: + cms_opts.append( + f'availability-zones={os.environ["JUJU_AVAILABILITY_ZONE"]}') return cms_opts def render_nrpe(self): diff --git a/unit_tests/test_lib_charms_ovn_charm.py b/unit_tests/test_lib_charms_ovn_charm.py index 3a10c08..698034b 100644 --- a/unit_tests/test_lib_charms_ovn_charm.py +++ b/unit_tests/test_lib_charms_ovn_charm.py @@ -15,6 +15,7 @@ import collections import copy import io +import os import textwrap import subprocess import unittest.mock as mock @@ -764,6 +765,7 @@ def setUp(self): 'vpd-device-spec': '', 'pmd-cpu-set': '', 'ovn-source': 'distro', + 'customize-failure-domain': False, }) self.patch_object(ovn_charm.OVNConfigurationAdapter, '_ovs_dpdk_cpu_overlap_check') @@ -1097,6 +1099,7 @@ def setUp(self): '[{"bus": "pci", "vendor_id": "beef", "device_id": "cafe"}]', 'ovn-source': 'distro', 'ovs-exporter-channel': '', + 'customize-failure-domain': False, }) def test_optional_openstack_metadata(self): @@ -1734,6 +1737,13 @@ def test_assess_exporter_no_channel_not_installed(self): self.refresh.assert_not_called() self.remove.assert_not_called() + @mock.patch.dict(os.environ, {"JUJU_AVAILABILITY_ZONE": "az1"}, clear=True) + def test_configure_customize_failure_domain(self): + self.target.options.customize_failure_domain = True + self.assertEqual( + self.target._get_ovn_cms_options(), + ['enable-chassis-as-gw', 'availability-zones=az1']) + class TestOVNChassisCharmOvsExporter(Helper):