コード例 #1
0
    def update_usage(self, cpu_usage=6001, gpu_usage=12001, ram_usage=2048):
        allocation = self.fixture.allocation
        allocation.cpu_usage = cpu_usage
        allocation.gpu_usage = gpu_usage
        allocation.ram_usage = ram_usage  # in MB
        allocation.save()
        now = timezone.now()
        existing_usage = slurm_models.AllocationUsage.objects.filter(
            allocation=allocation,
            month=now.month,
            year=now.year,
        ).first()

        if existing_usage:
            existing_usage.cpu_usage = allocation.cpu_usage
            existing_usage.gpu_usage = allocation.gpu_usage
            existing_usage.ram_usage = allocation.ram_usage
            existing_usage.save()
            return existing_usage

        allocation_usage = slurm_factories.AllocationUsageFactory(
            allocation=allocation,
            cpu_usage=allocation.cpu_usage,
            gpu_usage=allocation.gpu_usage,
            ram_usage=allocation.ram_usage,
            month=now.month,
            year=now.year,
        )
        return allocation_usage
コード例 #2
0
 def test_not_create_component_usage_if_create_other_allocation_usage(self):
     slurm_factories.AllocationUsageFactory()
     self.assertFalse(marketplace_models.ComponentUsage.objects
                      .filter(resource=self.resource, component__type='cpu').exists())
     self.assertFalse(marketplace_models.ComponentUsage.objects
                      .filter(resource=self.resource, component__type='gpu').exists())
     self.assertFalse(marketplace_models.ComponentUsage.objects
                      .filter(resource=self.resource, component__type='ram').exists())
コード例 #3
0
 def test_create_component_usage(self):
     slurm_factories.AllocationUsageFactory(allocation=self.allocation, year=2017, month=1)
     self.assertTrue(marketplace_models.ComponentUsage.objects
                     .filter(resource=self.resource, component__type='cpu').exists())
     self.assertTrue(marketplace_models.ComponentUsage.objects
                     .filter(resource=self.resource, component__type='gpu').exists())
     self.assertTrue(marketplace_models.ComponentUsage.objects
                     .filter(resource=self.resource, component__type='ram').exists())
コード例 #4
0
ファイル: test_import.py プロジェクト: yyri/waldur-mastermind
    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,
        )