예제 #1
0
class ExceptionBase(Exception):
    """Base Exception

    To correctly use this class, inherit from it and define
    a 'msg_fmt' property. That msg_fmt will get printf'd
    with the keyword arguments provided to the constructor.

    """
    msg_fmt = _("An unknown exception occurred.")

    def __init__(self, message=None, **kwargs):
        self.kwargs = kwargs

        if not message:
            try:
                message = self.msg_fmt % kwargs
            except Exception:
                # at least get the core message out if something happened
                message = self.msg_fmt

        self.message = message
        super(ExceptionBase, self).__init__(message)

    def format_message(self):
        # NOTE(mrodden): use the first argument to the python Exception object
        # which should be our full NovaException message, (see __init__)
        return self.args[0]
예제 #2
0
class NoSupportedVIFVersion(ExceptionBase):
    msg_fmt = _("VIF class %(name)s versions %(got_versions)s "
                "do not satisfy min=%(min_version)s max=%(max_version)s")
예제 #3
0
class NoMatchingVIFClass(ExceptionBase):
    msg_fmt = _("No VIF class was found with the name %(name)s")
예제 #4
0
class NoSupportedPortProfileVersion(ExceptionBase):
    msg_fmt = _("PortProfile class %(name)s "
                "versions %(got_versions)s do not satisfy "
                "min=%(min_version)s max=%(max_version)s")
예제 #5
0
class NoMatchingPortProfileClass(ExceptionBase):
    msg_fmt = _("No PortProfile class was found with the name %(name)s")
    def execute(self, *cmd, **kwargs):
        # NOTE(dims): This method is to provide compatibility with the
        # processutils.execute interface. So that calling daemon or direct
        # rootwrap to honor the same set of flags in kwargs and to ensure
        # that we don't regress any current behavior.
        cmd = [str(c) for c in cmd]
        loglevel = kwargs.pop('loglevel', std_logging.DEBUG)
        log_errors = kwargs.pop('log_errors', None)
        process_input = kwargs.pop('process_input', None)
        delay_on_retry = kwargs.pop('delay_on_retry', True)
        attempts = kwargs.pop('attempts', 1)
        check_exit_code = kwargs.pop('check_exit_code', [0])
        ignore_exit_code = False
        if isinstance(check_exit_code, bool):
            ignore_exit_code = not check_exit_code
            check_exit_code = [0]
        elif isinstance(check_exit_code, int):
            check_exit_code = [check_exit_code]

        sanitized_cmd = strutils.mask_password(' '.join(cmd))
        LOG.info(_LI('Executing RootwrapDaemonHelper.execute '
                     'cmd=[%(cmd)r] kwargs=[%(kwargs)r]'),
                 {'cmd': sanitized_cmd, 'kwargs': kwargs})

        while attempts > 0:
            attempts -= 1
            try:
                start_time = time.time()
                LOG.log(loglevel, _('Running cmd (subprocess): %s'),
                        sanitized_cmd)

                (returncode, out, err) = self.client.execute(
                    cmd, process_input)

                end_time = time.time() - start_time
                LOG.log(loglevel,
                        'CMD "%(sanitized_cmd)s" returned: %(return_code)s '
                        'in %(end_time)0.3fs',
                        {'sanitized_cmd': sanitized_cmd,
                         'return_code': returncode,
                         'end_time': end_time})

                if not ignore_exit_code and returncode not in check_exit_code:
                    out = strutils.mask_password(out)
                    err = strutils.mask_password(err)
                    raise processutils.ProcessExecutionError(
                        exit_code=returncode,
                        stdout=out,
                        stderr=err,
                        cmd=sanitized_cmd)
                return (out, err)

            except processutils.ProcessExecutionError as err:
                # if we want to always log the errors or if this is
                # the final attempt that failed and we want to log that.
                if log_errors == processutils.LOG_ALL_ERRORS or (
                                log_errors == processutils.LOG_FINAL_ERROR and
                            not attempts):
                    format = _('%(desc)r\ncommand: %(cmd)r\n'
                               'exit code: %(code)r\nstdout: %(stdout)r\n'
                               'stderr: %(stderr)r')
                    LOG.log(loglevel, format, {"desc": err.description,
                                               "cmd": err.cmd,
                                               "code": err.exit_code,
                                               "stdout": err.stdout,
                                               "stderr": err.stderr})
                if not attempts:
                    LOG.log(loglevel, _('%r failed. Not Retrying.'),
                            sanitized_cmd)
                    raise
                else:
                    LOG.log(loglevel, _('%r failed. Retrying.'),
                            sanitized_cmd)
                    if delay_on_retry:
                        time.sleep(random.randint(20, 200) / 100.0)
예제 #7
0
class ExternalImport(ExceptionBase):
    msg_fmt = _("Use of this module outside of os_vif is not allowed. It must "
                "not be imported in os-vif plugins that are out of tree as it "
                "is not a public interface of os-vif.")
예제 #8
0
class NetworkInterfaceNotFound(ExceptionBase):
    msg_fmt = _("Network interface %(interface)s not found")
예제 #9
0
class WrongPortProfile(osv_exception.ExceptionBase):
    msg_fmt = _('Port profile %(profile)s is not a subclass '
                'of VIFPortProfileOpenVSwitch')
예제 #10
0
class MissingPortProfile(osv_exception.ExceptionBase):
    msg_fmt = _('A port profile is mandatory for the OpenVSwitch plugin')
예제 #11
0
class AgentError(osv_exception.ExceptionBase):
    msg_fmt = _('Error during following call to agent: %(method)s')
예제 #12
0
class NoMatchingPlugin(ExceptionBase):
    msg_fmt = _("No plugin was found that handles VIF of type %(vif_type)s")
예제 #13
0
class PciDeviceNotFoundById(osv_exception.ExceptionBase):
    msg_fmt = _("PCI device %(id)s not found")
예제 #14
0
class RepresentorNotFound(osv_exception.ExceptionBase):
    msg_fmt = _('Failed getting representor port for PF %(ifname)s with '
                '%(vf_num)s')
예제 #15
0
class UnplugException(ExceptionBase):
    msg_fmt = _("Failed to unplug VIF %(vif)s. Got error: %(err)s")
예제 #16
0
class NetworkMissingPhysicalNetwork(ExceptionBase):
    msg_fmt = _("Physical network is missing for network %(network_uuid)s")
예제 #17
0
class LibraryNotInitialized(ExceptionBase):
    msg_fmt = _("Before using the os_vif library, you need to call "
                "os_vif.initialize()")
예제 #18
0
class NetworkInterfaceTypeNotDefined(ExceptionBase):
    msg_fmt = _("Network interface type %(type)s not defined")
예제 #19
0
class NoMatchingPlugin(ExceptionBase):
    msg_fmt = _("No VIF plugin was found with the name %(plugin_name)s")
예제 #20
0
    def execute(self, *cmd, **kwargs):
        # NOTE(dims): This method is to provide compatibility with the
        # processutils.execute interface. So that calling daemon or direct
        # rootwrap to honor the same set of flags in kwargs and to ensure
        # that we don't regress any current behavior.
        cmd = [str(c) for c in cmd]
        loglevel = kwargs.pop('loglevel', std_logging.DEBUG)
        log_errors = kwargs.pop('log_errors', None)
        process_input = kwargs.pop('process_input', None)
        delay_on_retry = kwargs.pop('delay_on_retry', True)
        attempts = kwargs.pop('attempts', 1)
        check_exit_code = kwargs.pop('check_exit_code', [0])
        ignore_exit_code = False
        if isinstance(check_exit_code, bool):
            ignore_exit_code = not check_exit_code
            check_exit_code = [0]
        elif isinstance(check_exit_code, int):
            check_exit_code = [check_exit_code]

        sanitized_cmd = strutils.mask_password(' '.join(cmd))
        LOG.info(
            _LI('Executing RootwrapDaemonHelper.execute '
                'cmd=[%(cmd)r] kwargs=[%(kwargs)r]'), {
                    'cmd': sanitized_cmd,
                    'kwargs': kwargs
                })

        while attempts > 0:
            attempts -= 1
            try:
                start_time = time.time()
                LOG.log(loglevel, _('Running cmd (subprocess): %s'),
                        sanitized_cmd)

                (returncode, out,
                 err) = self.client.execute(cmd, process_input)

                end_time = time.time() - start_time
                LOG.log(
                    loglevel,
                    'CMD "%(sanitized_cmd)s" returned: %(return_code)s '
                    'in %(end_time)0.3fs', {
                        'sanitized_cmd': sanitized_cmd,
                        'return_code': returncode,
                        'end_time': end_time
                    })

                if not ignore_exit_code and returncode not in check_exit_code:
                    out = strutils.mask_password(out)
                    err = strutils.mask_password(err)
                    raise processutils.ProcessExecutionError(
                        exit_code=returncode,
                        stdout=out,
                        stderr=err,
                        cmd=sanitized_cmd)
                return (out, err)

            except processutils.ProcessExecutionError as err:
                # if we want to always log the errors or if this is
                # the final attempt that failed and we want to log that.
                if log_errors == processutils.LOG_ALL_ERRORS or (
                        log_errors == processutils.LOG_FINAL_ERROR
                        and not attempts):
                    format = _('%(desc)r\ncommand: %(cmd)r\n'
                               'exit code: %(code)r\nstdout: %(stdout)r\n'
                               'stderr: %(stderr)r')
                    LOG.log(
                        loglevel, format, {
                            "desc": err.description,
                            "cmd": err.cmd,
                            "code": err.exit_code,
                            "stdout": err.stdout,
                            "stderr": err.stderr
                        })
                if not attempts:
                    LOG.log(loglevel, _('%r failed. Not Retrying.'),
                            sanitized_cmd)
                    raise
                else:
                    LOG.log(loglevel, _('%r failed. Retrying.'), sanitized_cmd)
                    if delay_on_retry:
                        time.sleep(random.randint(20, 200) / 100.0)
예제 #21
0
class UnsupportedPlatform(osv_exception.ExceptionBase):
    msg_fmt = _('VPP vhostuser interface is not supported on this platform')