Ejemplo n.º 1
0
    def test_membership_list_loads_correctly(self):
        member_css_class = ".available_members"
        users = self.users.list()

        api.base.is_service_enabled(IsA(http.HttpRequest), 'network') \
            .MultipleTimes().AndReturn(False)
        api.cinder.is_volume_service_enabled(IsA(http.HttpRequest)) \
            .MultipleTimes().AndReturn(False)
        api.keystone.get_default_domain(IsA(http.HttpRequest)) \
            .AndReturn(self.domain)
        quotas.get_default_quota_data(IsA(http.HttpRequest)) \
              .AndReturn(self.quotas.first())

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .MultipleTimes().AndReturn(self.roles.first())
        api.keystone.user_list(IsA(http.HttpRequest), domain=self.domain.id) \
            .AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)) \
            .AndReturn(self.roles.list())
        api.keystone.group_list(IsA(http.HttpRequest), domain=self.domain.id) \
            .AndReturn(self.groups.list())
        api.keystone.role_list(IsA(http.HttpRequest)) \
            .AndReturn(self.roles.list())

        self.mox.ReplayAll()

        self.selenium.get("%s%s" %
                          (self.live_server_url,
                           reverse('horizon:identity:projects:create')))

        members = self.selenium.find_element_by_css_selector(member_css_class)

        for user in users:
            self.assertIn(user.name, members.text)
Ejemplo n.º 2
0
    def test_add_project_missing_field_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.keystone.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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        self.mox.ReplayAll()

        workflow_data = self._get_workflow_data(project, quota)
        workflow_data["name"] = ""

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertContains(res, "field is required")
Ejemplo n.º 3
0
    def test_add_project_tenant_create_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
            .AndRaise(self.exceptions.keystone)

        self.mox.ReplayAll()

        workflow_data = self._get_workflow_data(project, quota)

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 4
0
    def test_add_project_missing_field_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        self.mox.ReplayAll()

        workflow_data = self._get_workflow_data(project, quota)
        workflow_data["name"] = ""

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertContains(res, "field is required")
Ejemplo n.º 5
0
    def test_update_default_quotas(self):
        quota = self.quotas.first()

        # init
        quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
            .AndReturn(self.disabled_quotas.first())
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        # update some fields
        quota[0].limit = 123
        quota[1].limit = -1
        updated_quota = self._get_quota_info(quota)

        # handle
        nova_fields = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS
        nova_updated_quota = dict([(key, updated_quota[key]) for key in
                                   nova_fields if key != 'fixed_ips'])
        api.nova.default_quota_update(IsA(http.HttpRequest),
                                      **nova_updated_quota)

        cinder_updated_quota = dict([(key, updated_quota[key]) for key in
                                    quotas.CINDER_QUOTA_FIELDS])
        api.cinder.default_quota_update(IsA(http.HttpRequest),
                                        **cinder_updated_quota)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:defaults:update_defaults')
        res = self.client.post(url, updated_quota)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 6
0
    def test_update_default_quotas(self):
        quota = self.quotas.first()

        # init
        quotas.get_disabled_quotas(IsA(http.HttpRequest)) \
            .AndReturn(self.disabled_quotas.first())
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        # update some fields
        quota[0].limit = 123
        quota[1].limit = -1
        updated_quota = self._get_quota_info(quota)

        # handle
        nova_fields = quotas.NOVA_QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS
        nova_updated_quota = dict([(key, updated_quota[key])
                                   for key in nova_fields
                                   if key != 'fixed_ips'])
        api.nova.default_quota_update(IsA(http.HttpRequest),
                                      **nova_updated_quota)

        cinder_updated_quota = dict([(key, updated_quota[key])
                                     for key in quotas.CINDER_QUOTA_FIELDS])
        api.cinder.default_quota_update(IsA(http.HttpRequest),
                                        **cinder_updated_quota)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:defaults:update_defaults')
        res = self.client.post(url, updated_quota)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 7
0
    def test_add_project_get(self):
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        # init
        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)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:create')
        res = self.client.get(url)

        self.assertTemplateUsed(res, 'admin/projects/create.html')

        workflow = res.context['workflow']
        self.assertEqual(res.context['workflow'].name, CreateProject.name)

        step = workflow.get_step("createprojectinfoaction")
        self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
        self.assertEqual(step.action.initial['injected_files'],
                         quota.get('injected_files').limit)
        self.assertQuerysetEqual(workflow.steps,
                            ['<CreateProjectInfo: createprojectinfoaction>',
                             '<UpdateProjectMembers: update_members>',
                             '<UpdateProjectQuota: update_quotas>'])
Ejemplo n.º 8
0
    def test_add_project_tenant_create_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.keystone.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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
            .AndRaise(self.exceptions.keystone)

        self.mox.ReplayAll()

        workflow_data = self._get_workflow_data(project, quota)

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 9
0
    def test_add_project_get(self):
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        # init
        api.keystone.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)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:create')
        res = self.client.get(url)

        self.assertTemplateUsed(res, 'admin/projects/create.html')

        workflow = res.context['workflow']
        self.assertEqual(res.context['workflow'].name, CreateProject.name)

        step = workflow.get_step("createprojectinfoaction")
        self.assertEqual(step.action.initial['ram'], quota.get('ram').limit)
        self.assertEqual(step.action.initial['injected_files'],
                         quota.get('injected_files').limit)
        self.assertQuerysetEqual(workflow.steps,
                            ['<CreateProjectInfo: createprojectinfoaction>',
                             '<UpdateProjectMembers: update_members>',
                             '<UpdateProjectQuota: update_quotas>'])
Ejemplo n.º 10
0
    def test_add_project_user_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.keystone.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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)
        quota_data = self._get_quota_info(quota)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
                    .AndReturn(project)

        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for role in roles:
            if "role_" + role.id in workflow_data:
                ulist = workflow_data["role_" + role.id]
                for user_id in ulist:
                    api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
                                                      project=self.tenant.id,
                                                      user=user_id,
                                                      role=role.id) \
                       .AndRaise(self.exceptions.keystone)
                    break
            break

        nova_updated_quota = dict([(key, quota_data[key])
                                   for key in quotas.NOVA_QUOTA_FIELDS])
        api.nova.tenant_quota_update(IsA(http.HttpRequest), project.id,
                                     **nova_updated_quota)

        cinder_updated_quota = dict([(key, quota_data[key])
                                     for key in quotas.CINDER_QUOTA_FIELDS])
        api.cinder.tenant_quota_update(IsA(http.HttpRequest), project.id,
                                       **cinder_updated_quota)

        self.mox.ReplayAll()

        workflow_data.update(self._get_workflow_data(project, quota))

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 11
0
    def test_add_project_user_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        domain_id = self._get_domain_id()
        users = self._get_all_users(domain_id)
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
            .AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)) \
            .MultipleTimes().AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)
        quota_data = self._get_quota_info(quota)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
            .AndReturn(project)

        workflow_data = {}
        for role in roles:
            if USER_ROLE_PREFIX + role.id in workflow_data:
                ulist = workflow_data[USER_ROLE_PREFIX + role.id]
                for user_id in ulist:
                    api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
                                                      project=self.tenant.id,
                                                      user=user_id,
                                                      role=role.id) \
                       .AndRaise(self.exceptions.keystone)
                    break
            break

        nova_updated_quota = dict([(key, quota_data[key]) for key in
                                   quotas.NOVA_QUOTA_FIELDS])
        api.nova.tenant_quota_update(IsA(http.HttpRequest),
                                     project.id,
                                     **nova_updated_quota)

        cinder_updated_quota = dict([(key, quota_data[key]) for key in
                                    quotas.CINDER_QUOTA_FIELDS])
        api.cinder.tenant_quota_update(IsA(http.HttpRequest),
                                       project.id,
                                       **cinder_updated_quota)

        self.mox.ReplayAll()

        workflow_data.update(self._get_workflow_data(project, quota))

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 12
0
    def test_add_project_post(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndReturn(quota)

        api.keystone.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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)
        quota_data = self._get_quota_info(quota)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details) \
                    .AndReturn(project)

        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for role in roles:
            if "role_" + role.id in workflow_data:
                ulist = workflow_data["role_" + role.id]
                for user_id in ulist:
                    api.keystone.add_tenant_user_role(IsA(http.HttpRequest),
                                                      tenant_id=self.tenant.id,
                                                      user_id=user_id,
                                                      role_id=role.id)

        nova_updated_quota = dict([(key, quota_data[key]) for key in
                                   quotas.NOVA_QUOTA_FIELDS])
        api.nova.tenant_quota_update(IsA(http.HttpRequest),
                                     project.id,
                                     **nova_updated_quota)
        cinder_updated_quota = dict([(key, quota_data[key]) for key in
                                   quotas.CINDER_QUOTA_FIELDS])
        api.cinder.tenant_quota_update(IsA(http.HttpRequest),
                                       project.id,
                                       **cinder_updated_quota)

        self.mox.ReplayAll()

        workflow_data.update(self._get_workflow_data(project, quota))

        url = reverse('horizon:admin:projects:create')
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 13
0
    def get_initial(self):
        initial = super(CreateProjectView, self).get_initial()

        # Set the domain of the project
        domain = api.keystone.get_default_domain(self.request)
        initial["domain_id"] = domain.id
        initial["domain_name"] = domain.name

        # get initial quota defaults
        try:
            quota_defaults = quotas.get_default_quota_data(self.request)

            try:
                if api.base.is_service_enabled(self.request, 'network') and \
                        api.neutron.is_quotas_extension_supported(
                            self.request):
                    # TODO(jpichon): There is no API to access the Neutron
                    # default quotas (LP#1204956). For now, use the values
                    # from the current project.
                    project_id = self.request.user.project_id
                    quota_defaults += api.neutron.tenant_quota_get(
                        self.request, tenant_id=project_id)
            except Exception:
                error_msg = _('Unable to retrieve default Neutron quota '
                              'values.')
                self.add_error_to_step(error_msg, 'update_quotas')

            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_defaults.get(field).limit

        except Exception:
            error_msg = _('Unable to retrieve default quota values.')
            self.add_error_to_step(error_msg, 'update_quotas')

        return initial
Ejemplo n.º 14
0
    def get_initial(self):

        if (api.keystone.is_multi_domain_enabled()
                and not api.keystone.is_cloud_admin(self.request)):
            self.workflow_class = project_workflows.CreateProjectNoQuota

        initial = super(CreateProjectView, self).get_initial()

        # Set the domain of the project
        domain = api.keystone.get_default_domain(self.request)
        initial["domain_id"] = domain.id
        initial["domain_name"] = domain.name

        # get initial quota defaults
        if api.keystone.is_cloud_admin(self.request):
            try:
                # mj - remove the pre-queens code that ignored Neutron
                quota_defaults = quotas.get_default_quota_data(self.request)
                for field in quotas.QUOTA_FIELDS:
                    initial[field] = quota_defaults.get(field).limit

            except Exception:
                error_msg = _('Unable to retrieve default quota values.')
                self.add_error_to_step(error_msg, 'create_quotas')

        return initial
Ejemplo n.º 15
0
    def get_initial(self):
        initial = super(CreateProjectView, self).get_initial()

        # get initial quota defaults
        try:
            quota_defaults = quotas.get_default_quota_data(self.request)

            try:
                if api.base.is_service_enabled(self.request, 'network') and \
                       api.neutron.is_quotas_extension_supported(self.request):
                    # TODO(jpichon): There is no API to access the Neutron
                    # default quotas (LP#1204956). For now, use the values
                    # from the current project.
                    project_id = self.request.user.project_id
                    quota_defaults += api.neutron.tenant_quota_get(
                                                          self.request,
                                                          tenant_id=project_id)
            except Exception:
                error_msg = _('Unable to retrieve default Neutron quota '
                              'values.')
                self.add_error_to_step(error_msg, 'update_quotas')

            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_defaults.get(field).limit

        except Exception:
            error_msg = _('Unable to retrieve default quota values.')
            self.add_error_to_step(error_msg, 'update_quotas')

        return initial
Ejemplo n.º 16
0
    def test_add_project_user_update_error(self):
        project = self.tenants.first()
        quota = self.quotas.first()
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).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)

        # contribute
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        # handle
        project_details = self._get_project_info(project)
        quota_data = self._get_quota_info(quota)

        api.keystone.tenant_create(IsA(http.HttpRequest), **project_details).AndReturn(project)

        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        workflow_data = {}
        for role in roles:
            if "role_" + role.id in workflow_data:
                ulist = workflow_data["role_" + role.id]
                for user_id in ulist:
                    api.add_tenant_user_role(
                        IsA(http.HttpRequest), tenant_id=self.tenant.id, user_id=user_id, role_id=role.id
                    ).AndRaise(self.exceptions.keystone)
                    break
            break

        api.nova.tenant_quota_update(IsA(http.HttpRequest), project.id, **quota_data)

        self.mox.ReplayAll()

        workflow_data.update(self._get_workflow_data(project, quota))

        url = reverse("horizon:admin:projects:create")
        res = self.client.post(url, workflow_data)

        self.assertNoFormErrors(res)
        self.assertRedirectsNoFollow(res, INDEX_URL)
Ejemplo n.º 17
0
 def get_quotas_data(self):
     request = self.tab_group.request
     try:
         data = quotas.get_default_quota_data(request)
     except Exception:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 18
0
 def get_quotas_data(self):
     request = self.tab_group.request
     try:
         data = quotas.get_default_quota_data(request)
     except Exception:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 19
0
    def test_add_project_quota_defaults_error(self):
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)).AndRaise(self.exceptions.nova)

        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)

        self.mox.ReplayAll()

        url = reverse("horizon:admin:projects:create")
        res = self.client.get(url)

        self.assertTemplateUsed(res, "admin/projects/create.html")
        self.assertContains(res, "Unable to retrieve default quota values")
Ejemplo n.º 20
0
 def get_quotas_data(self):
     request = self.tab_group.request
     disabled_quotas = []
     if not is_service_enabled(self.request, 'volume'):
         disabled_quotas.extend(CINDER_QUOTA_FIELDS)
     try:
         quota_set = quotas.get_default_quota_data(request, disabled_quotas)
         data = quota_set.items
     except:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 21
0
 def get_quotas_data(self):
     request = self.tab_group.request
     disabled_quotas = []
     if not is_service_enabled(self.request, 'volume'):
         disabled_quotas.extend(['volumes', 'gigabytes'])
     try:
         quota_set = quotas.get_default_quota_data(request, disabled_quotas)
         data = quota_set.items
     except:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 22
0
    def test_add_project_quota_defaults_error(self):
        default_role = self.roles.first()
        users = self.users.list()
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)) \
            .AndRaise(self.exceptions.nova)

        api.keystone.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)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:create')
        res = self.client.get(url)

        self.assertTemplateUsed(res, 'admin/projects/create.html')
        self.assertContains(res, "Unable to retrieve default quota values")
Ejemplo n.º 23
0
    def get_initial(self):
        initial = super(UpdateDefaultQuotasView, self).get_initial()

        # get initial quota defaults
        try:
            quota_defaults = quotas.get_default_quota_data(self.request)
            for field in (quotas.QUOTA_FIELDS + quotas.MISSING_QUOTA_FIELDS):
                initial[field] = quota_defaults.get(field).limit

        except Exception:
            error_msg = _('Unable to retrieve default quota values.')
            self.add_error_to_step(error_msg, 'update_default_quotas')

        return initial
Ejemplo n.º 24
0
    def test_add_project_quota_defaults_error(self):
        default_role = self.roles.first()
        domain_id = self._get_domain_id()
        users = self._get_all_users(domain_id)
        roles = self.roles.list()

        # init
        quotas.get_default_quota_data(IsA(http.HttpRequest)) \
            .AndRaise(self.exceptions.nova)

        api.keystone.get_default_role(IsA(http.HttpRequest)) \
            .AndReturn(default_role)
        api.keystone.user_list(IsA(http.HttpRequest), domain=domain_id) \
            .AndReturn(users)
        api.keystone.role_list(IsA(http.HttpRequest)).AndReturn(roles)

        self.mox.ReplayAll()

        url = reverse('horizon:admin:projects:create')
        res = self.client.get(url)

        self.assertTemplateUsed(res, WorkflowView.template_name)
        self.assertContains(res, "Unable to retrieve default quota values")
Ejemplo n.º 25
0
    def get_initial(self):
        initial = super(CreateProjectView, self).get_initial()

        # get initial quota defaults
        try:
            quota_defaults = quotas.get_default_quota_data(self.request)
            for field in quotas.QUOTA_FIELDS:
                initial[field] = quota_defaults.get(field).limit

        except:
            error_msg = _('Unable to retrieve default quota values.')
            self.add_error_to_step(error_msg, 'update_quotas')

        return initial
Ejemplo n.º 26
0
    def get_initial(self):
        initial = super(CreateProjectView, self).get_initial()

        # get initial quota defaults
        try:
            quota_defaults = quotas.get_default_quota_data(self.request)
            for field in QUOTA_FIELDS:
                initial[field] = quota_defaults.get(field).limit

        except:
            error_msg = _("Unable to retrieve default quota values.")
            self.add_error_to_step(error_msg, "update_quotas")

        return initial
Ejemplo n.º 27
0
 def get_quotas_data(self):
     request = self.tab_group.request
     try:
         quota_set = quotas.get_default_quota_data(request)
         data = quota_set.items
         # There is no API to get the default system quotas in
         # Neutron (cf. LP#1204956). Remove the network-related
         # quotas from the list for now to avoid confusion
         if base.is_service_enabled(self.request, 'network'):
             data = [quota for quota in data
                     if quota.name not in ['floating_ips', 'fixed_ips']]
     except Exception:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 28
0
 def get_quotas_data(self):
     request = self.tab_group.request
     try:
         quota_set = quotas.get_default_quota_data(request)
         data = quota_set.items
         # There is no API to get the default system quotas in
         # Neutron (cf. LP#1204956). Remove the network-related
         # quotas from the list for now to avoid confusion
         if base.is_service_enabled(self.request, 'network'):
             data = [
                 quota for quota in data
                 if quota.name not in ['floating_ips', 'fixed_ips']
             ]
     except Exception:
         data = []
         exceptions.handle(self.request, _('Unable to get quota info.'))
     return data
Ejemplo n.º 29
0
    def get_initial(self):

        if (api.keystone.is_multi_domain_enabled() and
                not api.keystone.is_cloud_admin(self.request)):
            self.workflow_class = project_workflows.CreateProjectNoQuota

        initial = super(CreateProjectView, self).get_initial()

        # Set the domain of the project
        domain = api.keystone.get_default_domain(self.request)
        initial["domain_id"] = domain.id
        initial["domain_name"] = domain.name

        # TODO(esp): fix this for Domain Admin or find a work around
        # get initial quota defaults
        if api.keystone.is_cloud_admin(self.request):
            try:
                quota_defaults = quotas.get_default_quota_data(self.request)

                try:
                    if api.base.is_service_enabled(
                            self.request, 'network') and \
                            api.neutron.is_quotas_extension_supported(
                                self.request):
                        # TODO(jpichon): There is no API to access the Neutron
                        # default quotas (LP#1204956). For now, use the values
                        # from the current project.
                        project_id = self.request.user.project_id
                        quota_defaults += api.neutron.tenant_quota_get(
                            self.request,
                            tenant_id=project_id)
                except Exception:
                    error_msg = _('Unable to retrieve default Neutron quota '
                                  'values.')
                    self.add_error_to_step(error_msg, 'create_quotas')

                for field in quotas.QUOTA_FIELDS:
                    initial[field] = quota_defaults.get(field).limit

            except Exception:
                error_msg = _('Unable to retrieve default quota values.')
                self.add_error_to_step(error_msg, 'create_quotas')

        return initial