Merge "Add nova-manage quota_usage_refresh command"

This commit is contained in:
Jenkins 2016-07-10 06:12:37 +00:00 committed by Gerrit Code Review
commit 66d4ab7579
4 changed files with 80 additions and 0 deletions

View File

@ -105,6 +105,24 @@ Nova Shell
Runs the named script from the specified path with flags set. Runs the named script from the specified path with flags set.
Nova Project
~~~~~~~~~~~~
``nova-manage project quota <project_id> [--user <user_id>] [--key <key>] [--value <value>]``
Create, update or display quotas for project/user. If a key is
not specified then the current usages are displayed.
``nova-manage project quota_usage_refresh <project_id> [--user <user_id>] [--key <key>]``
Refresh the quota usages for the project/user so that the
usage record matches the actual used. If a key is not specified
then all quota usages relevant to the project/user are refreshed.
``nova-manage project scrub <project-id>``
Deletes data associated with project.
Nova VPN Nova VPN
~~~~~~~~ ~~~~~~~~

View File

@ -292,6 +292,30 @@ class ProjectCommands(object):
print(print_format % (key, value['limit'], value['in_use'], print(print_format % (key, value['limit'], value['in_use'],
value['reserved'])) value['reserved']))
@args('--project', dest='project_id', metavar='<Project Id>',
help='Project Id', required=True)
@args('--user', dest='user_id', metavar='<User Id>',
help='User Id')
@args('--key', metavar='<key>', help='Key')
def quota_usage_refresh(self, project_id, user_id=None, key=None):
"""Refresh the quotas for project/user
If no quota key is provided, all the quota usages will be refreshed.
If a valid quota key is provided and it does not exist,
it will be created. Otherwise, it will be refreshed.
"""
ctxt = context.get_admin_context()
keys = None
if key:
keys = [key]
try:
QUOTAS.usage_refresh(ctxt, project_id, user_id, keys)
except exception.QuotaUsageRefreshNotAllowed as e:
print(e.format_message())
return 2
@args('--project', dest='project_id', metavar='<Project name>', @args('--project', dest='project_id', metavar='<Project name>',
help='Project name') help='Project name')
def scrub(self, project_id): def scrub(self, project_id):

View File

@ -391,6 +391,33 @@ class ProjectCommandsTestCase(test.TestCase):
def test_quota_update_invalid_key(self): def test_quota_update_invalid_key(self):
self.assertEqual(2, self.commands.quota('admin', 'volumes1', '10')) self.assertEqual(2, self.commands.quota('admin', 'volumes1', '10'))
def test_quota_usage_refresh_all_user_keys(self):
self.assertIsNone(self.commands.quota_usage_refresh(
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaab'))
def test_quota_usage_refresh_all_project_keys(self):
self.assertIsNone(self.commands.quota_usage_refresh(
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'))
def test_quota_usage_refresh_with_keys(self):
self.assertIsNone(self.commands.quota_usage_refresh(
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaab',
'ram'))
def test_quota_usage_refresh_invalid_user_key(self):
self.assertEqual(2, self.commands.quota_usage_refresh(
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaab',
'fixed_ip'))
def test_quota_usage_refresh_invalid_project_key(self):
self.assertEqual(2, self.commands.quota_usage_refresh(
'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
None,
'ram'))
class VmCommandsTestCase(test.NoDBTestCase): class VmCommandsTestCase(test.NoDBTestCase):
def setUp(self): def setUp(self):

View File

@ -0,0 +1,11 @@
---
features:
- Add a nova-manage command to refresh the quota
usages for a project or user. This can be used
when the usages in the quota-usages database table
are out-of-sync with the actual usages. For example,
if a resource usage is at the limit in the quota_usages
table, but the actual usage is less, then nova will
not allow VMs to be created for that project or user.
The nova-manage command can be used to re-sync
the quota_usages table with the actual usage.