def setUp(self): super(NestedQuotasTest, self).setUp() self.api.create_type(self._vol_type_name) fake_driver.LoggingVolumeDriver.clear_logs() self._create_project_hierarchy() # Need to mock out Keystone so the functional tests don't require other # services _keystone_client = mock.MagicMock() _keystone_client.version = 'v3' _keystone_client.projects.get.side_effect = self._get_project _keystone_client_get = mock.patch( 'cinder.quota_utils._keystone_client', lambda *args, **kwargs: _keystone_client) _keystone_client_get.start() self.addCleanup(_keystone_client_get.stop) # The QUOTA engine in Cinder is a global variable that lazy loads the # quota driver, so even if we change the config for the quota driver, # we won't reliably change the driver being used (or change it back) # unless the global variables get cleaned up, so using mock instead to # simulate this change nested_driver = quota.NestedDbQuotaDriver() _driver_patcher = mock.patch( 'cinder.quota.QuotaEngine._driver', new=nested_driver) _driver_patcher.start() self.addCleanup(_driver_patcher.stop) # Default to using the top parent in the hierarchy self._update_project(self.A.id)
def validate_setup_for_nested_quota_use(self, req): """Validates that the setup supports using nested quotas. Ensures that Keystone v3 or greater is being used, and that the existing quotas make sense to nest in the current hierarchy (e.g. that no child quota would be larger than it's parent). """ ctxt = req.environ['cinder.context'] ctxt.authorize(policy.VALIDATE_NESTED_QUOTA_POLICY) params = req.params try: resources = QUOTAS.resources resources.update(GROUP_QUOTAS.resources) allocated = params.get('fix_allocated_quotas', 'False') try: fix_allocated = strutils.bool_from_string(allocated, strict=True) except ValueError: msg = _("Invalid param 'fix_allocated_quotas':%s") % allocated raise webob.exc.HTTPBadRequest(explanation=msg) quota_utils.validate_setup_for_nested_quota_use( ctxt, resources, quota.NestedDbQuotaDriver(), fix_allocated_quotas=fix_allocated) except exception.InvalidNestedQuotaSetup as e: raise webob.exc.HTTPBadRequest(explanation=e.msg)
def setUp(self): super(QuotaSetsControllerNestedQuotasTest, self).setUp() driver = quota.NestedDbQuotaDriver() patcher = mock.patch('cinder.quota.VolumeTypeQuotaEngine._driver', driver) patcher.start() self.addCleanup(patcher.stop)
def validate_setup_for_nested_quota_use(self, req): """Validates that the setup supports using nested quotas. Ensures that Keystone v3 or greater is being used, and that the existing quotas make sense to nest in the current hierarchy (e.g. that no child quota would be larger than it's parent). """ ctxt = req.environ['cinder.context'] params = req.params try: quota_utils.validate_setup_for_nested_quota_use( ctxt, QUOTAS.resources, quota.NestedDbQuotaDriver(), fix_allocated_quotas=params.get('fix_allocated_quotas')) except exception.InvalidNestedQuotaSetup as e: raise webob.exc.HTTPBadRequest(explanation=e.msg)