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('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
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('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
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('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
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('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))