diff --git a/.gitreview b/.gitreview new file mode 100644 index 0000000..129ce1a --- /dev/null +++ b/.gitreview @@ -0,0 +1,4 @@ +[gerrit] +host=review.opendev.org +port=29418 +project=openstack/charm-interface-mysql-router.git diff --git a/.zuul.yaml b/.zuul.yaml new file mode 100644 index 0000000..34184f1 --- /dev/null +++ b/.zuul.yaml @@ -0,0 +1,4 @@ +- project: + templates: + - python35-charm-jobs + - openstack-python3-ussuri-jobs diff --git a/provides.py b/provides.py index 3b562b3..0e05233 100644 --- a/provides.py +++ b/provides.py @@ -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[ diff --git a/requires.py b/requires.py index c139d92..43cc9dc 100644 --- a/requires.py +++ b/requires.py @@ -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): 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 cd6e261..7d0ab5a 100644 --- a/unit_tests/test_provides.py +++ b/unit_tests/test_provides.py @@ -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) diff --git a/unit_tests/test_requires.py b/unit_tests/test_requires.py index 58ffe95..bafbe14 100644 --- a/unit_tests/test_requires.py +++ b/unit_tests/test_requires.py @@ -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",