From: Michael Fritch Date: Wed, 18 Mar 2020 19:57:18 +0000 (-0600) Subject: mgr/cephadm: check for an existing NFS config object X-Git-Tag: v15.2.1~19^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=e001fd35ecab001ad6320dee4944da233ccb41f4;p=ceph.git mgr/cephadm: check for an existing NFS config object assume an existing NFS config if the named rados object already exists Signed-off-by: Michael Fritch (cherry picked from commit 75b988f314ab8792cccad70bb9894ff1a50ae3f3) --- diff --git a/src/pybind/mgr/cephadm/nfs.py b/src/pybind/mgr/cephadm/nfs.py index 081b5237859..f03a840461f 100644 --- a/src/pybind/mgr/cephadm/nfs.py +++ b/src/pybind/mgr/cephadm/nfs.py @@ -1,4 +1,5 @@ import logging +import rados from typing import Dict, Optional @@ -81,14 +82,27 @@ class NFSGanesha(object): 'Unable to update keyring caps %s: %s %s' \ % (entity, ret, err)) - def create_rados_config_obj(self): - # type: () -> None + def create_rados_config_obj(self, clobber=False): + # type: (Optional[bool]) -> None obj = self.get_rados_config_name() - logger.info('Create rados config object: %s' % obj) + with self.mgr.rados.open_ioctx(self.spec.pool) as ioctx: if self.spec.namespace: ioctx.set_namespace(self.spec.namespace) - ioctx.write_full(obj, ''.encode('utf-8')) + + exists = True + try: + ioctx.stat(obj) + except rados.ObjectNotFound as e: + 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')) def get_ganesha_conf(self): # type: () -> str