diff --git a/provides.py b/provides.py index 4fb65d3..8a5cb1f 100644 --- a/provides.py +++ b/provides.py @@ -76,13 +76,14 @@ class MySQLSharedProvides(reactive.Endpoint): def set_db_connection_info( self, relation_id, db_host, password, - allowed_units=None, prefix=None, wait_timeout=None): + allowed_units=None, prefix=None, wait_timeout=None, db_port=3306): # 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 # No prefix for db_host and wait_timeout self.relations[relation_id].to_publish_raw["db_host"] = db_host + self.relations[relation_id].to_publish_raw["db_port"] = db_port if wait_timeout: self.relations[relation_id].to_publish_raw["wait_timeout"] = ( wait_timeout) diff --git a/requires.py b/requires.py index 74fa9bf..e49a794 100644 --- a/requires.py +++ b/requires.py @@ -9,7 +9,7 @@ class MySQLSharedRequires(RelationBase): # These remote data fields will be automatically mapped to accessors # with a basic documentation string provided. - auto_accessors = ['access-network', 'db_host', + auto_accessors = ['access-network', 'db_host', 'db_port', 'ssl_ca', 'ssl_cert', 'ssl_key', 'cluster-series-upgrading', 'wait_timeout'] diff --git a/unit_tests/test_provides.py b/unit_tests/test_provides.py index fff19f3..d2ea914 100644 --- a/unit_tests/test_provides.py +++ b/unit_tests/test_provides.py @@ -133,6 +133,7 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): def test_set_db_connection_info_no_prefix(self): _pw = "fakepassword" + _port = 3306 self.ep.set_db_connection_info( self.fake_relation_id, self.ep.ingress_address, @@ -140,6 +141,23 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): allowed_units=self.fake_unit.unit_name) _calls = [ mock.call("db_host", self.ep.ingress_address), + mock.call("db_port", _port), + mock.call("password", _pw), + mock.call("allowed_units", self.fake_unit.unit_name)] + self.fake_relation.to_publish_raw.__setitem__.assert_has_calls(_calls) + + def test_set_db_connection_w_port(self): + _pw = "fakepassword" + _port = 3316 + self.ep.set_db_connection_info( + self.fake_relation_id, + self.ep.ingress_address, + _pw, + allowed_units=self.fake_unit.unit_name, + db_port=_port) + _calls = [ + mock.call("db_host", self.ep.ingress_address), + mock.call("db_port", _port), mock.call("password", _pw), mock.call("allowed_units", self.fake_unit.unit_name)] self.fake_relation.to_publish_raw.__setitem__.assert_has_calls(_calls) @@ -147,6 +165,7 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): def test_set_db_connection_info_prefixed(self): _p = "prefix" _pw = "fakepassword" + _port = 3306 self.ep.set_db_connection_info( self.fake_relation_id, self.ep.ingress_address, @@ -155,6 +174,7 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): prefix=_p) _calls = [ mock.call("db_host", self.ep.ingress_address), + mock.call("db_port", _port), 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) @@ -163,6 +183,7 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): _wto = 90 _p = "prefix" _pw = "fakepassword" + _port = 3306 self.ep.set_db_connection_info( self.fake_relation_id, self.ep.ingress_address, @@ -171,6 +192,7 @@ class TestMySQLSharedProvides(test_utils.PatchHelper): prefix=_p, wait_timeout=_wto) _calls = [ mock.call("db_host", self.ep.ingress_address), + mock.call("db_port", _port), mock.call("wait_timeout", _wto), mock.call("{}_password".format(_p), _pw), mock.call("{}_allowed_units".format(_p), self.fake_unit.unit_name)]