self._orch_cmd("apply", "nfs", "service_name", "2")
def test_error(self):
- ret = self._orch_cmd_result("host", "add", "raise_no_support")
- self.assertEqual(ret, errno.ENOENT)
+ ret = self._orch_cmd_result("host", "add", "raise_validation_error")
+ self.assertEqual(ret, errno.EINVAL)
+ ret = self._orch_cmd_result("host", "add", "raise_error")
+ self.assertEqual(ret, errno.EINVAL)
ret = self._orch_cmd_result("host", "add", "raise_bug")
self.assertEqual(ret, errno.EINVAL)
ret = self._orch_cmd_result("host", "add", "raise_not_implemented")
It's not intended for programming errors or orchestrator internal errors.
"""
- def __init__(self, msg, event_kind_subject: Optional[Tuple[str, str]]=None):
+ def __init__(self,
+ msg: str,
+ errno: int = -errno.EINVAL,
+ event_kind_subject: Optional[Tuple[str, str]] = None):
super(Exception, self).__init__(msg)
+ self.errno = errno
# See OrchestratorEvent.subject
self.event_subject = event_kind_subject
No orchestrator in configured.
"""
def __init__(self, msg="No orchestrator configured (try `ceph orch set backend`)"):
- super(NoOrchestrator, self).__init__(msg)
+ super(NoOrchestrator, self).__init__(msg, errno=-errno.ENOENT)
class OrchestratorValidationError(OrchestratorError):
def wrapper(*args, **kwargs):
try:
return func(*args, **kwargs)
- except (OrchestratorError, ImportError, ServiceSpecValidationError) as e:
+ except (OrchestratorError, ServiceSpecValidationError) as e:
# Do not print Traceback for expected errors.
+ return HandleCommandResult(e.errno, stderr=str(e))
+ except ImportError as e:
return HandleCommandResult(-errno.ENOENT, stderr=str(e))
except NotImplementedError:
msg = 'This Orchestrator does not support `{}`'.format(prefix)
def add_host(self, spec):
# type: (orchestrator.HostSpec) -> None
host = spec.hostname
- if host == 'raise_no_support':
+ if host == 'raise_validation_error':
raise orchestrator.OrchestratorValidationError("MON count must be either 1, 3 or 5")
+ if host == 'raise_error':
+ raise orchestrator.OrchestratorError("host address is empty")
if host == 'raise_bug':
raise ZeroDivisionError()
if host == 'raise_not_implemented':
+import errno
import fnmatch
import re
from collections import namedtuple, OrderedDict
Defining an exception here is a bit problematic, cause you cannot properly catch it,
if it was raised in a different mgr module.
"""
-
- def __init__(self, msg):
+ def __init__(self,
+ msg: str,
+ errno: int = -errno.EINVAL):
super(ServiceSpecValidationError, self).__init__(msg)
+ self.errno = errno
def assert_valid_host(name):