Add support for snapshot quotas.
Now we have [volumes, gigabyes, snapshots] as valid tenant quotas. Change-Id: Iae8a86b31e63b9e56d6ef0bee7e03f4089aa8138
This commit is contained in:
		@@ -36,11 +36,12 @@ class QuotaSetManager(base.ManagerWithFind):
 | 
			
		||||
            tenant_id = tenant_id.tenant_id
 | 
			
		||||
        return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
 | 
			
		||||
 | 
			
		||||
    def update(self, tenant_id, volumes=None, gigabytes=None):
 | 
			
		||||
    def update(self, tenant_id, volumes=None, snapshots=None, gigabytes=None):
 | 
			
		||||
 | 
			
		||||
        body = {'quota_set': {
 | 
			
		||||
                'tenant_id': tenant_id,
 | 
			
		||||
                'volumes': volumes,
 | 
			
		||||
                'snapshots': snapshots,
 | 
			
		||||
                'gigabytes': gigabytes}}
 | 
			
		||||
 | 
			
		||||
        for key in body['quota_set'].keys():
 | 
			
		||||
 
 | 
			
		||||
@@ -500,7 +500,7 @@ def do_credentials(cs, args):
 | 
			
		||||
    utils.print_dict(catalog['access']['user'], "User Credentials")
 | 
			
		||||
    utils.print_dict(catalog['access']['token'], "Token")
 | 
			
		||||
 | 
			
		||||
_quota_resources = ['volumes', 'gigabytes']
 | 
			
		||||
_quota_resources = ['volumes', 'snapshots', 'gigabytes']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _quota_show(quotas):
 | 
			
		||||
@@ -545,6 +545,10 @@ def do_quota_defaults(cs, args):
 | 
			
		||||
           metavar='<volumes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "volumes" quota.')
 | 
			
		||||
@utils.arg('--snapshots',
 | 
			
		||||
           metavar='<snapshots>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "snapshots" quota.')
 | 
			
		||||
@utils.arg('--gigabytes',
 | 
			
		||||
           metavar='<gigabytes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
@@ -571,6 +575,10 @@ def do_quota_class_show(cs, args):
 | 
			
		||||
           metavar='<volumes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "volumes" quota.')
 | 
			
		||||
@utils.arg('--snapshots',
 | 
			
		||||
           metavar='<snapshots>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "snapshots" quota.')
 | 
			
		||||
@utils.arg('--gigabytes',
 | 
			
		||||
           metavar='<gigabytes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
 
 | 
			
		||||
@@ -35,11 +35,12 @@ class QuotaSetManager(base.ManagerWithFind):
 | 
			
		||||
            tenant_id = tenant_id.tenant_id
 | 
			
		||||
        return self._get("/os-quota-sets/%s" % (tenant_id), "quota_set")
 | 
			
		||||
 | 
			
		||||
    def update(self, tenant_id, volumes=None, gigabytes=None):
 | 
			
		||||
    def update(self, tenant_id, volumes=None, snapshots=None, gigabytes=None):
 | 
			
		||||
 | 
			
		||||
        body = {'quota_set': {
 | 
			
		||||
                'tenant_id': tenant_id,
 | 
			
		||||
                'volumes': volumes,
 | 
			
		||||
                'snapshots': snapshots,
 | 
			
		||||
                'gigabytes': gigabytes}}
 | 
			
		||||
 | 
			
		||||
        for key in body['quota_set'].keys():
 | 
			
		||||
 
 | 
			
		||||
@@ -544,7 +544,7 @@ def do_credentials(cs, args):
 | 
			
		||||
    utils.print_dict(catalog['access']['user'], "User Credentials")
 | 
			
		||||
    utils.print_dict(catalog['access']['token'], "Token")
 | 
			
		||||
 | 
			
		||||
_quota_resources = ['volumes', 'gigabytes']
 | 
			
		||||
_quota_resources = ['volumes', 'snapshots', 'gigabytes']
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def _quota_show(quotas):
 | 
			
		||||
@@ -592,6 +592,10 @@ def do_quota_defaults(cs, args):
 | 
			
		||||
           metavar='<volumes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "volumes" quota.')
 | 
			
		||||
@utils.arg('--snapshots',
 | 
			
		||||
           metavar='<snapshots>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "snapshots" quota.')
 | 
			
		||||
@utils.arg('--gigabytes',
 | 
			
		||||
           metavar='<gigabytes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
@@ -620,6 +624,10 @@ def do_quota_class_show(cs, args):
 | 
			
		||||
           metavar='<volumes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "volumes" quota.')
 | 
			
		||||
@utils.arg('--snapshots',
 | 
			
		||||
           metavar='<snapshots>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
           help='New value for the "snapshots" quota.')
 | 
			
		||||
@utils.arg('--gigabytes',
 | 
			
		||||
           metavar='<gigabytes>',
 | 
			
		||||
           type=int, default=None,
 | 
			
		||||
 
 | 
			
		||||
@@ -196,6 +196,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def get_os_quota_sets_test_defaults(self):
 | 
			
		||||
@@ -203,6 +204,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def put_os_quota_sets_test(self, body, **kw):
 | 
			
		||||
@@ -213,6 +215,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 2,
 | 
			
		||||
                          'snapshots': 2,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
@@ -224,6 +227,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'class_name': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def put_os_quota_class_sets_test(self, body, **kw):
 | 
			
		||||
@@ -234,6 +238,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'class_name': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 2,
 | 
			
		||||
                          'snapshots': 2,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
 
 | 
			
		||||
@@ -35,13 +35,18 @@ class QuotaSetsTest(utils.TestCase):
 | 
			
		||||
    def test_update_quota(self):
 | 
			
		||||
        q = cs.quotas.get('test')
 | 
			
		||||
        q.update(volumes=2)
 | 
			
		||||
        q.update(snapshots=2)
 | 
			
		||||
        cs.assert_called('PUT', '/os-quota-sets/test')
 | 
			
		||||
 | 
			
		||||
    def test_refresh_quota(self):
 | 
			
		||||
        q = cs.quotas.get('test')
 | 
			
		||||
        q2 = cs.quotas.get('test')
 | 
			
		||||
        self.assertEqual(q.volumes, q2.volumes)
 | 
			
		||||
        self.assertEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
        q2.volumes = 0
 | 
			
		||||
        self.assertNotEqual(q.volumes, q2.volumes)
 | 
			
		||||
        q2.snapshots = 0
 | 
			
		||||
        self.assertNotEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
        q2.get()
 | 
			
		||||
        self.assertEqual(q.volumes, q2.volumes)
 | 
			
		||||
        self.assertEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
 
 | 
			
		||||
@@ -203,6 +203,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def get_os_quota_sets_test_defaults(self):
 | 
			
		||||
@@ -210,6 +211,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def put_os_quota_sets_test(self, body, **kw):
 | 
			
		||||
@@ -220,6 +222,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'tenant_id': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 2,
 | 
			
		||||
                          'snapshots': 2,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
@@ -231,6 +234,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'class_name': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 1,
 | 
			
		||||
                          'snapshots': 1,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    def put_os_quota_class_sets_test(self, body, **kw):
 | 
			
		||||
@@ -241,6 +245,7 @@ class FakeHTTPClient(base_client.HTTPClient):
 | 
			
		||||
                          'class_name': 'test',
 | 
			
		||||
                          'metadata_items': [],
 | 
			
		||||
                          'volumes': 2,
 | 
			
		||||
                          'snapshots': 2,
 | 
			
		||||
                          'gigabytes': 1}})
 | 
			
		||||
 | 
			
		||||
    #
 | 
			
		||||
 
 | 
			
		||||
@@ -35,13 +35,18 @@ class QuotaSetsTest(utils.TestCase):
 | 
			
		||||
    def test_update_quota(self):
 | 
			
		||||
        q = cs.quotas.get('test')
 | 
			
		||||
        q.update(volumes=2)
 | 
			
		||||
        q.update(snapshots=2)
 | 
			
		||||
        cs.assert_called('PUT', '/os-quota-sets/test')
 | 
			
		||||
 | 
			
		||||
    def test_refresh_quota(self):
 | 
			
		||||
        q = cs.quotas.get('test')
 | 
			
		||||
        q2 = cs.quotas.get('test')
 | 
			
		||||
        self.assertEqual(q.volumes, q2.volumes)
 | 
			
		||||
        self.assertEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
        q2.volumes = 0
 | 
			
		||||
        self.assertNotEqual(q.volumes, q2.volumes)
 | 
			
		||||
        q2.snapshots = 0
 | 
			
		||||
        self.assertNotEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
        q2.get()
 | 
			
		||||
        self.assertEqual(q.volumes, q2.volumes)
 | 
			
		||||
        self.assertEqual(q.snapshots, q2.snapshots)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user