def setUp(self):
     # users
     self.admin = structure_factories.UserFactory()
     self.staff = structure_factories.UserFactory(is_staff=True)
     # project
     self.project = structure_factories.ProjectFactory()
     self.project.add_user(self.admin, ProjectRole.ADMINISTRATOR)
     # resource quotas
     quotas = [
         {
             'name': 'vcpu',
             'usage': 5,
             'limit': 10
         },
         {
             'name': 'ram',
             'usage': 1024,
             'limit': 2048
         },
         {
             'name': 'storage',
             'usage': 512,
             'limit': 20 * 1048
         },
         {
             'name': 'max_instances',
             'usage': 5,
             'limit': 10
         },
     ]
     self.membership1 = factories.CloudProjectMembershipFactory(
         project=self.project, quotas=quotas)
     self.membership2 = factories.CloudProjectMembershipFactory(
         project=self.project, quotas=quotas)
Example #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')
Example #3
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)
Example #4
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)
Example #5
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)
        ]
Example #6
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):
     # 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)
 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)
Example #9
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()
Example #10
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)
Example #11
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')
Example #12
0
    def setUp(self):
        self.keystone_client = mock.Mock()
        self.nova_client = mock.Mock()
        self.neutron_client = mock.Mock()
        self.cloud_account = mock.Mock()
        self.membership = factories.CloudProjectMembershipFactory()
        self.tenant = mock.Mock()

        # Mock low level non-AbstractCloudBackend api methods
        self.backend = OpenStackBackend()
        self.backend.create_session = mock.Mock()
        self.backend.create_keystone_client = mock.Mock(return_value=self.keystone_client)
        self.backend.create_nova_client = mock.Mock(return_value=self.nova_client)
        self.backend.create_neutron_client = mock.Mock(return_value=self.neutron_client)
        self.backend.get_or_create_tenant = mock.Mock(return_value=self.tenant)
        self.backend.get_or_create_user = mock.Mock(return_value=('john', 'doe'))
        self.backend.get_or_create_internal_network = mock.Mock()
        self.backend.ensure_user_is_tenant_admin = mock.Mock()
        self.floating_ips = [
            {'status': 'ACTIVE', 'floating_ip_address': '10.7.201.163',
             'id': '063795b7-23ac-4a0d-82f0-4326e73ee1bc',
             'port_id': 'fakeport',
             'floating_network_id': 'd5e27df4-6754-46ac-903c-5b3fa25e21dd'},
            {'status': 'DOWN', 'floating_ip_address': '10.7.201.114',
             'id': '063795b7-23ac-4a0d-82f0-432as73asdas', 'port_id': 'fakeport',
             'floating_network_id': '83353d4a-a2d2-4f24-a472-57578699a6b1'},
            {'status': 'ACTIVE', 'floating_ip_address': '10.7.201.107',
             'id': '063795b7-asds-aq34-3df4-23asdasddssc', 'port_id': 'fakeport',
             'floating_network_id': '34918c99-de9f-4cd3-b56c-fc982429f481'},
        ]
        self.backend.get_floating_ips = mock.Mock(return_value=self.floating_ips)
Example #13
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()
Example #14
0
 def test_pull_quota_resource_calls_clients_quotas_gets_methods_with_membership_tenant_id(self):
     membership = factories.CloudProjectMembershipFactory(tenant_id='test_backend_id')
      # when
     self.backend.pull_resource_quota(membership)
     # then
     self.nova_client.quotas.get.assert_called_once_with(tenant_id=membership.tenant_id)
     self.cinder_client.quotas.get.assert_called_once_with(tenant_id=membership.tenant_id)
Example #15
0
    def setUp(self):
        self.keystone_client = mock.Mock()
        self.nova_client = mock.Mock()
        self.neutron_client = mock.Mock()
        self.cloud_account = mock.Mock()
        self.membership = factories.CloudProjectMembershipFactory()
        self.tenant = mock.Mock()

        # Mock low level non-AbstractCloudBackend api methods
        self.backend = OpenStackBackend()
        self.backend.create_session = mock.Mock()
        self.backend.create_keystone_client = mock.Mock(
            return_value=self.keystone_client)
        self.backend.create_nova_client = mock.Mock(
            return_value=self.nova_client)
        self.backend.create_neutron_client = mock.Mock(
            return_value=self.neutron_client)
        self.backend.get_or_create_tenant = mock.Mock(return_value=self.tenant)
        self.backend.get_or_create_user = mock.Mock(return_value=('john',
                                                                  'doe'))
        self.backend.get_or_create_network = mock.Mock()
        self.backend.ensure_user_is_tenant_admin = mock.Mock()
        self.backend.push_security_group = mock.Mock()
        self.backend.create_security_group = mock.Mock()
        self.backend.update_security_group = mock.Mock()
        self.backend.delete_security_group = mock.Mock()
        self.backend.push_security_group_rules = mock.Mock()
Example #16
0
    def test_user_cannot_list_flavors_of_projects_he_has_no_role_in(self):
        inaccessible_project = structure_factories.ProjectFactory()
        factories.CloudProjectMembershipFactory(
            project=inaccessible_project,
            cloud=self.flavors['inaccessible'].cloud)

        for user_role, flavor in self.forbidden_combinations:
            self._ensure_list_access_forbidden(user_role, flavor)
Example #17
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)
Example #18
0
    def test_erred_cpm_is_passed_to_backend_task(self, mock_task):
        erred_cpm = factories.CloudProjectMembershipFactory(
            state=SynchronizationStates.ERRED)

        response = self.recover_cpm([erred_cpm])
        self.assertContains(
            response, 'One cloud project membership scheduled for recovery')
        mock_task('structure', 'recover_erred_services').assert_called_with(
            [erred_cpm.to_string()])
Example #19
0
    def test_user_cannot_access_flavor_allowed_for_project_he_has_no_role_in(
            self):
        inaccessible_project = structure_factories.ProjectFactory()
        factories.CloudProjectMembershipFactory(
            cloud=self.flavors['inaccessible'].cloud,
            project=inaccessible_project)

        for user_role, flavor in self.forbidden_combinations:
            self._ensure_direct_access_forbidden(user_role, flavor)
Example #20
0
 def test_pull_quota_resource_initiates_quota_parameters(self):
     membership = factories.CloudProjectMembershipFactory(tenant_id='test_backend_id')
     # when
     self.backend.pull_resource_quota(membership)
     # then
     self.assertEqual(membership.quotas.get(name='ram').limit, self.nova_quota.ram)
     self.assertEqual(membership.quotas.get(name='max_instances').limit, self.nova_quota.instances)
     self.assertEqual(membership.quotas.get(name='vcpu').limit, self.nova_quota.cores)
     self.assertEqual(membership.quotas.get(name='storage').limit, self.cinder_quota.gigabytes * 1024)
Example #21
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)
        ]
Example #22
0
 def test_pull_quota_resource_usage_rewrite_old_resource_quota_usage_data(
         self):
     membership = factories.CloudProjectMembershipFactory()
     # when
     self.backend.pull_resource_quota_usage(membership)
     # then
     self.assertEqual(
         membership.quotas.get(name='max_instances').usage,
         len(self.instances))
Example #23
0
 def test_pull_quota_resource_rewrite_old_resource_quota_data(self):
     membership = factories.CloudProjectMembershipFactory(
         tenant_id='test_backend_id')
     # when
     self.backend.pull_resource_quota(membership)
     # then
     self.assertEqual(
         membership.quotas.get(name='max_instances').limit,
         self.nova_quota.instances)
    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)
Example #25
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'])
Example #26
0
    def test_security_group_cloud_project_membership_can_not_be_updated(self):
        new_cpm = factories.CloudProjectMembershipFactory(project=self.project)
        new_cpm_url = factories.CloudProjectMembershipFactory.get_url(new_cpm)

        self.client.force_authenticate(self.admin)
        response = self.client.patch(self.url, data={'cloud_project_membership': {'url': new_cpm_url}})

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        reread_security_group = models.SecurityGroup.objects.get(pk=self.security_group.pk)
        self.assertEqual(self.cloud_project_membership, reread_security_group.cloud_project_membership)
    def test_user_can_allocate_floating_ip_from_cpm_with_external_network_id(self, mocked_task):
        self.client.force_authenticate(user=self.staff)

        cpm = factories.CloudProjectMembershipFactory(external_network_id='12345', state=SynchronizationStates.IN_SYNC)
        url = factories.CloudProjectMembershipFactory.get_url(cpm, 'allocate_floating_ip')
        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_202_ACCEPTED)
        self.assertEqual(response.data['detail'], 'Floating IP allocation has been scheduled.')
        self.assertTrue(mocked_task.delay.called)
Example #28
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)
    def test_user_cannot_allocate_floating_ip_from_cpm_in_unstable_state(self, mocked_task):
        self.client.force_authenticate(user=self.staff)

        cpm = factories.CloudProjectMembershipFactory(external_network_id='12345', state=SynchronizationStates.ERRED)
        url = factories.CloudProjectMembershipFactory.get_url(cpm, 'allocate_floating_ip')
        response = self.client.post(url)

        self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
        self.assertEqual(response.data['detail'], 'Cloud project membership must be in stable state.')
        self.assertFalse(mocked_task.delay.called)
Example #30
0
    def setUp(self):
        self.admin = structure_factories.UserFactory()
        self.user = structure_factories.UserFactory()
        self.staff = structure_factories.UserFactory(is_staff=True)

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

        self.cloud_project_membership = factories.CloudProjectMembershipFactory(project=self.project)

        self.security_group = factories.SecurityGroupFactory(cloud_project_membership=self.cloud_project_membership)