def test_update_project_get(self): project = self.tenants.first() quota = self.quotas.first() api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True) \ .AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \ .AndReturn(quota) self.mox.ReplayAll() url = reverse('horizon:syspanel:projects:update', args=[self.tenant.id]) res = self.client.get(url) self.assertTemplateUsed(res, 'syspanel/projects/update.html') workflow = res.context['workflow'] self.assertEqual(res.context['workflow'].name, UpdateProject.name) step = workflow.get_step("update_info") self.assertEqual(step.action.initial['ram'], quota.ram) self.assertEqual(step.action.initial['injected_files'], quota.injected_files) self.assertEqual(step.action.initial['name'], project.name) self.assertEqual(step.action.initial['description'], project.description) self.assertQuerysetEqual(workflow.steps, ['<UpdateProjectInfo: update_info>', '<UpdateProjectQuota: update_quotas>'])
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_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_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_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_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_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_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_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_update_project_tenant_update_error(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() # get/init api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True).AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id).AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) workflow_data = {} for user in users: api.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(roles) role_ids = [role.id for role in roles] if role_ids: workflow_data.setdefault("role_" + role_ids[0], []).append(user.id) # update some fields project._info["name"] = "updated name" project._info["description"] = "updated description" quota.metadata_items = 444 quota.volumes = 444 updated_project = { "tenant_name": project._info["name"], "tenant_id": project.id, "description": project._info["description"], "enabled": project.enabled, } updated_quota = self._get_quota_info(quota) # contribute api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # handle api.tenant_update(IsA(http.HttpRequest), **updated_project).AndRaise(self.exceptions.keystone) self.mox.ReplayAll() # submit form data project_data = { "name": project._info["name"], "id": project.id, "description": project._info["description"], "enabled": project.enabled, } workflow_data.update(project_data) workflow_data.update(updated_quota) url = reverse("horizon:admin:projects:update", args=[self.tenant.id]) res = self.client.post(url, workflow_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
def test_update_project_get_error(self): project = self.tenants.first() api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True) \ .AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() url = reverse('horizon:syspanel:projects:update', args=[self.tenant.id]) res = self.client.get(url) self.assertRedirectsNoFollow(res, INDEX_URL)
def test_index_no_images(self): 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(IMAGES_INDEX_URL) self.assertTemplateUsed(res, 'nova/images/index.html')
def test_index_glance_error(self): self.mox.StubOutWithMock(api, 'image_list_detailed') exception = glance_exception.Error('glanceError') api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception) self.mox.StubOutWithMock(api, 'tenant_quota_get') api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT) \ .AndReturn({}) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get(IMAGES_INDEX_URL) self.assertTemplateUsed(res, 'nova/images/index.html')
def test_index_client_conn_error(self): self.mox.StubOutWithMock(api, "image_list_detailed") exception = glance_exception.ClientConnectionError("clientConnError") api.image_list_detailed(IsA(http.HttpRequest)).AndRaise(exception) self.mox.StubOutWithMock(api, "tenant_quota_get") api.tenant_quota_get(IsA(http.HttpRequest), self.TEST_TENANT).AndReturn({}) self.mox.StubOutWithMock(messages, "error") messages.error(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_update_project_quota_update_error(self): project = self.tenants.first() quota = self.quotas.first() # first set of calls for 'get' because the url takes an arg api.tenant_get(IsA(http.HttpRequest), project.id, admin=True) \ .AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), project.id) \ .AndReturn(quota) # update some fields project._info["name"] = "updated name" project._info["description"] = "updated description" quota.metadata_items = '444' quota.volumes = '444' updated_project = {"tenant_name": project._info["name"], "tenant_id": project.id, "description": project._info["description"], "enabled": project.enabled} updated_quota = self._get_quota_info(quota) api.tenant_update(IsA(http.HttpRequest), **updated_project) \ .AndReturn(project) api.tenant_quota_update(IsA(http.HttpRequest), project.id, **updated_quota) \ .AndRaise(self.exceptions.nova) self.mox.ReplayAll() # submit form data workflow_data = {"name": updated_project["tenant_name"], "id": project.id, "description": updated_project["description"], "enabled": project.enabled} workflow_data.update(updated_quota) url = reverse('horizon:syspanel:projects:update', args=[self.tenant.id]) res = self.client.post(url, workflow_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
def get_context_data(self, **kwargs): context = super(LaunchView, self).get_context_data(**kwargs) tenant_id = self.request.user.tenant_id try: quotas = api.tenant_quota_get(self.request, tenant_id) quotas.ram = int(quotas.ram) context['quotas'] = quotas except: exceptions.handle(self.request) return context
def test_update_project_get(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True).AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id).AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) for user in users: api.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(roles) self.mox.ReplayAll() url = reverse("horizon:admin:projects:update", args=[self.tenant.id]) res = self.client.get(url) self.assertTemplateUsed(res, "admin/projects/update.html") workflow = res.context["workflow"] self.assertEqual(res.context["workflow"].name, UpdateProject.name) step = workflow.get_step("update_info") self.assertEqual(step.action.initial["ram"], quota.ram) self.assertEqual(step.action.initial["injected_files"], quota.injected_files) self.assertEqual(step.action.initial["name"], project.name) self.assertEqual(step.action.initial["description"], project.description) self.assertQuerysetEqual( workflow.steps, [ "<UpdateProjectInfo: update_info>", "<UpdateProjectMembers: update_members>", "<UpdateProjectQuota: update_quotas>", ], )
def get_initial(self): initial = super(UpdateProjectView, self).get_initial() project_id = self.kwargs['tenant_id'] initial['project_id'] = project_id try: # get initial project info project_info = api.tenant_get(self.request, project_id, admin=True) for field in PROJECT_INFO_FIELDS: initial[field] = getattr(project_info, field, None) # get initial project quota quota_data = api.tenant_quota_get(self.request, project_id) for field in QUOTA_FIELDS: initial[field] = getattr(quota_data, field, None) except: exceptions.handle(self.request, _('Unable to retrieve project details.'), redirect=reverse(INDEX_URL)) return initial
def test_update_project_post(self): project = self.tenants.first() quota = self.quotas.first() default_role = self.roles.first() users = self.users.list() roles = self.roles.list() current_roles = self.roles.list() # get/init api.tenant_get(IsA(http.HttpRequest), self.tenant.id, admin=True).AndReturn(project) api.tenant_quota_get(IsA(http.HttpRequest), self.tenant.id).AndReturn(quota) api.get_default_role(IsA(http.HttpRequest)).AndReturn(default_role) api.keystone.user_list(IsA(http.HttpRequest)).AndReturn(users) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) workflow_data = {} for user in users: api.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(roles) role_ids = [role.id for role in roles] if role_ids: workflow_data.setdefault("role_" + role_ids[0], []).append(user.id) # update some fields project._info["name"] = "updated name" project._info["description"] = "updated description" quota.metadata_items = 444 quota.volumes = 444 updated_project = { "tenant_name": project._info["name"], "tenant_id": project.id, "description": project._info["description"], "enabled": project.enabled, } updated_quota = self._get_quota_info(quota) # contribute api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) # handle api.tenant_update(IsA(http.HttpRequest), **updated_project).AndReturn(project) api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles) api.keystone.user_list(IsA(http.HttpRequest), tenant_id=self.tenant.id).AndReturn(users) for user in users: api.roles_for_user(IsA(http.HttpRequest), user.id, self.tenant.id).AndReturn(current_roles) for role in roles: if "role_" + role.id in workflow_data: ulist = workflow_data["role_" + role.id] if role not in current_roles: api.add_tenant_user_role( IsA(http.HttpRequest), tenant_id=self.tenant.id, user_id=user, role_id=role.id ) else: current_roles.pop(current_roles.index(role)) for to_delete in current_roles: api.remove_tenant_user_role( IsA(http.HttpRequest), tenant_id=self.tenant.id, user_id=user.id, role_id=to_delete.id ) for role in roles: if "role_" + role.id in workflow_data: ulist = workflow_data["role_" + role.id] for user in ulist: if not filter(lambda x: user == x.id, users): api.add_tenant_user_role( IsA(http.HttpRequest), tenant_id=self.tenant.id, user_id=user, role_id=role.id ) api.tenant_quota_update(IsA(http.HttpRequest), project.id, **updated_quota) self.mox.ReplayAll() # submit form data project_data = { "name": project._info["name"], "id": project.id, "description": project._info["description"], "enabled": project.enabled, } workflow_data.update(project_data) workflow_data.update(updated_quota) url = reverse("horizon:admin:projects:update", args=[self.tenant.id]) res = self.client.post(url, workflow_data) self.assertNoFormErrors(res) self.assertRedirectsNoFollow(res, INDEX_URL)
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')
messages.info(request, _("There are currently no images.")) except glance_exception.ClientConnectionError, e: LOG.exception("Error connecting to glance") messages.error(request, _("Error connecting to glance: %s") % str(e)) except glance_exception.Error, e: LOG.exception("Error retrieving image list") messages.error(request, _("Error retrieving image list: %s") % str(e)) except api_exceptions.ApiException, e: msg = _("Unable to retrieve image info from glance: %s") % str(e) LOG.exception(msg) messages.error(request, msg) images = [im for im in all_images if im['container_format'] not in ['aki', 'ari']] quotas = api.tenant_quota_get(request, request.user.tenant_id) return shortcuts.render(request, 'nova/images/index.html', { 'delete_form': DeleteImage(), 'quotas': quotas, 'images': images}) @login_required def launch(request, image_id): def flavorlist(): try: fl = api.flavor_list(request)
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'))