Ejemplo n.º 1
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)
Ejemplo n.º 2
0
    def test_import_limits(self):
        allocation = slurm_factories.AllocationFactory()
        slurm_invoices_factories.SlurmPackageFactory(
            service_settings=allocation.service_settings,
            cpu_price=5,
            gpu_price=15,
            ram_price=30)
        customer = structure_factories.CustomerFactory()

        import_slurm_service_settings(customer)
        import_allocation()

        resource = marketplace_models.Resource.objects.get(scope=allocation)
        self.assertEqual(resource.quotas.count(), 3)
        self.assertEqual(
            resource.quotas.filter(component__type='cpu').get().limit,
            allocation.cpu_limit)
        self.assertEqual(
            resource.quotas.filter(component__type='gpu').get().limit,
            allocation.gpu_limit)
        self.assertEqual(
            resource.quotas.filter(component__type='ram').get().limit,
            allocation.ram_limit)
        self.assertEqual(resource.limits['deposit_limit'],
                         allocation.deposit_limit)
Ejemplo n.º 3
0
    def test_resource_plan_imported_once(self):
        allocation = slurm_factories.AllocationFactory()
        allocation = slurm_factories.AllocationFactory(
            service_project_link=allocation.service_project_link)
        slurm_invoices_factories.SlurmPackageFactory(
            service_settings=allocation.service_settings,
            cpu_price=5,
            gpu_price=15,
            ram_price=30)
        customer = structure_factories.CustomerFactory()

        import_slurm_service_settings(customer)
        import_allocation()

        self.assertEqual(marketplace_models.Plan.objects.count(), 1)
        self.assertEqual(marketplace_models.PlanComponent.objects.count(), 3)
Ejemplo n.º 4
0
 def test_service_settings_import(self):
     allocation = slurm_factories.AllocationFactory()
     customer = structure_factories.CustomerFactory()
     offerings_counter = import_slurm_service_settings(customer)
     self.assertEqual(offerings_counter, 1)
     offering = marketplace_models.Offering.objects.get(type=PLUGIN_NAME)
     self.assertEqual(offering.components.count(), 3)
     self.assertEqual(allocation.service_settings, offering.scope)
     self.assertTrue(offering.components.filter(type='cpu').exists())
     self.assertTrue(offering.components.filter(type='cpu').exists())
     self.assertTrue(offering.components.filter(type='cpu').exists())
Ejemplo n.º 5
0
    def test_allocation_import(self):
        allocation = slurm_factories.AllocationFactory()
        package = slurm_invoices_factories.SlurmPackageFactory(
            service_settings=allocation.service_settings,
            cpu_price=5,
            gpu_price=15,
            ram_price=30,
        )
        allocation_usage = slurm_factories.AllocationUsageFactory(
            allocation=allocation,
            year=allocation.created.year,
            month=allocation.created.month,
            cpu_usage=1,
            gpu_usage=5,
            ram_usage=10,
        )
        customer = structure_factories.CustomerFactory()

        import_slurm_service_settings(customer)
        import_allocation()

        self.assertTrue(
            marketplace_models.Resource.objects.filter(
                scope=allocation).exists())
        self.assertEqual(marketplace_models.Resource.objects.count(), 1)
        resource = marketplace_models.Resource.objects.get(scope=allocation)
        self.assertEqual(
            resource.plan.components.get(component__type='cpu').price,
            package.cpu_price)
        self.assertEqual(
            resource.plan.components.get(component__type='gpu').price,
            package.gpu_price)
        self.assertEqual(
            resource.plan.components.get(component__type='ram').price,
            package.ram_price)
        self.assertEqual(marketplace_models.ComponentUsage.objects.count(), 3)
        self.assertEqual(
            marketplace_models.ComponentUsage.objects.get(
                component__type='cpu').usage,
            allocation_usage.cpu_usage,
        )
        self.assertEqual(
            marketplace_models.ComponentUsage.objects.get(
                component__type='gpu').usage,
            allocation_usage.gpu_usage,
        )
        self.assertEqual(
            marketplace_models.ComponentUsage.objects.get(
                component__type='ram').usage,
            allocation_usage.ram_usage,
        )
Ejemplo n.º 6
0
    def test_dry_run_allocation_import(self):
        allocation = slurm_factories.AllocationFactory()
        slurm_invoices_factories.SlurmPackageFactory(
            service_settings=allocation.service_settings,
            cpu_price=5,
            gpu_price=15,
            ram_price=30)
        customer = structure_factories.CustomerFactory()

        import_slurm_service_settings(customer)
        allocation_counter = import_allocation(True)
        self.assertEqual(allocation_counter, 1)
        self.assertFalse(
            marketplace_models.Resource.objects.filter(
                scope=allocation).exists())
Ejemplo n.º 7
0
    def test_inactive_allocation_import(self):
        allocation = slurm_factories.AllocationFactory(is_active=False)
        slurm_invoices_factories.SlurmPackageFactory(
            service_settings=allocation.service_settings,
            cpu_price=5,
            gpu_price=15,
            ram_price=30)
        customer = structure_factories.CustomerFactory()

        import_slurm_service_settings(customer)
        import_allocation()

        self.assertTrue(
            marketplace_models.Resource.objects.filter(
                scope=allocation).exists())
        self.assertEqual(marketplace_models.Resource.objects.count(), 1)
        resource = marketplace_models.Resource.objects.get(scope=allocation)
        self.assertEqual(resource.state,
                         marketplace_models.Resource.States.TERMINATED)
Ejemplo n.º 8
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,
     )
     for component in manager.get_components(PLUGIN_NAME):
         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,
         )
Ejemplo n.º 9
0
 def test_dry_run_service_settings_import(self):
     slurm_factories.AllocationFactory()
     customer = structure_factories.CustomerFactory()
     offerings_counter = import_slurm_service_settings(customer, True)
     self.assertEqual(offerings_counter, 1)
     self.assertEqual(marketplace_models.Offering.objects.count(), 0)