Example #1
0
    def check_suspend_complete(self, cookie):
        server, suspend_runner, volumes_runner = cookie

        if not volumes_runner.started():
            volumes_runner.start()

        if volumes_runner.done():
            if not suspend_runner.started():
                suspend_runner.start()

            if suspend_runner.done():
                if server.status == 'SUSPENDED':
                    return True

                nova_utils.refresh_server(server)
                logger.debug(_("%(name)s check_suspend_complete "
                               "status = %(status)s"),
                             {'name': self.name,
                              'status': server.status})
                if server.status in list(nova_utils.deferred_server_statuses +
                                         ['ACTIVE']):
                    return server.status == 'SUSPENDED'
                else:
                    raise exception.Error(_(' nova reported unexpected '
                                            'instance[%(instance)s] '
                                            'status[%(status)s]') %
                                          {'instance': self.name,
                                           'status': server.status})
            else:
                suspend_runner.step()
        else:
            return volumes_runner.step()
Example #2
0
    def _check_active(self, server):
        if server.status != 'ACTIVE':
            nova_utils.refresh_server(server)

        if server.status == 'ACTIVE':
            return True

        # Some clouds append extra (STATUS) strings to the status
        short_server_status = server.status.split('(')[0]
        if short_server_status in nova_utils.deferred_server_statuses:
            return False

        if server.status == 'ERROR':
            fault = getattr(server, 'fault', {})
            message = fault.get('message', 'Unknown')
            code = fault.get('code', 500)
            exc = exception.Error(
                _("Creation of server %(server)s "
                  "failed: %(message)s (%(code)s)") %
                dict(server=server.name, message=message, code=code))
            raise exc

        exc = exception.Error(
            _("Creation of server %(server)s failed "
              "with unknown status: %(status)s") %
            dict(server=server.name, status=server.status))
        raise exc
Example #3
0
    def _check_active(self, server):
        if server.status != 'ACTIVE':
            nova_utils.refresh_server(server)

        if server.status == 'ACTIVE':
            return True

        # Some clouds append extra (STATUS) strings to the status
        short_server_status = server.status.split('(')[0]
        if short_server_status in nova_utils.deferred_server_statuses:
            return False

        if server.status == 'ERROR':
            fault = getattr(server, 'fault', {})
            message = fault.get('message', 'Unknown')
            code = fault.get('code', 500)
            exc = exception.Error(_("Creation of server %(server)s "
                                    "failed: %(message)s (%(code)s)") %
                                  dict(server=server.name,
                                       message=message,
                                       code=code))
            raise exc

        exc = exception.Error(_("Creation of server %(server)s failed "
                                "with unknown status: %(status)s") %
                              dict(server=server.name,
                                   status=server.status))
        raise exc
Example #4
0
    def check_suspend_complete(self, cookie):
        server, suspend_runner = cookie

        if not suspend_runner.started():
            suspend_runner.start()

        if suspend_runner.done():
            if server.status == 'SUSPENDED':
                return True

            nova_utils.refresh_server(server)
            logger.debug(
                _('%(name)s check_suspend_complete status '
                  '= %(status)s') % {
                      'name': self.name,
                      'status': server.status
                  })
            if server.status in list(nova_utils.deferred_server_statuses +
                                     ['ACTIVE']):
                return server.status == 'SUSPENDED'
            else:
                exc = exception.Error(
                    _('Suspend of server %(server)s failed '
                      'with unknown status: %(status)s') %
                    dict(server=server.name, status=server.status))
                raise exc
Example #5
0
    def test_successful_refresh(self):
        server = self.m.CreateMockAnything()
        server.get().AndReturn(None)
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
Example #6
0
    def test_successful_refresh(self):
        server = self.m.CreateMockAnything()
        server.get().AndReturn(None)
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
Example #7
0
    def check_create_complete(self, server):
        """Check if server creation is complete and handle server configs."""
        if not self._check_active(server):
            return False

        nova_utils.refresh_server(server)

        if 'rack_connect' in self.context.roles and not \
           self._check_rack_connect_complete(server):
            return False

        if 'rax_managed' in self.context.roles and not \
           self._check_managed_cloud_complete(server):
            return False

        return True
Example #8
0
    def check_create_complete(self, server):
        """Check if server creation is complete and handle server configs."""
        if not self._check_active(server):
            return False

        nova_utils.refresh_server(server)

        if 'rack_connect' in self.context.roles and not \
           self._check_rack_connect_complete(server):
            return False

        if 'rax_managed' in self.context.roles and not \
           self._check_managed_cloud_complete(server):
            return False

        return True
Example #9
0
    def test_503_error(self):
        server = self.m.CreateMockAnything()
        server.get().AndRaise(fakes.fake_exception(503))
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
Example #10
0
    def test_503_error(self):
        server = self.m.CreateMockAnything()
        msg = "ClientException: The server has either erred or is " "incapable of performing the requested operation."
        server.get().AndRaise(clients.novaclient.exceptions.ClientException(503, msg))
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
Example #11
0
    def _delete_server(self, server):
        '''
        Return a co-routine that deletes the server and waits for it to
        disappear from Nova.
        '''
        yield self._detach_volumes_task()()
        server.delete()

        while True:
            yield

            try:
                nova_utils.refresh_server(server)
                if server.status == "DELETED":
                    break
            except clients.novaclient.exceptions.NotFound:
                break
        self.resource_id_set(None)
Example #12
0
    def _delete_server(self, server):
        '''
        Return a co-routine that deletes the server and waits for it to
        disappear from Nova.
        '''
        yield self._detach_volumes_task()()
        server.delete()

        while True:
            yield

            try:
                nova_utils.refresh_server(server)
                if server.status == "DELETED":
                    break
            except clients.novaclient.exceptions.NotFound:
                break
        self.resource_id_set(None)
Example #13
0
    def test_503_error(self):
        server = self.m.CreateMockAnything()
        msg = ("ClientException: The server has either erred or is "
               "incapable of performing the requested operation.")
        server.get().AndRaise(
            clients.novaclient.exceptions.ClientException(503, msg))
        self.m.ReplayAll()

        self.assertIsNone(nova_utils.refresh_server(server))
        self.m.VerifyAll()
Example #14
0
    def _check_active(self, server):

        if server.status != 'ACTIVE':
            nova_utils.refresh_server(server)

        # Some clouds append extra (STATUS) strings to the status
        short_server_status = server.status.split('(')[0]
        if short_server_status in nova_utils.deferred_server_statuses:
            return False
        elif server.status == 'ACTIVE':
            return True
        elif server.status == 'ERROR':
            exc = exception.Error(_('Creation of server %s failed.') %
                                  server.name)
            raise exc
        else:
            exc = exception.Error(_('Creation of server %(server)s failed '
                                    'with unknown status: %(status)s') %
                                  dict(server=server.name,
                                       status=server.status))
            raise exc
Example #15
0
    def _check_active(self, server):

        if server.status != 'ACTIVE':
            nova_utils.refresh_server(server)

        # Some clouds append extra (STATUS) strings to the status
        short_server_status = server.status.split('(')[0]
        if short_server_status in nova_utils.deferred_server_statuses:
            return False
        elif server.status == 'ACTIVE':
            return True
        elif server.status == 'ERROR':
            exc = exception.Error(
                _('Creation of server %s failed.') % server.name)
            raise exc
        else:
            exc = exception.Error(
                _('Creation of server %(server)s failed '
                  'with unknown status: %(status)s') %
                dict(server=server.name, status=server.status))
            raise exc
Example #16
0
    def _delete_server(self, server):
        '''
        Return a co-routine that deletes the server and waits for it to
        disappear from Nova.
        '''
        yield self._detach_volumes_task()()
        server.delete()

        while True:
            yield

            try:
                nova_utils.refresh_server(server)
                if server.status == "DELETED":
                    self.resource_id_set(None)
                    break
                elif server.status == "ERROR":
                    raise exception.Error(_("Deletion of server %s failed.") %
                                          server.id)
            except clients.novaclient.exceptions.NotFound:
                self.resource_id_set(None)
                break
Example #17
0
    def _delete_server(self, server):
        '''
        Return a co-routine that deletes the server and waits for it to
        disappear from Nova.
        '''
        yield self._detach_volumes_task()()
        server.delete()

        while True:
            yield

            try:
                nova_utils.refresh_server(server)
                if server.status == "DELETED":
                    self.resource_id_set(None)
                    break
                elif server.status == "ERROR":
                    raise exception.Error(
                        _("Deletion of server %s failed.") % server.id)
            except clients.novaclient.exceptions.NotFound:
                self.resource_id_set(None)
                break
Example #18
0
    def _check_active(self, server):

        if server.status != 'ACTIVE':
            nova_utils.refresh_server(server)

        # Some clouds append extra (STATUS) strings to the status
        short_server_status = server.status.split('(')[0]
        if short_server_status in nova_utils.deferred_server_statuses:
            return False
        elif server.status == 'ACTIVE':
            return True
        elif server.status == 'ERROR':
            fault = getattr(server, 'fault', {})
            raise resource.ResourceInError(
                resource_status=server.status,
                status_reason=_("Message: %(message)s, Code: %(code)s") % {
                    'message': fault.get('message', _('Unknown')),
                    'code': fault.get('code', _('Unknown'))
                })
        else:
            raise resource.ResourceUnknownStatus(
                resource_status=server.status)
Example #19
0
    def check_suspend_complete(self, cookie):
        server, suspend_runner = cookie

        if not suspend_runner.started():
            suspend_runner.start()

        if suspend_runner.done():
            if server.status == 'SUSPENDED':
                return True

            nova_utils.refresh_server(server)
            LOG.debug('%(name)s check_suspend_complete status = %(status)s'
                      % {'name': self.name, 'status': server.status})
            if server.status in list(nova_utils.deferred_server_statuses +
                                     ['ACTIVE']):
                return server.status == 'SUSPENDED'
            else:
                exc = exception.Error(_('Suspend of server %(server)s failed '
                                        'with unknown status: %(status)s') %
                                      dict(server=server.name,
                                           status=server.status))
                raise exc
Example #20
0
 def test_overlimit_error(self):
     server = mock.Mock()
     server.get.side_effect = clients.novaclient.exceptions.OverLimit(
         413, "limit reached")
     self.assertIsNone(nova_utils.refresh_server(server))
Example #21
0
 def test_overlimit_error(self):
     server = mock.Mock()
     server.get.side_effect = fakes.fake_exception(413)
     self.assertIsNone(nova_utils.refresh_server(server))
Example #22
0
 def test_overlimit_error(self):
     server = mock.Mock()
     server.get.side_effect = clients.novaclient.exceptions.OverLimit(
         413, "limit reached")
     self.assertIsNone(nova_utils.refresh_server(server))