Esempio n. 1
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)
 def setUp(self):
     self.fixture = slurm_fixtures.SlurmFixture()
     self.package = slurm_factories.SlurmPackageFactory(
         service_settings=self.fixture.service.settings)
     self.invoice = factories.InvoiceFactory(customer=self.fixture.customer)
     self.scope = self.fixture.allocation
     self.item = models.GenericInvoiceItem.objects.filter(
         scope=self.scope).get()
Esempio n. 3
0
 def setUp(self):
     self.fixture = slurm_fixtures.SlurmFixture()
     self.package = slurm_factories.SlurmPackageFactory(service_settings=self.fixture.service.settings)
     self.invoice = factories.InvoiceFactory(customer=self.fixture.customer)
     self.scope = self.fixture.allocation
     self.item = models.InvoiceItem.objects.filter(scope=self.scope).get()
     self.item.unit = models.InvoiceItem.Units.QUANTITY
     self.item.quantity = 10
     self.item.unit_price = 10
     self.item.save()
Esempio n. 4
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,
        )
Esempio n. 5
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())
Esempio n. 6
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)
Esempio 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)