]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
Check cephadm is available before running the rgw commands
authorRedouane Kachach <rkachach@redhat.com>
Mon, 10 Oct 2022 13:22:45 +0000 (15:22 +0200)
committerAdam King <adking@redhat.com>
Wed, 5 Apr 2023 17:30:51 +0000 (13:30 -0400)
Signed-off-by: Redouane Kachach <rkachach@redhat.com>
(cherry picked from commit 0bd530db3f0f0596d42f32b23913541a6c71d42f)

src/pybind/mgr/rgw/module.py
src/python-common/ceph/rgw/rgwam_core.py

index fd7246c28a276fe6ff24bd2345cbec05641f6571..b402b37f413674e4308056f36fbd4d7b18db21cd 100644 (file)
@@ -3,6 +3,7 @@ import threading
 import yaml
 import errno
 import base64
+import functools
 
 from mgr_module import MgrModule, CLICommand, HandleCommandResult
 import orchestrator
@@ -12,8 +13,21 @@ from typing import Any, Optional, Sequence, Iterator, List
 
 from ceph.rgw.types import RGWAMException, RGWAMEnvMgr, RealmToken
 from ceph.rgw.rgwam_core import EnvArgs, RGWAM
+from orchestrator import OrchestratorClientMixin, OrchestratorError
 
 
+class OrchestratorAPI(OrchestratorClientMixin):
+    def __init__(self, mgr):
+        super(OrchestratorAPI, self).__init__()
+        self.set_mgr(mgr)  # type: ignore
+
+    def status(self):
+        try:
+            status, message, _module_details = super().available()
+            return dict(available=status, message=message)
+        except (RuntimeError, OrchestratorError, ImportError) as e:
+            return dict(available=False, message=f'Orchestrator is unavailable: {e}')
+
 class RGWAMOrchMgr(RGWAMEnvMgr):
     def __init__(self, mgr):
         self.mgr = mgr
@@ -46,6 +60,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         self.inited = False
         self.lock = threading.Lock()
         super(Module, self).__init__(*args, **kwargs)
+        self.api = OrchestratorAPI(self)
 
         # ensure config options members are initialized; see config_notify()
         self.config_notify()
@@ -78,6 +93,19 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
                     self.get_ceph_option(opt))
             self.log.debug(' native option %s = %s', opt, getattr(self, opt))
 
+    def check_orchestrator():
+        def inner(func):
+            @functools.wraps(func)
+            def wrapper(self, *args, **kwargs):
+                available = self.api.status()['available']
+                if available:
+                    return func(self, *args, **kwargs)
+                else:
+                    err_msg = f"Cephadm is not available. Please enable cephadm by 'ceph mgr module enable cephadm'."
+                    return HandleCommandResult(retval=-errno.EINVAL, stdout='', stderr=err_msg)
+            return wrapper
+        return inner
+
     @CLICommand('rgw admin', perm='rw')
     def _cmd_rgw_admin(self, params: Sequence[str]):
         """rgw admin"""
@@ -90,6 +118,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
         return HandleCommandResult(retval=returncode, stdout=out, stderr=err)
 
     @CLICommand('rgw realm bootstrap', perm='rw')
+    @check_orchestrator()
     def _cmd_rgw_realm_bootstrap(self,
                                  realm_name: Optional[str] = None,
                                  zonegroup_name: Optional[str] = None,
@@ -195,6 +224,7 @@ class Module(orchestrator.OrchestratorClientMixin, MgrModule):
             return (e.retcode, e.message, e.stderr)
 
     @CLICommand('rgw zone create', perm='rw')
+    @check_orchestrator()
     def _cmd_rgw_zone_create(self,
                              zone_name: Optional[str] = None,
                              realm_token: Optional[str] = None,
index c9e8f2f94e21d50fb8930452fe12a18562a092db..2bfaf97e55a335b379bc64d0d702648ab27de647 100644 (file)
@@ -522,7 +522,7 @@ class RGWAM:
         if zone_name in self.zone_op().list():
             raise RGWAMException(f'Zone {zone_name} already exists')
 
-        # Create RGW multisite entities and update the period
+        # Create RGW entities and update the period
         realm = self.create_realm(realm_name)
         zonegroup = self.create_zonegroup(realm, zonegroup_name, zonegroup_is_master=True)
         zone = self.create_zone(realm, zonegroup, zone_name, zone_is_master=True)