From 7c50d9e1dcd8361047a90619588c94756165b318 Mon Sep 17 00:00:00 2001 From: David Ames Date: Wed, 15 Apr 2020 15:13:54 -0700 Subject: [PATCH] Pass wait timeout all the way through to clients Pass the non-interactive wait timeout value through. Change-Id: I25c2e982ebabe09385e52fef0fb8c97cabe60756 Closes-Bug: #1841063 --- provides.py | 7 +++++-- requires.py | 2 +- test-requirements.txt | 2 +- unit_tests/test_provides.py | 17 +++++++++++++++++ unit_tests/test_requires.py | 11 +++++++++++ 5 files changed, 35 insertions(+), 4 deletions(-) diff --git a/provides.py b/provides.py index 05125b3..4fb65d3 100644 --- a/provides.py +++ b/provides.py @@ -76,13 +76,16 @@ class MySQLSharedProvides(reactive.Endpoint): def set_db_connection_info( self, relation_id, db_host, password, - allowed_units=None, prefix=None): + allowed_units=None, prefix=None, wait_timeout=None): # Implementations of shared-db pre-date the json encoded era of # interface layers. In order not to have to update dozens of charms, # publish in raw data - # Everyone gets db_host + # No prefix for db_host and wait_timeout self.relations[relation_id].to_publish_raw["db_host"] = db_host + if wait_timeout: + self.relations[relation_id].to_publish_raw["wait_timeout"] = ( + wait_timeout) if not prefix: self.relations[relation_id].to_publish_raw["password"] = password self.relations[relation_id].to_publish_raw[ diff --git a/requires.py b/requires.py index be47392..74fa9bf 100644 --- a/requires.py +++ b/requires.py @@ -11,7 +11,7 @@ class MySQLSharedRequires(RelationBase): # with a basic documentation string provided. auto_accessors = ['access-network', 'db_host', 'ssl_ca', 'ssl_cert', 'ssl_key', - 'cluster-series-upgrading'] + 'cluster-series-upgrading', 'wait_timeout'] @hook('{requires:mysql-shared}-relation-joined') def joined(self): diff --git a/test-requirements.txt b/test-requirements.txt index 3900c51..0ea7ad6 100644 --- a/test-requirements.txt +++ b/test-requirements.txt @@ -1,5 +1,5 @@ charms.reactive -flake8>=2.2.4,<=2.4.1 +flake8>=2.2.4 mock>=1.2 stestr>=2.2.0 git+https://github.com/openstack/charms.openstack.git#egg=charms.openstack diff --git a/unit_tests/test_provides.py b/unit_tests/test_provides.py index 393ea46..fff19f3 100644 --- a/unit_tests/test_provides.py +++ b/unit_tests/test_provides.py @@ -158,3 +158,20 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): mock.call("{}_password".format(_p), _pw), mock.call("{}_allowed_units".format(_p), self.fake_unit.unit_name)] self.fake_relation.to_publish_raw.__setitem__.assert_has_calls(_calls) + + def test_set_db_connection_info_wait_timeout(self): + _wto = 90 + _p = "prefix" + _pw = "fakepassword" + self.ep.set_db_connection_info( + self.fake_relation_id, + self.ep.ingress_address, + _pw, + allowed_units=self.fake_unit.unit_name, + prefix=_p, wait_timeout=_wto) + _calls = [ + mock.call("db_host", self.ep.ingress_address), + mock.call("wait_timeout", _wto), + mock.call("{}_password".format(_p), _pw), + mock.call("{}_allowed_units".format(_p), self.fake_unit.unit_name)] + self.fake_relation.to_publish_raw.__setitem__.assert_has_calls(_calls) diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index 6119b88..ecd6f74 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -80,6 +80,7 @@ class TestMySQLSharedRequires(unittest.TestCase): self.patch_mysql_shared('set_state') self.patch_mysql_shared('remove_state') self.patch_mysql_shared('db_host', "10.5.0.21") + self.patch_mysql_shared('wait_timeout', 90) def tearDown(self): self.mysql_shared = None @@ -161,6 +162,16 @@ class TestMySQLSharedRequires(unittest.TestCase): self.db_host.return_value = None assert self.mysql_shared.base_data_complete() is False + def test_shared_db_data_complete_wait_timeout(self): + self._local_data = {"prefixes": ["myprefix"]} + self._remote_data = {"myprefix_password": "1234", + "myprefix_allowed_units": "unit/1"} + # Wait timeout is an optional value and should not affect data complete + self.wait_timeout.return_value = None + assert self.mysql_shared.base_data_complete() is True + self.wait_timeout.return_value = 90 + assert self.mysql_shared.base_data_complete() is True + def test_base_data_incomplete(self): assert self.mysql_shared.base_data_complete() is False