예제 #1
0
 def check_create_complete(self, data):
     attributes = self._show_resource()
     status = attributes['status']
     if status == 'PENDING_CREATE':
         return False
     elif status == 'ACTIVE':
         vip_attributes = self.client().show_vip(
             self.metadata_get()['vip'])['vip']
         vip_status = vip_attributes['status']
         if vip_status == 'PENDING_CREATE':
             return False
         if vip_status == 'ACTIVE':
             return True
         if vip_status == 'ERROR':
             raise exception.ResourceInError(
                 resource_status=vip_status,
                 status_reason=_('error in vip'))
         raise exception.ResourceUnknownStatus(
             resource_status=vip_status,
             result=_('Pool creation failed due to vip'))
     elif status == 'ERROR':
         raise exception.ResourceInError(
             resource_status=status,
             status_reason=_('error in pool'))
     else:
         raise exception.ResourceUnknownStatus(
             resource_status=status,
             result=_('Pool creation failed'))
예제 #2
0
    def _check_job_success(self, job_id, ignore_not_found=False):
        job_status, entities, error_code = self._get_job_info(job_id)
        if job_status == utils.FAIL:
            # for the user case of delete
            if ignore_not_found:
                # the user case of delete loadbalancer or member if they
                # do not exist
                if error_code == 'NOT_FOUND_ERROR':
                    return True
                # the user case of remove members when listener has been
                # deleted, elb will raise ELB.2050: member listener not
                # belong to any loadbalancer
                error_msg = json.dumps(entities)
                if 'ELB.2050' in error_msg:
                    return True
            raise exception.ResourceUnknownStatus(
                result=(_('Job %(job)s failed: %(error_code)s, '
                          '%(entities)s') % {
                              'job': job_id,
                              'error_code': error_code,
                              'entities': entities
                          }),
                resource_status='unknown')

        return job_status == utils.SUCCESS
예제 #3
0
 def check_create_complete(self, job_id):
     if self.resource_id is None:
         job_status, entities, error_code = self._get_job_info(job_id)
         elb_status = 'unknown'
         if entities:
             elb_info = entities.get('elb', {})
             elb_id = elb_info.get('id')
             elb_status = elb_info.get('status')
             if elb_id:
                 self.resource_id_set(elb_id)
                 self._set_job({})
         if job_status == utils.FAIL:
             self._set_job({})
             raise exception.ResourceUnknownStatus(
                 result=(_('Job %(job)s failed: %(error_code)s, '
                           '%(entities)s') % {
                               'job': job_id,
                               'error_code': error_code,
                               'entities': entities
                           }),
                 resource_status=elb_status)
         return self._check_active(elb_status)
     else:
         elb = self.client().loadbalancer.get(self.resource_id)
         return self._check_active(elb.status)
예제 #4
0
 def _check_create_backup_complete(self, prg):
     backup = self.client().backups.get(prg.backup_id)
     if backup.status == 'creating':
         return False
     if backup.status == 'available':
         return True
     else:
         raise exception.ResourceUnknownStatus(
             resource_status=backup.status,
             result=_('Volume backup failed'))
예제 #5
0
 def is_built(attributes):
     status = attributes['status']
     if status == 'BUILD':
         return False
     if status in ('ACTIVE', 'DOWN'):
         return True
     elif status == 'ERROR':
         raise exception.ResourceInError(resource_status=status)
     else:
         raise exception.ResourceUnknownStatus(
             resource_status=status, result=_('Resource is not built'))
예제 #6
0
 def verify_resize(self, server_id):
     server = self.fetch_server(server_id)
     if not server:
         return False
     status = self.get_status(server)
     if status == 'VERIFY_RESIZE':
         server.confirm_resize()
         return True
     else:
         msg = _("Could not confirm resize of server %s") % server_id
         raise exception.ResourceUnknownStatus(result=msg,
                                               resource_status=status)
예제 #7
0
    def check_create_complete(self, vol_id):
        vol = self.client().volumes.get(vol_id)

        if vol.status == 'available':
            return True
        if vol.status in self._volume_creating_status:
            return False
        if vol.status == 'error':
            raise exception.ResourceInError(resource_status=vol.status)
        else:
            raise exception.ResourceUnknownStatus(
                resource_status=vol.status, result=_('Volume create failed'))
예제 #8
0
    def _check_status_complete(self, expected_action, cookie=None):

        try:
            data = stack_object.Stack.get_status(self.context,
                                                 self.resource_id)
        except exception.NotFound:
            if expected_action == self.DELETE:
                return True
            # It's possible the engine handling the create hasn't persisted
            # the stack to the DB when we first start polling for state
            return False

        action, status, status_reason, updated_time = data

        if action != expected_action:
            return False

        # Has the action really started?
        #
        # The rpc call to update does not guarantee that the stack will be
        # placed into IN_PROGRESS by the time it returns (it runs stack.update
        # in a thread) so you could also have a situation where we get into
        # this method and the update hasn't even started.
        #
        # So we are using a mixture of state (action+status) and updated_at
        # to see if the action has actually progressed.
        # - very fast updates (like something with one RandomString) we will
        #   probably miss the state change, but we should catch the updated_at.
        # - very slow updates we won't see the updated_at for quite a while,
        #   but should see the state change.
        if cookie is not None:
            prev_state = cookie['previous']['state']
            prev_updated_at = cookie['previous']['updated_at']
            if (prev_updated_at == updated_time
                    and prev_state == (action, status)):
                return False

        if status == self.IN_PROGRESS:
            return False
        elif status == self.COMPLETE:
            ret = stack_lock.StackLock.get_engine_id(self.resource_id) is None
            if ret:
                # Reset nested, to indicate we changed status
                self._nested = None
            return ret
        elif status == self.FAILED:
            raise exception.ResourceFailure(status_reason, self, action=action)
        else:
            raise exception.ResourceUnknownStatus(
                resource_status=status,
                status_reason=status_reason,
                result=_('Stack unknown status'))
예제 #9
0
 def check_verify_resize(self, server_id):
     server = self.fetch_server(server_id)
     if not server:
         return False
     status = self.get_status(server)
     if status == 'ACTIVE':
         return True
     if status == 'VERIFY_RESIZE':
         return False
     else:
         msg = _("Confirm resize for server %s failed") % server_id
         raise exception.ResourceUnknownStatus(result=msg,
                                               resource_status=status)
예제 #10
0
    def check_update_complete(self, job_ids):
        add_job_id, remove_job_id = job_ids
        if not add_job_id and not remove_job_id:
            return True
        # check add job
        if add_job_id and not self.add_job_success:
            job_status, entities, error_code = self._get_job_info(add_job_id)
            if job_status == utils.FAIL:
                raise exception.ResourceUnknownStatus(
                    result=(_('Job %(job)s failed: %(error_code)s, '
                              '%(entities)s') % {
                                  'job': add_job_id,
                                  'error_code': error_code,
                                  'entities': entities
                              }),
                    resource_status='Unknown')
            if job_status == utils.SUCCESS:
                self.add_job_success = True
                self._handle_job_success(operate='update_add',
                                         entities=entities)
        if remove_job_id and not self.remove_job_success:
            job_status, entities, error_code =\
                self._get_job_info(remove_job_id)
            if job_status == utils.FAIL:
                raise exception.ResourceUnknownStatus(
                    result=(_('Job %(job)s failed: %(error_code)s, '
                              '%(entities)s') % {
                                  'job': remove_job_id,
                                  'error_code': error_code,
                                  'entities': entities
                              }),
                    resource_status='Unknown')
            if job_status == utils.SUCCESS:
                self.remove_job_success = True
                self._handle_job_success(operate='update_remove',
                                         entities=entities)

        return self.add_job_success and self.remove_job_success
예제 #11
0
 def check_create_complete(self, job_id):
     job_status, entities, error_code = self._get_job_info(job_id)
     if job_status == utils.FAIL:
         self._set_job({})
         raise exception.ResourceUnknownStatus(
             result=(_('Job %(job)s failed: %(error_code)s, '
                       '%(entities)s') % {
                           'job': job_id,
                           'error_code': error_code,
                           'entities': entities
                       }),
             resource_status='Unknown')
     if job_status == utils.SUCCESS:
         self._handle_job_success(entities=entities)
         self._set_job({})
         return True
예제 #12
0
 def check_suspend_complete(self, server_id):
     cp = self.client_plugin()
     server = cp.fetch_server(server_id)
     if not server:
         return False
     status = cp.get_status(server)
     LOG.debug('%(name)s check_suspend_complete status = %(status)s' % {
         'name': self.name,
         'status': status
     })
     if status in list(cp.deferred_server_statuses + ['ACTIVE']):
         return status == 'SUSPENDED'
     else:
         exc = exception.ResourceUnknownStatus(
             result=_('Suspend of instance %s failed') % server.name,
             resource_status=status)
         raise exc
예제 #13
0
    def check_attach_volume_complete(self, vol_id):
        vol = self.client().volumes.get(vol_id)
        if vol.status in ('available', 'attaching'):
            LOG.debug("Volume %(id)s is being attached - "
                      "volume status: %(status)s" % {'id': vol_id,
                                                     'status': vol.status})
            return False

        if vol.status != 'in-use':
            LOG.debug("Attachment failed - volume %(vol)s is "
                      "in %(status)s status" % {"vol": vol_id,
                                                "status": vol.status})
            raise exception.ResourceUnknownStatus(
                resource_status=vol.status,
                result=_('Volume attachment failed'))

        LOG.info(_LI('Attaching volume %(id)s complete'), {'id': vol_id})
        return True
예제 #14
0
    def _check_action_complete(self, action):
        stack = self.heat().stacks.get(stack_id=self.resource_id)
        if stack.action != action:
            return False

        if stack.status == self.IN_PROGRESS:
            return False
        elif stack.status == self.COMPLETE:
            return True
        elif stack.status == self.FAILED:
            raise exception.ResourceInError(
                resource_status=stack.stack_status,
                status_reason=stack.stack_status_reason)
        else:
            # Note: this should never happen, so it really means that
            # the resource/engine is in serious problem if it happens.
            raise exception.ResourceUnknownStatus(
                resource_status=stack.stack_status,
                status_reason=stack.stack_status_reason)
예제 #15
0
    def _check_active(self, server, res_name='Server'):
        """Check server status.

        Accepts both server IDs and server objects.
        Returns True if server is ACTIVE,
        raises errors when server has an ERROR or unknown to Heat status,
        returns False otherwise.

        :param res_name: name of the resource to use in the exception message

        """
        # not checking with is_uuid_like as most tests use strings e.g. '1234'
        if isinstance(server, six.string_types):
            server = self.fetch_server(server)
            if server is None:
                return False
            else:
                status = self.get_status(server)
        else:
            status = self.get_status(server)
            if status != 'ACTIVE':
                self.refresh_server(server)
                status = self.get_status(server)

        if status in self.deferred_server_statuses:
            return False
        elif status == 'ACTIVE':
            return True
        elif status == 'ERROR':
            fault = getattr(server, 'fault', {})
            raise exception.ResourceInError(
                resource_status=status,
                status_reason=_("Message: %(message)s, Code: %(code)s") % {
                    'message': fault.get('message', _('Unknown')),
                    'code': fault.get('code', _('Unknown'))
                })
        else:
            raise exception.ResourceUnknownStatus(
                resource_status=server.status,
                result=_('%s is not active') % res_name)
예제 #16
0
    def check_detach_volume_complete(self, vol_id):
        try:
            vol = self.client().volumes.get(vol_id)
        except Exception as ex:
            self.ignore_not_found(ex)
            return True

        if vol.status in ('in-use', 'detaching'):
            LOG.info('%s - volume still in use' % vol_id)
            return False

        LOG.info('Volume %(id)s - status: %(status)s' % {
            'id': vol.id, 'status': vol.status})

        if vol.status not in ('available', 'deleting'):
            LOG.error("Detachment failed - volume %(vol)s "
                      "is in %(status)s status" % {"vol": vol.id,
                                                   "status": vol.status})
            raise exception.ResourceUnknownStatus(
                resource_status=vol.status,
                result=_('Volume detachment failed'))
        else:
            return True