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_create_snapshot_post(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, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server) self.mox.StubOutWithMock(api, 'snapshot_create') api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).\ AndReturn(new_snapshot) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id]), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:images_and_snapshots:snapshots:index'))
def test_create_snapshot_post(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, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server) self.mox.StubOutWithMock(api, 'snapshot_create') api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).\ AndReturn(new_snapshot) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id]), formData) self.assertRedirectsNoFollow(res, reverse('steer:engine:images_and_snapshots:snapshots: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 test_instance_update_post_api_exception(self): INSTANCE_ID = self.servers[0].id NAME = 'myname' formData = { 'method': 'UpdateInstance', 'instance': INSTANCE_ID, 'name': NAME, 'tenant_id': self.TEST_TENANT } self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_update') api.server_update(IsA(http.HttpRequest), str(INSTANCE_ID), NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID]), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_instance_update_post_api_exception(self): INSTANCE_ID = self.servers[0].id NAME = 'myname' formData = {'method': 'UpdateInstance', 'instance': INSTANCE_ID, 'name': NAME, 'tenant_id': self.TEST_TENANT} self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_update') api.server_update(IsA(http.HttpRequest), str(INSTANCE_ID), NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID]), formData) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_create_snapshot_get(self): self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id])) self.assertTemplateUsed( res, 'engine/images_and_snapshots/snapshots/create.html')
def test_create_snapshot_get_with_invalid_status(self): self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.bad_server.id)).AndReturn(self.bad_server) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.bad_server.id])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_create_snapshot_get_with_invalid_status(self): self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.bad_server.id)).AndReturn(self.bad_server) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.bad_server.id])) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_create_snapshot_get(self): self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndReturn(self.good_server) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id])) self.assertTemplateUsed(res, 'engine/images_and_snapshots/snapshots/create.html')
def test_create_get_server_exception(self): self.mox.StubOutWithMock(api, 'server_get') exception = api_exceptions.ApiException('apiException') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_create_get_server_exception(self): self.mox.StubOutWithMock(api, 'server_get') exception = api_exceptions.ApiException('apiException') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id])) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_instance_update_get(self): INSTANCE_ID = self.servers[0].id self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID])) self.assertTemplateUsed(res, 'engine/instances_and_volumes/instances/update.html')
def test_instance_update_get(self): INSTANCE_ID = self.servers[0].id self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID])) self.assertTemplateUsed( res, 'engine/instances_and_volumes/instances/update.html')
def test_instance_update_get_server_get_exception(self): INSTANCE_ID = self.servers[0].id exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def detail(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) volumes = api.volume_instance_list(request, instance_id) try: console = api.console_create(request, instance_id, 'vnc') vnc_url = "%s&title=%s(%s)" % (console.output, instance.name, instance_id) except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance vnc \ connection')) messages.error(request, _('Unable to get vnc console for instance %(inst)s: %(msg)s') % {"inst": instance_id, "msg": e.message}) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance info')) messages.error(request, _('Unable to get information for instance %(inst)s: %(msg)s') % {"inst": instance_id, "msg": e.message}) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
def test_instance_update_get_server_get_exception(self): INSTANCE_ID = self.servers[0].id exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
def detail(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) volumes = api.volume_instance_list(request, instance_id) try: console = api.console_create(request, instance_id, 'vnc') vnc_url = "%s&title=%s(%s)" % (console.output, instance.name, instance_id) except api_exceptions.ApiException, e: LOG.exception( _('ApiException while fetching instance vnc \ connection')) messages.error( request, _('Unable to get vnc console for instance %(inst)s: %(msg)s') % { "inst": instance_id, "msg": e.message }) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance info')) messages.error( request, _('Unable to get information for instance %(inst)s: %(msg)s') % { "inst": instance_id, "msg": e.message }) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
def detail(request, instance_id): try: instance = api.server_get(request, instance_id) try: console = api.console_create(request, instance_id, 'vnc') vnc_url = "%s&title=%s(%s)" % (console.output, instance.name, instance_id) except api_exceptions.ApiException, e: LOG.exception('ApiException while fetching instance vnc \ connection') messages.error( request, _('Unable to get vnc console for instance %(inst)s: %(message)s' ) % { "inst": instance_id, "message": e.message }) return redirect('steer:syspanel:instances:index', tenant_id) except api_exceptions.ApiException, e: LOG.exception('ApiException while fetching instance info') messages.error( request, _('Unable to get information for instance %(inst)s: %(message)s') % { "inst": instance_id, "message": e.message }) return redirect('steer:syspanel:instances:index', tenant_id)
def update(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance info')) messages.error(request, _('Unable to get information for instance %(inst)s: %(message)s') % {"inst": instance_id, "message": e.message}) return shortcuts.redirect( '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'))
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 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_instance_vnc(self): INSTANCE_ID = self.servers[0].id CONSOLE_OUTPUT = '/vncserver' console_mock = self.mox.CreateMock(api.Console) console_mock.output = CONSOLE_OUTPUT self.mox.StubOutWithMock(api, 'console_create') self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.servers[0].id)).AndReturn(self.servers[0]) api.console_create(IgnoreArg(), unicode(INSTANCE_ID), 'vnc').AndReturn(console_mock) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow(res, CONSOLE_OUTPUT + '&title=serverName(1)')
def vnc(request, instance_id): tenant_id = request.user.tenant_id try: console = api.console_create(request, instance_id, 'vnc') instance = api.server_get(request, instance_id) return shortcuts.redirect(console.output + ("&title=%s(%s)" % (instance.name, instance_id))) except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance vnc connection')) messages.error(request, _('Unable to get vnc console for instance %(inst)s: %(message)s') % {"inst": instance_id, "message": e.message}) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
def detail(request, volume_id): try: volume = api.volume_get(request, volume_id) attachment = volume.attachments[0] if attachment: instance = api.server_get( request, volume.attachments[0]['serverId']) else: instance = None except engineclient_exceptions.ClientException, e: LOG.exception("ClientException in volume get") messages.error(request, _('Error fetching volume: %s') % e.message) return shortcuts.redirect( 'steer:engine:instances_and_volumes:volumes:index')
def detail(request, volume_id): try: volume = api.volume_get(request, volume_id) attachment = volume.attachments[0] if attachment: instance = api.server_get(request, volume.attachments[0]['serverId']) else: instance = None except engineclient_exceptions.ClientException, e: LOG.exception("ClientException in volume get") messages.error(request, _('Error fetching volume: %s') % e.message) return shortcuts.redirect( 'steer:engine:instances_and_volumes:volumes:index')
def update(request, instance_id): tenant_id = request.user.tenant_id try: instance = api.server_get(request, instance_id) except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance info')) messages.error( request, _('Unable to get information for instance %(inst)s: %(message)s') % { "inst": instance_id, "message": e.message }) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
def create(request, instance_id): tenant_id = request.user.tenant_id form, handled = CreateSnapshot.maybe_handle(request, initial={'tenant_id': tenant_id, 'instance_id': instance_id}) if handled: return handled try: instance = api.server_get(request, instance_id) except api_exceptions.ApiException, e: msg = _("Unable to retrieve instance: %s") % e LOG.exception(msg) messages.error(request, msg) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
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('steer:engine:images_and_snapshots' ':snapshots:index') 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 create(request, instance_id): tenant_id = request.user.tenant_id form, handled = CreateSnapshot.maybe_handle(request, initial={ 'tenant_id': tenant_id, 'instance_id': instance_id }) if handled: return handled try: instance = api.server_get(request, instance_id) except api_exceptions.ApiException, e: msg = _("Unable to retrieve instance: %s") % e LOG.exception(msg) messages.error(request, msg) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
def vnc(request, instance_id): tenant_id = request.user.tenant_id try: console = api.console_create(request, instance_id, 'vnc') instance = api.server_get(request, instance_id) return shortcuts.redirect(console.output + ("&title=%s(%s)" % (instance.name, instance_id))) except api_exceptions.ApiException, e: LOG.exception(_('ApiException while fetching instance vnc connection')) messages.error( request, _('Unable to get vnc console for instance %(inst)s: %(message)s') % { "inst": instance_id, "message": e.message }) return shortcuts.redirect( 'steer:engine:instances_and_volumes:instances:index')
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('steer:engine:images_and_snapshots' ':snapshots:index') 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 detail(request, instance_id): try: instance = api.server_get(request, instance_id) try: console = api.console_create(request, instance_id, 'vnc') vnc_url = "%s&title=%s(%s)" % (console.output, instance.name, instance_id) except api_exceptions.ApiException, e: LOG.exception('ApiException while fetching instance vnc \ connection') messages.error(request, _('Unable to get vnc console for instance %(inst)s: %(message)s') % {"inst": instance_id, "message": e.message}) return redirect('steer:syspanel:instances:index', tenant_id) except api_exceptions.ApiException, e: LOG.exception('ApiException while fetching instance info') messages.error(request, _('Unable to get information for instance %(inst)s: %(message)s') % {"inst": instance_id, "message": e.message}) return redirect('steer:syspanel:instances:index', tenant_id)