from .exception import NFSInvalidOperation, ClusterNotFound
from .utils import (
+ ManualRestartRequired,
NonFatalError,
available_clusters,
conf_obj_name,
except Exception as e:
return exception_handler(e, f"Fetching NFS-Ganesha Config failed for {cluster_id}")
- def set_nfs_cluster_config(self, cluster_id: str, nfs_config: str) -> Tuple[int, str, str]:
+ def set_nfs_cluster_config(self, cluster_id: str, nfs_config: str) -> None:
try:
if cluster_id in available_clusters(self.mgr):
rados_obj = self._rados(cluster_id)
if rados_obj.check_user_config():
- return 0, "", "NFS-Ganesha User Config already exists"
+ raise NonFatalError("NFS-Ganesha User Config already exists")
rados_obj.write_obj(nfs_config, user_conf_obj_name(cluster_id),
conf_obj_name(cluster_id))
log.debug("Successfully saved %s's user config: \n %s", cluster_id, nfs_config)
restart_nfs_service(self.mgr, cluster_id)
- return 0, "NFS-Ganesha Config Set Successfully", ""
+ return
raise ClusterNotFound()
except NotImplementedError:
- return 0, "NFS-Ganesha Config Added Successfully "\
- "(Manual Restart of NFS PODS required)", ""
+ raise ManualRestartRequired("NFS-Ganesha Config Added Successfully")
except Exception as e:
- return exception_handler(e, f"Setting NFS-Ganesha Config failed for {cluster_id}")
+ log.exception(f"Setting NFS-Ganesha Config failed for {cluster_id}")
+ raise ErrorResponse.wrap(e)
def reset_nfs_cluster_config(self, cluster_id: str) -> Tuple[int, str, str]:
try:
@CLICommand('nfs cluster config set', perm='rw')
@CLICheckNonemptyFileInput(desc='NFS-Ganesha Configuration')
- def _cmd_nfs_cluster_config_set(self, cluster_id: str, inbuf: str) -> Tuple[int, str, str]:
+ @object_format.EmptyResponder()
+ def _cmd_nfs_cluster_config_set(self, cluster_id: str, inbuf: str) -> None:
"""Set NFS-Ganesha config by `-i <config_file>`"""
return self.nfs.set_nfs_cluster_config(cluster_id=cluster_id, nfs_config=inbuf)
assert rc == 0
assert out == ""
- rc, out, err = cluster.set_nfs_cluster_config(self.cluster_id, '# foo\n')
- assert rc == 0
+ cluster.set_nfs_cluster_config(self.cluster_id, '# foo\n')
rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id)
assert rc == 0
assert out == "# foo\n"
- rc, out, err = cluster.reset_nfs_cluster_config(self.cluster_id)
- assert rc == 0
+ cluster.reset_nfs_cluster_config(self.cluster_id)
rc, out, err = cluster.get_nfs_cluster_config(self.cluster_id)
assert rc == 0
return 0, "", self.msg
+class ManualRestartRequired(NonFatalError):
+ """Raise this exception type if all other changes were successful but
+ user needs to manually restart nfs services.
+ """
+
+ def __init__(self, msg: str) -> None:
+ super().__init__(" ".join((msg, "(Manual Restart of NFS Pods required)")))
+
+
def export_obj_name(export_id: int) -> str:
"""Return a rados object name for the export."""
return f"{EXPORT_PREFIX}{export_id}"