def test_create_snapshot_post_exception(self): SNAPSHOT_NAME = 'snappy' new_snapshot = self.mox.CreateMock(api.Image) new_snapshot.name = SNAPSHOT_NAME formData = { 'method': 'CreateSnapshot', 'tenant_id': self.TEST_TENANT, 'instance_id': self.good_server.id, 'name': SNAPSHOT_NAME } self.mox.StubOutWithMock(api, 'snapshot_create') exception = api_exceptions.ApiException('apiException', message='apiException') api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('dash_snapshots_create', args=[self.TEST_TENANT, self.good_server.id]), formData) self.assertRedirectsNoFollow( res, reverse('dash_snapshots_create', args=[self.TEST_TENANT, self.good_server.id])) self.mox.VerifyAll()
def test_create_snapshot_post_exception(self): SNAPSHOT_NAME = 'snappy' new_snapshot = self.mox.CreateMock(api.Image) new_snapshot.name = SNAPSHOT_NAME formData = {'method': 'CreateSnapshot', 'tenant_id': self.TEST_TENANT, 'instance_id': self.good_server.id, 'name': SNAPSHOT_NAME} self.mox.StubOutWithMock(api, 'snapshot_create') exception = api_exceptions.ApiException('apiException', message='apiException') api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post(reverse('dash_snapshots_create', args=[self.TEST_TENANT, self.good_server.id]), formData) self.assertRedirectsNoFollow(res, reverse('dash_snapshots_create', args=[self.TEST_TENANT, self.good_server.id])) self.mox.VerifyAll()
def test_server_snapshot_create(self): novaclient = self.stub_novaclient() novaclient.servers = self.mox.CreateMockAnything() novaclient.servers.create_image(IsA(int), IsA(str)).AndReturn(self.server) self.mox.ReplayAll() server = api.snapshot_create(self.request, 1, "test-snapshot") self.assertIsInstance(server, api.Server) self.mox.VerifyAll()
def handle(self, request, data): try: LOG.info('Creating snapshot "%s"' % data['name']) snapshot = api.snapshot_create(request, data['instance_id'], data['name']) instance = api.server_get(request, data['instance_id']) messages.info(request, 'Snapshot "%s" created for instance "%s"' %\ (data['name'], instance.name)) return shortcuts.redirect('dash_snapshots', data['tenant_id']) except api_exceptions.ApiException, e: msg = 'Error Creating Snapshot: %s' % e.message LOG.error(msg, exc_info=True) messages.error(request, msg) return shortcuts.redirect(request.build_absolute_uri())
def handle(self, request, data): try: LOG.info('Creating snapshot "%s"' % data['name']) snapshot = api.snapshot_create(request, data['instance_id'], data['name']) instance = api.server_get(request, data['instance_id']) messages.info(request, 'Snapshot "%s" created for instance "%s"' %\ (data['name'], instance.name)) return shortcuts.redirect('dash_snapshots', data['tenant_id']) except api_exceptions.ApiException, e: msg = 'Error Creating Snapshot: %s' % e.message LOG.exception(msg) messages.error(request, msg) return shortcuts.redirect(request.build_absolute_uri())
def handle(self, request, data): try: LOG.info('Creating snapshot "%s"' % data['name']) snapshot = api.snapshot_create(request, data['instance_id'], data['name']) instance = api.server_get(request, data['instance_id']) messages.info(request, _('Snapshot "%(name)s" created for instance "%(inst)s"') % {"name": data['name'], "inst": instance.name}) return shortcuts.redirect('dash_snapshots', data['tenant_id']) except api_exceptions.ApiException, e: msg = _('Error Creating Snapshot: %s') % e.message LOG.exception(msg) messages.error(request, msg) return shortcuts.redirect(request.build_absolute_uri())