Skip to content

Commit

Permalink
mgr/cephadm: nfs: shell out to rados tool for conf creation
Browse files Browse the repository at this point in the history
This avoids any hangs due to rados.

Signed-off-by: Sage Weil <sage@newdream.net>
  • Loading branch information
liewegas committed Apr 26, 2021
1 parent bc4d1a0 commit 5a028ae
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
43 changes: 24 additions & 19 deletions src/pybind/mgr/cephadm/services/nfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from mgr_module import HandleCommandResult

from ceph.deployment.service_spec import ServiceSpec, NFSServiceSpec
import rados

from orchestrator import DaemonDescription

Expand Down Expand Up @@ -136,24 +135,30 @@ def get_cephadm_config() -> Dict[str, Any]:
def create_rados_config_obj(self,
spec: NFSServiceSpec,
clobber: bool = False) -> None:
with self.mgr.rados.open_ioctx(spec.pool) as ioctx:
if spec.namespace:
ioctx.set_namespace(spec.namespace)

obj = spec.rados_config_name()
exists = True
try:
ioctx.stat(obj)
except rados.ObjectNotFound:
exists = False

if exists and not clobber:
# Assume an existing config
logger.info('Rados config object exists: %s' % obj)
else:
# Create an empty config object
logger.info('Creating rados config object: %s' % obj)
ioctx.write_full(obj, ''.encode('utf-8'))
objname = spec.rados_config_name()
cmd = [
'rados',
'-n', f"mgr.{self.mgr.get_mgr_id()}",
'-k', str(self.mgr.get_ceph_option('keyring')),
'-p', cast(str, spec.pool),
]
if spec.namespace:
cmd += ['--namespace', spec.namespace]
result = subprocess.run(
cmd + ['get', objname],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if not result.returncode and not clobber:
logger.info('Rados config object exists: %s' % objname)
else:
logger.info('Creating rados config object: %s' % objname)
result = subprocess.run(
cmd + ['put', objname, '-'],
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if result.returncode:
self.mgr.log.warning(
f'Unable to create rados config object {objname}: {result.stderr.decode("utf-8")}'
)
raise RuntimeError(result.stderr.decode("utf-8"))

def create_keyring(self, daemon_spec: CephadmDaemonDeploySpec) -> str:
daemon_id = daemon_spec.daemon_id
Expand Down
3 changes: 2 additions & 1 deletion src/pybind/mgr/cephadm/tests/test_cephadm.py
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ def test_daemon_add_fail(self, _run_cephadm, cephadm_module):

@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@mock.patch("cephadm.services.nfs.NFSService.run_grace_tool", mock.MagicMock())
@mock.patch("cephadm.module.CephadmOrchestrator.rados", mock.MagicMock())
@mock.patch("cephadm.services.nfs.NFSService.create_rados_config_obj", mock.MagicMock())
def test_nfs(self, cephadm_module):
with with_host(cephadm_module, 'test'):
ps = PlacementSpec(hosts=['test'], count=1)
Expand Down Expand Up @@ -914,6 +914,7 @@ def test_blink_device_light_custom_per_host(self, _run_cephadm, cephadm_module):
@mock.patch("cephadm.serve.CephadmServe._deploy_cephadm_binary", _deploy_cephadm_binary('test'))
@mock.patch("cephadm.serve.CephadmServe._run_cephadm", _run_cephadm('{}'))
@mock.patch("cephadm.services.nfs.NFSService.run_grace_tool", mock.MagicMock())
@mock.patch("cephadm.services.nfs.NFSService.create_rados_config_obj", mock.MagicMock())
def test_apply_save(self, spec: ServiceSpec, meth, cephadm_module: CephadmOrchestrator):
with with_host(cephadm_module, 'test'):
with with_service(cephadm_module, spec, meth, 'test'):
Expand Down

0 comments on commit 5a028ae

Please sign in to comment.