From cdd963163f46886b0218025d9045bc66e605c7ea Mon Sep 17 00:00:00 2001 From: Liam Young Date: Thu, 18 Jun 2020 12:14:23 +0000 Subject: [PATCH] Add helper to send application name to ceph-mons Add helper to send application name to ceph-mons. When clients are connecting to the ceph-mons via a cross-model relation the ceph-mons have no way to derive the remote application name so they need to send it via relation data. The corresponding ceph-mon change is here https://review.opendev.org/736709 --- charmhelpers/contrib/storage/linux/ceph.py | 12 ++++++++++++ tests/contrib/storage/test_linux_ceph.py | 13 +++++++++++++ 2 files changed, 25 insertions(+) diff --git a/charmhelpers/contrib/storage/linux/ceph.py b/charmhelpers/contrib/storage/linux/ceph.py index 526b95ad2..0a13e5806 100644 --- a/charmhelpers/contrib/storage/linux/ceph.py +++ b/charmhelpers/contrib/storage/linux/ceph.py @@ -41,6 +41,7 @@ ) from charmhelpers import deprecate from charmhelpers.core.hookenv import ( + application_name, config, service_name, local_unit, @@ -162,6 +163,17 @@ def get_osd_settings(relation_name): return _order_dict_by_key(osd_settings) +def send_application_name(relid=None): + """Send the application name down the relation. + + :param relid: Relation id to set application name in. + :type relid: str + """ + relation_set( + relation_id=relid, + relation_settings={'application-name': application_name()}) + + def send_osd_settings(): """Pass on requested OSD settings to osd units.""" try: diff --git a/tests/contrib/storage/test_linux_ceph.py b/tests/contrib/storage/test_linux_ceph.py index a39d5e289..44e6feb0f 100644 --- a/tests/contrib/storage/test_linux_ceph.py +++ b/tests/contrib/storage/test_linux_ceph.py @@ -267,6 +267,19 @@ def test_get_osd_settings_conflicting_options(self): self._get_osd_settings_test_helper, settings) + @patch.object(ceph_utils, 'application_name') + def test_send_application_name(self, application_name): + application_name.return_value = 'client' + ceph_utils.send_application_name() + self.relation_set.assert_called_once_with( + relation_settings={'application-name': 'client'}, + relation_id=None) + self.relation_set.reset_mock() + ceph_utils.send_application_name(relid='rid:1') + self.relation_set.assert_called_once_with( + relation_settings={'application-name': 'client'}, + relation_id='rid:1') + @patch.object(ceph_utils, 'get_osd_settings') def test_send_osd_settings(self, _get_osd_settings): self.relation_ids.return_value = ['client:1', 'client:3']