Example #1
0
 def create_limit(cls, context, project_id, resource, limit, user_id=None):
     try:
         db.quota_get(context, project_id, resource, user_id=user_id)
     except exception.QuotaNotFound:
         cls._create_limit_in_db(context, project_id, resource, limit,
                                 user_id=user_id)
     else:
         raise exception.QuotaExists(project_id=project_id,
                                     resource=resource)
Example #2
0
 def test_user_quotas_update_quota_exist(self, mock_createlimit,
                                           mock_updatelimit):
     body = {'quota_set': {'instances': 1}}
     mock_createlimit.side_effect = exception.QuotaExists(project_id='1',
         resource='dummy')
     url = '/v2/fake4/os-quota-sets/update_me?user_id=1'
     req = fakes.HTTPRequest.blank(url, use_admin_context=True)
     self.controller.update(req, 'update_me', body=body)
     mock_updatelimit.assert_called_once_with(req.environ['nova.context'],
         'update_me', 'instances', 1, user_id='1')
Example #3
0
 def test_user_quotas_update_project_not_exist(self, mock_createlimit,
                                           mock_updatelimit):
     body = {'quota_set': {'instances': 1}}
     mock_createlimit.side_effect = exception.QuotaExists(project_id='1',
         resource='dummy')
     mock_updatelimit.side_effect = exception.ProjectQuotaNotFound(
         project_id='1')
     url = '/v2/fake4/os-quota-sets/update_me?user_id=1'
     req = fakes.HTTPRequest.blank(url, use_admin_context=True)
     ret = self.controller.update(req, 'update_me', body=body)
     mock_updatelimit.assert_called_once_with(req.environ['nova.context'],
         'update_me', 'instances', 1, user_id='1')
     expected_quota_set = quota_set('123', self.include_server_group_quotas)
     expected_quota_set['quota_set'].pop('id')
     self.assertEqual(expected_quota_set, ret)
Example #4
0
 def _create_limit_in_db(context, project_id, resource, limit,
                         user_id=None):
     # TODO(melwitt): We won't have per project resources after nova-network
     # is removed.
     per_user = (user_id and
                 resource not in db_api.quota_get_per_project_resources())
     quota_ref = (api_models.ProjectUserQuota() if per_user
                  else api_models.Quota())
     if per_user:
         quota_ref.user_id = user_id
     quota_ref.project_id = project_id
     quota_ref.resource = resource
     quota_ref.hard_limit = limit
     try:
         quota_ref.save(context.session)
     except db_exc.DBDuplicateEntry:
         raise exception.QuotaExists(project_id=project_id,
                                     resource=resource)
     return quota_ref