Пример #1
0
    def setUp(self):
        super(BaseClusterCreateTest, self).setUp()
        self.fixture = fixtures.RancherFixture()
        self.url = factories.ClusterFactory.get_list_url()
        openstack_service_settings = openstack_factories.OpenStackServiceSettingsFactory(
            customer=self.fixture.customer)
        openstack_service = openstack_factories.OpenStackServiceFactory(
            customer=self.fixture.customer,
            settings=openstack_service_settings)
        openstack_spl = openstack_factories.OpenStackServiceProjectLinkFactory(
            project=self.fixture.project, service=openstack_service)
        self.tenant = openstack_factories.TenantFactory(
            service_project_link=openstack_spl)

        settings = ServiceSettings.objects.get(scope=self.tenant)
        project = self.fixture.project
        instance_spl = OpenStackTenantServiceProjectLink.objects.get(
            project=project, service__settings=settings)

        openstack_tenant_factories.FlavorFactory(
            settings=instance_spl.service.settings)
        image = openstack_tenant_factories.ImageFactory(
            settings=instance_spl.service.settings)
        openstack_tenant_factories.SecurityGroupFactory(
            name='default', settings=instance_spl.service.settings)
        self.fixture.settings.options['base_image_name'] = image.name
        self.fixture.settings.save()

        network = openstack_tenant_factories.NetworkFactory(
            settings=instance_spl.service.settings)
        self.subnet = openstack_tenant_factories.SubNetFactory(
            network=network, settings=instance_spl.service.settings)
        self.fixture.settings.options['base_subnet_name'] = self.subnet.name
        self.fixture.settings.save()
Пример #2
0
    def test_order_item_set_state_done(self):
        tenant = openstack_factories.TenantFactory()
        resource = marketplace_factories.ResourceFactory(scope=tenant)

        order_item = marketplace_factories.OrderItemFactory(resource=resource)
        order_item.set_state_executing()
        order_item.save()

        order_item.order.approve()
        order_item.order.save()

        tenant.state = openstack_models.Tenant.States.CREATING
        tenant.save()

        tenant.state = openstack_models.Tenant.States.OK
        tenant.save()

        order_item.refresh_from_db()
        self.assertEqual(order_item.state, order_item.States.DONE)

        order_item.resource.refresh_from_db()
        self.assertEqual(order_item.resource.state,
                         marketplace_models.Resource.States.OK)

        order_item.order.refresh_from_db()
        self.assertEqual(order_item.order.state,
                         marketplace_models.Order.States.DONE)
Пример #3
0
    def setUp(self):
        self.tenant = openstack_factories.TenantFactory()
        self.project = self.tenant.service_project_link.project
        self.resource = marketplace_factories.ResourceFactory(
            project=self.project)
        self.resource.scope = self.tenant
        self.resource.save()
        self.order = marketplace_factories.OrderFactory(project=self.project)
        marketplace_factories.OrderItemFactory(resource=self.resource,
                                               order=self.order)
        self.new_project = structure_factories.ProjectFactory()

        self.start_invoice = invoices_factories.InvoiceFactory(
            customer=self.project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )

        invoices_factories.InvoiceItemFactory(
            invoice=self.start_invoice,
            project=self.project,
            scope=self.resource,
        )

        self.target_invoice = invoices_factories.InvoiceFactory(
            customer=self.new_project.customer,
            year=2020,
            month=1,
            state=invoices_models.Invoice.States.PENDING,
        )
Пример #4
0
    def test_service_is_created_on_tenant_creation(self):
        tenant = openstack_factories.TenantFactory()

        self.assertTrue(structure_models.ServiceSettings.objects.filter(scope=tenant).exists())
        service_settings = structure_models.ServiceSettings.objects.get(
            scope=tenant,
            type=apps.OpenStackTenantConfig.service_name,
        )
        self.assertEquals(service_settings.name, tenant.name)
        self.assertEquals(service_settings.customer, tenant.service_project_link.project.customer)
        self.assertEquals(service_settings.username, tenant.user_username)
        self.assertEquals(service_settings.password, tenant.user_password)
        self.assertEquals(service_settings.domain, tenant.service_project_link.service.settings.domain)
        self.assertEquals(service_settings.backend_url, tenant.service_project_link.service.settings.backend_url)
        self.assertEquals(service_settings.type, apps.OpenStackTenantConfig.service_name)
        self.assertEquals(service_settings.options['tenant_id'], tenant.backend_id)
        self.assertEquals(service_settings.options['availability_zone'], tenant.availability_zone)
        self.assertFalse('console_type' in service_settings.options)

        self.assertTrue(models.OpenStackTenantService.objects.filter(
            settings=service_settings,
            customer=tenant.service_project_link.project.customer
        ).exists())

        service = models.OpenStackTenantService.objects.get(
            settings=service_settings,
            customer=tenant.service_project_link.project.customer,
        )

        self.assertTrue(models.OpenStackTenantServiceProjectLink.objects.filter(
            service=service,
            project=tenant.service_project_link.project,
        ).exists())
Пример #5
0
    def setUp(self):
        super(BaseClusterCreateTest, self).setUp()
        self.fixture = fixtures.RancherFixture()
        self.url = factories.ClusterFactory.get_list_url()
        openstack_service_settings = openstack_factories.OpenStackServiceSettingsFactory(
            customer=self.fixture.customer
        )
        self.tenant = openstack_factories.TenantFactory(
            service_settings=openstack_service_settings
        )

        openstack_tenant_factories.FlavorFactory(settings=self.fixture.tenant_settings)
        image = openstack_tenant_factories.ImageFactory(
            settings=self.fixture.tenant_settings
        )
        self.default_security_group = openstack_tenant_factories.SecurityGroupFactory(
            name='default', settings=self.fixture.tenant_settings
        )
        self.fixture.settings.options['base_image_name'] = image.name
        self.fixture.settings.save()

        self.network = openstack_tenant_factories.NetworkFactory(
            settings=self.fixture.tenant_settings
        )
        self.subnet = openstack_tenant_factories.SubNetFactory(
            network=self.network, settings=self.fixture.tenant_settings
        )
        self.flavor = Flavor.objects.get(settings=self.fixture.tenant_settings)
        self.flavor.ram = 1024 * 8
        self.flavor.cores = 2
        self.flavor.save()
        self.fixture.settings.options['base_subnet_name'] = self.subnet.name
        self.fixture.settings.save()
Пример #6
0
    def test_openstack_tenant_settings_certifications_are_copied_from_openstack_settings(self):
        tenant = openstack_factories.TenantFactory()
        certifications = structure_factories.ServiceCertificationFactory.create_batch(2)
        tenant.service_project_link.service.settings.certifications.add(*certifications)

        settings = factories.OpenStackTenantServiceSettingsFactory(scope=tenant)

        certifications_pk = [c.pk for c in certifications]
        self.assertEqual(settings.certifications.filter(pk__in=certifications_pk).count(), 2)
Пример #7
0
    def test_openstack_tenant_service_certifications_are_removed_if_tenant_settings_certifications_are_removed(self):
        tenant = openstack_factories.TenantFactory()
        tenant_service = factories.OpenStackTenantServiceFactory(settings__scope=tenant)
        new_certification = structure_factories.ServiceCertificationFactory()

        tenant.service_project_link.service.settings.certifications.add(new_certification)
        self.assertEqual(tenant_service.settings.certifications.count(), 1)
        tenant.service_project_link.service.settings.certifications.clear()

        self.assertEqual(tenant.service_project_link.service.settings.certifications.count(), 0)
        self.assertEquals(tenant_service.settings.certifications.count(), 0)
Пример #8
0
 def test_copy_config_drive_from_admin_settings_to_private_settings(self):
     shared_settings = openstack_factories.OpenStackServiceSettingsFactory()
     shared_settings.options['config_drive'] = True
     shared_settings.save()
     tenant = openstack_factories.TenantFactory(
         service_settings=shared_settings)
     private_settings = structure_models.ServiceSettings.objects.get(
         scope=tenant,
         type=apps.OpenStackTenantConfig.service_name,
     )
     self.assertTrue(private_settings.options['config_drive'])
Пример #9
0
 def test_copy_console_type_from_admin_settings_to_private_settings(self):
     service_project_link = openstack_factories.OpenStackServiceProjectLinkFactory()
     service_project_link.service.settings.options['console_type'] = 'console_type'
     service_project_link.service.settings.save()
     tenant = openstack_factories.TenantFactory(service_project_link=service_project_link)
     service_settings = structure_models.ServiceSettings.objects.get(
         scope=tenant,
         type=apps.OpenStackTenantConfig.service_name,
     )
     self.assertTrue('console_type' in service_settings.options)
     self.assertEquals(service_settings.options['console_type'],
                       service_project_link.service.settings.options['console_type'])
Пример #10
0
    def test_openstack_tenant_service_certifications_are_update_when_tenant_settings_certification_are_added(self):
        tenant = openstack_factories.TenantFactory()
        tenant_service1 = factories.OpenStackTenantServiceFactory(settings__scope=tenant)
        tenant_service2 = factories.OpenStackTenantServiceFactory(settings__scope=tenant)
        self.assertEqual(tenant_service1.settings.certifications.count(), 0)
        self.assertEqual(tenant_service2.settings.certifications.count(), 0)
        new_certification = structure_factories.ServiceCertificationFactory()

        tenant.service_project_link.service.settings.certifications.add(new_certification)

        self.assertTrue(tenant_service1.settings.certifications.filter(pk__in=[new_certification.pk]).exists())
        self.assertTrue(tenant_service2.settings.certifications.filter(pk__in=[new_certification.pk]).exists())
Пример #11
0
    def test_openstack_tenant_settings_certifications_are_not_copied_on_update(self):
        tenant = openstack_factories.TenantFactory()
        certification = structure_factories.ServiceCertificationFactory()
        tenant.service_project_link.service.settings.certifications.add(certification)
        settings = factories.OpenStackTenantServiceSettingsFactory(scope=tenant)
        self.assertEquals(settings.certifications.count(), 1)

        settings.name = 'new_name'
        settings.save()

        self.assertEquals(settings.certifications.count(), 1)
        self.assertEquals(settings.certifications.first().pk, certification.pk)
Пример #12
0
    def test_cannot_update_tenant_with_duplicated_tenant_name(self):
        other_tenant = factories.TenantFactory(
            service_settings=self.fixture.openstack_service_settings,
            project=self.fixture.project,
        )
        payload = dict(name=other_tenant.name)

        self.client.force_authenticate(self.fixture.staff)
        response = self.client.put(self.get_url(), payload)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(models.Tenant.objects.filter(name=payload['name']).count(), 1)
Пример #13
0
    def test_service_settings_config_drive_is_updated(self):
        # Arrange
        tenant = openstack_factories.TenantFactory()
        service_settings = structure_models.ServiceSettings.objects.get(
            scope=tenant, type=apps.OpenStackTenantConfig.service_name)

        # Act
        tenant.service_settings.options['config_drive'] = True
        tenant.service_settings.save()

        # Assert
        service_settings.refresh_from_db()
        self.assertEqual(service_settings.options['config_drive'], True)
Пример #14
0
 def test_copy_tenant_id_from_tenant_to_private_settings(self):
     shared_settings = openstack_factories.OpenStackServiceSettingsFactory()
     tenant = openstack_factories.TenantFactory(
         service_settings=shared_settings, backend_id=None)
     private_settings = structure_models.ServiceSettings.objects.get(
         scope=tenant,
         type=apps.OpenStackTenantConfig.service_name,
     )
     tenant.backend_id = 'VALID_BACKEND_ID'
     tenant.save()
     private_settings.refresh_from_db()
     self.assertTrue(private_settings.options['tenant_id'],
                     tenant.backend_id)
Пример #15
0
    def setUp(self):
        self.tenant = openstack_factories.TenantFactory()
        self.fixture = fixtures.ProjectFixture()
        self.new_project = ProjectFactory()
        self.project = self.fixture.project

        self.resource = factories.ResourceFactory(project=self.project)
        self.resource.scope = self.tenant
        self.resource.save()

        self.url = factories.ResourceFactory.get_url(
            self.resource, action='move_resource'
        )
Пример #16
0
    def test_service_settings_password_and_username_are_updated_when_tenant_user_password_changes(self):
        tenant = openstack_factories.TenantFactory()
        service_settings = structure_models.ServiceSettings.objects.first()
        service_settings.scope = tenant
        service_settings.password = tenant.user_password
        service_settings.save()

        new_password = '******'
        new_username = '******'

        tenant.user_password = new_password
        tenant.user_username = new_username
        tenant.save()
        service_settings.refresh_from_db()
        self.assertEqual(service_settings.password, new_password)
        self.assertEqual(service_settings.username, new_username)
Пример #17
0
 def test_create_management_security_group(self, user):
     tenant = openstack_factories.TenantFactory(project=self.fixture.project)
     self.fixture.settings.options['management_tenant_uuid'] = tenant.uuid.hex
     self.fixture.settings.save()
     self.client.force_authenticate(getattr(self.fixture, user))
     response = self.client.post(self.url, self.get_payload())
     self.assertEqual(response.status_code, status.HTTP_201_CREATED)
     self.fixture.cluster.refresh_from_db()
     self.assertTrue(self.fixture.cluster.management_security_group)
     group_uuid = response.data['security_group_uuid']
     group = openstack_models.SecurityGroup.objects.get(uuid=group_uuid)
     self.assertEqual(
         group.rules.first().direction, openstack_models.SecurityGroupRule.INGRESS
     )
     self.assertEqual(
         group.rules.first().ethertype, openstack_models.SecurityGroupRule.IPv4
     )
     self.assertEqual(group.rules.first().cidr, '192.168.77.0/24')
     self.assertEqual(group.rules.first().to_port, 443)
     self.assertEqual(group.rules.first().from_port, 443)
Пример #18
0
 def test_resource_with_scope_returns_valid_resource_details(self):
     self.resource.scope = openstack_factories.TenantFactory(project=self.project)
     self.resource.save()
     response = self.make_request()
     self.assertEqual(response.status_code, status.HTTP_200_OK)
Пример #19
0
 def setUp(self):
     self.tenant = openstack_factories.TenantFactory()
     self.service_settings = structure_models.ServiceSettings.objects.get(
         scope=self.tenant,
         type=apps.OpenStackTenantConfig.service_name)
Пример #20
0
 def test_floating_ip_attaching_to_port_from_different_tenant(self):
     self.port.tenant = factories.TenantFactory()
     self.port.save()
     response = self.client.post(self.url, self.request_data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertIn('tenant', response.data['detail'])