def test_index_flavor_list_exception(self): servers = self.servers.list() flavors = self.flavors.list() volumes = self.volumes.list() full_flavors = SortedDict([(f.id, f) for f in flavors]) api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \ AndReturn(full_flavors[server.flavor["id"]]) api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:instances_and_volumes:index')) self.assertTemplateUsed(res, 'nova/instances_and_volumes/index.html') instances = res.context['instances_table'].data volumes = res.context['volumes_table'].data self.assertItemsEqual(instances, self.servers.list()) self.assertItemsEqual(volumes, self.volumes.list())
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_instance_details_volumes(self): server = self.servers.first() volumes = deepcopy(self.volumes.list()) volumes[0].device = "/dev/hdk" second_vol = deepcopy(volumes[0]) second_vol.id = 2 second_vol.device = "/dev/hdb" volumes.append(second_vol) api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn(volumes) api.flavor_get(IsA(http.HttpRequest), server.flavor['id']).AndReturn(self.flavors.first()) api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.first()) self.mox.ReplayAll() url = reverse('horizon:nova:instances_and_volumes:instances:detail', args=[server.id]) res = self.client.get(url) self.assertItemsEqual(res.context['instance'].volumes, volumes) # Test device ordering self.assertEquals(res.context['instance'].volumes[0].device, "/dev/hdb") self.assertEquals(res.context['instance'].volumes[1].device, "/dev/hdk")
def test_instance_details_metadata(self): server = self.servers.first() api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn([]) api.flavor_get(IsA(http.HttpRequest), server.flavor['id']).AndReturn(self.flavors.first()) api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.list()) self.mox.ReplayAll() url = reverse('horizon:nova:instances:detail', args=[server.id]) tg = InstanceDetailTabs(self.request, instance=server) qs = "?%s=%s" % (tg.param_name, tg.get_tab("overview").get_id()) res = self.client.get(url + qs) self.assertContains(res, "<dd>keyName</dd>", 1) self.assertContains(res, "<dt>someMetaLabel</dt>", 1) self.assertContains(res, "<dd>someMetaData</dd>", 1) self.assertContains(res, "<dt>some<b>html</b>label</dt>", 1) self.assertContains(res, "<dd><!--</dd>", 1) self.assertContains(res, "<dt>empty</dt>", 1) self.assertContains(res, "<dd><em>N/A</em></dd>", 1)
def test_ajax_loading_instances(self): server = self.servers.first() flavor = self.flavors.list()[0] tenant = self.tenants.list()[0] api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.flavor_get(IsA(http.HttpRequest), server.flavor['id']).AndReturn(flavor) api.keystone.tenant_get(IsA(http.HttpRequest), server.tenant_id, admin=True).AndReturn(tenant) self.mox.ReplayAll() url = reverse('horizon:admin:instances:index') + \ "?action=row_update&table=instances&obj_id=" + server.id res = self.client.get(url, {}, HTTP_X_REQUESTED_WITH='XMLHttpRequest') self.assertTemplateUsed(res, "horizon/common/_data_table_row.html") self.assertContains(res, "test_tenant", 1, 200) self.assertContains(res, "instance-host", 1, 200) self.assertContains(res, "server_1", 1, 200) self.assertContains(res, "10.0.0.1", 1, 200) self.assertContains(res, "512MB RAM | 1 VCPU | 0 Disk", 1, 200) self.assertContains(res, "Active", 1, 200) self.assertContains(res, "Running", 1, 200)
def test_index_flavor_get_exception(self): servers = self.servers.list() flavors = self.flavors.list() volumes = self.volumes.list() max_id = max([int(flavor.id) for flavor in flavors]) for server in servers: max_id += 1 server.flavor["id"] = max_id api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \ AndRaise(self.exceptions.nova) api.volume_list(IsA(http.HttpRequest)).AndReturn(volumes) self.mox.ReplayAll() res = self.client.get( reverse('horizon:nova:instances_and_volumes:index')) instances = res.context['instances_table'].data volumes = res.context['volumes_table'].data self.assertTemplateUsed(res, 'nova/instances_and_volumes/index.html') self.assertMessageCount(res, error=len(servers)) self.assertItemsEqual(instances, self.servers.list()) self.assertItemsEqual(volumes, self.volumes.list())
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_instance_details_volumes(self): server = self.servers.first() volumes = [self.volumes.list()[1]] api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn(volumes) api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]).AndReturn(self.flavors.first()) api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.first()) self.mox.ReplayAll() url = reverse("horizon:project:instances:detail", args=[server.id]) res = self.client.get(url) self.assertItemsEqual(res.context["instance"].volumes, volumes)
def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] try: image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], image, flavor, data.get('key_name'), normalize_newlines(data.get('user_data')), data.get('security_groups')) msg = _('Instance was successfully launched') LOG.info(msg) messages.success(request, msg) return redirect( 'horizon:nova:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception('ApiException while creating instances of image "%s"' % image_id) messages.error(request, _('Unable to launch instance: %s') % e.message)
def get_data(self): # Gather our instances try: instances = api.server_list(self.request) except: instances = [] exceptions.handle(self.request, _('Unable to retrieve instances.')) # Gather our flavors and correlate our instances to them if instances: try: flavors = api.flavor_list(self.request) except: flavors = [] exceptions.handle(self.request, ignore=True) full_flavors = SortedDict([(str(flavor.id), flavor) for flavor in flavors]) # Loop through instances to get flavor info. for instance in instances: try: flavor_id = instance.flavor["id"] if flavor_id in full_flavors: instance.full_flavor = full_flavors[flavor_id] else: # If the flavor_id is not in full_flavors list, # get it via nova api. instance.full_flavor = api.flavor_get(self.request, flavor_id) except: msg = _('Unable to retrieve instance size information.') exceptions.handle(self.request, msg) return instances
def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] # flavor = "m1.tiny" #KDS: hack to give some valid user_data user_data=data['tenant_id'] meta_data = {'input_array' : 'default_input', 'output_array' : 'default_output'} # print("KDS4 xcp forms.py: dataget-metadata=%s\n" %(data.get('meta_data'))) try: image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], image, flavor, data.get('key_name'), user_data, meta_data, # data.get('meta_data'), data.get('security_groups')) #KDS: pass meta_data as 'meta' instead of 'user_data' print("KDS2 xcp forms.py: meta-data=%s dataget-metadata=%s\n" %(meta_data, data.get('meta_data'))) msg = _('Instance was successfully launched') LOG.info(msg) messages.success(request, msg) return redirect( 'horizon:nova:instances_and_volumes:instances:index') except api_exceptions.ApiException, e: LOG.exception('ApiException while creating instances of image "%s"' % image_id) messages.error(request, _('Unable to launch instance: %s') % e.message) print("KDS3 xcp forms.py: meta-data=%s dataget-metadata=%s\n" %(meta_data, data.get('meta_data')))
def get_context_data(self, request): image_id = self.tab_group.kwargs['image_id'] try: image = api.quantum.image_get(self.request, image_id) image.category = api.quantum.category_get(self.request, image.category_id) image.vendor = api.quantum.vendor_get(self.request, image.vendor_id) image.full_flavor = api.flavor_get(self.request, image.flavor_id) image.security_group = api.security_group_get( self.request, image.security_group_id) image.glance_image = api.glance.image_get(self.request, image.image_id) metadata = api.quantum.metadata_list_for_image(self.request, image_id) image.metadata = api.quantum.metadata_get(self.request, metadata[0].id) personality = api.quantum.personality_list_for_image(self.request, image_id) image.personality = api.quantum.personality_get(self.request, personality[0].id) except: redirect = reverse('horizon:nova:images:index') msg = _('Unable to retrieve image map details.') exceptions.handle(request, msg, redirect=redirect) return {'image': image}
def test_index_flavor_list_exception(self): servers = self.servers.list() flavors = self.flavors.list() full_flavors = SortedDict([(f.id, f) for f in flavors]) api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]).AndReturn(full_flavors[server.flavor["id"]]) self.mox.ReplayAll() res = self.client.get(reverse("horizon:project:instances:index")) self.assertTemplateUsed(res, "project/instances/index.html") instances = res.context["instances_table"].data self.assertItemsEqual(instances, self.servers.list())
def handle(self, request, data): try: flavor_id = data["flavorid"] flavor = api.flavor_get(request, flavor_id) LOG.info('Deleting flavor with id "%s"' % flavor_id) api.flavor_delete(request, flavor_id, False) messages.info(request, _("Successfully deleted flavor: %s") % flavor.name) except api_exceptions.ApiException, e: messages.error(request, _("Unable to delete flavor: %s") % e.message)
def test_instance_details_volumes(self): server = self.servers.first() volumes = [self.volumes.list()[1]] api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn(volumes) api.flavor_get(IsA(http.HttpRequest), server.flavor['id']).AndReturn(self.flavors.first()) api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.first()) self.mox.ReplayAll() url = reverse('horizon:nova:instances:detail', args=[server.id]) res = self.client.get(url) self.assertItemsEqual(res.context['instance'].volumes, volumes)
def test_index_flavor_list_exception(self): servers = self.servers.list() flavors = self.flavors.list() full_flavors = SortedDict([(f.id, f) for f in flavors]) api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \ AndReturn(full_flavors[server.flavor["id"]]) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:instances:index')) self.assertTemplateUsed(res, 'nova/instances/index.html') instances = res.context['instances_table'].data self.assertItemsEqual(instances, self.servers.list())
def handle(self, request, data): try: flavor_id = data['flavorid'] flavor = api.flavor_get(request, flavor_id) LOG.info('Deleting flavor with id "%s"' % flavor_id) api.flavor_delete(request, flavor_id, False) messages.info(request, _('Successfully deleted flavor: %s') % flavor.name) except api_exceptions.ApiException, e: messages.error(request, _('Unable to delete flavor: %s') % e.message)
def test_index_flavor_get_exception(self): servers = self.servers.list() flavors = self.flavors.list() max_id = max([int(flavor.id) for flavor in flavors]) for server in servers: max_id += 1 server.flavor["id"] = max_id api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]).AndRaise(self.exceptions.nova) self.mox.ReplayAll() res = self.client.get(reverse("horizon:project:instances:index")) instances = res.context["instances_table"].data self.assertTemplateUsed(res, "project/instances/index.html") self.assertMessageCount(res, error=len(servers)) self.assertItemsEqual(instances, self.servers.list())
def test_index_flavor_get_exception(self): servers = self.servers.list() flavors = self.flavors.list() max_id = max([int(flavor.id) for flavor in flavors]) for server in servers: max_id += 1 server.flavor["id"] = max_id api.server_list(IsA(http.HttpRequest)).AndReturn(servers) api.flavor_list(IsA(http.HttpRequest)).AndReturn(flavors) for server in servers: api.flavor_get(IsA(http.HttpRequest), server.flavor["id"]). \ AndRaise(self.exceptions.nova) self.mox.ReplayAll() res = self.client.get(reverse('horizon:nova:instances:index')) instances = res.context['instances_table'].data self.assertTemplateUsed(res, 'nova/instances/index.html') self.assertMessageCount(res, error=len(servers)) self.assertItemsEqual(instances, self.servers.list())
def test_instance_details_volume_sorting(self): server = self.servers.first() volumes = self.volumes.list()[1:3] api.server_get(IsA(http.HttpRequest), server.id).AndReturn(server) api.volume_instance_list(IsA(http.HttpRequest), server.id).AndReturn(volumes) api.flavor_get(IsA(http.HttpRequest), server.flavor['id']).AndReturn(self.flavors.first()) api.server_security_groups(IsA(http.HttpRequest), server.id).AndReturn(self.security_groups.first()) self.mox.ReplayAll() url = reverse('horizon:nova:instances:detail', args=[server.id]) res = self.client.get(url) self.assertItemsEqual(res.context['instance'].volumes, volumes) self.assertEquals(res.context['instance'].volumes[0].device, "/dev/hda") self.assertEquals(res.context['instance'].volumes[1].device, "/dev/hdk")
def get_data(self): if not hasattr(self, "_instance"): try: instance_id = self.kwargs['instance_id'] instance = api.server_get(self.request, instance_id) instance.volumes = api.volume_instance_list(self.request, instance_id) instance.full_flavor = api.flavor_get(self.request, instance.flavor["id"]) instance.security_groups = api.server_security_groups( self.request, instance_id) except: redirect = reverse('horizon:nova:instances_and_volumes:index') exceptions.handle(self.request, _('Unable to retrieve details for ' 'instance "%s".') % instance_id, redirect=redirect) self._instance = instance return self._instance
def handle(self, request, data): image_id = data['image_id'] tenant_id = data['tenant_id'] try: image = api.image_get_meta(request, image_id) flavor = api.flavor_get(request, data['flavor']) api.server_create(request, data['name'], image, flavor, data.get('key_name'), normalize_newlines(data.get('user_data')), data.get('security_groups')) msg = _('Instance was successfully launched') LOG.info(msg) messages.success(request, msg) return redirect('horizon:nova:instances:index') except api_exceptions.ApiException, e: LOG.exception( 'ApiException while creating instances of image "%s"' % image_id) messages.error(request, _('Unable to launch instance: %s') % e.message)
def get_instances_data(self): if not hasattr(self, "_instances"): # Gather our instances try: instances = self._get_instances() except: instances = [] exceptions.handle(self.request, _('Unable to retrieve instances.')) # Gather our flavors and correlate our instances to them if instances: try: flavors = api.flavor_list(self.request) except: # If fails to retrieve flavor list, creates an empty list. flavors = [] full_flavors = SortedDict([(str(flavor.id), flavor) for flavor in flavors]) # Loop through instances to get flavor info. for instance in instances: try: flavor_id = instance.flavor["id"] if flavor_id in full_flavors: instance.full_flavor = full_flavors[flavor_id] else: # If the flavor_id is not in full_flavors list, # gets it via nova api. instance.full_flavor = api.flavor_get( self.request, flavor_id) except: msg = _('Unable to retrieve instance \ size information.') exceptions.handle(self.request, msg) self._instances = instances return self._instances
def get_data(self): if not hasattr(self, "_instance"): try: instance_id = self.kwargs['instance_id'] instance = api.server_get(self.request, instance_id) with open('/tmp/srik2.out', 'w+') as f: f.write(str(instance.id)) f.close() instance.volumes = api.volume_instance_list(self.request, instance_id) # Sort by device name instance.volumes.sort(key=lambda vol: vol.device) instance.full_flavor = api.flavor_get(self.request, instance.flavor["id"]) instance.security_groups = api.server_security_groups( self.request, instance_id) except: redirect = reverse('horizon:nova:instances:index') exceptions.handle(self.request, _('Unable to retrieve details for ' 'instance "%s".') % instance_id, redirect=redirect) self._instance = instance return self._instance
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_and_snapshots:images:launch', args=[IMAGE_ID]) res = self.client.post(url, form_data) self.assertTemplateUsed(res, 'nova/images_and_snapshots/images/launch.html')
def get_data(self, request, instance_id): instance = api.server_get(request, instance_id) instance.full_flavor = api.flavor_get(request, instance.flavor["id"]) return instance
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_and_snapshots:images:launch', args=[IMAGE_ID]), form_data) self.assertRedirectsNoFollow(res, reverse('horizon:nova:instances_and_volumes:instances:index'))