From 08d985933c529216c6e9aacc89fa1b03a0cdcc56 Mon Sep 17 00:00:00 2001 From: Anoop C S Date: Mon, 15 Jul 2024 12:37:59 +0530 Subject: [PATCH] cephadm/smb: Determine samba version within container Implement a `get_version()` method to figure out the version of samba running inside the container using smbd. This will help us to avoid reporting version as "" while listing the daemons via `ceph orch ps`. Signed-off-by: Anoop C S --- src/cephadm/cephadm.py | 2 ++ src/cephadm/cephadmlib/daemons/smb.py | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/src/cephadm/cephadm.py b/src/cephadm/cephadm.py index 5deaec55949..ecac9afa16d 100755 --- a/src/cephadm/cephadm.py +++ b/src/cephadm/cephadm.py @@ -3528,6 +3528,8 @@ def list_daemons( version = CephIscsi.get_version(ctx, container_id) if daemon_type == CephNvmeof.daemon_type: version = CephNvmeof.get_version(ctx, container_id) + if daemon_type == SMB.daemon_type: + version = SMB.get_version(ctx, container_id) elif not version: if daemon_type in ceph_daemons(): out, err, code = call(ctx, diff --git a/src/cephadm/cephadmlib/daemons/smb.py b/src/cephadm/cephadmlib/daemons/smb.py index e90329787c7..27256623890 100644 --- a/src/cephadm/cephadmlib/daemons/smb.py +++ b/src/cephadm/cephadmlib/daemons/smb.py @@ -2,6 +2,7 @@ import enum import json import logging import pathlib +import re import socket from typing import List, Dict, Tuple, Optional, Any @@ -11,6 +12,7 @@ from .. import daemon_form from .. import data_utils from .. import deployment_utils from .. import file_utils +from ..call_wrappers import call, CallVerbosity from ..constants import DEFAULT_SMB_IMAGE from ..container_daemon_form import ContainerDaemonForm, daemon_to_container from ..container_engines import Podman @@ -220,6 +222,7 @@ class SMB(ContainerDaemonForm): """Provides a form for SMB containers.""" daemon_type = 'smb' + daemon_base = '/usr/sbin/smbd' default_image = DEFAULT_SMB_IMAGE @classmethod @@ -237,6 +240,27 @@ class SMB(ContainerDaemonForm): self.smb_port = 445 logger.debug('Created SMB ContainerDaemonForm instance') + @staticmethod + def get_version(ctx: CephadmContext, container_id: str) -> Optional[str]: + version = None + out, _, ret = call( + ctx, + [ + ctx.container_engine.path, + 'exec', + container_id, + SMB.daemon_base, + '-V', + ], + verbosity=CallVerbosity.QUIET, + ) + + if ret == 0: + match = re.search(r'Version\s*([\d.]+)', out) + if match: + version = match.group(1) + return version + def validate(self) -> None: if self._instance_cfg is not None: return -- 2.39.5