Example #1
0
    def _wait(self, unpair=True):
        timeout = self._local_conf['thread_timeout'] * 24
        start_time = time.time()
        retry_count = 0
        while True:
            cur_time = time.time()
            if (cur_time - start_time) > timeout:
                raise exception.APITimeout(_('UnpairWait wait timeout.'))

            sleep_time = get_sleep_time_for_clone(retry_count)
            LOG.debug('Sleep %d seconds Start', sleep_time)
            time.sleep(sleep_time)
            retry_count += 1

            query_status = self._cli.query_MV_RV_status(self._rvname, 'RV')
            if query_status == 'separated':
                if unpair is True:
                    self._cli.unpair(self._mvname, self._rvname, 'normal')
                break
            elif query_status == 'sep/exec':
                continue
            else:
                LOG.debug('iSMrc_query command result abnormal.'
                          'Query status = %(status)s, RV = %(rv)s.',
                          {'status': query_status, 'rv': self._rvname})
                break
Example #2
0
 def get_server(self, context, server_id, privileged_user=False,
                timeout=None):
     try:
         return novaclient(context, privileged_user=privileged_user,
                           timeout=timeout).servers.get(server_id)
     except nova_exceptions.NotFound:
         raise exception.ServerNotFound(uuid=server_id)
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
Example #3
0
    def _sync_execute(self, command, diskarray_name,
                      expected_status=[0], raise_exec=True):
        retry_flag = True
        retry_count = 0
        while retry_flag is True:
            try:
                out, err, status = self._cli_execute(command, expected_status,
                                                     False)
                if status != 0:
                    errflg = 0
                    errnum = out + err
                    LOG.debug('ismcli failed (errnum=%s).', errnum)
                    for retry_msgid in retry_msgids:
                        if errnum.find(retry_msgid) >= 0:
                            LOG.debug('`%(command)s` failed. '
                                      '%(name)s %(errnum)s '
                                      'retry_count=%(retry_count)d',
                                      {'command': command,
                                       'name': __name__,
                                       'errnum': errnum,
                                       'retry_count': retry_count})
                            errflg = 1
                            break
                    if errflg == 1:
                        retry_count += 1
                        if retry_count >= 60:
                            msg = (_('Timeout `%(command)s`.'
                                     ' status=%(status)d, '
                                     'out="%(out)s", '
                                     'err="%(err)s".') %
                                   {'command': command,
                                    'status': status,
                                    'out': out,
                                    'err': err})
                            raise exception.APITimeout(msg)
                        time.sleep(5)
                        continue
                    else:
                        if raise_exec is True:
                            msg = _('Command `%s` failed.') % command
                            raise exception.VolumeBackendAPIException(data=msg)
            except EOFError:
                with excutils.save_and_reraise_exception() as ctxt:
                    LOG.debug('EOFError has occurred. '
                              '%(name)s retry_count=%(retry_count)d',
                              {'name': __name__,
                               'retry_count': retry_count})
                    retry_count += 1
                    if retry_count < 60:
                        ctxt.reraise = False
                time.sleep(5)
                continue
            retry_flag = False

        return out, err, status
Example #4
0
    def has_extension(self, context, extension, timeout=None):
        try:
            client = novaclient(context, timeout=timeout)

            # Pylint gives a false positive here because the 'list_extensions'
            # method is not explicitly declared. Overriding the error.
            # pylint: disable-msg=E1101
            nova_exts = client.list_extensions.show_all()
        except request_exceptions.Timeout:
            raise exception.APITimeout(service='Nova')
        return extension in [e.name for e in nova_exts]
Example #5
0
 def exec_cmd(self,
              context,
              server_id,
              command,
              run_as="root",
              timeout=None):
     server = self.get_server(context, server_id, timeout=timeout)
     try:
         return novaclient(context, timeout=timeout)\
             .servers.exec_cmd_by_qga(server, command, run_as)
     except nova_exceptions.NotFound:
         raise exception.ServerNotFound(uuid=server_id)
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
     except Exception as e:
         LOG.error(_LE("Run cmd error, %s"), e)
         raise exception.ExecCmdError()
Example #6
0
 def set_vm_state(self, context, server_id, vm_state, timeout=None):
     server = self.get_server(context, server_id, timeout=timeout)
     try:
         return novaclient(context, timeout=timeout).servers.reset_state(
             server, vm_state)
     except nova_exceptions.NotFound:
         raise exception.ServerNotFound(uuid=server_id)
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
     except Exception as e:
         if isinstance(e, basestring):
             errmsg = e
         else:
             errmsg = e.message
         if errmsg.find(NOT_PERMIT_VM_STATE) != -1:
             raise exception.NotPermitVmState()
         else:
             raise
Example #7
0
 def thaw_filesystem(self, context, server_id, timeout=None):
     server = self.get_server(context, server_id, timeout=timeout)
     if server.status in [
             "SHUTOFF", "PAUSED", "SUSPENDED", "SHELVED_OFFLOADED"
     ]:
         LOG.warn(
             _LW("VM %(server_id)s is in %(state)s state, do not need"
                 "to thaw filesystem"), {
                     'server_id': server_id,
                     'state': server.status
                 })
         return
     try:
         return novaclient(context,
                           timeout=timeout).servers.thaw_filesystem(server)
     except nova_exceptions.NotFound:
         raise exception.ServerNotFound(uuid=server_id)
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
     except nova_exceptions.Conflict as e:
         if isinstance(e, basestring):
             errmsg = e
         else:
             errmsg = e.message
         LOG.warn(
             _LW('vm %(server_id)s freeze fs meet error,'
                 'error message is %(message)s'), {
                     'server_id': server_id,
                     'message': e.message
                 })
         if errmsg.find(QEMU_GA_NOT_ENABLE) != -1:
             raise exception.QemuGANotEnable()
         elif errmsg.find(QEMU_GA_NOT_AVAILABLE) != -1:
             raise exception.QemuGANotAvailable()
         elif errmsg.find(QEMU_GA_REPEAT_THAW) != -1:
             raise exception.QemuGARepeatThaw()
         else:
             raise
Example #8
0
 def has_extension(self, context, extension, timeout=None):
     try:
         nova_exts = novaclient(context).list_extensions.show_all()
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
     return extension in [e.name for e in nova_exts]
Example #9
0
 def has_extension(self, context, extension, timeout=None):
     try:
         nova_exts = nova_client.discover_extensions(NOVA_API_VERSION)
     except request_exceptions.Timeout:
         raise exception.APITimeout(service='Nova')
     return extension in [e.name for e in nova_exts]
 def _trace_test_method(*args, **kwargs):
     raise exception.APITimeout('test message')