Skip to content

Commit

Permalink
Merge pull request openstack-charmers#567 from freyes/get_subordinate…
Browse files Browse the repository at this point in the history
…s/xena

Test get_subordinates() - xena
  • Loading branch information
ajkavanagh authored Aug 24, 2022
2 parents af4c5fc + 18b5fc3 commit 16fb0e7
Show file tree
Hide file tree
Showing 9 changed files with 125 additions and 12 deletions.
33 changes: 28 additions & 5 deletions .github/workflows/tox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,27 @@ jobs:
codecov --verbose --gcov-glob unit_tests/*
func:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
juju_channel:
- latest/stable
- 2.9/stable
- 2.8/stable
bundle:
- first
- second
- third
exclude:
# disable 'first' and 'second' bundles for juju 2.8 since 'magpie'
# is not a promulgated charm in the charmstore, only on charmhub
# which 2.8 can't talk to.
- juju_channel: 2.8/stable
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 All @@ -39,7 +60,7 @@ jobs:
set -euxo pipefail
python -m pip install --upgrade pip
pip install tox tox-gh-actions
sudo snap install --classic juju
sudo snap install --channel ${{ matrix.juju_channel }} --classic juju
sudo snap install --classic juju-crashdump
sudo lxd init --auto
# This is a throw-away CI environment, do not do this at home
Expand All @@ -56,13 +77,15 @@ jobs:
run: |
set -euxo pipefail
mkdir logs
tox -e func | tee logs/tox-output.txt
juju status -m $(juju models --format yaml|grep "^- name:.*zaza"|cut -f2 -d/) | tee logs/juju-status.txt
tox -e func-target -- ${{ matrix.bundle }} | tee logs/tox-output.txt
- name: crashdump on failure
if: failure()
run: |
set -euxo pipefail
juju crashdump -o logs/
set -eux
juju models
model=$(juju models --format yaml|grep "^- name:.*zaza"|cut -f2 -d/)
juju status -m $model | tee logs/juju-status.txt
juju crashdump -m $model -o logs/
- name: upload logs on failure
if: failure()
uses: actions/upload-artifact@v2
Expand Down
3 changes: 3 additions & 0 deletions pip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
pip install pip==20.2.3
pip install "$@"
6 changes: 6 additions & 0 deletions tests/bundles/first.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,9 @@ applications:
ubuntu:
charm: ch:ubuntu
num_units: 3
ntp:
charm: ch:ntp
num_units: 0
relations:
- - ubuntu
- ntp
6 changes: 6 additions & 0 deletions tests/bundles/second.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ applications:
ubuntu:
charm: ch:ubuntu
num_units: 3
ntp:
charm: ch:ntp
num_units: 0
relations:
- - ubuntu
- ntp
9 changes: 7 additions & 2 deletions tests/bundles/third.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
series: focal
applications:
ubuntu:
charm: ch:ubuntu
charm: ubuntu
num_units: 10

ntp:
charm: ntp
num_units: 0
relations:
- - ubuntu
- ntp
11 changes: 9 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ whitelist_external = juju
passenv = HOME TERM CS_* OS_* TEST_*
deps = -r{toxinidir}/requirements.txt
install_command =
pip install {opts} {packages}
{toxinidir}/pip.sh install {opts} {packages}
commands = nosetests --with-coverage --cover-package=zaza {posargs} {toxinidir}/unit_tests

[testenv:py3]
Expand Down Expand Up @@ -56,7 +56,14 @@ basepython = python3
deps = -r{toxinidir}/requirements.txt
commands =
{envdir}/bin/python3 setup.py install
functest-run-suite --keep-model
functest-run-suite --keep-faulty-model

[testenv:func-target]
basepython = python3
deps = -r{toxinidir}/requirements.txt
commands =
{envdir}/bin/python3 setup.py install
functest-run-suite --keep-model --bundle {posargs}

[testenv:remove-placement]
basepython = python3
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
12 changes: 12 additions & 0 deletions zaza/charm_tests/libjuju/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import unittest

import zaza.model
import zaza.utilities.juju as juju_utils


class RegressionTest(unittest.TestCase):
Expand Down Expand Up @@ -50,3 +51,14 @@ def test_02_get_unit_public_address(self):
for ip in ips:
logging.info("Ip found %s", ip)
self.assertIsNotNone(ip)

def test_03_get_subordinates(self):
"""Get the subordinates associated to a principal."""
logging.info('Get the list of subordinates.')
units = [u.entity_id for u in zaza.model.get_units('ubuntu')]
logging.info('principal units found: %s', units)
subordinate = juju_utils.get_subordinate_units([units[0]],
charm_name='ntp')
logging.info('subordinate(s) found %s for principal %s',
subordinate, units[0])
self.assertEqual(len(subordinate), 1)
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 16fb0e7

Please sign in to comment.