Skip to content

Commit

Permalink
Find subordinates reading from top level tree.
Browse files Browse the repository at this point in the history
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 fc26818)
  • Loading branch information
freyes committed Aug 24, 2022
1 parent 0a6b19b commit 18b5fc3
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions unit_tests/utilities/test_zaza_utilities_juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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'}}
Expand Down
11 changes: 8 additions & 3 deletions zaza/utilities/juju.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 18b5fc3

Please sign in to comment.