def test_volume_type_limits_are_propagated(self): create_offering_components(self.offering) marketplace_models.OfferingComponent.objects.create( offering=self.offering, type='gigabytes_llvm', billing_type=marketplace_models.OfferingComponent.BillingTypes. USAGE, ) response = self.create_order(limits={ 'cores': 2, 'ram': 1024 * 10, 'gigabytes_llvm': 10, }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) order = marketplace_models.Order.objects.get( uuid=response.data['uuid']) serialized_order = core_utils.serialize_instance(order) serialized_user = core_utils.serialize_instance(self.fixture.staff) marketplace_tasks.process_order(serialized_order, serialized_user) tenant = order.items.get().resource.scope self.assertEqual(tenant.quotas.get(name='gigabytes_llvm').limit, 10)
def test_volume_type_limits_are_initialized_with_zero_by_default(self): create_offering_components(self.offering) openstack_factories.VolumeTypeFactory(settings=self.offering.scope, name='llvm') openstack_factories.VolumeTypeFactory(settings=self.offering.scope, name='ssd') openstack_factories.VolumeTypeFactory(settings=self.offering.scope, name='rbd') response = self.create_order(limits={ 'cores': 2, 'ram': 1024 * 10, 'gigabytes_llvm': 10 }) self.assertEqual(response.status_code, status.HTTP_201_CREATED) order = marketplace_models.Order.objects.get( uuid=response.data['uuid']) process_order(order, self.fixture.staff) tenant = order.items.get().resource.scope self.assertEqual(tenant.quotas.get(name='gigabytes_llvm').limit, 10) self.assertEqual(tenant.quotas.get(name='gigabytes_ssd').limit, 0) self.assertEqual(tenant.quotas.get(name='gigabytes_rbd').limit, 0)
def test_limits_are_not_checked_if_offering_components_limits_are_not_defined( self): create_offering_components(self.offering) response = self.create_order(limits={ 'cores': 2, 'ram': 1024 * 10, 'storage': 1024 * 1024 * 10 }) self.assertEqual(response.status_code, status.HTTP_201_CREATED)
def test_cost_estimate_is_calculated_using_limits(self): create_offering_components(self.offering) self.create_plan_component(CORES_TYPE, 1) self.create_plan_component(RAM_TYPE, 0.5) self.create_plan_component(STORAGE_TYPE, 0.1) response = self.create_order( limits={'cores': 20, 'ram': 1024 * 100, 'storage': 1024 * 10000} ) expected = 20 * 1 + 100 * 0.5 + 10000 * 0.1 self.assertEqual(float(response.data['total_cost']), expected)
def test_limits_are_checked_against_offering_components(self): create_offering_components(self.offering) self.offering.components.filter(type=CORES_TYPE).update(max_value=10) self.offering.components.filter(type=RAM_TYPE).update(max_value=1024 * 10) self.offering.components.filter(type=STORAGE_TYPE).update( max_value=1024 * 1024 * 10 ) response = self.create_order( limits={'cores': 20, 'ram': 1024 * 100, 'storage': 1024 * 1024 * 100} ) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
def test_cost_estimate_is_calculated_using_dynamic_storage(self): create_offering_components(self.offering) self.create_plan_component(CORES_TYPE, 1) self.create_plan_component(RAM_TYPE, 0.5) marketplace_models.OfferingComponent.objects.create( offering=self.offering, type='gigabytes_llvm', billing_type=marketplace_models.OfferingComponent.BillingTypes. LIMIT, ) self.create_plan_component('gigabytes_llvm', 0.1) response = self.create_order(limits={ 'cores': 20, 'ram': 1024 * 100, 'gigabytes_llvm': 10000 }) expected = 20 * 1 + 100 * 0.5 + 10000 * 0.1 self.assertEqual(float(response.data['total_cost']), expected)