From 18b5fc3b7b33b4245b50e1544434328dfdf1ed07 Mon Sep 17 00:00:00 2001 From: Felipe Reyes Date: Mon, 22 Aug 2022 22:06:28 -0400 Subject: [PATCH] Find subordinates reading from top level tree. This patch changes the way subordinates are filtered, since juju-2.9 doesn't populate the 'charm' key within the 'subordinates' key in the principal, so instead this change uses the unit id to get the app name and read the 'charm' value from the 'applications' section. This functionality is behind a feature a flag, if the environment variable TEST_ZAZA_BUG_LP1987332 is set to anything that evaluates to true, then this new code path is executed. Related-Bug: #1987332 (cherry picked from commit fc268181e8da1cb4293328fa2e78082873d98697) --- .github/workflows/tox.yaml | 2 + .../utilities/test_zaza_utilities_juju.py | 46 +++++++++++++++++++ zaza/utilities/juju.py | 11 +++-- 3 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tox.yaml b/.github/workflows/tox.yaml index c2f83a3ff..3bdd5dba2 100644 --- a/.github/workflows/tox.yaml +++ b/.github/workflows/tox.yaml @@ -50,6 +50,8 @@ jobs: bundle: first - juju_channel: 2.8/stable bundle: second + env: + TEST_ZAZA_BUG_LP1987332: "on" # http://pad.lv/1987332 needs: build steps: - uses: actions/checkout@v1 diff --git a/unit_tests/utilities/test_zaza_utilities_juju.py b/unit_tests/utilities/test_zaza_utilities_juju.py index f15b3e4f5..7fa5e2187 100644 --- a/unit_tests/utilities/test_zaza_utilities_juju.py +++ b/unit_tests/utilities/test_zaza_utilities_juju.py @@ -13,6 +13,7 @@ # limitations under the License. import mock +import os import unit_tests.utils as ut_utils from zaza.utilities import juju as juju_utils @@ -411,6 +412,51 @@ def test_get_subordinate_units(self): status=juju_status), ['cinder-ceph/3']) + def test_get_subordinate_units_lp1987332(self): + juju_status = mock.MagicMock() + juju_status.applications = { + 'nova-compute': { + 'charm': 'ch:amd64/focal/nova-compute-1', + 'units': { + 'nova-compute/0': { + 'subordinates': { + 'neutron-openvswitch/2': { + 'charm': ''}}}}}, + 'cinder': { + 'charm': 'ch:amd64/focal/cinder-2', + 'units': { + 'cinder/1': { + 'subordinates': { + 'cinder-hacluster/0': { + 'charm': ''}, + 'cinder-ceph/3': { + 'charm': ''}}}}}, + 'cinder-hacluster': { + 'charm': 'ch:amd64/focal/hacluster-3', + }, + 'cinder-ceph': { + 'charm': 'ch:amd64/focal/cinder-ceph-4', + }, + 'neutron-openvswitch': { + 'charm': 'ch:amd64/focal/neutron-openvswitch-5', + }, + } + self.model.get_status.return_Value = juju_status + with mock.patch.dict(os.environ, + {'TEST_ZAZA_BUG_LP1987332': '1'}): + self.assertEqual( + sorted(juju_utils.get_subordinate_units( + ['nova-compute/0', 'cinder/1'], + status=juju_status)), + sorted(['neutron-openvswitch/2', 'cinder-hacluster/0', + 'cinder-ceph/3'])) + self.assertEqual( + juju_utils.get_subordinate_units( + ['nova-compute/0', 'cinder/1'], + charm_name='ceph', + status=juju_status), + ['cinder-ceph/3']) + def test_get_application_ip(self): self.model.get_application_config.return_value = { 'vip': {'value': '10.0.0.10'}} diff --git a/zaza/utilities/juju.py b/zaza/utilities/juju.py index 95dd94671..de9b942e9 100644 --- a/zaza/utilities/juju.py +++ b/zaza/utilities/juju.py @@ -480,9 +480,14 @@ def get_subordinate_units(unit_list, charm_name=None, status=None, subs = status.applications[app_name]['units'][unit_name].get( 'subordinates') or {} if charm_name: - for unit_name, unit_data in subs.items(): - if charm_name in unit_data['charm']: - sub_units.append(unit_name) + for subordinate_name, unit_data in subs.items(): + if os.environ.get('TEST_ZAZA_BUG_LP1987332'): + sub_app = subordinate_name.split('/')[0] + charm = status.applications[sub_app]['charm'] + else: + charm = unit_data['charm'] + if charm_name in charm: + sub_units.append(subordinate_name) else: sub_units.extend([n for n in subs.keys()]) return sub_units