Exemple #1
0
 def test_quota_update(self):
     api.quota_create(self.context, 'project1', 'resource1', 41)
     api.quota_update(self.context, 'project1', 'resource1', 42)
     _quota = api.quota_get(self.context, 'project1', 'resource1')
     self.assertEqual(42, _quota.hard_limit)
     self.assertEqual('resource1', _quota.resource)
     self.assertEqual('project1', _quota.project_id)
Exemple #2
0
 def test_quota_get_all_by_project(self):
     for i in range(3):
         for j in range(3):
             api.quota_create(self.context, 'proj%d' % i, 'res%d' % j, j)
     for i in range(3):
         quotas_db = api.quota_get_all_by_project(self.context,
                                                  'proj%d' % i)
         self.assertEqual({'project_id': 'proj%d' % i,
                           'res0': 0,
                           'res1': 1,
                           'res2': 2}, quotas_db)
Exemple #3
0
    def _quota_reserve(self, context, project_id):
        """Create sample Quota, QuotaUsage and Reservation objects.

        There is no method api.quota_usage_create(), so we have to use
        api.quota_reserve() for creating QuotaUsage objects.

        Returns reservations uuids.

        """
        quotas = {}
        resources = {}
        deltas = {}
        for i, resource in enumerate(('volumes', 'gigabytes')):
            quota_obj = api.quota_create(context, project_id, resource, i + 1)
            quotas[resource] = quota_obj.hard_limit
            resources[resource] = quota.ReservableResource(resource, None)
            deltas[resource] = i + 1
        return api.quota_reserve(
            context, resources, quotas, deltas,
            datetime.datetime.utcnow(), datetime.datetime.utcnow(),
            datetime.timedelta(days=1), project_id
        )
Exemple #4
0
 def test_quota_destroy(self):
     api.quota_create(self.context, 'project1', 'resource1', 41)
     self.assertIsNone(api.quota_destroy(self.context, 'project1',
                                         'resource1'))
     self.assertRaises(exceptions.ProjectQuotaNotFound, api.quota_get,
                       self.context, 'project1', 'resource1')
Exemple #5
0
 def test_quota_get(self):
     _quota = api.quota_create(self.context, 'project1', 'resource', 99)
     quota_db = api.quota_get(self.context, 'project1', 'resource')
     self._assertEqualObjects(_quota, quota_db)
Exemple #6
0
 def test_quota_create(self):
     _quota = api.quota_create(self.context, 'project1', 'resource', 99)
     self.assertEqual('resource', _quota.resource)
     self.assertEqual(99, _quota.hard_limit)
     self.assertEqual('project1', _quota.project_id)