コード例 #1
0
    def setUp(self):
        self.fixture = fixtures.ServiceFixture()
        self.project = self.fixture.project
        self.plan1 = factories.PlanFactory()
        self.offering = self.plan1.offering
        self.plan2 = factories.PlanFactory(offering=self.offering)

        factories.ResourceFactory.create_batch(
            3,
            project=self.project,
            offering=self.offering,
            plan=self.plan1,
            state=models.Resource.States.OK,
        )

        factories.ResourceFactory.create_batch(
            2,
            project=self.project,
            offering=self.offering,
            plan=self.plan2,
            state=models.Resource.States.OK,
        )

        factories.ResourceFactory.create_batch(
            2,
            project=self.project,
            offering=self.offering,
            plan=self.plan2,
            state=models.Resource.States.TERMINATED,
        )
コード例 #2
0
    def test_when_plan_is_changed_old_period_is_closed_new_is_opened(self):
        # Arrange
        old_start = parse_datetime('2018-10-01')
        new_start = parse_datetime('2018-11-01')

        old_plan = factories.PlanFactory()
        new_plan = factories.PlanFactory()

        resource = factories.ResourceFactory(plan=old_plan)
        old_period = models.ResourcePlanPeriod.objects.create(
            resource=resource, plan=old_plan, start=old_start, end=None)
        order_item = factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            type=models.OrderItem.Types.UPDATE,
            resource=resource,
            plan=new_plan,
        )

        # Act
        callbacks.resource_update_succeeded(resource)

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

        old_period.refresh_from_db()
        self.assertEqual(old_period.end, new_start)

        self.assertTrue(
            models.ResourcePlanPeriod.objects.filter(resource=resource,
                                                     plan=new_plan,
                                                     start=new_start,
                                                     end=None).exists())
コード例 #3
0
    def setUp(self):
        self.provider = marketplace_factories.ServiceProviderFactory()
        self.provider_2 = marketplace_factories.ServiceProviderFactory()

        self.offering = marketplace_factories.OfferingFactory(
            type=PACKAGE_TYPE, customer=self.provider.customer)

        self.offering_component = marketplace_factories.OfferingComponentFactory(
            offering=self.offering)
        self.plan = marketplace_factories.PlanFactory(
            offering=self.offering,
            unit=UnitPriceMixin.Units.PER_DAY,
        )
        self.component = marketplace_factories.PlanComponentFactory(
            component=self.offering_component,
            price=Decimal(5),
            plan=self.plan)

        self.offering_2 = marketplace_factories.OfferingFactory(
            type=PACKAGE_TYPE, customer=self.provider_2.customer)

        self.offering_component_2 = marketplace_factories.OfferingComponentFactory(
            offering=self.offering_2)
        self.plan_2 = marketplace_factories.PlanFactory(
            offering=self.offering_2,
            unit=UnitPriceMixin.Units.PER_DAY,
        )
        self.component_2 = marketplace_factories.PlanComponentFactory(
            component=self.offering_component_2,
            price=Decimal(7),
            plan=self.plan_2)

        self.resource_1 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering,
            plan=self.plan,
            limits={'cpu': 1},
        )

        self.resource_2 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering,
            project=self.resource_1.project,
            plan=self.plan,
            limits={'cpu': 1},
        )

        self.resource_3 = marketplace_factories.ResourceFactory(
            state=marketplace_models.Resource.States.OK,
            offering=self.offering_2,
            project=self.resource_1.project,
            plan=self.plan_2,
            limits={'cpu': 1},
        )

        self.customer = self.resource_1.project.customer
コード例 #4
0
 def setUp(self):
     self.fixture = fixtures.ServiceFixture()
     self.project = self.fixture.project
     self.plan1 = factories.PlanFactory()
     self.offering = self.plan1.offering
     self.plan2 = factories.PlanFactory(offering=self.offering)
     self.resource1 = models.Resource.objects.create(
         project=self.project,
         offering=self.offering,
         plan=self.plan1,
         state=models.Resource.States.OK,
     )
     self.resource2 = models.Resource.objects.create(
         project=self.project, offering=self.offering, plan=self.plan2,
     )
コード例 #5
0
 def setUp(self):
     self.offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE)
     self.plan = marketplace_factories.PlanFactory(offering=self.offering)
     self.limits = {
         RAM_TYPE: 1 * 1024,
         CORES_TYPE: 2,
         STORAGE_TYPE: 3 * 1024,
     }
     self.prices = {
         RAM_TYPE: 10,
         CORES_TYPE: 100,
         STORAGE_TYPE: 1,
     }
     for ct in self.prices.keys():
         marketplace_factories.PlanComponentFactory(
             plan=self.plan,
             component=marketplace_factories.OfferingComponentFactory(
                 offering=self.offering,
                 type=ct,
             ),
             price=self.prices[ct],
         )
     self.resource = marketplace_factories.ResourceFactory(
         offering=self.offering,
         plan=self.plan,
         limits=self.limits,
         state=marketplace_models.Resource.States.OK,
     )
コード例 #6
0
    def test_user_can_not_create_order_with_invalid_limits(self):
        limits = {
            'storage': 1000,
            'ram': 30,
            'cpu_count': 5,
        }

        offering = factories.OfferingFactory(
            state=models.Offering.States.ACTIVE)
        plan = factories.PlanFactory(offering=offering)

        for key in limits.keys():
            models.OfferingComponent.objects.create(
                offering=offering,
                type=key,
                billing_type=models.OfferingComponent.BillingTypes.FIXED,
            )

        add_payload = {
            'items': [
                {
                    'offering': factories.OfferingFactory.get_url(offering),
                    'plan': factories.PlanFactory.get_url(plan),
                    'limits': limits,
                    'attributes': {},
                },
            ]
        }

        response = self.create_order(self.fixture.staff,
                                     offering,
                                     add_payload=add_payload)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #7
0
 def setUp(self):
     fixture = package_fixtures.OpenStackFixture()
     offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE, scope=fixture.openstack_service_settings
     )
     create_offering_components(offering)
     for name in 'Basic', 'Advanced':
         plan = marketplace_factories.PlanFactory(offering=offering, name=name)
         prices = {
             CORES_TYPE: 1,
             RAM_TYPE: 0.1,
             STORAGE_TYPE: 0.01,
         }
         for key, value in prices.items():
             component = marketplace_models.OfferingComponent.objects.get(
                 offering=offering, type=key,
             )
             marketplace_models.PlanComponent.objects.create(
                 plan=plan, component=component, price=value,
             )
         resource = marketplace_factories.ResourceFactory(
             offering=offering, plan=plan,
         )
         marketplace_factories.OrderItemFactory(
             offering=offering, plan=plan, resource=resource,
         )
     self.offering = offering
コード例 #8
0
 def setUp(self):
     self.fixture = openstack_tenant_fixtures.OpenStackTenantFixture()
     self.offering = marketplace_factories.OfferingFactory(
         type=PACKAGE_TYPE)
     self.plan = marketplace_factories.PlanFactory(offering=self.offering)
     self.resource = marketplace_factories.ResourceFactory(
         offering=self.offering,
         project=self.fixture.project,
         plan=self.plan,
         state=marketplace_models.Resource.States.OK)
     tenant = self.fixture.tenant
     self.mock_get_backend = mock.MagicMock()
     tenant.get_backend = self.mock_get_backend
     self.resource.scope = tenant
     self.resource.save()
     self.quotas = {
         'network_count': 100,
         'cores': 4,
         'ram': 1024,
         'storage': 1024,
         'snapshots': 50,
         'instances': 30,
         'floating_ip_count': 50,
         'subnet_count': 100,
         'volumes': 50,
         'security_group_rule_count': 100,
         'security_group_count': 100
     }
コード例 #9
0
    def test_plan_switch_cost_is_added_to_cost_estimate_for_order_item(self):
        # Arrange
        offering = factories.OfferingFactory(type='Support.OfferingTemplate')
        switch_offering_component = factories.OfferingComponentFactory(
            offering=offering,
            billing_type=models.OfferingComponent.BillingTypes.ON_PLAN_SWITCH,
            type='plan_switch',
        )
        usage_offering_component = factories.OfferingComponentFactory(
            offering=offering,
            billing_type=models.OfferingComponent.BillingTypes.USAGE,
            type='cpu',
        )

        plan = factories.PlanFactory()
        factories.PlanComponentFactory(
            plan=plan, component=switch_offering_component, price=50
        )
        factories.PlanComponentFactory(
            plan=plan, component=usage_offering_component, price=10
        )

        order_item = factories.OrderItemFactory(
            offering=offering, plan=plan, type=models.OrderItem.Types.UPDATE,
        )
        order_item.init_cost()
        self.assertEqual(order_item.cost, 50)
コード例 #10
0
    def test_initialization_cost_is_added_to_cost_estimate_for_creation_request(self):
        # Arrange
        offering = factories.OfferingFactory(type='Support.OfferingTemplate')
        one_time_offering_component = factories.OfferingComponentFactory(
            offering=offering,
            billing_type=models.OfferingComponent.BillingTypes.ONE_TIME,
            type='signup',
        )
        usage_offering_component = factories.OfferingComponentFactory(
            offering=offering,
            billing_type=models.OfferingComponent.BillingTypes.USAGE,
            type='cpu',
        )

        plan = factories.PlanFactory()
        factories.PlanComponentFactory(
            plan=plan, component=one_time_offering_component, price=100
        )
        factories.PlanComponentFactory(
            plan=plan, component=usage_offering_component, price=10
        )

        order_item = factories.OrderItemFactory(offering=offering, plan=plan,)
        order_item.init_cost()
        self.assertEqual(order_item.cost, 100)
コード例 #11
0
    def test_when_resource_is_terminated_old_period_is_closed(self):
        # Arrange
        start = parse_datetime('2018-10-01')
        end = parse_datetime('2018-11-01')

        plan = factories.PlanFactory()
        resource = factories.ResourceFactory(plan=plan)

        period = models.ResourcePlanPeriod.objects.create(resource=resource,
                                                          plan=plan,
                                                          start=start,
                                                          end=None)
        order_item = factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            type=models.OrderItem.Types.TERMINATE,
            resource=resource,
            plan=plan,
        )

        # Act
        callbacks.resource_deletion_succeeded(resource)

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

        period.refresh_from_db()
        self.assertEqual(period.end, end)
コード例 #12
0
    def test_limits_are_not_allowed_for_components_with_disabled_quotas(self):
        limits = {
            'storage': 1000,
            'ram': 30,
            'cpu_count': 5,
        }

        plan = factories.PlanFactory(offering=self.offering)

        for key in limits.keys():
            models.OfferingComponent.objects.create(
                offering=self.offering,
                type=key,
                billing_type=models.OfferingComponent.BillingTypes.USAGE,
            )

        payload = {
            'offering': factories.OfferingFactory.get_url(self.offering),
            'plan': factories.PlanFactory.get_url(plan),
            'limits': limits,
        }

        self.client.force_authenticate(self.fixture.staff)

        url = factories.CartItemFactory.get_list_url()
        response = self.client.post(url, payload)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #13
0
    def get_payload(self, project):
        limits = {
            'storage': 1000,
            'ram': 30,
            'cpu_count': 5,
        }

        plan = factories.PlanFactory(offering=self.offering)

        for key in limits.keys():
            models.OfferingComponent.objects.create(
                offering=self.offering,
                type=key,
                billing_type=models.OfferingComponent.BillingTypes.LIMIT,
            )

        return {
            'offering': factories.OfferingFactory.get_url(self.offering),
            'plan': factories.PlanFactory.get_url(plan),
            'project': structure_factories.ProjectFactory.get_url(project),
            'limits': limits,
            'attributes': {
                'name': 'test'
            },
        }
コード例 #14
0
    def setUp(self):
        fixture = structure_fixtures.ProjectFixture()
        service_settings = structure_factories.ServiceSettingsFactory(type='SLURM')
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME, scope=service_settings)
        plan = marketplace_factories.PlanFactory(offering=offering)
        self.allocation = slurm_factories.AllocationFactory()
        self.resource = marketplace_models.Resource.objects.create(
            scope=self.allocation,
            offering=offering,
            plan=plan,
            project=fixture.project,
        )
        self.plan_period = marketplace_models.ResourcePlanPeriod.objects.create(
            resource=self.resource,
            plan=plan,
            start=timezone.make_aware(datetime.datetime.now())
        )
        for component in manager.get_components(PLUGIN_NAME):
            offering_component = marketplace_models.OfferingComponent.objects.create(
                offering=offering,
                type=component.type,
                name=component.name,
                measured_unit=component.measured_unit,
                billing_type=marketplace_models.OfferingComponent.BillingTypes.USAGE,
            )
            marketplace_models.PlanComponent.objects.create(
                component=offering_component,
                plan=plan,
                price=3
            )

        marketplace_models.ResourcePlanPeriod.objects.create(
            start=datetime.date(2017, 1, 1),
            resource=self.resource,
            plan=plan)
コード例 #15
0
    def test_when_order_item_is_approved_openstack_tenant_is_created(self):
        # Arrange
        fixture = package_fixtures.PackageFixture()
        offering = marketplace_factories.OfferingFactory(
            scope=fixture.openstack_service_settings, type=PLUGIN_NAME)
        order = marketplace_factories.OrderFactory(
            state=marketplace_models.Order.States.REQUESTED_FOR_APPROVAL,
            project=fixture.project,
        )
        plan = marketplace_factories.PlanFactory(
            scope=fixture.openstack_template)
        attributes = dict(
            name='My first VPC',
            description='Database cluster',
            user_username='******',
        )
        order_item = marketplace_factories.OrderItemFactory(
            order=order, offering=offering, attributes=attributes, plan=plan)

        serialized_order = core_utils.serialize_instance(order)
        serialized_user = core_utils.serialize_instance(fixture.staff)
        marketplace_tasks.process_order(serialized_order, serialized_user)

        # Assert
        order_item.refresh_from_db()
        self.assertTrue(isinstance(order_item.scope, openstack_models.Tenant))
コード例 #16
0
    def test_when_limits_are_updated_estimate_is_recalculated(self):
        # Arrange
        oc = factories.OfferingComponentFactory(
            offering=self.cart_item.offering,
            billing_type=models.OfferingComponent.BillingTypes.LIMIT,
            type='cpu',
        )
        plan = factories.PlanFactory(offering=self.cart_item.offering)
        factories.PlanComponentFactory(
            plan=plan,
            component=oc,
            price=10,
        )
        self.cart_item.limits = {'cpu': 2}
        self.cart_item.plan = plan
        self.cart_item.save()

        # Act
        self.client.force_authenticate(self.cart_item.user)
        url = factories.CartItemFactory.get_url(item=self.cart_item)
        response = self.client.patch(url, {'limits': {'cpu': 4}})
        self.assertEqual(response.status_code, status.HTTP_200_OK,
                         response.data)
        self.cart_item.refresh_from_db()

        # Assert
        self.assertEqual(self.cart_item.cost, 4 * 10)
コード例 #17
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)
コード例 #18
0
    def setUp(self):
        fixture = slurm_fixtures.SlurmFixture()
        service_settings = fixture.service.settings
        offering = marketplace_factories.OfferingFactory(
            type=PLUGIN_NAME, scope=service_settings)
        plan = marketplace_factories.PlanFactory(offering=offering)
        order = marketplace_factories.OrderFactory(
            project=fixture.project,
            state=marketplace_models.Order.States.EXECUTING)
        order_item = marketplace_factories.OrderItemFactory(
            order=order,
            offering=offering,
            limits={
                component.type: 10
                for component in manager.get_components(PLUGIN_NAME)
            })
        for component in manager.get_components(PLUGIN_NAME):
            component = marketplace_models.OfferingComponent.objects.create(
                offering=offering,
                type=component.type,
                name=component.name,
                measured_unit=component.measured_unit,
            )
            marketplace_models.PlanComponent.objects.create(
                plan=plan,
                component=component,
            )

        # Create SPL
        fixture.spl
        self.fixture = fixture
        self.order_item = order_item
        self.offering = offering
コード例 #19
0
 def setUp(self):
     self.fixture = fixtures.ServiceFixture()
     self.project = self.fixture.project
     self.plan = factories.PlanFactory()
     self.offering = self.plan.offering
     self.resource = models.Resource.objects.create(
         project=self.project, offering=self.offering, plan=self.plan,
     )
コード例 #20
0
 def new_plan(self):
     new_plan = marketplace_factories.PlanFactory(
         offering=self.offering,
         unit_price=0,
         name='Small plan',
         unit=marketplace_models.Plan.Units.PER_MONTH,
     )
     return new_plan
コード例 #21
0
 def plan(self):
     plan = marketplace_factories.PlanFactory(
         offering=self.offering,
         name='Standard plan',
         unit_price=0,
         unit=marketplace_models.Plan.Units.PER_MONTH,
     )
     return plan
コード例 #22
0
    def test_plan_switch_is_not_available_if_plan_is_related_to_another_offering(self):
        # Act
        response = self.switch_plan(
            self.fixture.owner, self.resource1, factories.PlanFactory()
        )

        # Assert
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
コード例 #23
0
 def setUp(self):
     super(RequestSwitchPlanTest, self).setUp()
     self.plan = marketplace_factories.PlanFactory(offering=self.offering,
                                                   unit_price=50)
     marketplace_factories.PlanComponentFactory(
         plan=self.plan,
         component=self.offering_component,
         price=Decimal(50))
コード例 #24
0
 def setUp(self):
     super(RequestUpdateTest, self).setUp()
     self.fixture = MarketplaceSupportApprovedFixture()
     self.resource = self.fixture.resource
     self.resource.state = marketplace_models.Resource.States.OK
     self.resource.save()
     self.new_plan = marketplace_factories.PlanFactory(
         offering=self.fixture.marketplace_offering
     )
コード例 #25
0
    def test_offering_plan_is_created(self):
        offering = marketplace_factories.OfferingFactory(type=PLUGIN_NAME)
        plan = marketplace_factories.PlanFactory(offering=offering)
        plan.refresh_from_db()

        self.assertTrue(isinstance(plan.scope, support_models.OfferingPlan))
        self.assertEqual(plan.unit_price, plan.scope.unit_price)
        self.assertTrue(plan.unit, plan.scope.unit)
        self.assertTrue(plan.name, plan.scope.name)
コード例 #26
0
 def setUp(self):
     super(TenantCreateTest, self).setUp()
     self.fixture = package_fixtures.MarketplaceOpenStackFixture()
     self.offering = marketplace_factories.OfferingFactory(
         scope=self.fixture.openstack_service_settings,
         type=TENANT_TYPE,
         state=marketplace_models.Offering.States.ACTIVE,
         plugin_options={'storage_mode': STORAGE_MODE_DYNAMIC},
     )
     self.plan = marketplace_factories.PlanFactory(offering=self.offering)
コード例 #27
0
 def setUp(self):
     super(TenantCreateTest, self).setUp()
     self.fixture = package_fixtures.PackageFixture()
     self.offering = marketplace_factories.OfferingFactory(
         scope=self.fixture.openstack_service_settings,
         type=PACKAGE_TYPE,
         state=marketplace_models.Offering.States.ACTIVE,
     )
     self.plan = marketplace_factories.PlanFactory(
         scope=self.fixture.openstack_template, offering=self.offering)
コード例 #28
0
    def test_when_plan_is_switched_cost_estimate_is_updated(self):
        # Arrange
        old_plan = factories.PlanFactory(unit_price=10)
        new_plan = factories.PlanFactory(unit_price=100)
        resource = factories.ResourceFactory(plan=old_plan)

        factories.OrderItemFactory(
            state=models.OrderItem.States.EXECUTING,
            type=models.OrderItem.Types.UPDATE,
            resource=resource,
            plan=new_plan,
        )

        # Act
        callbacks.resource_update_succeeded(resource)
        resource.refresh_from_db()

        # Assert
        self.assertEqual(resource.cost, new_plan.unit_price)
コード例 #29
0
 def create_plan(self, prices, unit=marketplace_models.Plan.Units.PER_DAY):
     plan = marketplace_factories.PlanFactory(offering=self.offering,
                                              unit=unit)
     for ct in prices.keys():
         marketplace_factories.PlanComponentFactory(
             plan=plan,
             component=self.offering.components.get(type=ct),
             price=prices[ct],
         )
     return plan
コード例 #30
0
 def setUp(self):
     self.fixture = structure_fixtures.ServiceFixture()
     self.project = self.fixture.project
     self.customer = self.fixture.customer
     self.plan = factories.PlanFactory()
     self.resource = models.Resource.objects.create(
         project=self.project,
         offering=self.plan.offering,
         plan=self.plan,
     )
     self.category = self.plan.offering.category