def test_terminate_instance_exception(self): formData = {'method': 'TerminateInstance', 'instance': self.servers[0].id, } self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.servers[0].id)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('ApiException', message='apiException') self.mox.StubOutWithMock(api, 'server_delete') api.server_delete(IsA(http.HttpRequest), self.servers[0]).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(unicode)) self.mox.ReplayAll() res = self.client.post(reverse('dash_instances', args=[self.TEST_TENANT]), formData) self.assertRedirectsNoFollow(res, reverse('dash_instances', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def handle(self, request, data): instance_id = data['instance'] instance = api.server_get(request, instance_id) try: api.server_delete(request, instance) except api_exceptions.ApiException, e: messages.error(request, 'Unable to terminate %s: %s' % (instance_id, e.message,))
def handle(self, request, data): instance_id = data["instance"] instance = api.server_get(request, instance_id) try: api.server_delete(request, instance) except api_exceptions.ApiException, e: LOG.exception('ApiException while terminating instance "%s"' % instance_id) messages.error( request, _("Unable to terminate %(inst)s: %(message)s") % {"inst": instance_id, "message": e.message} )
def handle(self, request, data): instance_id = data['instance'] instance = api.server_get(request, instance_id) try: api.server_delete(request, instance) except api_exceptions.ApiException, e: LOG.error('ApiException while terminating instance "%s"' % instance_id, exc_info=True) messages.error(request, 'Unable to terminate %s: %s' % (instance_id, e.message,))
def handle(self, request, data): instance_id = data['instance'] instance = api.server_get(request, instance_id) try: api.server_delete(request, instance) except api_exceptions.ApiException, e: LOG.exception('ApiException while terminating instance "%s"' % instance_id) messages.error( request, 'Unable to terminate %s: %s' % ( instance_id, e.message, ))
def handle(self, request, data): instance_id = data['instance'] instance = api.server_get(request, instance_id) try: api.server_delete(request, instance) except api_exceptions.ApiException, e: LOG.exception( _('ApiException while terminating instance "%s"') % instance_id) messages.error( request, _('Unable to terminate %(inst)s: %(message)s') % { "inst": instance_id, "message": e.message })
def test_terminate_instance(self): formData = {'method': 'TerminateInstance', 'instance': self.servers[0].id, } self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.servers[0].id)).AndReturn(self.servers[0]) self.mox.StubOutWithMock(api, 'server_delete') api.server_delete(IsA(http.HttpRequest), self.servers[0]) self.mox.ReplayAll() res = self.client.post(reverse('dash_instances', args=[self.TEST_TENANT]), formData) self.assertRedirectsNoFollow(res, reverse('dash_instances', args=[self.TEST_TENANT])) self.mox.VerifyAll()
def test_server_delete(self): INSTANCE = "anInstance" compute_api = self.stub_compute_api() compute_api.servers = self.mox.CreateMockAnything() compute_api.servers.delete(INSTANCE).AndReturn(TEST_RETURN) self.mox.ReplayAll() ret_val = api.server_delete(self.request, INSTANCE) self.assertIsNone(ret_val) self.mox.VerifyAll()