Skip to content

Commit d4c8375

Browse files
ShwetaBhosale1adk3798
authored andcommitted
mgr/cephadm: updated nfs cluster create command and addressed review comments
Fixes: https://tracker.ceph.com/issues/71551 Signed-off-by: Shweta Bhosale <[email protected]> (cherry picked from commit 0ae93ec) Conflicts: src/cephadm/cephadm.py src/pybind/mgr/cephadm/module.py src/pybind/mgr/cephadm/serve.py src/pybind/mgr/nfs/module.py src/pybind/mgr/nfs/tests/test_nfs.py Resolves: rhbz#2373703
1 parent 35544aa commit d4c8375

File tree

9 files changed

+79
-58
lines changed

9 files changed

+79
-58
lines changed

src/cephadm/cephadm.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -768,15 +768,15 @@ def lookup_container_id_by_daemon_name(ctx: CephadmContext, fsid: str, name: str
768768
)
769769
daemons = [updater.expand(ctx, entry) for entry in daemon_entries]
770770
if not daemons:
771-
raise Error('Failed to find daemon {}'.format(name))
771+
raise Error(f'Failed to find daemon {name}')
772772
if len(daemons) > 1:
773-
raise Error('Found multiple daemons matching name {}: {}'.format(name, daemons))
773+
raise Error(f'Found multiple daemons matching name {name}: {daemons}')
774774

775775
daemon = daemons[0]
776776
try:
777777
return daemon['container_id']
778778
except KeyError:
779-
raise Error('Failed to get container id for {}'.format(daemon))
779+
raise Error(f'Failed to get container id for {daemon}')
780780

781781

782782
def create_daemon_dirs(
@@ -1166,14 +1166,15 @@ def deploy_daemon(
11661166
# If this was a reconfig and the daemon is not a Ceph daemon, restart it
11671167
# so it can pick up potential changes to its configuration files
11681168
if deployment_type == DeploymentType.RECONFIG and daemon_type not in ceph_daemons():
1169-
if not ctx.skip_restart:
1169+
if not ctx.skip_restart_for_reconfig:
11701170
# ceph daemons do not need a restart; others (presumably) do to pick
11711171
# up the new config
11721172
call_throws(ctx, ['systemctl', 'reset-failed', ident.unit_name])
11731173
call_throws(ctx, ['systemctl', 'restart', ident.unit_name])
1174-
else:
1175-
# perform default action
1176-
daemon_form_create(ctx, ident).perform_default_restart()
1174+
elif ctx.send_signal_to_daemon:
1175+
ctx.signal_name = ctx.send_signal_to_daemon
1176+
ctx.signal_number = None
1177+
command_signal(ctx)
11771178

11781179

11791180
def clean_cgroup(ctx: CephadmContext, fsid: str, unit_name: str) -> None:
@@ -3586,8 +3587,7 @@ def command_unit(ctx):
35863587

35873588

35883589
@infer_fsid
3589-
def command_signal(ctx):
3590-
# type: (CephadmContext) -> int
3590+
def command_signal(ctx: CephadmContext) -> int:
35913591
if not ctx.fsid:
35923592
raise Error('must pass --fsid to specify cluster')
35933593

@@ -5300,11 +5300,15 @@ def _add_deploy_parser_args(
53005300
help='Set LimitCORE=infinity in ceph unit files'
53015301
)
53025302
parser_deploy.add_argument(
5303-
'--skip-restart',
5303+
'--skip-restart-for-reconfig',
53045304
action='store_true',
53055305
default=False,
53065306
help='skip restart for non ceph daemons and perform default action'
53075307
)
5308+
parser_deploy.add_argument(
5309+
'--send-signal-to-daemon',
5310+
help='Send signal to daemon'
5311+
)
53085312

53095313

53105314
def _get_parser():

src/cephadm/cephadmlib/daemon_form.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ def identity(self) -> DaemonIdentity:
4444
"""
4545
raise NotImplementedError() # pragma: no cover
4646

47-
def perform_default_restart(self) -> int:
48-
return 0
49-
5047

5148
DF = TypeVar('DF', bound=DaemonForm)
5249

src/cephadm/cephadmlib/daemons/nfs.py

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import logging
22
import os
33
import re
4-
import signal
5-
import subprocess
64
from typing import Dict, List, Optional, Tuple, Union
75

86
from ..call_wrappers import call, CallVerbosity
@@ -237,25 +235,3 @@ def customize_container_args(
237235

238236
def default_entrypoint(self) -> str:
239237
return self.entrypoint
240-
241-
def perform_default_restart(self) -> int:
242-
pid = None
243-
try:
244-
output = subprocess.check_output(['pidof', 'ganesha.nfsd'])
245-
pid = int(output.strip())
246-
except subprocess.CalledProcessError:
247-
return 1
248-
if pid:
249-
logger.debug(
250-
f'Sending SIGHUP signal to ganesha.nfsd process, pid: {pid}'
251-
)
252-
try:
253-
os.kill(pid, signal.SIGHUP)
254-
except Exception:
255-
logger.error(
256-
f'Not able to send SIGHUP signal to ganesha.nfsd process, pid: {pid}'
257-
)
258-
return 1
259-
return 0
260-
logger.error('Process ganesha.nfsd not found.')
261-
return 1

src/pybind/mgr/cephadm/module.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2686,7 +2686,8 @@ def _daemon_action(self,
26862686
action: str,
26872687
image: Optional[str] = None,
26882688
spec: Optional[ServiceSpec] = None,
2689-
skip_restart: bool = False) -> str:
2689+
skip_restart_for_reconfig: bool = False,
2690+
send_signal_to_daemon: Optional[str] = None) -> str:
26902691
self._daemon_action_set_image(action, image, daemon_spec.daemon_type,
26912692
daemon_spec.daemon_id)
26922693

@@ -2712,7 +2713,13 @@ def _daemon_action(self,
27122713
daemon_spec)
27132714
with self.async_timeout_handler(daemon_spec.host, f'cephadm deploy ({daemon_spec.daemon_type} daemon)'):
27142715
successes, failures = self.wait_async(
2715-
CephadmServe(self)._create_daemon([daemon_spec], reconfig=(action == 'reconfig'), skip_restart=skip_restart))
2716+
CephadmServe(self)._create_daemon(
2717+
[daemon_spec],
2718+
reconfig=(action == 'reconfig'),
2719+
skip_restart_for_reconfig=skip_restart_for_reconfig,
2720+
send_signal_to_daemon=send_signal_to_daemon
2721+
)
2722+
)
27162723
# we're only deploying one daemon here, so we expect successes or failures to container one entry
27172724
for res in [successes, failures]:
27182725
if daemon_spec.name() in res:

src/pybind/mgr/cephadm/serve.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,8 @@ def _check_daemons(self) -> None:
13421342
if last_deps is None:
13431343
last_deps = []
13441344
action = self.mgr.cache.get_scheduled_daemon_action(dd.hostname, dd.name())
1345-
skip_restart = False
1345+
skip_restart_for_reconfig = False
1346+
send_signal_to_daemon = None
13461347
if not last_config:
13471348
self.log.info('Reconfiguring %s (unknown last config time)...' % (
13481349
dd.name()))
@@ -1364,8 +1365,8 @@ def _check_daemons(self) -> None:
13641365
if not only_kmip_updated:
13651366
action = 'redeploy'
13661367
else:
1367-
skip_restart = True
1368-
1368+
skip_restart_for_reconfig = True
1369+
send_signal_to_daemon = 'SIGHUP'
13691370
elif spec is not None and hasattr(spec, 'extra_container_args') and dd.extra_container_args != spec.extra_container_args:
13701371
self.log.debug(
13711372
f'{dd.name()} container cli args {dd.extra_container_args} -> {spec.extra_container_args}')
@@ -1393,7 +1394,13 @@ def _check_daemons(self) -> None:
13931394
action = 'redeploy'
13941395
try:
13951396
daemon_spec = CephadmDaemonDeploySpec.from_daemon_description(dd)
1396-
self.mgr._daemon_action(daemon_spec, action=action, spec=spec, skip_restart=skip_restart)
1397+
self.mgr._daemon_action(
1398+
daemon_spec,
1399+
action=action,
1400+
spec=spec,
1401+
skip_restart_for_reconfig=skip_restart_for_reconfig,
1402+
send_signal_to_daemon=send_signal_to_daemon
1403+
)
13971404
if self.mgr.cache.rm_scheduled_daemon_action(dd.hostname, dd.name()):
13981405
self.mgr.cache.save_host(dd.hostname)
13991406
except OrchestratorError as e:
@@ -1573,7 +1580,8 @@ async def _create_daemon(self,
15731580
daemon_specs: List[CephadmDaemonDeploySpec],
15741581
reconfig: bool = False,
15751582
osd_uuid_map: Optional[Dict[str, Any]] = None,
1576-
skip_restart: bool = False
1583+
skip_restart_for_reconfig: bool = False,
1584+
send_signal_to_daemon: Optional[str] = None
15771585
) -> Tuple[Dict[str, str], Dict[str, str]]:
15781586

15791587
exchanges: List[exchange.Deploy] = []
@@ -1619,8 +1627,10 @@ async def _create_daemon(self,
16191627
daemon_params['allow_ptrace'] = True
16201628
if self.mgr.set_coredump_overrides:
16211629
daemon_params['limit_core_infinity'] = True
1622-
if skip_restart:
1623-
daemon_params['skip_restart'] = True
1630+
if skip_restart_for_reconfig:
1631+
daemon_params['skip_restart_for_reconfig'] = True
1632+
if send_signal_to_daemon:
1633+
daemon_params['send_signal_to_daemon'] = send_signal_to_daemon
16241634

16251635
daemon_spec, extra_container_args, extra_entrypoint_args = self._setup_extra_deployment_args(daemon_spec, daemon_params)
16261636
init_containers = self._setup_init_containers(daemon_spec, daemon_params)

src/pybind/mgr/cephadm/service_discovery.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Server: # type: ignore
1212
from mgr_module import ServiceInfoT
1313
from mgr_util import build_url
1414
from typing import Dict, List, TYPE_CHECKING, cast, Collection, Callable, NamedTuple, Optional, IO
15-
15+
from cephadm.services.nfs import NFSService
1616
from cephadm.services.smb import SMBService
1717
from cephadm.services.monitoring import AlertmanagerService, NodeExporterService, PrometheusService
1818
import secrets
@@ -265,7 +265,6 @@ def nvmeof_sd_config(self) -> List[Dict[str, Collection[str]]]:
265265
def nfs_sd_config(self) -> List[Dict[str, Collection[str]]]:
266266
"""Return <http_sd_config> compatible prometheus config for nfs service."""
267267
srv_entries = []
268-
from cephadm.services.nfs import NFSService
269268
for dd in self.mgr.cache.get_daemons_by_type('nfs'):
270269
assert dd.hostname is not None
271270
nfs = cast(NFSService, service_registry.get_service('nfs'))

src/pybind/mgr/cephadm/services/nfs.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from orchestrator import DaemonDescription, OrchestratorError
1818

19+
from cephadm import utils
1920
from cephadm.services.cephadmservice import AuthEntity, CephadmDaemonDeploySpec, CephService
2021
if TYPE_CHECKING:
2122
from ..module import CephadmOrchestrator
@@ -87,11 +88,11 @@ def get_dependencies(
8788
nfs_spec = cast(NFSServiceSpec, spec)
8889
if (nfs_spec.kmip_cert and nfs_spec.kmip_key and nfs_spec.kmip_ca_cert and nfs_spec.kmip_host_list):
8990
# add dependency of kmip fields
90-
deps.append(f'kmip_cert: {nfs_spec.kmip_cert}')
91-
deps.append(f'kmip_key: {nfs_spec.kmip_key}')
92-
deps.append(f'kmip_ca_cert: {nfs_spec.kmip_ca_cert}')
91+
deps.append(f'kmip_cert: {str(utils.md5_hash(nfs_spec.kmip_cert))}')
92+
deps.append(f'kmip_key: {str(utils.md5_hash(nfs_spec.kmip_key))}')
93+
deps.append(f'kmip_ca_cert: {str(utils.md5_hash(nfs_spec.kmip_ca_cert))}')
9394
deps.append(f'kmip_host_list: {nfs_spec.kmip_host_list}')
94-
return deps
95+
return sorted(deps)
9596

9697
def generate_config(self, daemon_spec: CephadmDaemonDeploySpec) -> Tuple[Dict[str, Any], List[str]]:
9798
assert self.TYPE == daemon_spec.daemon_type
@@ -218,7 +219,7 @@ def get_cephadm_config() -> Dict[str, Any]:
218219
logger.debug('Generated cephadm config-json: %s' % config)
219220
return config
220221

221-
return get_cephadm_config(), sorted(self.get_dependencies(self.mgr, spec))
222+
return get_cephadm_config(), self.get_dependencies(self.mgr, spec)
222223

223224
def create_rados_config_obj(self,
224225
spec: NFSServiceSpec,

src/pybind/mgr/nfs/module.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import threading
33
from typing import Tuple, Optional, List, Dict, Any
4+
import yaml
45

56
from mgr_module import MgrModule, CLICommand, Option, CLICheckNonemptyFileInput
67
import object_format
@@ -153,12 +154,17 @@ def _cmd_nfs_cluster_create(self,
153154
ingress_mode: Optional[IngressType] = None,
154155
port: Optional[int] = None,
155156
enable_virtual_server: bool = False,
156-
kmip_cert: Optional[str] = None,
157-
kmip_key: Optional[str] = None,
158-
kmip_ca_cert: Optional[str] = None,
159-
kmip_host_list: Optional[List[str]] = None,
157+
inbuf: Optional[str] = None
160158
) -> None:
161159
"""Create an NFS Cluster"""
160+
kmip_cert = kmip_key = kmip_ca_cert = kmip_host_list = None
161+
if inbuf:
162+
kmip_config = yaml.safe_load(inbuf)
163+
kmip_cert = kmip_config.get('kmip_cert')
164+
kmip_key = kmip_config.get('kmip_key')
165+
kmip_ca_cert = kmip_config.get('kmip_ca_cert')
166+
kmip_host_list = kmip_config.get('kmip_host_list')
167+
162168
return self.nfs.create_nfs_cluster(cluster_id=cluster_id, placement=placement,
163169
virtual_ip=virtual_ip, ingress=ingress,
164170
ingress_mode=ingress_mode, port=port,

src/pybind/mgr/nfs/tests/test_nfs.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from ceph.utils import with_units_to_int, bytes_to_human
1515
from nfs import Module
1616
from nfs.export import ExportMgr, normalize_path
17-
from nfs.ganesha_conf import GaneshaConfParser, Export
17+
from nfs.ganesha_conf import GaneshaConfParser, Export, format_block
1818
from nfs.qos_conf import (
1919
RawBlock,
2020
QOS,
@@ -1665,6 +1665,27 @@ def _do_test_export_qos_bw_ops(self, qos_type, clust_bw_params, clust_ops_params
16651665
def test_export_qos_bw_ops(self, qos_type, clust_bw_params, clust_ops_params, export_bw_params, export_ops_params):
16661666
self._do_mock_test(self._do_test_export_qos_bw_ops, qos_type, clust_bw_params, clust_ops_params, export_bw_params, export_ops_params)
16671667

1668+
def _do_test_nfs_byok_export(self):
1669+
nfs_mod = Module('nfs', '', '')
1670+
conf = ExportMgr(nfs_mod)
1671+
1672+
conf.create_export(
1673+
fsal_type='cephfs',
1674+
cluster_id=self.cluster_id,
1675+
fs_name='myfs',
1676+
path='/',
1677+
pseudo_path='/cephfs4',
1678+
read_only=False,
1679+
squash='root',
1680+
kmip_key_id='12345'
1681+
)
1682+
export = conf._fetch_export(self.cluster_id, '/cephfs4')
1683+
block = format_block(export.to_export_block())
1684+
assert block.startswith('EXPORT {\n kmip_key_id = "12345";')
1685+
1686+
def test_nfs_byok_export(self):
1687+
self._do_mock_test(self._do_test_nfs_byok_export)
1688+
16681689

16691690
@pytest.mark.parametrize(
16701691
"path,expected",

0 commit comments

Comments
 (0)