Пример #1
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'])
Пример #2
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')
Пример #3
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)
Пример #4
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)
     }
Пример #5
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()
Пример #6
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()
Пример #7
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')
Пример #8
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)
Пример #9
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)
Пример #10
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")
Пример #11
0
    def test_customer_instances_quota_increases_on_instance_creation(self):
        from nodeconductor.iaas.tests import factories as iaas_factories
        project = factories.ProjectFactory(customer=self.customer)
        cloud = iaas_factories.CloudFactory(customer=self.customer)
        cpm = iaas_factories.CloudProjectMembershipFactory(cloud=cloud, project=project)
        iaas_factories.InstanceFactory(cloud_project_membership=cpm)

        self.assertEqual(self.customer.quotas.get(name='nc_resource_count').usage, 1)
Пример #12
0
    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.cloud = factories.CloudFactory(
            auth_url='http://some-unique-example.com:5000/v231', customer=self.customer)
Пример #13
0
 def setUp(self):
     self.cloud = factories.CloudFactory()
     self.flavor = factories.FlavorFactory(cloud=self.cloud)
     self.image = factories.ImageFactory(cloud=self.cloud)
     self.template = template_factories.TemplateFactory()
     self.iaas_template_service = factories.IaasTemplateServiceFactory(
         template=self.template,
         service=self.cloud,
         flavor=self.flavor,
         image=self.image)
Пример #14
0
    def test_customer_instances_quota_decreases_on_instance_deletion(self):
        from nodeconductor.iaas.tests import factories as iaas_factories
        project = factories.ProjectFactory(customer=self.customer)
        cloud = iaas_factories.CloudFactory(customer=self.customer)
        cpm = iaas_factories.CloudProjectMembershipFactory(cloud=cloud,
                                                           project=project)
        instance = iaas_factories.InstanceFactory(cloud_project_membership=cpm)
        instance.delete()

        self.assert_quota_usage('nc_resource_count', 0)
Пример #15
0
    def setUp(self):
        self.users = {
            'owner': structure_factories.UserFactory(),
            'admin': structure_factories.UserFactory(),
            'manager': structure_factories.UserFactory(),
            'group_manager': structure_factories.UserFactory(),
        }

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

        self.clouds = {
            'admin': factories.CloudFactory(customer=self.customer),
            'manager': factories.CloudFactory(customer=self.customer),
            'group_manager': factories.CloudFactory(customer=self.customer),
        }

        self.projects = {
            'admin':
            structure_factories.ProjectFactory(customer=self.customer),
            'manager':
            structure_factories.ProjectFactory(customer=self.customer),
            'group_manager':
            structure_factories.ProjectFactory(customer=self.customer)
        }

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

        factories.CloudProjectMembershipFactory(project=self.projects['admin'],
                                                cloud=self.clouds['admin'])
        factories.CloudProjectMembershipFactory(
            project=self.projects['manager'], cloud=self.clouds['manager'])
        factories.CloudProjectMembershipFactory(
            project=self.projects['group_manager'],
            cloud=self.clouds['group_manager'])
Пример #16
0
    def test_group_manager_can_connect_project_and_cloud(self):
        user = self.users['group_manager']
        self.client.force_authenticate(user=user)

        cloud = factories.CloudFactory(customer=self.customer)
        project = self.connected_project
        payload = self._get_valid_payload(cloud, project)

        with patch('nodeconductor.iaas.tasks.sync_cloud_membership.delay'):
            response = self.client.post(reverse('cloudproject_membership-list'), payload)
            self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Пример #17
0
    def test_user_can_connect_cloud_and_project_he_owns(self):
        user = self.users['owner']
        self.client.force_authenticate(user=user)

        cloud = factories.CloudFactory(customer=self.customer)
        project = structure_factories.ProjectFactory(customer=self.customer)

        payload = self._get_valid_payload(cloud, project)

        response = self.client.post(reverse('cloudproject_membership-list'), payload)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
Пример #18
0
    def setUp(self):
        self.nova_client = mock.Mock()
        self.nova_client.flavors.findall.return_value = []

        self.cloud_account = factories.CloudFactory()
        self.flavors = factories.FlavorFactory.create_batch(2, cloud=self.cloud_account)

        # Mock low level non-AbstractCloudBackend api methods
        self.backend = OpenStackBackend()
        self.backend.create_session = mock.Mock()
        self.backend.create_nova_client = mock.Mock(return_value=self.nova_client)
Пример #19
0
    def test_user_cannot_modify_in_unstable_state(self):
        self.client.force_authenticate(user=self.users['customer_owner'])

        for state in SynchronizationStates.UNSTABLE_STATES:
            cloud = factories.CloudFactory(state=state, customer=self.customers['owned'])
            url = factories.CloudFactory.get_url(cloud)

            for method in ('PUT', 'PATCH', 'DELETE'):
                func = getattr(self.client, method.lower())
                response = func(url)
                self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
Пример #20
0
    def test_non_staff_user_gets_no_templates_when_filtering_by_cloud_he_has_no_access_to(
            self):
        for role in ('admin', 'group_manager'):
            self.client.force_authenticate(user=self.users[role])

            cloud = factories.CloudFactory()
            response = self.client.get(reverse('iaastemplate-list'),
                                       {'cloud': cloud.uuid})
            self.assertEqual(response.status_code, status.HTTP_200_OK)

            self.assertEqual(0, len(response.data),
                             'User should see no templates')
Пример #21
0
    def test_admin_cannot_connect_new_cloud_and_project_if_he_is_project_admin(self):
        user = self.users['admin']
        self.client.force_authenticate(user=user)

        cloud = factories.CloudFactory(customer=self.customer)
        project = self.connected_project
        payload = self._get_valid_payload(cloud, project)

        response = self.client.post(reverse('cloudproject_membership-list'), payload)
        # the new cloud should not be visible to the user
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertDictContainsSubset(
            {'cloud': ['Invalid hyperlink - Object does not exist.']}, response.data)
Пример #22
0
    def setUp(self):
        self.customer = structure_factories.CustomerFactory()
        self.owner = structure_factories.UserFactory(username='******')
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)

        self.owners_cloud = iaas_factories.CloudFactory(customer=self.customer)

        self.owners_memberships = [
            iaas_factories.CloudProjectMembershipFactory(
                cloud=self.owners_cloud) for _ in range(3)
        ]
        self.other_memberships = [
            iaas_factories.CloudProjectMembershipFactory() for _ in range(3)
        ]
Пример #23
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.security_group = factories.SecurityGroupFactory(
            cloud_project_membership=self.cloud_project_membership, state=SynchronizationStates.IN_SYNC)
        self.url = factories.SecurityGroupFactory.get_url(self.security_group)
Пример #24
0
 def setUp(self):
     # objects
     self.customer = structure_factories.CustomerFactory()
     self.project = structure_factories.ProjectFactory(customer=self.customer)
     self.cloud = factories.CloudFactory(customer=self.customer)
     self.membership = factories.CloudProjectMembershipFactory(cloud=self.cloud, project=self.project)
     self.active_ip = factories.FloatingIPFactory(status='ACTIVE', cloud_project_membership=self.membership)
     self.down_ip = factories.FloatingIPFactory(status='DOWN', cloud_project_membership=self.membership)
     self.other_ip = factories.FloatingIPFactory(status='UNDEFINED')
     # users
     self.staff = structure_factories.UserFactory(is_staff=True)
     self.owner = structure_factories.UserFactory()
     self.customer.add_user(self.owner, models.CustomerRole.OWNER)
     self.admin = structure_factories.UserFactory()
     self.project.add_user(self.admin, models.ProjectRole.ADMINISTRATOR)
     self.user = structure_factories.UserFactory()
Пример #25
0
 def setUp(self):
     """
     In setup we will create:
     license, template, instance, project and project role.
     """
     # license and template
     self.license = factories.TemplateLicenseFactory()
     self.template = factories.TemplateFactory()
     self.license.templates.add(self.template)
     # project and project group
     self.project = structure_factories.ProjectFactory()
     self.project_group = structure_factories.ProjectGroupFactory()
     self.project_group.projects.add(self.project)
     # cloud and image
     self.cloud = factories.CloudFactory()
     factories.CloudProjectMembershipFactory(cloud=self.cloud, project=self.project)
     self.image = factories.ImageFactory(cloud=self.cloud, template=self.template)
Пример #26
0
 def test_licenses_stats_filtering_by_customer_without_instances(self):
     self.client.force_authenticate(self.staff)
     # other customer is connected with same template, but doesn't have any instances
     other_customer = structure_factories.CustomerFactory()
     other_cloud = factories.CloudFactory(customer=other_customer)
     factories.ImageFactory(cloud=other_cloud, template=self.template)
     # when
     response = self.client.get(self.url, {
         'customer': other_customer.uuid,
         'aggregate': 'project'
     })
     # then: response should return data for first_instance and second_instance, but not other_instance
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertFalse(
         response.data,
         "Customer doesn't have any instances response data should be empty"
     )
Пример #27
0
    def setUp(self):
        self.url = _template_license_stats_url()
        self.customer = structure_factories.CustomerFactory()
        # we have 2 projects groups:
        self.first_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        self.second_group = structure_factories.ProjectGroupFactory(
            customer=self.customer)
        # and 2 template licenses:
        self.first_template_license = factories.TemplateLicenseFactory(
            name='first_template_license', license_type='first license type')
        self.second_template_license = factories.TemplateLicenseFactory(
            name='second_template_license', license_type='second license type')
        self.cloud = factories.CloudFactory(customer=self.customer)
        self.template = factories.TemplateFactory()
        factories.ImageFactory(cloud=self.cloud, template=self.template)

        self.template.template_licenses.add(self.first_template_license)
        self.template.template_licenses.add(self.second_template_license)
        # every group has 1 projects:
        self.first_project = structure_factories.ProjectFactory(
            customer=self.customer, name='first_project')
        self.first_project.project_groups.add(self.first_group)
        self.second_project = structure_factories.ProjectFactory(
            customer=self.customer, name='second_project')
        self.second_project.project_groups.add(self.second_group)
        # every project has 1 instance with first and second template licenses:
        self.first_instance = factories.InstanceFactory(
            template=self.template,
            cloud_project_membership__project=self.first_project,
        )
        self.second_instance = factories.InstanceFactory(
            template=self.template,
            cloud_project_membership__project=self.second_project,
        )
        # also first group has manger:
        self.admin = structure_factories.UserFactory()
        self.first_project.add_user(self.admin,
                                    structure_models.ProjectRole.ADMINISTRATOR)
        self.group_manager = structure_factories.UserFactory()
        self.first_group.add_user(self.group_manager,
                                  structure_models.ProjectGroupRole.MANAGER)
        self.staff = structure_factories.UserFactory(is_staff=True)
        self.owner = structure_factories.UserFactory()
        self.customer.add_user(self.owner, structure_models.CustomerRole.OWNER)
Пример #28
0
    def setUp(self):
        from nodeconductor.structure import models as structure_models
        from nodeconductor.structure.tests import factories as structure_factories
        from nodeconductor.iaas.tests import factories as iaas_factories

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

        self.owners_cloud = iaas_factories.CloudFactory(customer=self.customer)

        self.owners_memberships = [
            iaas_factories.CloudProjectMembershipFactory(
                cloud=self.owners_cloud) for _ in range(3)
        ]
        self.other_memberships = [
            iaas_factories.CloudProjectMembershipFactory() for _ in range(3)
        ]
Пример #29
0
    def test_customer_and_project_service_project_link_quota_updated(self):
        from nodeconductor.iaas.tests import factories as iaas_factories
        cloud = iaas_factories.CloudFactory(customer=self.customer)

        project1 = factories.ProjectFactory(customer=self.customer)
        cpm1 = iaas_factories.CloudProjectMembershipFactory(cloud=cloud,
                                                            project=project1)

        project2 = factories.ProjectFactory(customer=self.customer)
        cpm2 = iaas_factories.CloudProjectMembershipFactory(cloud=cloud,
                                                            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)
Пример #30
0
    def setUp(self):
        self.glance_client = mock.Mock()

        #  C
        #  ^
        #  |
        # (I0)
        #  |
        #  v
        #  T0          T1        T2
        #  ^           ^         ^
        #  | \         | \       |
        #  |  \        |  \      |
        #  |   \       |   \     |
        #  v    v      v    v    v
        #  TM0  TM1    TM2  TM3  TM4
        #

        self.cloud_account = factories.CloudFactory()
        self.templates = factories.TemplateFactory.create_batch(3)

        self.template_mappings = (
            factories.TemplateMappingFactory.create_batch(
                2, template=self.templates[0]) +
            factories.TemplateMappingFactory.create_batch(
                2, template=self.templates[1]) +
            factories.TemplateMappingFactory.create_batch(
                1, template=self.templates[2]))

        self.image = factories.ImageFactory(
            cloud=self.cloud_account,
            template=self.template_mappings[0].template,
            backend_id=self.template_mappings[0].backend_image_id,
        )

        # Mock low level non-AbstractCloudBackend api methods
        self.backend = OpenStackBackend()
        self.backend.create_session = mock.Mock()
        self.backend.create_glance_client = mock.Mock(
            return_value=self.glance_client)