Add binary_prefix=true argument to mysql uri

This patch adds the argument binary_prefix=true to MySQL uri if
OpenStack version is equal or greater than Rocky due to Python
upper-constraints [1]. This argument is required because of PyMySQL's
change from version 0.8 and on [2], in order to fix Gnocchi API
warnings like this [3].

[1] https://github.com/openstack/requirements/blob/stable/rocky/upper-constraints.txt#L377
[2] https://github.com/PyMySQL/PyMySQL/blob/master/CHANGELOG#L61-L64
[3] https://github.com/gnocchixyz/gnocchi/issues/847

Change-Id: Ie8b10209daa4de74427e175ef21ddf306a17a0ae
Signed-off-by: Stamatis Katsaounis <skatsaounis@admin.grnet.gr>
(cherry picked from commit bf7ac78d07)
This commit is contained in:
Stamatis Katsaounis 2019-10-24 11:30:56 +03:00 committed by Seyeong Kim
parent 6f23e43434
commit d3980909ad
1 changed files with 20 additions and 1 deletions

View File

@ -76,6 +76,25 @@ def ceph_config(config):
return CEPH_CONF
class GnocchiCharmDatabaseRelationAdapter(adapters.DatabaseRelationAdapter):
"""
Overrides default class to add binary_prefix option to solve
'Invalid utf8 character' warnings
"""
def get_uri(self, prefix=None):
uri = super(GnocchiCharmDatabaseRelationAdapter, self).get_uri(prefix)
release = ch_utils.get_os_codename_install_source(
self.config['openstack-origin'])
if (ch_utils.OPENSTACK_RELEASES.index(release) >=
ch_utils.OPENSTACK_RELEASES.index('rocky')):
if '?' in uri:
uri += '&binary_prefix=true'
else:
uri += '?binary_prefix=true'
return uri
class GnocchiCharmRelationAdapaters(adapters.OpenStackAPIRelationAdapters):
"""
@ -84,7 +103,7 @@ class GnocchiCharmRelationAdapaters(adapters.OpenStackAPIRelationAdapters):
relation_adapters = {
'storage_ceph': charms_openstack.plugins.CephRelationAdapter,
'shared_db': adapters.DatabaseRelationAdapter,
'shared_db': GnocchiCharmDatabaseRelationAdapter,
'cluster': adapters.PeerHARelationAdapter,
'coordinator_memcached': adapters.MemcacheRelationAdapter,
}