Use single credential for configuring object storage gw in dashboard.

The radosgw relation provides the same credential mapped to the
hostnames of all the related radosgw application units. This extra
information is not needed. Even when multiple radosgw applications
are present in the same Juju model, a single instance of credentials
is sufficient for dashbaord to present Object GW UI.

Closes-Bug: #1986593
Change-Id: Ib56e0bd4fe588219d6b5728d9a71cf09abdd25de
Signed-off-by: Utkarsh Bhatt <utkarsh.bhatt@canonical.com>
This commit is contained in:
Utkarsh Bhatt 2023-12-14 16:19:28 +05:30
parent db59732503
commit fa621d1062
6 changed files with 20 additions and 36 deletions

View File

@ -18,7 +18,6 @@ import tempfile
from pathlib import Path from pathlib import Path
from typing import List, Tuple, Union from typing import List, Tuple, Union
import charmhelpers.core.host as ch_host
import charms_ceph.utils as ceph_utils import charms_ceph.utils as ceph_utils
import cryptography.hazmat.primitives.serialization as serialization import cryptography.hazmat.primitives.serialization as serialization
import interface_ceph_iscsi_admin_access.admin_access as admin_access import interface_ceph_iscsi_admin_access.admin_access as admin_access
@ -180,8 +179,9 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
logging.debug( logging.debug(
"register_grafana_dashboard: {}".format(dash_file)) "register_grafana_dashboard: {}".format(dash_file))
def _update_legacy_radosgw_creds(self, access_key: str, def _update_radosgw_creds(
secret_key: str) -> None: self, access_key: str, secret_key: str
) -> None:
"""Update dashboard db with access & secret key for rados gateways. """Update dashboard db with access & secret key for rados gateways.
This method uses the legacy format which only supports one gateway. This method uses the legacy format which only supports one gateway.
@ -189,21 +189,6 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
self._apply_file_setting('set-rgw-api-access-key', access_key) self._apply_file_setting('set-rgw-api-access-key', access_key)
self._apply_file_setting('set-rgw-api-secret-key', secret_key) self._apply_file_setting('set-rgw-api-secret-key', secret_key)
def _update_multi_radosgw_creds(self, creds: str) -> None:
"""Update dashboard db with access & secret key for rados gateway."""
access_keys = {c['daemon_id']: c['access_key'] for c in creds}
secret_keys = {c['daemon_id']: c['secret_key'] for c in creds}
self._apply_file_setting(
'set-rgw-api-access-key',
json.dumps(access_keys))
self._apply_file_setting(
'set-rgw-api-secret-key',
json.dumps(secret_keys))
def _support_multiple_gateways(self) -> bool:
"""Check if version of dashboard supports multiple rados gateways"""
return ch_host.cmp_pkgrevno('ceph-common', '16.0') > 0
def _manage_radosgw(self) -> None: def _manage_radosgw(self) -> None:
"""Register rados gateways in dashboard db""" """Register rados gateways in dashboard db"""
if self.unit.is_leader(): if self.unit.is_leader():
@ -214,16 +199,12 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
if cred_count < 1: if cred_count < 1:
logging.info("No object gateway creds found") logging.info("No object gateway creds found")
return return
if self._support_multiple_gateways(): # Update the provided creds for radosgw.
self._update_multi_radosgw_creds(creds) # NOTE(utkarshbhatthere): Having multiple credentials is not
else: # required even where there are multiple radosgw applications
if cred_count > 1: # in the juju model. Therefore, first available creds are
logging.error( # populated in dashboard.
"Cannot enable object gateway support. Ceph release " self._update_radosgw_creds(
"does not support multiple object gateways in the "
"dashboard")
else:
self._update_legacy_radosgw_creds(
creds[0]['access_key'], creds[0]['access_key'],
creds[0]['secret_key']) creds[0]['secret_key'])

View File

@ -40,6 +40,8 @@ applications:
# SSL and allow_embedding are not released into cs:grafana yet, due # SSL and allow_embedding are not released into cs:grafana yet, due
# October 2021 # October 2021
charm: ch:grafana charm: ch:grafana
series: focal
channel: latest/stable
num_units: 1 num_units: 1
options: options:
anonymous: True anonymous: True
@ -52,6 +54,7 @@ applications:
hostname: "{host}" hostname: "{host}"
prometheus-alertmanager: prometheus-alertmanager:
charm: ch:prometheus-alertmanager charm: ch:prometheus-alertmanager
series: focal
num_units: 1 num_units: 1
ceph-radosgw: ceph-radosgw:
charm: ch:ceph-radosgw charm: ch:ceph-radosgw

View File

@ -41,6 +41,8 @@ applications:
# October 2021 # October 2021
charm: ch:grafana charm: ch:grafana
num_units: 1 num_units: 1
series: focal
channel: latest/stable
options: options:
anonymous: True anonymous: True
install_method: snap install_method: snap
@ -52,6 +54,7 @@ applications:
hostname: "{host}" hostname: "{host}"
prometheus-alertmanager: prometheus-alertmanager:
charm: ch:prometheus-alertmanager charm: ch:prometheus-alertmanager
series: focal
num_units: 1 num_units: 1
ceph-radosgw: ceph-radosgw:
charm: ch:ceph-radosgw charm: ch:ceph-radosgw

View File

@ -47,6 +47,7 @@ applications:
charm: ch:grafana charm: ch:grafana
num_units: 1 num_units: 1
series: focal series: focal
channel: latest/stable
options: options:
anonymous: True anonymous: True
install_method: snap install_method: snap

View File

@ -65,7 +65,8 @@ applications:
channel: latest/edge channel: latest/edge
ceph-iscsi: ceph-iscsi:
charm: ch:ceph-iscsi charm: ch:ceph-iscsi
series: mantic # ceph-iscsi is deprecated therefore using older series.
series: jammy
num_units: 2 num_units: 2
options: options:
gateway-metadata-pool: iscsi-foo-metadata gateway-metadata-pool: iscsi-foo-metadata

View File

@ -162,10 +162,8 @@ class TestCephDashboardCharmBase(CharmTestCase):
PATCHES = [ PATCHES = [
'ceph_utils', 'ceph_utils',
'ch_host',
'socket', 'socket',
'subprocess', # charm's subprocess import 'subprocess', # charm's subprocess import
'ch_host',
] ]
def setUp(self): def setUp(self):
@ -515,7 +513,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.subprocess') @patch('ceph_dashboard_commands.subprocess')
def test_rados_gateway(self, subprocess): def test_rados_gateway(self, subprocess):
self.ceph_utils.is_dashboard_enabled.return_value = True self.ceph_utils.is_dashboard_enabled.return_value = True
self.ch_host.cmp_pkgrevno.return_value = 1
mon_rel_id = self.harness.add_relation('dashboard', 'ceph-mon') mon_rel_id = self.harness.add_relation('dashboard', 'ceph-mon')
rel_id = self.harness.add_relation('radosgw-dashboard', 'ceph-radosgw') rel_id = self.harness.add_relation('radosgw-dashboard', 'ceph-radosgw')
self.harness.begin() self.harness.begin()
@ -563,7 +560,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.subprocess') @patch('ceph_dashboard_commands.subprocess')
def test_rados_gateway_multi_relations_pacific(self, subprocess): def test_rados_gateway_multi_relations_pacific(self, subprocess):
self.ceph_utils.is_dashboard_enabled.return_value = True self.ceph_utils.is_dashboard_enabled.return_value = True
self.ch_host.cmp_pkgrevno.return_value = 1
rel_id1 = self.harness.add_relation('radosgw-dashboard', 'ceph-eu') rel_id1 = self.harness.add_relation('radosgw-dashboard', 'ceph-eu')
rel_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us') rel_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us')
mon_rel_id = self.harness.add_relation('dashboard', 'ceph-mon') mon_rel_id = self.harness.add_relation('dashboard', 'ceph-mon')
@ -619,7 +615,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.subprocess') @patch('ceph_dashboard_commands.subprocess')
def test_rados_gateway_multi_relations_octopus(self, subprocess): def test_rados_gateway_multi_relations_octopus(self, subprocess):
self.ch_host.cmp_pkgrevno.return_value = -1
rel_id1 = self.harness.add_relation('radosgw-dashboard', 'ceph-eu') rel_id1 = self.harness.add_relation('radosgw-dashboard', 'ceph-eu')
rel_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us') rel_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us')
self.harness.begin() self.harness.begin()