Beispiel #1
0
    def setUp(self):
        self.fixture = structure_fixtures.ProjectFixture()
        self.service_provider = factories.ServiceProviderFactory()
        self.secret_code = self.service_provider.api_secret_code
        self.offering = factories.OfferingFactory(
            customer=self.fixture.customer)
        self.plan = factories.PlanFactory(unit=UnitPriceMixin.Units.PER_DAY,
                                          offering=self.offering)
        self.offering_component = factories.OfferingComponentFactory(
            offering=self.offering,
            billing_type=models.OfferingComponent.BillingTypes.USAGE,
        )
        self.component = factories.PlanComponentFactory(
            plan=self.plan, component=self.offering_component)
        self.resource = models.Resource.objects.create(
            offering=self.offering,
            plan=self.plan,
            project=self.fixture.project,
        )

        factories.OrderItemFactory(
            resource=self.resource,
            type=models.RequestTypeMixin.Types.CREATE,
            state=models.OrderItem.States.EXECUTING,
            plan=self.plan,
        )
        callbacks.resource_creation_succeeded(self.resource)
        self.plan_period = models.ResourcePlanPeriod.objects.get(
            resource=self.resource)
Beispiel #2
0
def change_order_item_state(sender, instance, created=False, **kwargs):
    if created:
        return

    if not instance.tracker.has_changed('state'):
        return

    try:
        resource = marketplace_models.Resource.objects.get(scope=instance)
    except ObjectDoesNotExist:
        logger.warning(
            'Skipping support offering state synchronization '
            'because related order item is not found. Offering ID: %s',
            instance.id,
        )
        return

    if instance.state == support_models.Offering.States.OK:
        callbacks.resource_creation_succeeded(resource)
    elif instance.state == support_models.Offering.States.TERMINATED:
        if (instance.tracker.previous('state') ==
                support_models.Offering.States.REQUESTED):
            callbacks.resource_creation_failed(resource)
        if instance.tracker.previous(
                'state') == support_models.Offering.States.OK:
            callbacks.resource_deletion_succeeded(resource)
Beispiel #3
0
    def setUp(self):
        # Arrange
        super(StorageModeInvoiceTest, self).setUp()
        fixture = OpenStackFixture()
        tenant = fixture.openstack_tenant
        offering_component = marketplace_models.OfferingComponent.objects.create(
            offering=self.offering,
            type='gigabytes_gpfs',
            billing_type=marketplace_models.OfferingComponent.BillingTypes.
            LIMIT,
        )

        plan = self.create_plan(self.prices)
        marketplace_models.PlanComponent.objects.create(
            component=offering_component,
            plan=plan,
            price=10,
        )
        self.resource = marketplace_factories.ResourceFactory(
            offering=self.offering,
            plan=plan,
            limits=self.limits,
            state=marketplace_models.Resource.States.CREATING,
        )

        callbacks.resource_creation_succeeded(self.resource)
        self.resource.scope = tenant
        self.resource.save()
        tenant.set_quota_limit('vcpu', 6)
        tenant.set_quota_limit('ram', 10 * 1024)
        tenant.set_quota_usage('storage', 30 * 1024)
        tenant.set_quota_usage('gigabytes_gpfs', 100 * 1024)
Beispiel #4
0
    def _init(self, price, unit):
        self.fixture = package_fixtures.PackageFixture()
        self.project_url = structure_factories.ProjectFactory.get_url(
            self.fixture.project)

        self.offering = marketplace_factories.OfferingFactory(
            scope=self.fixture.openstack_service_settings,
            type=PACKAGE_TYPE,
            state=marketplace_models.Offering.States.ACTIVE,
        )

        self.offering_url = marketplace_factories.OfferingFactory.get_url(
            self.offering)

        plan = self._create_plan(price=price, unit=unit)
        plan_url = marketplace_factories.PlanFactory.get_url(plan)

        # Create SPL
        self.fixture.openstack_spl

        attributes = dict(
            name='My first VPC',
            description='Database cluster',
            user_username='******',
        )

        payload = {
            'project':
            self.project_url,
            'items': [
                {
                    'offering': self.offering_url,
                    'plan': plan_url,
                    'attributes': attributes,
                },
            ]
        }

        user = self.fixture.staff
        self.client.force_login(user)
        url = marketplace_factories.OrderFactory.get_list_url()
        response = self.client.post(url, payload)

        order_item = marketplace_models.OrderItem.objects.get(
            uuid=response.data['items'][0]['uuid'])
        marketplace_utils.process_order_item(order_item, user)
        self.resource = order_item.resource
        callbacks.resource_creation_succeeded(self.resource)

        self.tenant = plan.scope.openstack_packages.first().tenant
        self.tenant.state = openstack_models.Tenant.States.OK
        self.tenant.backend_id = 'tenant id'
        self.tenant.save()

        self.package = package_models.OpenStackPackage.objects.get(
            tenant=self.tenant)
        self.invoice = invoices_models.Invoice.objects.get(
            customer=self.fixture.customer)
Beispiel #5
0
    def process_order_item(self, user):
        # scope can be a reference to a different object or a string representing
        # unique key of a scoped object, e.g. remote UUID
        scope = self.send_request(user)

        with transaction.atomic():
            resource = create_local_resource(self.order_item, scope)

            if not scope or type(scope) == str:
                resource_creation_succeeded(resource)
Beispiel #6
0
 def create_resource(self,
                     prices,
                     limits,
                     unit=marketplace_models.Plan.Units.PER_DAY
                     ) -> marketplace_models.Resource:
     plan = self.create_plan(prices, unit)
     resource = marketplace_factories.ResourceFactory(
         offering=self.offering,
         plan=plan,
         limits=limits,
         state=marketplace_models.Resource.States.CREATING,
     )
     callbacks.resource_creation_succeeded(resource)
     return resource
Beispiel #7
0
    def accept(self, request, uuid=None):
        resource = self.get_object()

        with transaction.atomic():
            order_item = resource_creation_succeeded(resource, validate=True)

        return Response({'order_item_uuid': order_item.uuid.hex},
                        status=status.HTTP_200_OK)
    def test_when_resource_is_created_new_period_is_opened(self):
        # Arrange
        start = parse_datetime('2018-11-01')
        plan = factories.PlanFactory()
        resource = factories.ResourceFactory(plan=plan)
        order_item = factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            resource=resource,
        )

        # Act
        callbacks.resource_creation_succeeded(resource)

        # Assert
        self.assertTrue(
            models.ResourcePlanPeriod.objects.filter(resource=resource,
                                                     plan=plan,
                                                     start=start,
                                                     end=None).exists())

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