예제 #1
0
    def setUp(self):
        self.customer = structure_factories.CustomerFactory()
        self.project_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        self.project1 = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project2 = structure_factories.ProjectFactory(
            customer=self.customer)
        self.membership1 = factories.CloudProjectMembershipFactory(
            project=self.project1)
        self.membership2 = factories.CloudProjectMembershipFactory(
            project=self.project2)

        self.project_group.projects.add(self.project1)
        # users
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.customer_owner = structure_factories.UserFactory()
        self.customer.add_user(self.customer_owner,
                               structure_models.CustomerRole.OWNER)
        self.project_group_manager = structure_factories.UserFactory()
        self.project_group.add_user(self.project_group_manager,
                                    structure_models.ProjectGroupRole.MANAGER)
        self.project1_admin = structure_factories.UserFactory()
        self.project1.add_user(self.project1_admin,
                               structure_models.ProjectRole.ADMINISTRATOR)

        quota_names = ['vcpu', 'ram', 'storage', 'max_instances']

        self.expected_quotas_for_project1 = models.CloudProjectMembership.get_sum_of_quotas_as_dict(
            [self.membership1], quota_names)

        self.expected_quotas_for_both_projects = models.CloudProjectMembership.get_sum_of_quotas_as_dict(
            [self.membership1, self.membership2], quota_names)
예제 #2
0
    def setUp(self):
        self.users = {
            'owner': factories.UserFactory(),
            'admin': factories.UserFactory(),
            'manager': factories.UserFactory(),
            'group_manager': factories.UserFactory(),
            'no_role': factories.UserFactory(),
        }

        self.customer = factories.CustomerFactory()
        self.customer.add_user(self.users['owner'], CustomerRole.OWNER)

        project_groups = factories.ProjectGroupFactory.create_batch(
            3, customer=self.customer)
        project_groups.append(factories.ProjectGroupFactory())

        self.project_groups = {
            'owner': project_groups[:-1],
            'admin': project_groups[0:2],
            'manager': project_groups[1:3],
            'group_manager': project_groups[2:3],
            'inaccessible': project_groups[-1:],
        }
        project_groups[2].add_user(self.users['group_manager'],
                                   ProjectGroupRole.MANAGER)

        admined_project = factories.ProjectFactory(customer=self.customer)
        admined_project.add_user(self.users['admin'], ProjectGroupRole.MANAGER)
        admined_project.project_groups.add(*self.project_groups['admin'])

        managed_project = factories.ProjectFactory(customer=self.customer)
        managed_project.add_user(self.users['manager'], ProjectRole.MANAGER)
        managed_project.project_groups.add(*self.project_groups['manager'])
예제 #3
0
    def setUp(self):
        self.users = {
            'owner': structure_factories.UserFactory(),
            'admin': structure_factories.UserFactory(),
            'manager': structure_factories.UserFactory(),
            'group_manager': structure_factories.UserFactory(),
            'no_role': structure_factories.UserFactory(),
            'not_connected': structure_factories.UserFactory(),
        }

        # a single customer
        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.users['owner'], CustomerRole.OWNER)

        # that has 3 users connected: admin, manager, group_manager
        self.connected_project = structure_factories.ProjectFactory(customer=self.customer)
        self.connected_project.add_user(self.users['admin'], ProjectRole.ADMINISTRATOR)
        self.connected_project.add_user(self.users['manager'], ProjectRole.MANAGER)
        project_group = structure_factories.ProjectGroupFactory()
        project_group.projects.add(self.connected_project)
        project_group.add_user(self.users['group_manager'], ProjectGroupRole.MANAGER)

        # has defined a cloud and connected cloud to a project
        self.cloud = factories.CloudFactory(customer=self.customer)
        factories.CloudProjectMembershipFactory(project=self.connected_project, cloud=self.cloud)

        # the customer also has another project with users but without a permission link
        self.not_connected_project = structure_factories.ProjectFactory(customer=self.customer)
        self.not_connected_project.add_user(self.users['not_connected'], ProjectRole.ADMINISTRATOR)
        self.not_connected_project.save()
    def setUp(self):
        self.users = {
            'owner': structure_factories.UserFactory(),
            'admin': structure_factories.UserFactory(),
            'manager': structure_factories.UserFactory(),
            'group_manager': structure_factories.UserFactory(),
            'no_role': structure_factories.UserFactory(),
            'not_connected': structure_factories.UserFactory(),
        }

        # a single customer
        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.users['owner'], CustomerRole.OWNER)

        # that has 3 users connected: admin, manager, group_manager
        self.connected_project = structure_factories.ProjectFactory(customer=self.customer)
        self.connected_project.add_user(self.users['admin'], ProjectRole.ADMINISTRATOR)
        self.connected_project.add_user(self.users['manager'], ProjectRole.MANAGER)
        project_group = structure_factories.ProjectGroupFactory()
        project_group.projects.add(self.connected_project)
        project_group.add_user(self.users['group_manager'], ProjectGroupRole.MANAGER)

        # has defined a service and connected service to a project
        self.service = factories.OpenStackServiceFactory(customer=self.customer)
        self.service_project_link = factories.OpenStackServiceProjectLinkFactory(
            project=self.connected_project,
            service=self.service,
            state=SynchronizationStates.IN_SYNC)

        # the customer also has another project with users but without a permission link
        self.not_connected_project = structure_factories.ProjectFactory(customer=self.customer)
        self.not_connected_project.add_user(self.users['not_connected'], ProjectRole.ADMINISTRATOR)
        self.not_connected_project.save()

        self.url = factories.OpenStackServiceProjectLinkFactory.get_list_url()
예제 #5
0
    def setUp(self):
        self.users = {
            'owner': factories.UserFactory(),
            'admin': factories.UserFactory(),
            'manager': factories.UserFactory(),
            'group_manager': factories.UserFactory(),
            'no_role': factories.UserFactory(),
            'multirole': factories.UserFactory(),
        }

        self.projects = {
            'owner': factories.ProjectFactory(),
            'admin': factories.ProjectFactory(),
            'manager': factories.ProjectFactory(),
            'group_manager': factories.ProjectFactory(),
            'inaccessible': factories.ProjectFactory(),
        }

        self.projects['admin'].add_user(self.users['admin'],
                                        ProjectRole.ADMINISTRATOR)
        self.projects['manager'].add_user(self.users['manager'],
                                          ProjectRole.MANAGER)

        self.projects['admin'].add_user(self.users['multirole'],
                                        ProjectRole.ADMINISTRATOR)
        self.projects['manager'].add_user(self.users['multirole'],
                                          ProjectRole.MANAGER)
        self.project_group = factories.ProjectGroupFactory()
        self.project_group.add_user(self.users['group_manager'],
                                    ProjectGroupRole.MANAGER)
        self.project_group.projects.add(self.projects['group_manager'])

        self.projects['owner'].customer.add_user(self.users['owner'],
                                                 CustomerRole.OWNER)
예제 #6
0
    def setUp(self):
        self.users = {
            'admin': structure_factories.UserFactory(),
            'manager': structure_factories.UserFactory(),
            'group_manager': structure_factories.UserFactory(),
            'no_role': structure_factories.UserFactory(),
        }

        self.flavors = {
            'admin': factories.FlavorFactory(),
            'manager': factories.FlavorFactory(),
            'group_manager': factories.FlavorFactory(),
            'inaccessible': factories.FlavorFactory(),
        }

        admined_project = structure_factories.ProjectFactory()
        managed_project = structure_factories.ProjectFactory()
        group_managed_project = structure_factories.ProjectFactory()
        project_group = structure_factories.ProjectGroupFactory()
        project_group.projects.add(group_managed_project)

        project_group.add_user(self.users['group_manager'],
                               ProjectGroupRole.MANAGER)
        admined_project.add_user(self.users['admin'],
                                 ProjectRole.ADMINISTRATOR)
        managed_project.add_user(self.users['manager'], ProjectRole.MANAGER)

        factories.CloudProjectMembershipFactory(
            cloud=self.flavors['group_manager'].cloud,
            project=group_managed_project)
        factories.CloudProjectMembershipFactory(
            cloud=self.flavors['admin'].cloud, project=admined_project)
        factories.CloudProjectMembershipFactory(
            cloud=self.flavors['manager'].cloud, project=managed_project)
예제 #7
0
    def test_customer_and_project_service_project_link_quota_updated(self):
        from nodeconductor.openstack.tests import factories as openstack_factories

        self.assert_quota_usage('nc_service_project_link_count', 0)
        service = openstack_factories.OpenStackServiceFactory(
            customer=self.customer)

        project1 = factories.ProjectFactory(customer=self.customer)
        openstack_factories.OpenStackServiceProjectLinkFactory(
            service=service, project=project1)

        project2 = factories.ProjectFactory(customer=self.customer)
        openstack_factories.OpenStackServiceProjectLinkFactory(
            service=service, project=project2)

        self.assertEqual(
            project1.quotas.get(name='nc_service_project_link_count').usage, 1)
        self.assertEqual(
            project2.quotas.get(name='nc_service_project_link_count').usage, 1)

        self.assert_quota_usage('nc_service_project_link_count', 2)
        self.assert_quota_usage('nc_service_count', 1)

        project2.delete()
        project1.delete()

        self.assert_quota_usage('nc_service_count', 1)
        self.assert_quota_usage('nc_service_project_link_count', 0)
예제 #8
0
    def setUp(self):
        self.auth_url = 'http://example.com/'

        self.project1 = structure_factories.ProjectFactory()
        self.project2 = structure_factories.ProjectFactory()

        self.cloud = factories.CloudFactory(auth_url=self.auth_url)
        self.membership1 = factories.CloudProjectMembershipFactory(
            cloud=self.cloud, project=self.project1, tenant_id='1')
        self.membership2 = factories.CloudProjectMembershipFactory(
            cloud=self.cloud, project=self.project2, tenant_id='2')

        self.user = structure_factories.UserFactory()
        self.staff = structure_factories.UserFactory(is_staff=True)

        self.stats = {
            u'count': '2',
            u'vcpus_used': '0',
            u'local_gb_used': '0',
            u'memory_mb': '7660',
            u'current_workload': '0',
            u'vcpus': '2',
            u'running_vms': '0',
            u'free_disk_gb': '12',
            u'disk_available_least': '6',
            u'local_gb': '12',
            u'free_ram_mb': '6636',
            u'memory_mb_used': '1024'
        }
        models.ServiceStatistics.objects.bulk_create(
            models.ServiceStatistics(cloud=self.cloud, key=k, value=v)
            for k, v in self.stats.iteritems())

        self.url = reverse('stats_resource')
예제 #9
0
    def test_quotas_are_reseted_on_scope_delete(self):
        customer = structure_factories.CustomerFactory()
        project1 = structure_factories.ProjectFactory(customer=customer)
        project2 = structure_factories.ProjectFactory(customer=customer)

        project1.add_quota_usage('nc_resource_count', 50)
        project2.add_quota_usage('nc_resource_count', 20)
        project1.delete()

        self.assertEqual(customer.quotas.get(name='nc_resource_count').usage, 20)
예제 #10
0
    def setUp(self):
        self.users = {
            'staff': factories.UserFactory(is_staff=True),
            'owner': factories.UserFactory(),
            'not_owner': factories.UserFactory(),
            'admin': factories.UserFactory(),
            'admin_other': factories.UserFactory(),
            'manager': factories.UserFactory(),
            'group_manager': factories.UserFactory(),
        }

        self.customers = {
            'owned': factories.CustomerFactory.create_batch(2),
            'inaccessible': factories.CustomerFactory.create_batch(2),
            'admin': factories.CustomerFactory(),
            'manager': factories.CustomerFactory(),
            'group_manager': factories.CustomerFactory(),
        }

        for customer in self.customers['owned']:
            customer.add_user(self.users['owner'], CustomerRole.OWNER)

        self.projects = {
            'admin':
            factories.ProjectFactory(customer=self.customers['admin']),
            'manager':
            factories.ProjectFactory(customer=self.customers['manager']),
            'group_manager':
            factories.ProjectFactory(customer=self.customers['group_manager']),
        }

        self.projects['admin'].add_user(self.users['admin'],
                                        ProjectRole.ADMINISTRATOR)
        self.projects['manager'].add_user(self.users['manager'],
                                          ProjectRole.MANAGER)

        self.project_groups = {
            'admin':
            factories.ProjectGroupFactory(customer=self.customers['admin']),
            'manager':
            factories.ProjectGroupFactory(customer=self.customers['manager']),
            'group_manager':
            factories.ProjectGroupFactory(
                customer=self.customers['group_manager']),
        }

        self.project_groups['admin'].projects.add(self.projects['admin'])
        self.project_groups['manager'].projects.add(self.projects['manager'])
        self.project_groups['group_manager'].projects.add(
            self.projects['group_manager'])
        self.project_groups['group_manager'].add_user(
            self.users['group_manager'], ProjectGroupRole.MANAGER)
예제 #11
0
    def test_if_service_became_available_it_connects_to_all_projects_of_customer(self):
        customer = factories.CustomerFactory()
        service = self.create_service(customer, available_for_all=False)
        project = factories.ProjectFactory(customer=customer)

        other_customer = factories.CustomerFactory()
        other_project = factories.ProjectFactory(customer=other_customer)

        # Act
        service.available_for_all = True
        service.save()

        # Assert
        self.assertTrue(self.link_exists(project, service))
        self.assertFalse(self.link_exists(other_project, service))
예제 #12
0
    def setUp(self):
        self.customers = {
            'owned': structure_factories.CustomerFactory(),
            'has_admined_project': structure_factories.CustomerFactory(),
            'has_managed_project': structure_factories.CustomerFactory(),
            'has_managed_by_group_manager': structure_factories.CustomerFactory(),
        }

        self.users = {
            'customer_owner': structure_factories.UserFactory(),
            'project_admin': structure_factories.UserFactory(),
            'project_manager': structure_factories.UserFactory(),
            'group_manager': structure_factories.UserFactory(),
            'no_role': structure_factories.UserFactory(),
        }

        self.projects = {
            'owned': structure_factories.ProjectFactory(customer=self.customers['owned']),
            'admined': structure_factories.ProjectFactory(customer=self.customers['has_admined_project']),
            'managed': structure_factories.ProjectFactory(customer=self.customers['has_managed_project']),
            'managed_by_group_manager': structure_factories.ProjectFactory(
                customer=self.customers['has_managed_by_group_manager']),
        }

        self.clouds = {
            'owned': factories.CloudFactory(
                state=SynchronizationStates.IN_SYNC, customer=self.customers['owned']),
            'admined': factories.CloudFactory(
                state=SynchronizationStates.IN_SYNC, customer=self.customers['has_admined_project']),
            'managed': factories.CloudFactory(
                state=SynchronizationStates.IN_SYNC, customer=self.customers['has_managed_project']),
            'managed_by_group_manager': factories.CloudFactory(
                state=SynchronizationStates.IN_SYNC, customer=self.customers['has_managed_by_group_manager']),
            'not_in_project': factories.CloudFactory(),
        }

        self.customers['owned'].add_user(self.users['customer_owner'], CustomerRole.OWNER)

        self.projects['admined'].add_user(self.users['project_admin'], ProjectRole.ADMINISTRATOR)
        self.projects['managed'].add_user(self.users['project_manager'], ProjectRole.MANAGER)
        project_group = structure_factories.ProjectGroupFactory()
        project_group.projects.add(self.projects['managed_by_group_manager'])
        project_group.add_user(self.users['group_manager'], ProjectGroupRole.MANAGER)

        factories.CloudProjectMembershipFactory(cloud=self.clouds['admined'], project=self.projects['admined'])
        factories.CloudProjectMembershipFactory(cloud=self.clouds['managed'], project=self.projects['managed'])
        factories.CloudProjectMembershipFactory(
            cloud=self.clouds['managed_by_group_manager'], project=self.projects['managed_by_group_manager'])
    def setUp(self):
        self.users = {
            'staff': factories.UserFactory(is_staff=True),
            'first': factories.UserFactory(),
            'first_manager': factories.UserFactory(),
            'first_admin': factories.UserFactory(),
            'second': factories.UserFactory(),
            'no_role': factories.UserFactory(),
        }

        self.customers = {
            'first': factories.CustomerFactory(),
            'second': factories.CustomerFactory(),
        }

        customer = self.customers['first']
        project = factories.ProjectFactory(customer=customer)
        project_group = factories.ProjectGroupFactory(customer=customer)
        project_group.projects.add(project)

        for user, customer, role in self.all_roles:
            self.customers[customer].add_user(self.users[user],
                                              self.role_map[role])

        project_group.add_user(self.users['first_manager'],
                               ProjectGroupRole.MANAGER)
        project.add_user(self.users['first_admin'], ProjectRole.ADMINISTRATOR)
예제 #14
0
 def setUp(self):
     # project, customer and project_group
     self.customer = structure_factories.CustomerFactory()
     self.project = structure_factories.ProjectFactory(
         customer=self.customer)
     self.project_group = structure_factories.ProjectGroupFactory()
     self.project_group.projects.add(self.project)
     # cloud and template
     self.cloud = factories.CloudFactory()
     factories.CloudProjectMembershipFactory(cloud=self.cloud,
                                             project=self.project)
     template = factories.TemplateFactory()
     factories.ImageFactory(cloud=self.cloud, template=template)
     # license
     self.license = factories.TemplateLicenseFactory()
     self.license.templates.add(template)
     # users
     self.staff = structure_factories.UserFactory(username='******',
                                                  is_superuser=True,
                                                  is_staff=True)
     self.manager = structure_factories.UserFactory(username='******')
     self.project.add_user(self.manager,
                           structure_models.ProjectRole.MANAGER)
     self.administrator = structure_factories.UserFactory(
         username='******')
     self.project.add_user(self.administrator,
                           structure_models.ProjectRole.ADMINISTRATOR)
     self.owner = structure_factories.UserFactory(username='******')
     self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)
     self.group_manager = structure_factories.UserFactory()
     self.project_group = structure_factories.ProjectGroupFactory()
     self.project_group.projects.add(self.project)
     self.project_group.add_user(self.group_manager,
                                 structure_models.ProjectGroupRole.MANAGER)
예제 #15
0
    def test_customer_quota_is_not_increased_on_adding_owner_as_manager(self):
        user = factories.UserFactory()
        project = factories.ProjectFactory(customer=self.customer)
        self.customer.add_user(user, CustomerRole.OWNER)
        project.add_user(user, ProjectRole.ADMINISTRATOR)

        self.assert_quota_usage('nc_user_count', 1)
    def test_target_model_instance_deletion_decreases_scope_counter_quota(
            self):
        customer = structure_factories.CustomerFactory()
        project = structure_factories.ProjectFactory(customer=customer)
        project.delete()

        self.assertEqual(customer.quotas.get(name='nc_project_count').usage, 0)
예제 #17
0
 def setUp(self):
     # project, customer and project_group
     self.customer = structure_factories.CustomerFactory()
     self.project = structure_factories.ProjectFactory(
         customer=self.customer)
     self.project_group = structure_factories.ProjectGroupFactory()
     self.project_group.projects.add(self.project)
     # cloud and template
     self.cloud = factories.CloudFactory(customer=self.customer)
     factories.CloudProjectMembershipFactory(cloud=self.cloud,
                                             project=self.project)
     self.template = factories.TemplateFactory(os='OS')
     factories.ImageFactory(cloud=self.cloud, template=self.template)
     # license
     self.license = factories.TemplateLicenseFactory()
     self.license.templates.add(self.template)
     # users
     self.staff = structure_factories.UserFactory(is_superuser=True,
                                                  is_staff=True)
     self.manager = structure_factories.UserFactory()
     self.project.add_user(self.manager,
                           structure_models.ProjectRole.MANAGER)
     self.group_manager = structure_factories.UserFactory()
     self.project_group.add_user(self.group_manager,
                                 structure_models.ProjectGroupRole.MANAGER)
예제 #18
0
 def test_anonymous_user_cannot_create_project(self):
     for old_project in self.projects.values():
         project = factories.ProjectFactory(customer=old_project.customer)
         response = self.client.post(reverse('project-list'),
                                     self._get_valid_payload(project))
         self.assertEqual(response.status_code,
                          status.HTTP_401_UNAUTHORIZED)
    def setUp(self):
        self.owner = structure_factories.UserFactory(is_staff=True, is_superuser=True)
        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.owner, CustomerRole.OWNER)

        self.project = structure_factories.ProjectFactory(customer=self.customer)
        self.service = factories.OpenStackServiceFactory(customer=self.customer)
예제 #20
0
    def test_group_manager_cannot_create_project_belonging_to_project_group_he_doesnt_manage(
            self):
        self.client.force_authenticate(self.group_manager)

        data = _get_valid_project_payload(
            factories.ProjectFactory.build(customer=self.customer))

        accessible_project_group = factories.ProjectGroupFactory(
            customer=self.customer)
        admined_project = factories.ProjectFactory(customer=self.customer)
        admined_project.add_user(self.group_manager, ProjectRole.ADMINISTRATOR)
        accessible_project_group.projects.add(admined_project)

        # group_manager now can see accessible_project_group because he admins
        # a project that is within accessible_project_group;
        # though he doesn't manage accessible_project_group

        data['project_groups'] = [{
            "url":
            factories.ProjectGroupFactory.get_url(accessible_project_group)
        }]
        response = self.client.post(factories.ProjectFactory.get_list_url(),
                                    data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
        self.assertDictContainsSubset(
            {'detail': 'You do not have permission to perform this action.'},
            response.data)
        self.assertFalse(Project.objects.filter(name=data['name']).exists())
    def setUp(self):
        self.users = {
            'staff':
            structure_factories.UserFactory(username='******', is_staff=True),
            'owner':
            structure_factories.UserFactory(username='******'),
            'administrator':
            structure_factories.UserFactory(username='******'),
            'manager':
            structure_factories.UserFactory(username='******'),
            'regular_user':
            structure_factories.UserFactory(username='******'),
        }

        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.users['owner'],
                               structure_models.CustomerRole.OWNER)
        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project.add_user(self.users['administrator'],
                              structure_models.ProjectRole.ADMINISTRATOR)
        self.project_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        self.project_group.add_user(self.users['manager'],
                                    structure_models.ProjectGroupRole.MANAGER)
        self.project_group.projects.add(self.project)

        self.default_price_list_item = factories.DefaultPriceListItemFactory()
예제 #22
0
    def setUp(self):
        self.user = structure_factories.UserFactory()

        self.customer = structure_factories.CustomerFactory()
        self.owner = structure_factories.UserFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)

        self.project_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        self.group_manager = structure_factories.UserFactory()
        self.project_group.add_user(self.group_manager,
                                    structure_models.ProjectGroupRole.MANAGER)

        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.admin = structure_factories.UserFactory()
        self.project.add_user(self.admin,
                              structure_models.ProjectRole.ADMINISTRATOR)

        self.events = {
            'customer_event':
            factories.EventFactory(customer_uuid=self.customer.uuid.hex),
            'project_group_event':
            factories.EventFactory(
                project_group_uuid=self.project_group.uuid.hex),
            'project_event':
            factories.EventFactory(project_uuid=self.project.uuid.hex),
        }
예제 #23
0
    def test_quotas_of_parents_change_on_child_quota_change(self):
        customer = structure_factories.CustomerFactory()
        project1 = structure_factories.ProjectFactory(customer=customer)
        project2 = structure_factories.ProjectFactory(customer=customer)

        project1.set_quota_usage('nc_resource_count', 1)
        project2.set_quota_usage('nc_resource_count', 2)

        self.assertEqual(
            customer.quotas.get(name='nc_resource_count').usage, 3)

        project1.add_quota_usage('nc_resource_count', 1)
        project2.add_quota_usage('nc_resource_count', -2)

        self.assertEqual(
            customer.quotas.get(name='nc_resource_count').usage, 2)
    def setUp(self):
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.owner = structure_factories.UserFactory()
        self.admin = structure_factories.UserFactory()

        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)
        self.service = factories.OpenStackServiceFactory(customer=self.customer)
        self.project = structure_factories.ProjectFactory(customer=self.customer)
        self.project.add_user(self.admin, structure_models.ProjectRole.ADMINISTRATOR)
        self.service_project_link = factories.OpenStackServiceProjectLinkFactory(
            service=self.service, project=self.project)

        self.valid_data = {
            'name': 'test_security_group',
            'description': 'test security_group description',
            'service_project_link': {
                'url': factories.OpenStackServiceProjectLinkFactory.get_url(self.service_project_link),
            },
            'rules': [
                {
                    'protocol': 'tcp',
                    'from_port': 1,
                    'to_port': 10,
                    'cidr': '11.11.1.2/24',
                }
            ]
        }
        self.url = factories.SecurityGroupFactory.get_list_url()
예제 #25
0
    def test_licenses_stats_filtering_by_customer_with_instances(self):
        self.client.force_authenticate(self.staff)
        # other customer is connected with another template and has one instance connected to it
        other_customer = structure_factories.CustomerFactory()
        other_project = structure_factories.ProjectFactory(
            customer=other_customer)
        other_cloud = factories.CloudFactory(customer=other_customer)
        other_template = factories.TemplateFactory()
        factories.ImageFactory(cloud=other_cloud, template=self.template)
        other_template_license = factories.TemplateLicenseFactory()
        other_template.template_licenses.add(other_template_license)

        factories.InstanceFactory(
            template=other_template,
            cloud_project_membership__project=other_project,
        )
        # when
        response = self.client.get(self.url, {
            'customer': other_customer.uuid,
            'aggregate': 'project'
        })
        # then: response should return data for other_instance, but not first_instance and second_instance
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 1,
                         "Response should contain data only for one project")
        self.assertEqual(response.data[0]['project_uuid'],
                         other_project.uuid.hex)
        self.assertEqual(
            response.data[0]['count'], 1,
            "Customer should have only one instance with one license")
예제 #26
0
    def setUp(self):
        self.customer = structure_factories.CustomerFactory()
        self.owner = structure_factories.UserFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)

        self.admin = structure_factories.UserFactory()
        self.manager = structure_factories.UserFactory()
        self.group_manager = structure_factories.UserFactory()
        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project.add_user(self.admin,
                              structure_models.ProjectRole.ADMINISTRATOR)
        self.project.add_user(self.manager,
                              structure_models.ProjectRole.MANAGER)
        project_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        project_group.projects.add(self.project)
        project_group.add_user(self.group_manager,
                               structure_models.ProjectGroupRole.MANAGER)
        self.cloud = factories.CloudFactory(customer=self.customer)
        factories.CloudProjectMembershipFactory(cloud=self.cloud,
                                                project=self.project)

        self.expected_public_fields = ('auth_url', 'uuid', 'url', 'name',
                                       'customer', 'customer_name',
                                       'customer_native_name', 'flavors',
                                       'projects', 'dummy', 'resources_count',
                                       'service_type')
예제 #27
0
    def setUp(self):
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.owner = structure_factories.UserFactory()
        self.admin = structure_factories.UserFactory()

        self.customer = structure_factories.CustomerFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)
        self.cloud = factories.CloudFactory(customer=self.customer)
        self.project = structure_factories.ProjectFactory(customer=self.customer)
        self.project.add_user(self.admin, structure_models.ProjectRole.ADMINISTRATOR)
        self.cloud_project_membership = factories.CloudProjectMembershipFactory(cloud=self.cloud, project=self.project)

        self.valid_data = {
            'name': 'test_security_group',
            'description': 'test security_group description',
            'cloud_project_membership': {
                'url': factories.CloudProjectMembershipFactory.get_url(self.cloud_project_membership),
            },
            'rules': [
                {
                    'protocol': 'tcp',
                    'from_port': 1,
                    'to_port': 10,
                    'cidr': '10.7.50.1/24',
                }
            ]
        }
        self.url = factories.SecurityGroupFactory.get_list_url()
예제 #28
0
 def _get_valid_payload(self, cloud=None, project=None):
     cloud = cloud or factories.CloudFactory()
     project = project or structure_factories.ProjectFactory()
     return {
         'cloud': self._get_cloud_url(cloud),
         'project': self._get_project_url(project)
     }
예제 #29
0
 def setUp(self):
     super(BackupSchedulePermissionsTest, self).setUp()
     # objects
     self.customer = structure_factories.CustomerFactory()
     self.project = structure_factories.ProjectFactory(
         customer=self.customer)
     self.project_group = structure_factories.ProjectGroupFactory(
         customer=self.customer)
     self.project_group.projects.add(self.project)
     self.cloud = iaas_factories.CloudFactory(customer=self.customer)
     self.cpm = iaas_factories.CloudProjectMembershipFactory(
         cloud=self.cloud, project=self.project)
     self.instance = iaas_factories.InstanceFactory(
         cloud_project_membership=self.cpm)
     self.schedule = factories.BackupScheduleFactory(
         backup_source=self.instance)
     # users
     self.staff = structure_factories.UserFactory(username='******',
                                                  is_staff=True)
     self.regular_user = structure_factories.UserFactory(
         username='******')
     self.project_admin = structure_factories.UserFactory(username='******')
     self.project.add_user(self.project_admin,
                           structure_models.ProjectRole.ADMINISTRATOR)
     self.customer_owner = structure_factories.UserFactory(username='******')
     self.customer.add_user(self.customer_owner,
                            structure_models.CustomerRole.OWNER)
     self.project_group_manager = structure_factories.UserFactory(
         username='******')
     self.project_group.add_user(self.project_group_manager,
                                 structure_models.ProjectGroupRole.MANAGER)
예제 #30
0
    def setUp(self):
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.customer = structure_factories.CustomerFactory()
        self.owner = structure_factories.UserFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)

        self.manager = structure_factories.UserFactory(username='******')
        self.admin = structure_factories.UserFactory(username='******')
        self.project = structure_factories.ProjectFactory(
            customer=self.customer)
        self.project.add_user(self.manager,
                              structure_models.ProjectRole.MANAGER)
        self.project.add_user(self.admin,
                              structure_models.ProjectRole.ADMINISTRATOR)
        project_group = structure_factories.ProjectGroupFactory()
        self.project.project_groups.add(project_group)

        self.group_manager = structure_factories.UserFactory(
            username='******')
        project_group.add_user(self.group_manager,
                               structure_models.ProjectGroupRole.MANAGER)

        models.Instance.objects.all().delete()
        self.instance = factories.InstanceFactory(
            cloud_project_membership__project=self.project)
        factories.InstanceSlaHistoryFactory(instance=self.instance,
                                            period='2015')
        self.other_instance = factories.InstanceFactory()
        factories.InstanceSlaHistoryFactory(instance=self.other_instance,
                                            period='2015')