diff options
author | jneo8 <james.lin@canonical.com> | 2023-05-03 17:25:26 +0800 |
---|---|---|
committer | Jake Hunsaker <jhunsake@redhat.com> | 2023-05-04 13:35:19 -0400 |
commit | f1a0ae1a469da5ecedd7faa7ce67bbf60eb93cb2 (patch) | |
tree | 3b0a8fd3bd72a924374f46be4b344658be5af9ac /tests | |
parent | b8724fd04f13542c17e7905c6eeec515d2636b6b (diff) | |
download | sos-f1a0ae1a469da5ecedd7faa7ce67bbf60eb93cb2.tar.gz |
[juju] Fix cluster collection doesn't work in 2 scenarios
Fix below two scenarios:
1. If subordinate's parent is missing.
2. If subordinate's parent's units is missing.
Closes: #3213
Signed-off-by: jneo8 <james.lin@canonical.com>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unittests/juju/juju_cluster_tests.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/unittests/juju/juju_cluster_tests.py b/tests/unittests/juju/juju_cluster_tests.py index 136dc49f..eae50b71 100644 --- a/tests/unittests/juju/juju_cluster_tests.py +++ b/tests/unittests/juju/juju_cluster_tests.py @@ -7,11 +7,12 @@ # version 2 of the GNU General Public License. # # See the LICENSE file in the source distribution for further information. +import json import pathlib import unittest from unittest.mock import call, patch -from sos.collector.clusters.juju import _parse_option_string, juju +from sos.collector.clusters.juju import _parse_option_string, juju, _get_index from sos.options import ClusterOption @@ -291,4 +292,33 @@ class JujuTest(unittest.TestCase): ) +class IndexTest(unittest.TestCase): + + def test_subordinate_parent_miss_units(self): + """Fix if subordinate's parent is missing units.""" + model = "sos" + index = _get_index(model_name=model) + + juju_status = json.loads(get_juju_output(model=model)) + juju_status["applications"]["ubuntu"].pop("units") + + # Ensure these commands won't fall even when + # subordinate's parent's units is missing. + index.add_principals(juju_status) + index.add_subordinates(juju_status) + + def test_subordinate_miss_parent(self): + """Fix if subordinate is missing parent.""" + model = "sos" + index = _get_index(model_name=model) + + juju_status = json.loads(get_juju_output(model=model)) + index.add_principals(juju_status) + + index.apps.pop("ubuntu") + # Ensure command won't fall even when + # subordinate's parent is missing + index.add_subordinates(juju_status) + + # vim: set et ts=4 sw=4 : |