Specify the port for Shared DB connections
Prior to this change there was no way to specify a port for mysql connections. Add this to the Shared DB connection information. Change-Id: Iafcc106fca44479e89b4b66a0a3988ffeee01f04 Closes-Bug: #1876188
This commit is contained in:
parent
7c50d9e1dc
commit
c31027400a
|
@ -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)
|
||||
|
|
|
@ -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']
|
||||
|
||||
|
|
|
@ -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)]
|
||||
|
|
Loading…
Reference in New Issue