def test_launch_get(self): IMAGE_ID = 1 self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_get') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), str(IMAGE_ID)) \ .AndReturn(self.visibleImage) api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:images_and_snapshots:images:launch', args=[IMAGE_ID])) form = res.context['form'] self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html') self.assertEqual(res.context['image'].name, self.visibleImage.name) self.assertIn('m1.massive', form.fields['flavor'].choices[0][1]) self.assertEqual(form.fields['keypair'].choices[0][0], self.keypairs[0].name)
def test_launch_flavorlist_error(self): image = self.images.first() self.mox.StubOutWithMock(api, 'image_get') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') self.mox.StubOutWithMock(api, 'volume_list') api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) api.volume_snapshot_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn( self.quota_usages.first()) api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova) api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) self.mox.ReplayAll() url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.get(url) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html')
def test_launch_keypairlist_error(self): IMAGE_ID = '2' self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:images:launch', args=[IMAGE_ID])) self.assertTemplateUsed(res, 'nova/images/launch.html') form = res.context['form'] form_keyfield = form.fields['key_name'] self.assertEqual(len(form_keyfield.choices), 0)
def test_launch_keypairlist_error(self): image = self.images.first() self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn( self.quota_usages.first()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) exception = keystone_exceptions.ClientException('Failed.') api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) self.mox.ReplayAll() url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.get(url) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html') self.assertEqual(len(res.context['form'].fields['keypair'].choices), 1)
def test_launch_post(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' KEY_NAME = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'key_name': KEY_NAME, 'name': SERVER_NAME, 'user_data': USER_DATA, 'tenant_id': self.TEST_TENANT, 'security_groups': 'default', } self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) # called again by the form api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') api.flavor_get(IsA(http.HttpRequest), IsA(unicode)).AndReturn(self.flavors[0]) self.mox.StubOutWithMock(api, 'server_create') api.server_create(IsA(http.HttpRequest), SERVER_NAME, self.visibleImage, self.flavors[0], KEY_NAME, USER_DATA, [self.security_groups[0].name]) self.mox.StubOutWithMock(messages, 'success') messages.success(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.post(reverse('horizon:nova:images:launch', args=[IMAGE_ID]), form_data) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances:index'))
def test_index(self): self.mox.StubOutWithMock(api, "image_list_detailed") api.image_list_detailed(IsA(http.HttpRequest)).AndReturn(self.images) self.mox.StubOutWithMock(api, "snapshot_list_detailed") api.snapshot_list_detailed(IsA(http.HttpRequest)).AndReturn(self.snapshots) self.mox.StubOutWithMock(api, "flavor_list") api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, "security_group_list") api.security_group_list(IsA(http.HttpRequest)).AndReturn(self.security_groups) api.security_group_list(IsA(http.HttpRequest)).AndReturn(self.security_groups) self.mox.StubOutWithMock(api, "keypair_list") api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, "tenant_quota_get") api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn({}) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, "nova/images_and_snapshots/index.html") self.assertIn("images", res.context) images = res.context["images"] self.assertEqual(len(images), 1) self.assertEqual(images[0].name, "visibleImage")
def test_index(self): self.mox.StubOutWithMock(api, 'image_list_detailed') api.image_list_detailed(IsA(http.HttpRequest)).AndReturn(self.images) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \ .AndReturn({}) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) self.mox.ReplayAll() res = self.client.get(IMAGES_INDEX_URL) self.assertTemplateUsed(res, 'nova/images/index.html') self.assertIn('images', res.context) images = res.context['images'] self.assertEqual(len(images), 1) self.assertEqual(images[0].name, 'visibleImage')
def test_index_no_images(self): self.mox.StubOutWithMock(api, 'snapshot_list_detailed') api.snapshot_list_detailed(IsA(http.HttpRequest)).\ AndReturn(self.snapshots) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'image_list_detailed') api.image_list_detailed(IsA(http.HttpRequest)).AndReturn([]) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \ .AndReturn({}) self.mox.StubOutWithMock(messages, 'info') messages.info(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get(INDEX_URL) self.assertTemplateUsed(res, 'nova/images_and_snapshots/index.html')
def test_disassociate_post_with_exception(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'server_remove_floating_ip') exception = novaclient_exceptions.ClientException('ClientException', message='clientException') api.server_remove_floating_ip(IsA(http.HttpRequest), IsA(int), IsA(int)).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.StubOutWithMock(api, 'tenant_floating_ip_get') api.tenant_floating_ip_get = self.mox.CreateMockAnything() api.tenant_floating_ip_get(IsA(http.HttpRequest), IsA(unicode)).\ AndReturn(self.floating_ip) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:access_and_security:floating_ips:disassociate', args=[1]), {'floating_ip_id': self.floating_ip.id, 'method': 'FloatingIpDisassociate'}) self.assertRaises(novaclient_exceptions.ClientException) self.assertRedirects(res, FLOATING_IPS_INDEX)
def test_launch_get(self): image = self.images.first() quota_usages = self.quota_usages.first() self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn(quota_usages) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) self.mox.ReplayAll() url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.get(url) form = res.context['form'] self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html') self.assertEqual(res.context['image'].name, image.name) self.assertIn(self.flavors.first().name, form.fields['flavor'].choices[0][1]) self.assertEqual(self.keypairs.first().name, form.fields['keypair'].choices[1][0])
def test_launch_flavorlist_error(self): IMAGE_ID = '1' self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_get') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) exception = keystone_exceptions.ClientException('Failed.') api.flavor_list(IsA(http.HttpRequest)).AndRaise(exception) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:images_and_snapshots:images:launch', args=[IMAGE_ID])) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html')
def test_launch_form_apiexception(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' KEY_NAME = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'key_name': KEY_NAME, 'name': SERVER_NAME, 'tenant_id': self.TEST_TENANT, 'user_data': USER_DATA, 'security_groups': 'default', } self.mox.StubOutWithMock(api, 'image_get_meta') api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn(FakeQuota) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IgnoreArg()).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IgnoreArg()).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) # called again by the form api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) self.mox.StubOutWithMock(api, 'flavor_get') api.flavor_get(IgnoreArg(), IsA(unicode)).AndReturn(self.flavors[0]) self.mox.StubOutWithMock(api, 'server_create') exception = api_exceptions.ApiException('apiException') api.server_create(IsA(http.HttpRequest), SERVER_NAME, self.visibleImage, self.flavors[0], KEY_NAME, USER_DATA, self.security_groups).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() url = reverse('horizon:nova:images:launch', args=[IMAGE_ID]) res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'nova/images/launch.html')
def test_launch_post(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() volume = self.volumes.first() sec_group = self.security_groups.first() USER_DATA = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id block_device_mapping = {device_name: u"%s::0" % volume_choice} self.mox.StubOutWithMock(api, 'image_get') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') api.volume_snapshot_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get(IsA(http.HttpRequest), image.id).AndReturn(image) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) api.server_create(IsA(http.HttpRequest), server.name, image.id, flavor.id, keypair.name, USER_DATA, [sec_group.name], block_device_mapping, instance_count=IsA(int)) self.mox.ReplayAll() form_data = {'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'user_data': USER_DATA, 'tenant_id': self.tenants.first().id, 'security_groups': sec_group.name, 'volume': volume_choice, 'device_name': device_name, 'count': 1} url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances_and_volumes:index'))
def test_index(self): self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:keypairs:index')) self.assertTemplateUsed(res, 'nova/keypairs/index.html') self.assertItemsEqual(res.context['keypairs'], self.keypairs)
def test_launch_post(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() volume = self.volumes.first() sec_group = self.security_groups.first() USER_DATA = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id block_device_mapping = {device_name: u"%s::0" % volume_choice} self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) api.server_create(IsA(http.HttpRequest), server.name, image.id, flavor.id, keypair.name, USER_DATA, [sec_group.name], block_device_mapping, instance_count=IsA(int)) self.mox.ReplayAll() form_data = { 'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'user_data': USER_DATA, 'tenant_id': self.tenants.first().id, 'security_groups': sec_group.name, 'volume': volume_choice, 'device_name': device_name, 'count': 1 } url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow( res, reverse('horizon:nova:instances_and_volumes:index'))
def test_launch_form_keystone_exception(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' keypair = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'keypair': keypair, 'name': SERVER_NAME, 'tenant_id': self.TEST_TENANT, 'user_data': USER_DATA, 'count': int(1), 'security_groups': 'default'} api.flavor_list(IgnoreArg()).AndReturn(self.flavors) api.keypair_list(IgnoreArg()).AndReturn(self.keypairs) api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) api.image_get_meta(IgnoreArg(), IMAGE_ID).AndReturn(self.visibleImage) api.volume_list(IgnoreArg()).AndReturn(self.volumes) exception = keystone_exceptions.ClientException('Failed') api.server_create(IsA(http.HttpRequest), SERVER_NAME, IMAGE_ID, str(FLAVOR_ID), keypair, USER_DATA, [group.name for group in self.security_groups], None, instance_count=IsA(int)).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[IMAGE_ID]) res = self.client.post(url, form_data) self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
def test_launch_post(self): FLAVOR_ID = self.flavors[0].id IMAGE_ID = '1' keypair = self.keypairs[0].name SERVER_NAME = 'serverName' USER_DATA = 'userData' volume = self.volumes[0].id device_name = 'vda' BLOCK_DEVICE_MAPPING = {device_name: "1:::0"} form_data = {'method': 'LaunchForm', 'flavor': FLAVOR_ID, 'image_id': IMAGE_ID, 'keypair': keypair, 'name': SERVER_NAME, 'user_data': USER_DATA, 'count': 1, 'tenant_id': self.TEST_TENANT, 'security_groups': 'default', 'volume': volume, 'device_name': device_name } self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) api.image_get_meta(IsA(http.HttpRequest), IMAGE_ID).AndReturn(self.visibleImage) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes) api.server_create(IsA(http.HttpRequest), SERVER_NAME, str(IMAGE_ID), str(FLAVOR_ID), keypair, USER_DATA, [self.security_groups[0].name], BLOCK_DEVICE_MAPPING, instance_count=IsA(int)) self.mox.ReplayAll() res = self.client.post( reverse('horizon:nova:images_and_snapshots:images:launch', args=[IMAGE_ID]), form_data) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances_and_volumes:index'))
def test_launch_form_keystone_exception(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() sec_group = self.security_groups.first() USER_DATA = 'userData' self.mox.StubOutWithMock(api, 'image_get') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') api.volume_snapshot_list(IsA(http.HttpRequest)) \ .AndReturn(self.volumes.list()) api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list()) api.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get(IgnoreArg(), image.id).AndReturn(image) api.volume_list(IgnoreArg()).AndReturn(self.volumes.list()) api.server_create(IsA(http.HttpRequest), server.name, image.id, flavor.id, keypair.name, USER_DATA, [sec_group.name], None, instance_count=IsA(int)) \ .AndRaise(self.exceptions.keystone) self.mox.ReplayAll() form_data = {'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'tenant_id': self.tenant.id, 'user_data': USER_DATA, 'count': 1, 'security_groups': sec_group.name} url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
def test_index_exception(self): exception = novaclient_exceptions.ClientException('clientException', message='clientException') self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:keypairs:index')) self.assertTemplateUsed(res, 'nova/keypairs/index.html') self.assertEqual(len(res.context['keypairs']), 0)
def test_launch_form_keystone_exception(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() sec_group = self.security_groups.first() USER_DATA = 'userData' self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'server_create') self.mox.StubOutWithMock(api, 'volume_list') api.flavor_list(IgnoreArg()).AndReturn(self.flavors.list()) api.keypair_list(IgnoreArg()).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get_meta(IgnoreArg(), image.id).AndReturn(image) api.volume_list(IgnoreArg()).AndReturn(self.volumes.list()) exc = keystone_exceptions.ClientException('Failed') api.server_create(IsA(http.HttpRequest), server.name, image.id, flavor.id, keypair.name, USER_DATA, [sec_group.name], None, instance_count=IsA(int)).AndRaise(exc) self.mox.ReplayAll() form_data = { 'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'tenant_id': self.tenant.id, 'user_data': USER_DATA, 'count': 1, 'security_groups': sec_group.name } url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertRedirectsNoFollow(res, IMAGES_INDEX_URL)
def test_launch_form_instance_count_error(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() volume = self.volumes.first() sec_group = self.security_groups.first() USER_DATA = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'volume_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') self.mox.StubOutWithMock(api, 'tenant_quota_usages') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([]) api.tenant_quota_usages(IsA(http.HttpRequest)) \ .AndReturn(self.quota_usages.first()) self.mox.ReplayAll() form_data = { 'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'user_data': USER_DATA, 'tenant_id': self.tenants.first().id, 'security_groups': sec_group.name, 'volume': volume_choice, 'device_name': device_name, 'count': 0 } url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertFormErrors(res, count=1)
def test_launch_form_instance_count_error(self): flavor = self.flavors.first() image = self.images.first() keypair = self.keypairs.first() server = self.servers.first() volume = self.volumes.first() sec_group = self.security_groups.first() USER_DATA = 'user data' device_name = u'vda' volume_choice = "%s:vol" % volume.id self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') self.mox.StubOutWithMock(api, 'volume_list') self.mox.StubOutWithMock(api, 'volume_snapshot_list') self.mox.StubOutWithMock(api, 'tenant_quota_usages') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors.list()) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes.list()) api.volume_snapshot_list(IsA(http.HttpRequest)).AndReturn([]) api.tenant_quota_usages(IsA(http.HttpRequest)) \ .AndReturn(self.quota_usages.first()) self.mox.ReplayAll() form_data = {'method': 'LaunchForm', 'flavor': flavor.id, 'image_id': image.id, 'keypair': keypair.name, 'name': server.name, 'user_data': USER_DATA, 'tenant_id': self.tenants.first().id, 'security_groups': sec_group.name, 'volume': volume_choice, 'device_name': device_name, 'count': 0} url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.post(url, form_data) self.assertFormErrors(res, count=1)
def keynamelist(): try: fl = api.keypair_list(request) sel = [(f.name, f.name) for f in fl] return sel except api_exceptions.ApiException: LOG.exception('Unable to retrieve list of keypairs') return []
def keypair_list(self): try: keypairs = api.keypair_list(self.request) keypair_list = [(kp.name, kp.name) for kp in keypairs] except: keypair_list = [] exceptions.handle(self.request, _('Unable to retrieve keypairs.')) return keypair_list
def test_index(self): self.mox.StubOutWithMock(api, 'tenant_floating_ip_list') api.tenant_floating_ip_list(IsA(http.HttpRequest)).\ AndReturn(self.floating_ips) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).\ AndReturn(self.security_groups) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:access_and_security:index')) self.assertTemplateUsed(res, 'nova/access_and_security/index.html') self.assertItemsEqual(res.context['keypairs'], self.keypairs) self.assertItemsEqual(res.context['security_groups'], self.security_groups) self.assertItemsEqual(res.context['floating_ips'], self.floating_ips)
def index(request): delete_form, handled = DeleteKeypair.maybe_handle(request) if handled: return handled try: keypairs = api.keypair_list(request) except novaclient_exceptions.ClientException, e: keypairs = [] LOG.exception("ClientException in keypair index") messages.error(request, _('Error fetching keypairs: %s') % e.message)
def test_launch_flavorlist_error(self): image = self.images.first() self.mox.StubOutWithMock(api, 'image_get_meta') self.mox.StubOutWithMock(api, 'tenant_quota_usages') self.mox.StubOutWithMock(api, 'flavor_list') self.mox.StubOutWithMock(api, 'keypair_list') self.mox.StubOutWithMock(api, 'security_group_list') api.image_get_meta(IsA(http.HttpRequest), image.id).AndReturn(image) api.tenant_quota_usages(IsA(http.HttpRequest)).AndReturn( self.quota_usages.first()) exc = keystone_exceptions.ClientException('Failed.') api.flavor_list(IsA(http.HttpRequest)).AndRaise(exc) api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs.list()) api.security_group_list(IsA(http.HttpRequest)) \ .AndReturn(self.security_groups.list()) self.mox.ReplayAll() url = reverse('horizon:nova:images_and_snapshots:images:launch', args=[image.id]) res = self.client.get(url) self.assertTemplateUsed( res, 'nova/images_and_snapshots/images/launch.html')
def test_index(self): self.mox.StubOutWithMock(api, 'snapshot_list_detailed') api.snapshot_list_detailed(IsA(http.HttpRequest)).\ AndReturn(self.images) self.mox.StubOutWithMock(api, 'flavor_list') api.flavor_list(IsA(http.HttpRequest)).AndReturn(self.flavors) self.mox.StubOutWithMock(api, 'keypair_list') api.keypair_list(IsA(http.HttpRequest)).AndReturn(self.keypairs) self.mox.StubOutWithMock(api, 'security_group_list') api.security_group_list(IsA(http.HttpRequest)).AndReturn( self.security_groups) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:snapshots:index')) self.assertTemplateUsed(res, 'nova/snapshots/index.html') self.assertIn('images', res.context) images = res.context['images'] self.assertEqual(len(images), 1)
try: security_groups = api.security_group_list(request) except novaclient_exceptions.ClientException, e: security_groups = [] LOG.exception("ClientException in security_groups index") messages.error(request, _('Error fetching security_groups: %s') % e.message) try: floating_ips = api.tenant_floating_ip_list(request) except novaclient_exceptions.ClientException, e: floating_ips = [] LOG.exception("ClientException in floating ip index") messages.error(request, _('Error fetching floating ips: %s') % e.message) try: keypairs = api.keypair_list(request) except novaclient_exceptions.ClientException, e: keypairs = [] LOG.exception("ClientException in keypair index") messages.error(request, _('Error fetching keypairs: %s') % e.message) context = {'keypairs': keypairs, 'floating_ips': floating_ips, 'security_groups': security_groups, 'keypair_delete_form': DeleteKeypair(), 'disassociate_form': FloatingIpDisassociate(), 'release_form': ReleaseFloatingIp(), 'allocate_form': FloatingIpAllocate(initial={ 'tenant_id': request.user.tenant_id}), 'sec_group_create_form': CreateGroup( initial={'tenant_id': tenant_id}),