From 9eb098b23dab04173b3aabc9c65b0b0f6622b6d8 Mon Sep 17 00:00:00 2001 From: Frode Nordahl Date: Mon, 13 Jun 2022 10:58:51 +0200 Subject: [PATCH] lib/ovsdb: Allow interface to work with CMR The interface code curretly strictly gates operation based on information from `goal-state`. This information is however not available when used with CMR. Since the ovn-central charm currently must be at least 3 units, we can assume a minimum of 3 units to be joined when the expected count from `goal-state` is 1. Also replace os-testr with stestr. Closes-Bug: #1976537 Change-Id: I5b91d3caa466383fec76a393556668eb3b59ec63 --- src/lib/ovsdb.py | 12 +++++++++--- test-requirements.txt | 2 +- tox.ini | 6 +++--- unit_tests/test_lib_ovsdb.py | 12 ++++++++++++ 4 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/lib/ovsdb.py b/src/lib/ovsdb.py index 358bf18..e456c26 100644 --- a/src/lib/ovsdb.py +++ b/src/lib/ovsdb.py @@ -156,9 +156,15 @@ class OVSDB(reactive.Endpoint): False otherwise. :rtype: bool """ - if len(self.all_joined_units) == len( - list(ch_core.hookenv.expected_related_units( - self.expand_name('{endpoint_name}')))): + expected_related_units = len( + list(ch_core.hookenv.expected_related_units( + self.expand_name('{endpoint_name}')))) + # A minimum of 3 ovn-central units are required for operation, if + # this number is 1 chances are we are consuming the realation over CMR + # which would not provide us with an accurate number. + if expected_related_units == 1: + expected_related_units = 3 + if len(self.all_joined_units) >= expected_related_units: bound_addrs = [unit.received.get('bound-address', None) is not None for relation in self.relations for unit in relation.units] diff --git a/test-requirements.txt b/test-requirements.txt index ac58161..5c881e6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,6 +1,6 @@ # Lint and unit test requirements flake8 -os-testr>=0.4.1 +stestr charms.reactive mock>=1.2 coverage>=3.6 diff --git a/tox.ini b/tox.ini index f2ff4e9..b2609cb 100644 --- a/tox.ini +++ b/tox.ini @@ -13,17 +13,17 @@ install_command = [testenv:py3] basepython = python3 deps = -r{toxinidir}/test-requirements.txt -commands = ostestr {posargs} +commands = stestr run {posargs} [testenv:py35] basepython = python3.5 deps = -r{toxinidir}/test-requirements.txt -commands = ostestr {posargs} +commands = stestr run {posargs} [testenv:py36] basepython = python3.6 deps = -r{toxinidir}/test-requirements.txt -commands = ostestr {posargs} +commands = stestr run {posargs} [testenv:pep8] basepython = python3 diff --git a/unit_tests/test_lib_ovsdb.py b/unit_tests/test_lib_ovsdb.py index 2684a15..73392d2 100644 --- a/unit_tests/test_lib_ovsdb.py +++ b/unit_tests/test_lib_ovsdb.py @@ -183,6 +183,18 @@ class TestOVSDBLib(test_utils.PatchHelper): unit3.received = {'bound-address': '6.7.8.9'} self.assertEquals(self.target.expected_units_available(), True) + # when related to ovn-central through CMR expected_related_units + # will always be 1. check that this works + self.expected_related_units.return_value = [ + 'controller:user/offer.name', + ] + self.target._all_joined_units = [ + 'unit/0', 'unit/1'] + self.assertEquals(self.target.expected_units_available(), False) + self.target._all_joined_units = [ + 'unit/0', 'unit/1', 'unit/2'] + self.assertEquals(self.target.expected_units_available(), True) + def test_publish_cluster_local_addr(self): to_publish = self.patch_topublish() self.target.publish_cluster_local_addr()