]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/cephadm: add get_dependencies to smb service class
authorJohn Mulligan <jmulligan@redhat.com>
Thu, 12 Mar 2026 22:42:51 +0000 (18:42 -0400)
committerJohn Mulligan <jmulligan@redhat.com>
Wed, 1 Apr 2026 15:11:32 +0000 (11:11 -0400)
Add a new get_dependencies method to the smb service class.
For now, the function returns one special dependency derived
from a hash digest of the external ceph cluster parameters,
to cause the service to be reloaded when these params change.
This approach is borrowed from a similar behavior of the nfs
service.

Signed-off-by: John Mulligan <jmulligan@redhat.com>
src/pybind/mgr/cephadm/services/smb.py

index 975c30a1e31d043954ebf808080d369671f0b20b..fbb4fcf57d8ae4543041a8ac91c7796beb11fa23 100644 (file)
@@ -1,7 +1,19 @@
+import enum
 import errno
+import hashlib
 import ipaddress
 import logging
-from typing import Any, Dict, List, Tuple, cast, Optional, Iterable, Union
+from typing import (
+    Any,
+    Dict,
+    Iterable,
+    List,
+    Optional,
+    TYPE_CHECKING,
+    Tuple,
+    Union,
+    cast,
+)
 
 from mgr_module import HandleCommandResult
 
@@ -21,6 +33,9 @@ from .cephadmservice import (
 )
 from ..schedule import DaemonPlacement
 
+if TYPE_CHECKING:
+    from ..module import CephadmOrchestrator
+
 logger = logging.getLogger(__name__)
 
 
@@ -211,7 +226,8 @@ class SMBService(CephService):
 
         logger.debug('smb generate_config: %r', config_blobs)
         self._configure_cluster_meta(smb_spec, daemon_spec)
-        return config_blobs, []
+        deps = self.get_dependencies(self.mgr, smb_spec)
+        return config_blobs, deps
 
     def _cert_or_uri(self, data: Optional[str]) -> Optional[str]:
         if data is None:
@@ -426,6 +442,26 @@ class SMBService(CephService):
             )
         return ip
 
+    @classmethod
+    def get_dependencies(
+        cls,
+        mgr: 'CephadmOrchestrator',
+        spec: Optional[ServiceSpec] = None,
+        daemon_type: Optional[str] = None,
+    ) -> List[str]:
+        if not spec:
+            return []
+        assert cls.TYPE == spec.service_type
+        smb_spec = cast(SMBSpec, spec)
+        # NOTE: to be very explicit and do a little future proofing our
+        # 'dependencies' that are not the names of other services will be
+        # "namespaced" using the Dep enum.
+        out = []
+        for ccc in smb_spec.ceph_cluster_configs or []:
+            value = _hash_ceph_cluster_config(ccc)
+            out.append(Dep.META(f'ceph_cluster_config.{ccc.alias}', value))
+        return out
+
 
 Network = Union[ipaddress.IPv4Network, ipaddress.IPv6Network]
 
@@ -469,3 +505,19 @@ def _to_keyring(ext_cluster: SMBExternalCephCluster) -> str:
             '',
         ]
     )
+
+
+def _hash_ceph_cluster_config(spec: SMBExternalCephCluster) -> str:
+    _fields = ['alias', 'fsid', 'mon_host', 'user', 'key']
+    fdg = hashlib.sha256()
+    for field_name in _fields:
+        fdg.update(getattr(spec, field_name, '').encode())
+    return f'sha256:{fdg.hexdigest()}'
+
+
+class Dep(enum.Enum):
+    META = 'smb+meta'  # multiple fields as a digest
+    FIELD = 'smb+field'  # a single field and unmanged value
+
+    def __call__(self, key: str, value: str) -> str:
+        return f'{self.value}:{key}={value}'