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 typing import List, Tuple, Union
import charmhelpers.core.host as ch_host
import charms_ceph.utils as ceph_utils
import cryptography.hazmat.primitives.serialization as serialization
import interface_ceph_iscsi_admin_access.admin_access as admin_access
@ -180,8 +179,9 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
logging.debug(
"register_grafana_dashboard: {}".format(dash_file))
def _update_legacy_radosgw_creds(self, access_key: str,
secret_key: str) -> None:
def _update_radosgw_creds(
self, access_key: str, secret_key: str
) -> None:
"""Update dashboard db with access & secret key for rados gateways.
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-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:
"""Register rados gateways in dashboard db"""
if self.unit.is_leader():
@ -214,18 +199,14 @@ class CephDashboardCharm(ops_openstack.core.OSBaseCharm):
if cred_count < 1:
logging.info("No object gateway creds found")
return
if self._support_multiple_gateways():
self._update_multi_radosgw_creds(creds)
else:
if cred_count > 1:
logging.error(
"Cannot enable object gateway support. Ceph release "
"does not support multiple object gateways in the "
"dashboard")
else:
self._update_legacy_radosgw_creds(
creds[0]['access_key'],
creds[0]['secret_key'])
# Update the provided creds for radosgw.
# NOTE(utkarshbhatthere): Having multiple credentials is not
# required even where there are multiple radosgw applications
# in the juju model. Therefore, first available creds are
# populated in dashboard.
self._update_radosgw_creds(
creds[0]['access_key'],
creds[0]['secret_key'])
def _request_certificates(self, event) -> None:
"""Request TLS certificates."""

View File

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

View File

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

View File

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

View File

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

View File

@ -162,10 +162,8 @@ class TestCephDashboardCharmBase(CharmTestCase):
PATCHES = [
'ceph_utils',
'ch_host',
'socket',
'subprocess', # charm's subprocess import
'ch_host',
]
def setUp(self):
@ -515,7 +513,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.subprocess')
def test_rados_gateway(self, subprocess):
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')
rel_id = self.harness.add_relation('radosgw-dashboard', 'ceph-radosgw')
self.harness.begin()
@ -563,7 +560,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.subprocess')
def test_rados_gateway_multi_relations_pacific(self, subprocess):
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_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us')
mon_rel_id = self.harness.add_relation('dashboard', 'ceph-mon')
@ -619,7 +615,6 @@ class TestCephDashboardCharmBase(CharmTestCase):
@patch('ceph_dashboard_commands.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_id2 = self.harness.add_relation('radosgw-dashboard', 'ceph-us')
self.harness.begin()