Fix openstack quota set/show --class not work
identity_client should not be used for quota class operation. Update code to fix the qutoa class set/show issue. Change-Id: I71c59c08a0d5da29982497f589e1efe131997f21 Closes-Bug: #1609233
This commit is contained in:
parent
6f326acd26
commit
2a01ede6b6
@ -154,36 +154,34 @@ class SetQuota(command.Command):
|
||||
if value is not None:
|
||||
compute_kwargs[k] = value
|
||||
|
||||
if parsed_args.project:
|
||||
project = utils.find_resource(
|
||||
identity_client.projects,
|
||||
parsed_args.project,
|
||||
)
|
||||
|
||||
if parsed_args.quota_class:
|
||||
if compute_kwargs:
|
||||
compute_client.quota_classes.update(
|
||||
project.id,
|
||||
parsed_args.project,
|
||||
**compute_kwargs)
|
||||
if volume_kwargs:
|
||||
volume_client.quota_classes.update(
|
||||
project.id,
|
||||
parsed_args.project,
|
||||
**volume_kwargs)
|
||||
if network_kwargs:
|
||||
sys.stderr.write("Network quotas are ignored since quota class"
|
||||
"is not supported.")
|
||||
else:
|
||||
project = utils.find_resource(
|
||||
identity_client.projects,
|
||||
parsed_args.project,
|
||||
).id
|
||||
if compute_kwargs:
|
||||
compute_client.quotas.update(
|
||||
project.id,
|
||||
project,
|
||||
**compute_kwargs)
|
||||
if volume_kwargs:
|
||||
volume_client.quotas.update(
|
||||
project.id,
|
||||
project,
|
||||
**volume_kwargs)
|
||||
if network_kwargs:
|
||||
network_client.update_quota(
|
||||
project.id,
|
||||
project,
|
||||
**network_kwargs)
|
||||
|
||||
|
||||
@ -230,15 +228,15 @@ class ShowQuota(command.ShowOne):
|
||||
return project
|
||||
|
||||
def get_compute_volume_quota(self, client, parsed_args):
|
||||
project = self._get_project(parsed_args)
|
||||
|
||||
try:
|
||||
if parsed_args.quota_class:
|
||||
quota = client.quota_classes.get(project)
|
||||
elif parsed_args.default:
|
||||
quota = client.quotas.defaults(project)
|
||||
quota = client.quota_classes.get(parsed_args.project)
|
||||
else:
|
||||
quota = client.quotas.get(project)
|
||||
project = self._get_project(parsed_args)
|
||||
if parsed_args.default:
|
||||
quota = client.quotas.defaults(project)
|
||||
else:
|
||||
quota = client.quotas.get(project)
|
||||
except Exception as e:
|
||||
if type(e).__name__ == 'EndpointNotFound':
|
||||
return {}
|
||||
|
@ -26,8 +26,8 @@ class QuotaTests(base.TestCase):
|
||||
cls.get_openstack_configuration_value('auth.project_name')
|
||||
|
||||
def test_quota_set(self):
|
||||
self.openstack('quota set --instances 11 --volumes 11 --networks 11 '
|
||||
+ self.PROJECT_NAME)
|
||||
self.openstack('quota set --instances 11 --volumes 11 --networks 11 ' +
|
||||
self.PROJECT_NAME)
|
||||
opts = self.get_opts(self.EXPECTED_FIELDS)
|
||||
raw_output = self.openstack('quota show ' + self.PROJECT_NAME + opts)
|
||||
self.assertEqual("11\n11\n11\n", raw_output)
|
||||
@ -51,3 +51,12 @@ class QuotaTests(base.TestCase):
|
||||
raw_output = self.openstack('quota show --class')
|
||||
for expected_field in self.EXPECTED_CLASS_FIELDS:
|
||||
self.assertIn(expected_field, raw_output)
|
||||
|
||||
def test_quota_class_set(self):
|
||||
class_name = 'default'
|
||||
class_expected_fields = ['instances', 'volumes']
|
||||
self.openstack('quota set --instances 11 --volumes 11 --class ' +
|
||||
class_name)
|
||||
opts = self.get_opts(class_expected_fields)
|
||||
raw_output = self.openstack('quota show --class ' + class_name + opts)
|
||||
self.assertEqual("11\n11\n", raw_output)
|
||||
|
@ -82,6 +82,18 @@ class TestQuotaSet(TestQuota):
|
||||
loaded=True,
|
||||
)
|
||||
|
||||
self.quotas_class_mock.update.return_value = FakeQuotaResource(
|
||||
None,
|
||||
copy.deepcopy(compute_fakes.QUOTA),
|
||||
loaded=True,
|
||||
)
|
||||
|
||||
self.volume_quotas_class_mock.update.return_value = FakeQuotaResource(
|
||||
None,
|
||||
copy.deepcopy(compute_fakes.QUOTA),
|
||||
loaded=True,
|
||||
)
|
||||
|
||||
self.network_mock = self.app.client_manager.network
|
||||
self.network_mock.update_quota = mock.Mock()
|
||||
|
||||
@ -294,27 +306,72 @@ class TestQuotaSet(TestQuota):
|
||||
|
||||
def test_quota_set_with_class(self):
|
||||
arglist = [
|
||||
'--injected-files', str(compute_fakes.injected_file_num),
|
||||
'--injected-file-size', str(compute_fakes.injected_file_size_num),
|
||||
'--injected-path-size', str(compute_fakes.injected_path_size_num),
|
||||
'--key-pairs', str(compute_fakes.key_pair_num),
|
||||
'--cores', str(compute_fakes.core_num),
|
||||
'--ram', str(compute_fakes.ram_num),
|
||||
'--instances', str(compute_fakes.instance_num),
|
||||
'--properties', str(compute_fakes.property_num),
|
||||
'--server-groups', str(compute_fakes.servgroup_num),
|
||||
'--server-group-members', str(compute_fakes.servgroup_members_num),
|
||||
'--gigabytes', str(compute_fakes.floating_ip_num),
|
||||
'--snapshots', str(compute_fakes.fix_ip_num),
|
||||
'--volumes', str(volume_fakes.QUOTA['volumes']),
|
||||
'--network', str(network_fakes.QUOTA['network']),
|
||||
'--class',
|
||||
identity_fakes.project_name,
|
||||
'--class', identity_fakes.project_name,
|
||||
]
|
||||
verifylist = [
|
||||
('injected_files', compute_fakes.injected_file_num),
|
||||
('injected_file_content_bytes',
|
||||
compute_fakes.injected_file_size_num),
|
||||
('injected_file_path_bytes', compute_fakes.injected_path_size_num),
|
||||
('key_pairs', compute_fakes.key_pair_num),
|
||||
('cores', compute_fakes.core_num),
|
||||
('ram', compute_fakes.ram_num),
|
||||
('instances', compute_fakes.instance_num),
|
||||
('metadata_items', compute_fakes.property_num),
|
||||
('server_groups', compute_fakes.servgroup_num),
|
||||
('server_group_members', compute_fakes.servgroup_members_num),
|
||||
('gigabytes', compute_fakes.floating_ip_num),
|
||||
('snapshots', compute_fakes.fix_ip_num),
|
||||
('volumes', volume_fakes.QUOTA['volumes']),
|
||||
('network', network_fakes.QUOTA['network']),
|
||||
('project', identity_fakes.project_name),
|
||||
('quota_class', True),
|
||||
]
|
||||
|
||||
parsed_args = self.check_parser(self.cmd, arglist, verifylist)
|
||||
|
||||
result = self.cmd.take_action(parsed_args)
|
||||
self.quotas_class_mock.update.assert_called_once_with(
|
||||
identity_fakes.project_id,
|
||||
**{'instances': compute_fakes.instance_num}
|
||||
|
||||
kwargs_compute = {
|
||||
'injected_files': compute_fakes.injected_file_num,
|
||||
'injected_file_content_bytes':
|
||||
compute_fakes.injected_file_size_num,
|
||||
'injected_file_path_bytes': compute_fakes.injected_path_size_num,
|
||||
'key_pairs': compute_fakes.key_pair_num,
|
||||
'cores': compute_fakes.core_num,
|
||||
'ram': compute_fakes.ram_num,
|
||||
'instances': compute_fakes.instance_num,
|
||||
'metadata_items': compute_fakes.property_num,
|
||||
'server_groups': compute_fakes.servgroup_num,
|
||||
'server_group_members': compute_fakes.servgroup_members_num,
|
||||
}
|
||||
kwargs_volume = {
|
||||
'gigabytes': compute_fakes.floating_ip_num,
|
||||
'snapshots': compute_fakes.fix_ip_num,
|
||||
'volumes': volume_fakes.QUOTA['volumes'],
|
||||
}
|
||||
|
||||
self.quotas_class_mock.update.assert_called_with(
|
||||
identity_fakes.project_name,
|
||||
**kwargs_compute
|
||||
)
|
||||
self.volume_quotas_class_mock.update.assert_called_once_with(
|
||||
identity_fakes.project_id,
|
||||
**{'volumes': volume_fakes.QUOTA['volumes']}
|
||||
self.volume_quotas_class_mock.update.assert_called_with(
|
||||
identity_fakes.project_name,
|
||||
**kwargs_volume
|
||||
)
|
||||
self.assertNotCalled(self.network_mock.update_quota)
|
||||
self.assertIsNone(result)
|
||||
@ -444,9 +501,9 @@ class TestQuotaShow(TestQuota):
|
||||
self.cmd.take_action(parsed_args)
|
||||
|
||||
self.quotas_class_mock.get.assert_called_once_with(
|
||||
identity_fakes.project_id)
|
||||
identity_fakes.project_name)
|
||||
self.volume_quotas_class_mock.get.assert_called_once_with(
|
||||
identity_fakes.project_id)
|
||||
identity_fakes.project_name)
|
||||
self.assertNotCalled(self.network.get_quota)
|
||||
self.assertNotCalled(self.network.get_quota_default)
|
||||
|
||||
|
4
releasenotes/notes/bug-1609233-90b2ddf8d941050e.yaml
Normal file
4
releasenotes/notes/bug-1609233-90b2ddf8d941050e.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
---
|
||||
fixes:
|
||||
- Fix the ``--class`` option not work when we set/show the quota class.
|
||||
[Bug `1609233 <https://bugs.launchpad.net/bugs/1609233>`_]
|
Loading…
Reference in New Issue
Block a user