def test_create_keypair_exception(self): keypair = self.keypairs.first() exc = novaclient_exceptions.ClientException('clientException') self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), keypair.name).AndRaise(exc) self.mox.ReplayAll() formData = {'method': 'CreateKeypair', 'name': keypair.name} url = reverse('horizon:nova:access_and_security:keypairs:create') res = self.client.post(url, formData) self.assertRedirectsNoFollow(res, url)
def test_create_keypair_post(self): keypair = self.keypairs.first() keypair.private_key = "secret" self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), keypair.name).AndReturn(keypair) self.mox.ReplayAll() formData = {'method': 'CreateKeypair', 'name': keypair.name} url = reverse('horizon:nova:access_and_security:keypairs:create') res = self.client.post(url, formData) self.assertTrue(res.has_header('Content-Disposition'))
def test_generate_keypair_get(self): keypair = self.keypairs.first() keypair.private_key = "secret" self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), keypair.name).AndReturn(keypair) self.mox.ReplayAll() context = {'keypair_name': keypair.name} url = reverse('horizon:nova:access_and_security:keypairs:generate', kwargs={'keypair_name': keypair.name}) res = self.client.get(url, context) self.assertTrue(res.has_header('content-disposition'))
def test_generate_keypair_exception(self): keypair = self.keypairs.first() self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), keypair.name) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() context = {'keypair_name': keypair.name} url = reverse('horizon:nova:access_and_security:keypairs:generate', kwargs={'keypair_name': keypair.name}) res = self.client.get(url, context) self.assertRedirectsNoFollow( res, reverse('horizon:nova:access_and_security:index'))
def test_create_keypair_exception(self): KEYPAIR_NAME = 'newKeypair' formData = {'method': 'CreateKeypair', 'name': KEYPAIR_NAME, } exception = novaclient_exceptions.ClientException('clientException', message='clientException') self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), KEYPAIR_NAME).AndRaise(exception) self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:keypairs:create'), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:keypairs:create'))
def test_create_keypair_exception(self): KEYPAIR_NAME = 'newKeypair' formData = {'method': 'CreateKeypair', 'name': KEYPAIR_NAME, } exception = novaclient_exceptions.ClientException('clientException', message='clientException') self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), KEYPAIR_NAME).AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:access_and_security:keypairs:create'), formData) self.assertRedirectsNoFollow(res, reverse('horizon:nova:access_and_security:keypairs:create'))
def test_create_keypair_post(self): KEYPAIR_NAME = 'newKeypair' PRIVATE_KEY = 'privateKey' newKeyPair = self.mox.CreateMock(api.KeyPair) newKeyPair.name = KEYPAIR_NAME newKeyPair.private_key = PRIVATE_KEY formData = {'method': 'CreateKeypair', 'name': KEYPAIR_NAME, } self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), KEYPAIR_NAME).AndReturn(newKeyPair) self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:keypairs:create'), formData) self.assertTrue(res.has_header('Content-Disposition'))
def test_create_keypair_post(self): KEYPAIR_NAME = 'newKeypair' PRIVATE_KEY = 'privateKey' newKeyPair = self.mox.CreateMock(api.KeyPair) newKeyPair.name = KEYPAIR_NAME newKeyPair.private_key = PRIVATE_KEY formData = {'method': 'CreateKeypair', 'name': KEYPAIR_NAME, } self.mox.StubOutWithMock(api, 'keypair_create') api.keypair_create(IsA(http.HttpRequest), KEYPAIR_NAME).AndReturn(newKeyPair) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:access_and_security:keypairs:create'), formData) self.assertTrue(res.has_header('Content-Disposition'))
def handle(self, request, data): try: LOG.info('Creating keypair "%s"' % data['name']) keypair = api.keypair_create(request, data['name']) response = http.HttpResponse(mimetype='application/binary') response['Content-Disposition'] = \ 'attachment; filename=%s.pem' % keypair.name response.write(keypair.private_key) return response except novaclient_exceptions.ClientException, e: LOG.exception("ClientException in CreateKeyPair") messages.error(request, _('Error Creating Keypair: %s') % e.message) return shortcuts.redirect(request.build_absolute_uri())
def get(self, request, keypair_name=None): try: keypair = api.keypair_create(request, keypair_name) except: redirect = reverse('horizon:nova:access_and_security:index') exceptions.handle(self.request, _('Unable to create keypair: %(exc)s'), redirect=redirect) response = http.HttpResponse(mimetype='application/binary') response['Content-Disposition'] = \ 'attachment; filename=%s.pem' % slugify(keypair.name) response.write(keypair.private_key) response['Content-Length'] = str(len(response.content)) return response
def get(self, request, keypair_name=None): try: keypair = api.keypair_create(request, keypair_name) except: redirect = reverse('horizon:project:access_and_security:index') exceptions.handle(self.request, _('Unable to create keypair: %(exc)s'), redirect=redirect) response = http.HttpResponse(mimetype='application/binary') response['Content-Disposition'] = \ 'attachment; filename=%s.pem' % slugify(keypair.name) response.write(keypair.private_key) response['Content-Length'] = str(len(response.content)) return response