Pass wait timeout all the way through to clients

Pass the non-interactive wait timeout value through.

Closes-Bug: #1841063
Change-Id: I6ec40bc65f719e1938d9b0ccdb7ad00236f435d0
This commit is contained in:
David Ames
2020-04-15 14:38:09 -07:00
parent 7e83ac1856
commit 19ac73ab80
7 changed files with 47 additions and 4 deletions

4
.gitreview Normal file
View File

@@ -0,0 +1,4 @@
[gerrit]
host=review.opendev.org
port=29418
project=openstack/charm-interface-mysql-router.git

4
.zuul.yaml Normal file
View File

@@ -0,0 +1,4 @@
- project:
templates:
- python35-charm-jobs
- openstack-python3-ussuri-jobs

View File

@@ -75,13 +75,15 @@ class MySQLRouterProvides(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):
"""Send database connection information to the client.
:param relation_id: Relation ID to set connection information on
:type relation_id: str
:param db_host: Host IP or hostname for connecting to the DB
:type db_host: str
:param wait_timeout: Non-interactive wait timeout in seconds
:type wait_timeout: int
:param password: Password for connecting to the DB
:type password: str
:param allowed_units: Space delimited unit names allowed to connect to
@@ -93,8 +95,12 @@ class MySQLRouterProvides(reactive.Endpoint):
:returns: None, this function is called for its side effect
:rtype: None
"""
# No prefix for db_host
# No prefix for db_host or wait_timeout
self.relations[relation_id].to_publish["db_host"] = db_host
if wait_timeout:
self.relations[relation_id].to_publish["wait_timeout"] = (
wait_timeout)
if not prefix:
self.relations[relation_id].to_publish["password"] = password
self.relations[relation_id].to_publish[

View File

@@ -9,7 +9,8 @@ class MySQLRouterRequires(RelationBase):
# These remote data fields will be automatically mapped to accessors
# with a basic documentation string provided.
auto_accessors = ['db_host', 'ssl_ca', 'ssl_cert', 'ssl_key']
auto_accessors = [
'db_host', 'ssl_ca', 'ssl_cert', 'ssl_key', 'wait_timeout']
@hook('{requires:mysql-router}-relation-joined')
def joined(self):

View File

@@ -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

View File

@@ -154,3 +154,20 @@ class TestMySQLRouterProvides(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.__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.__setitem__.assert_has_calls(_calls)

View File

@@ -80,6 +80,7 @@ class TestMySQLRouterRequires(unittest.TestCase):
self.patch_mysql_router('set_state')
self.patch_mysql_router('remove_state')
self.patch_mysql_router('db_host', "10.5.0.21")
self.patch_mysql_router('wait_timeout', 90)
def tearDown(self):
self.mysql_router = None
@@ -156,6 +157,16 @@ class TestMySQLRouterRequires(unittest.TestCase):
self.db_host.return_value = None
assert self.mysql_router.db_router_data_complete() is False
def test_db_router_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_router.db_router_data_complete() is True
self.wait_timeout.return_value = 90
assert self.mysql_router.db_router_data_complete() is True
def test_proxy_db_data_incomplete(self):
self._local_data = {"prefixes": ["myprefix"]}
self._remote_data = {"myprefix_password": "1234",