Funcional tests: quota list
The quota list tests have a race in them where occasionally a project is deleted in another test between the time that quota list gets a list of all projects and it gets the quota for the projects from the service; the get quota call fails on the non-existant project. The quota list functional tests have been substantially re-written to properly test the exception handling. Change-Id: I71e6bbb5d46fcea4718a5a870f9a66a2c20fff0f
This commit is contained in:
		| @@ -132,13 +132,27 @@ class ListQuota(command.Lister): | ||||
|         if parsed_args.compute: | ||||
|             compute_client = self.app.client_manager.compute | ||||
|             for p in project_ids: | ||||
|                 try: | ||||
|                     data = compute_client.quotas.get(p) | ||||
|                 result_data = _xform_get_quota(data, p, | ||||
|                                                COMPUTE_QUOTAS.keys()) | ||||
|                 default_data = compute_client.quotas.defaults(p) | ||||
|                 result_default = _xform_get_quota(default_data, | ||||
|                 except Exception as ex: | ||||
|                     if type(ex).__name__ == 'NotFound': | ||||
|                         # Project not found, move on to next one | ||||
|                         LOG.warning("Project %s not found: %s" % (p, ex)) | ||||
|                         continue | ||||
|                     else: | ||||
|                         raise | ||||
|  | ||||
|                 result_data = _xform_get_quota( | ||||
|                     data, | ||||
|                     p, | ||||
|                                                   COMPUTE_QUOTAS.keys()) | ||||
|                     COMPUTE_QUOTAS.keys(), | ||||
|                 ) | ||||
|                 default_data = compute_client.quotas.defaults(p) | ||||
|                 result_default = _xform_get_quota( | ||||
|                     default_data, | ||||
|                     p, | ||||
|                     COMPUTE_QUOTAS.keys(), | ||||
|                 ) | ||||
|                 if result_default != result_data: | ||||
|                     result += result_data | ||||
|  | ||||
| @@ -174,16 +188,31 @@ class ListQuota(command.Lister): | ||||
|                     (utils.get_dict_properties( | ||||
|                         s, columns, | ||||
|                     ) for s in result)) | ||||
|  | ||||
|         if parsed_args.volume: | ||||
|             volume_client = self.app.client_manager.volume | ||||
|             for p in project_ids: | ||||
|                 try: | ||||
|                     data = volume_client.quotas.get(p) | ||||
|                 result_data = _xform_get_quota(data, p, | ||||
|                                                VOLUME_QUOTAS.keys()) | ||||
|                 default_data = volume_client.quotas.defaults(p) | ||||
|                 result_default = _xform_get_quota(default_data, | ||||
|                 except Exception as ex: | ||||
|                     if type(ex).__name__ == 'NotFound': | ||||
|                         # Project not found, move on to next one | ||||
|                         LOG.warning("Project %s not found: %s" % (p, ex)) | ||||
|                         continue | ||||
|                     else: | ||||
|                         raise | ||||
|  | ||||
|                 result_data = _xform_get_quota( | ||||
|                     data, | ||||
|                     p, | ||||
|                                                   VOLUME_QUOTAS.keys()) | ||||
|                     VOLUME_QUOTAS.keys(), | ||||
|                 ) | ||||
|                 default_data = volume_client.quotas.defaults(p) | ||||
|                 result_default = _xform_get_quota( | ||||
|                     default_data, | ||||
|                     p, | ||||
|                     VOLUME_QUOTAS.keys(), | ||||
|                 ) | ||||
|                 if result_default != result_data: | ||||
|                     result += result_data | ||||
|  | ||||
| @@ -209,14 +238,31 @@ class ListQuota(command.Lister): | ||||
|                     (utils.get_dict_properties( | ||||
|                         s, columns, | ||||
|                     ) for s in result)) | ||||
|  | ||||
|         if parsed_args.network: | ||||
|             client = self.app.client_manager.network | ||||
|             for p in project_ids: | ||||
|                 try: | ||||
|                     data = client.get_quota(p) | ||||
|                 result_data = _xform_get_quota(data, p, NETWORK_KEYS) | ||||
|                 except Exception as ex: | ||||
|                     if type(ex).__name__ == 'NotFound': | ||||
|                         # Project not found, move on to next one | ||||
|                         LOG.warning("Project %s not found: %s" % (p, ex)) | ||||
|                         continue | ||||
|                     else: | ||||
|                         raise | ||||
|  | ||||
|                 result_data = _xform_get_quota( | ||||
|                     data, | ||||
|                     p, | ||||
|                     NETWORK_KEYS, | ||||
|                 ) | ||||
|                 default_data = client.get_quota_default(p) | ||||
|                 result_default = _xform_get_quota(default_data, | ||||
|                                                   p, NETWORK_KEYS) | ||||
|                 result_default = _xform_get_quota( | ||||
|                     default_data, | ||||
|                     p, | ||||
|                     NETWORK_KEYS, | ||||
|                 ) | ||||
|                 if result_default != result_data: | ||||
|                     result += result_data | ||||
|  | ||||
|   | ||||
| @@ -13,6 +13,8 @@ | ||||
| import copy | ||||
| import mock | ||||
|  | ||||
| from osc_lib import exceptions | ||||
|  | ||||
| from openstackclient.common import quota | ||||
| from openstackclient.tests.unit.compute.v2 import fakes as compute_fakes | ||||
| from openstackclient.tests.unit import fakes | ||||
| @@ -41,17 +43,25 @@ class TestQuota(compute_fakes.TestComputev2): | ||||
|  | ||||
|     def setUp(self): | ||||
|         super(TestQuota, self).setUp() | ||||
|         self.quotas_mock = self.app.client_manager.compute.quotas | ||||
|         self.quotas_mock.reset_mock() | ||||
|         self.quotas_class_mock = self.app.client_manager.compute.quota_classes | ||||
|         self.quotas_class_mock.reset_mock() | ||||
|  | ||||
|         # Set up common projects | ||||
|         self.projects = identity_fakes_v3.FakeProject.create_projects(count=2) | ||||
|         self.projects_mock = self.app.client_manager.identity.projects | ||||
|         self.projects_mock.reset_mock() | ||||
|         self.projects_mock.get.return_value = self.projects[0] | ||||
|  | ||||
|         self.compute_quotas_mock = self.app.client_manager.compute.quotas | ||||
|         self.compute_quotas_mock.reset_mock() | ||||
|         self.compute_quotas_class_mock = \ | ||||
|             self.app.client_manager.compute.quota_classes | ||||
|         self.compute_quotas_class_mock.reset_mock() | ||||
|  | ||||
|         self.volume_quotas_mock = self.app.client_manager.volume.quotas | ||||
|         self.volume_quotas_mock.reset_mock() | ||||
|         self.volume_quotas_class_mock = \ | ||||
|             self.app.client_manager.volume.quota_classes | ||||
|         self.volume_quotas_class_mock.reset_mock() | ||||
|         self.projects_mock = self.app.client_manager.identity.projects | ||||
|         self.projects_mock.reset_mock() | ||||
|  | ||||
|         self.app.client_manager.auth_ref = mock.Mock() | ||||
|         self.app.client_manager.auth_ref.service_catalog = mock.Mock() | ||||
|         self.service_catalog_mock = \ | ||||
| @@ -60,12 +70,352 @@ class TestQuota(compute_fakes.TestComputev2): | ||||
|         self.app.client_manager.auth_ref.project_id = identity_fakes.project_id | ||||
|  | ||||
|  | ||||
| class TestQuotaList(TestQuota): | ||||
|     """Test cases for quota list command""" | ||||
|  | ||||
|     compute_column_header = ( | ||||
|         'Project ID', | ||||
|         'Cores', | ||||
|         'Fixed IPs', | ||||
|         'Injected Files', | ||||
|         'Injected File Content Bytes', | ||||
|         'Injected File Path Bytes', | ||||
|         'Instances', | ||||
|         'Key Pairs', | ||||
|         'Metadata Items', | ||||
|         'Ram', | ||||
|         'Server Groups', | ||||
|         'Server Group Members', | ||||
|     ) | ||||
|  | ||||
|     network_column_header = ( | ||||
|         'Project ID', | ||||
|         'Floating IPs', | ||||
|         'Networks', | ||||
|         'Ports', | ||||
|         'RBAC Policies', | ||||
|         'Routers', | ||||
|         'Security Groups', | ||||
|         'Security Group Rules', | ||||
|         'Subnets', | ||||
|         'Subnet Pools' | ||||
|     ) | ||||
|  | ||||
|     volume_column_header = ( | ||||
|         'Project ID', | ||||
|         'Backups', | ||||
|         'Backup Gigabytes', | ||||
|         'Gigabytes', | ||||
|         'Per Volume Gigabytes', | ||||
|         'Snapshots', | ||||
|         'Volumes', | ||||
|     ) | ||||
|  | ||||
|     def setUp(self): | ||||
|         super(TestQuotaList, self).setUp() | ||||
|  | ||||
|         # Work with multiple projects in this class | ||||
|         self.projects_mock.get.side_effect = self.projects | ||||
|         self.projects_mock.list.return_value = self.projects | ||||
|  | ||||
|         self.compute_quotas = [ | ||||
|             compute_fakes.FakeQuota.create_one_comp_quota(), | ||||
|             compute_fakes.FakeQuota.create_one_comp_quota(), | ||||
|         ] | ||||
|         self.compute_default_quotas = [ | ||||
|             compute_fakes.FakeQuota.create_one_default_comp_quota(), | ||||
|             compute_fakes.FakeQuota.create_one_default_comp_quota(), | ||||
|         ] | ||||
|         self.compute = self.app.client_manager.compute | ||||
|         self.compute.quotas.defaults = mock.Mock( | ||||
|             side_effect=self.compute_default_quotas, | ||||
|         ) | ||||
|  | ||||
|         self.compute_reference_data = ( | ||||
|             self.projects[0].id, | ||||
|             self.compute_quotas[0].cores, | ||||
|             self.compute_quotas[0].fixed_ips, | ||||
|             self.compute_quotas[0].injected_files, | ||||
|             self.compute_quotas[0].injected_file_content_bytes, | ||||
|             self.compute_quotas[0].injected_file_path_bytes, | ||||
|             self.compute_quotas[0].instances, | ||||
|             self.compute_quotas[0].key_pairs, | ||||
|             self.compute_quotas[0].metadata_items, | ||||
|             self.compute_quotas[0].ram, | ||||
|             self.compute_quotas[0].server_groups, | ||||
|             self.compute_quotas[0].server_group_members, | ||||
|         ) | ||||
|  | ||||
|         self.network_quotas = [ | ||||
|             network_fakes.FakeQuota.create_one_net_quota(), | ||||
|             network_fakes.FakeQuota.create_one_net_quota(), | ||||
|         ] | ||||
|         self.network_default_quotas = [ | ||||
|             network_fakes.FakeQuota.create_one_default_net_quota(), | ||||
|             network_fakes.FakeQuota.create_one_default_net_quota(), | ||||
|         ] | ||||
|         self.network = self.app.client_manager.network | ||||
|         self.network.get_quota_default = mock.Mock( | ||||
|             side_effect=self.network_default_quotas, | ||||
|         ) | ||||
|  | ||||
|         self.network_reference_data = ( | ||||
|             self.projects[0].id, | ||||
|             self.network_quotas[0].floating_ips, | ||||
|             self.network_quotas[0].networks, | ||||
|             self.network_quotas[0].ports, | ||||
|             self.network_quotas[0].rbac_policies, | ||||
|             self.network_quotas[0].routers, | ||||
|             self.network_quotas[0].security_groups, | ||||
|             self.network_quotas[0].security_group_rules, | ||||
|             self.network_quotas[0].subnets, | ||||
|             self.network_quotas[0].subnet_pools, | ||||
|         ) | ||||
|  | ||||
|         self.volume_quotas = [ | ||||
|             volume_fakes.FakeQuota.create_one_vol_quota(), | ||||
|             volume_fakes.FakeQuota.create_one_vol_quota(), | ||||
|         ] | ||||
|         self.volume_default_quotas = [ | ||||
|             volume_fakes.FakeQuota.create_one_default_vol_quota(), | ||||
|             volume_fakes.FakeQuota.create_one_default_vol_quota(), | ||||
|         ] | ||||
|         self.volume = self.app.client_manager.volume | ||||
|         self.volume.quotas.defaults = mock.Mock( | ||||
|             side_effect=self.volume_default_quotas, | ||||
|         ) | ||||
|  | ||||
|         self.volume_reference_data = ( | ||||
|             self.projects[0].id, | ||||
|             self.volume_quotas[0].backups, | ||||
|             self.volume_quotas[0].backup_gigabytes, | ||||
|             self.volume_quotas[0].gigabytes, | ||||
|             self.volume_quotas[0].per_volume_gigabytes, | ||||
|             self.volume_quotas[0].snapshots, | ||||
|             self.volume_quotas[0].volumes, | ||||
|         ) | ||||
|  | ||||
|         self.cmd = quota.ListQuota(self.app, None) | ||||
|  | ||||
|     def test_quota_list_compute(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.compute.quotas.get = mock.Mock( | ||||
|             side_effect=self.compute_quotas, | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--compute', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('compute', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.compute_column_header, columns) | ||||
|         self.assertEqual(self.compute_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(2, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_compute_default(self): | ||||
|         # One of the projects is at defaults | ||||
|         self.compute.quotas.get = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.compute_quotas[0], | ||||
|                 compute_fakes.FakeQuota.create_one_default_comp_quota(), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--compute', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('compute', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.compute_column_header, columns) | ||||
|         self.assertEqual(self.compute_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_compute_no_project(self): | ||||
|         # Make one of the projects disappear | ||||
|         self.compute.quotas.get = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.compute_quotas[0], | ||||
|                 exceptions.NotFound("NotFound"), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--compute', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('compute', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.compute_column_header, columns) | ||||
|         self.assertEqual(self.compute_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_network(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.network.get_quota = mock.Mock( | ||||
|             side_effect=self.network_quotas, | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--network', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('network', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.network_column_header, columns) | ||||
|         self.assertEqual(self.network_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(2, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_network_default(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.network.get_quota = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.network_quotas[0], | ||||
|                 network_fakes.FakeQuota.create_one_default_net_quota(), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--network', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('network', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.network_column_header, columns) | ||||
|         self.assertEqual(self.network_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_network_no_project(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.network.get_quota = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.network_quotas[0], | ||||
|                 exceptions.NotFound("NotFound"), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--network', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('network', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.network_column_header, columns) | ||||
|         self.assertEqual(self.network_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_volume(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.volume.quotas.get = mock.Mock( | ||||
|             side_effect=self.volume_quotas, | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--volume', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('volume', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.volume_column_header, columns) | ||||
|         self.assertEqual(self.volume_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(2, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_volume_default(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.volume.quotas.get = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.volume_quotas[0], | ||||
|                 volume_fakes.FakeQuota.create_one_default_vol_quota(), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--volume', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('volume', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.volume_column_header, columns) | ||||
|         self.assertEqual(self.volume_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|     def test_quota_list_volume_no_project(self): | ||||
|         # Two projects with non-default quotas | ||||
|         self.volume.quotas.get = mock.Mock( | ||||
|             side_effect=[ | ||||
|                 self.volume_quotas[0], | ||||
|                 volume_fakes.FakeQuota.create_one_default_vol_quota(), | ||||
|             ], | ||||
|         ) | ||||
|  | ||||
|         arglist = [ | ||||
|             '--volume', | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('volume', True), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|         ret_quotas = list(data) | ||||
|  | ||||
|         self.assertEqual(self.volume_column_header, columns) | ||||
|         self.assertEqual(self.volume_reference_data, ret_quotas[0]) | ||||
|         self.assertEqual(1, len(ret_quotas)) | ||||
|  | ||||
|  | ||||
| class TestQuotaSet(TestQuota): | ||||
|  | ||||
|     def setUp(self): | ||||
|         super(TestQuotaSet, self).setUp() | ||||
|  | ||||
|         self.quotas_mock.update.return_value = FakeQuotaResource( | ||||
|         self.compute_quotas_mock.update.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|         self.compute_quotas_class_mock.update.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
| @@ -76,19 +426,6 @@ class TestQuotaSet(TestQuota): | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.projects_mock.get.return_value = fakes.FakeResource( | ||||
|             None, | ||||
|             copy.deepcopy(identity_fakes.PROJECT), | ||||
|             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), | ||||
| @@ -116,7 +453,7 @@ class TestQuotaSet(TestQuota): | ||||
|             '--secgroups', str(compute_fakes.secgroup_num), | ||||
|             '--server-groups', str(compute_fakes.servgroup_num), | ||||
|             '--server-group-members', str(compute_fakes.servgroup_members_num), | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('floating_ips', compute_fakes.floating_ip_num), | ||||
| @@ -134,9 +471,8 @@ class TestQuotaSet(TestQuota): | ||||
|             ('security_groups', compute_fakes.secgroup_num), | ||||
|             ('server_groups', compute_fakes.servgroup_num), | ||||
|             ('server_group_members', compute_fakes.servgroup_members_num), | ||||
|             ('project', identity_fakes.project_name), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         self.app.client_manager.network_endpoint_enabled = False | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
| @@ -160,8 +496,8 @@ class TestQuotaSet(TestQuota): | ||||
|             'server_group_members': compute_fakes.servgroup_members_num, | ||||
|         } | ||||
|  | ||||
|         self.quotas_mock.update.assert_called_once_with( | ||||
|             identity_fakes.project_id, | ||||
|         self.compute_quotas_mock.update.assert_called_once_with( | ||||
|             self.projects[0].id, | ||||
|             **kwargs | ||||
|         ) | ||||
|         self.assertIsNone(result) | ||||
| @@ -175,7 +511,7 @@ class TestQuotaSet(TestQuota): | ||||
|             '--backup-gigabytes', str(volume_fakes.QUOTA['backup_gigabytes']), | ||||
|             '--per-volume-gigabytes', | ||||
|             str(volume_fakes.QUOTA['per_volume_gigabytes']), | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('gigabytes', volume_fakes.QUOTA['gigabytes']), | ||||
| @@ -185,8 +521,8 @@ class TestQuotaSet(TestQuota): | ||||
|             ('backup_gigabytes', volume_fakes.QUOTA['backup_gigabytes']), | ||||
|             ('per_volume_gigabytes', | ||||
|                 volume_fakes.QUOTA['per_volume_gigabytes']), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         result = self.cmd.take_action(parsed_args) | ||||
| @@ -201,7 +537,7 @@ class TestQuotaSet(TestQuota): | ||||
|         } | ||||
|  | ||||
|         self.volume_quotas_mock.update.assert_called_once_with( | ||||
|             identity_fakes.project_id, | ||||
|             self.projects[0].id, | ||||
|             **kwargs | ||||
|         ) | ||||
|  | ||||
| @@ -217,7 +553,7 @@ class TestQuotaSet(TestQuota): | ||||
|             '--per-volume-gigabytes', | ||||
|             str(volume_fakes.QUOTA['per_volume_gigabytes']), | ||||
|             '--volume-type', 'volume_type_backend', | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('gigabytes', volume_fakes.QUOTA['gigabytes']), | ||||
| @@ -228,8 +564,8 @@ class TestQuotaSet(TestQuota): | ||||
|             ('per_volume_gigabytes', | ||||
|                 volume_fakes.QUOTA['per_volume_gigabytes']), | ||||
|             ('volume_type', 'volume_type_backend'), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         result = self.cmd.take_action(parsed_args) | ||||
| @@ -244,7 +580,7 @@ class TestQuotaSet(TestQuota): | ||||
|         } | ||||
|  | ||||
|         self.volume_quotas_mock.update.assert_called_once_with( | ||||
|             identity_fakes.project_id, | ||||
|             self.projects[0].id, | ||||
|             **kwargs | ||||
|         ) | ||||
|         self.assertIsNone(result) | ||||
| @@ -264,7 +600,7 @@ class TestQuotaSet(TestQuota): | ||||
|             '--vips', str(network_fakes.QUOTA['vip']), | ||||
|             '--health-monitors', str(network_fakes.QUOTA['healthmonitor']), | ||||
|             '--l7policies', str(network_fakes.QUOTA['l7policy']), | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('subnet', network_fakes.QUOTA['subnet']), | ||||
| @@ -280,6 +616,7 @@ class TestQuotaSet(TestQuota): | ||||
|             ('vip', network_fakes.QUOTA['vip']), | ||||
|             ('healthmonitor', network_fakes.QUOTA['healthmonitor']), | ||||
|             ('l7policy', network_fakes.QUOTA['l7policy']), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
| @@ -300,7 +637,7 @@ class TestQuotaSet(TestQuota): | ||||
|             'l7policy': network_fakes.QUOTA['l7policy'], | ||||
|         } | ||||
|         self.network_mock.update_quota.assert_called_once_with( | ||||
|             identity_fakes.project_id, | ||||
|             self.projects[0].id, | ||||
|             **kwargs | ||||
|         ) | ||||
|         self.assertIsNone(result) | ||||
| @@ -321,7 +658,8 @@ class TestQuotaSet(TestQuota): | ||||
|             '--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', | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('injected_files', compute_fakes.injected_file_num), | ||||
| @@ -339,10 +677,9 @@ class TestQuotaSet(TestQuota): | ||||
|             ('snapshots', compute_fakes.fix_ip_num), | ||||
|             ('volumes', volume_fakes.QUOTA['volumes']), | ||||
|             ('network', network_fakes.QUOTA['network']), | ||||
|             ('project', identity_fakes.project_name), | ||||
|             ('quota_class', True), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         result = self.cmd.take_action(parsed_args) | ||||
| @@ -366,12 +703,12 @@ class TestQuotaSet(TestQuota): | ||||
|             'volumes': volume_fakes.QUOTA['volumes'], | ||||
|         } | ||||
|  | ||||
|         self.quotas_class_mock.update.assert_called_with( | ||||
|             identity_fakes.project_name, | ||||
|         self.compute_quotas_class_mock.update.assert_called_with( | ||||
|             self.projects[0].name, | ||||
|             **kwargs_compute | ||||
|         ) | ||||
|         self.volume_quotas_class_mock.update.assert_called_with( | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|             **kwargs_volume | ||||
|         ) | ||||
|         self.assertNotCalled(self.network_mock.update_quota) | ||||
| @@ -383,25 +720,25 @@ class TestQuotaShow(TestQuota): | ||||
|     def setUp(self): | ||||
|         super(TestQuotaShow, self).setUp() | ||||
|  | ||||
|         self.quotas_mock.get.return_value = FakeQuotaResource( | ||||
|         self.compute_quota = compute_fakes.FakeQuota.create_one_comp_quota() | ||||
|         self.compute_quotas_mock.get.return_value = self.compute_quota | ||||
|         self.compute_default_quota = \ | ||||
|             compute_fakes.FakeQuota.create_one_default_comp_quota() | ||||
|         self.compute_quotas_mock.defaults.return_value = \ | ||||
|             self.compute_default_quota | ||||
|         self.compute_quotas_class_mock.get.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.quotas_mock.defaults.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.volume_quotas_mock.get.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(volume_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.volume_quotas_mock.defaults.return_value = FakeQuotaResource( | ||||
|         self.volume_quota = volume_fakes.FakeQuota.create_one_vol_quota() | ||||
|         self.volume_quotas_mock.get.return_value = self.volume_quota | ||||
|         self.volume_default_quota = \ | ||||
|             volume_fakes.FakeQuota.create_one_default_vol_quota() | ||||
|         self.volume_quotas_mock.defaults.return_value = \ | ||||
|             self.volume_default_quota | ||||
|         self.volume_quotas_class_mock.get.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(volume_fakes.QUOTA), | ||||
|             loaded=True, | ||||
| @@ -417,94 +754,85 @@ class TestQuotaShow(TestQuota): | ||||
|             'network': fake_network_endpoint | ||||
|         } | ||||
|  | ||||
|         self.quotas_class_mock.get.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(compute_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.volume_quotas_class_mock.get.return_value = FakeQuotaResource( | ||||
|             None, | ||||
|             copy.deepcopy(volume_fakes.QUOTA), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.projects_mock.get.return_value = fakes.FakeResource( | ||||
|             None, | ||||
|             copy.deepcopy(identity_fakes.PROJECT), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.app.client_manager.network = network_fakes.FakeNetworkV2Client( | ||||
|             endpoint=fakes.AUTH_URL, | ||||
|             token=fakes.AUTH_TOKEN, | ||||
|         ) | ||||
|         self.network = self.app.client_manager.network | ||||
|         self.network.get_quota = mock.Mock(return_value=network_fakes.QUOTA) | ||||
|         self.network.get_quota = mock.Mock( | ||||
|             return_value=network_fakes.QUOTA, | ||||
|         ) | ||||
|         self.network.get_quota_default = mock.Mock( | ||||
|             return_value=network_fakes.QUOTA) | ||||
|             return_value=network_fakes.QUOTA, | ||||
|         ) | ||||
|  | ||||
|         self.cmd = quota.ShowQuota(self.app, None) | ||||
|  | ||||
|     def test_quota_show(self): | ||||
|         arglist = [ | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('project', identity_fakes.project_name), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.quotas_mock.get.assert_called_once_with(identity_fakes.project_id) | ||||
|         self.compute_quotas_mock.get.assert_called_once_with( | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.volume_quotas_mock.get.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.network.get_quota.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.assertNotCalled(self.network.get_quota_default) | ||||
|  | ||||
|     def test_quota_show_with_default(self): | ||||
|         arglist = [ | ||||
|             '--default', | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('default', True), | ||||
|             ('project', identity_fakes.project_name), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.quotas_mock.defaults.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|         self.compute_quotas_mock.defaults.assert_called_once_with( | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.volume_quotas_mock.defaults.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.network.get_quota_default.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             self.projects[0].id, | ||||
|         ) | ||||
|         self.assertNotCalled(self.network.get_quota) | ||||
|  | ||||
|     def test_quota_show_with_class(self): | ||||
|         arglist = [ | ||||
|             '--class', | ||||
|             identity_fakes.project_name, | ||||
|             self.projects[0].name, | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('quota_class', True), | ||||
|             ('project', identity_fakes.project_name), | ||||
|             ('project', self.projects[0].name), | ||||
|         ] | ||||
|  | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.quotas_class_mock.get.assert_called_once_with( | ||||
|             identity_fakes.project_name) | ||||
|         self.compute_quotas_class_mock.get.assert_called_once_with( | ||||
|             self.projects[0].name, | ||||
|         ) | ||||
|         self.volume_quotas_class_mock.get.assert_called_once_with( | ||||
|             identity_fakes.project_name) | ||||
|             self.projects[0].name, | ||||
|         ) | ||||
|         self.assertNotCalled(self.network.get_quota) | ||||
|         self.assertNotCalled(self.network.get_quota_default) | ||||
|  | ||||
| @@ -513,167 +841,13 @@ class TestQuotaShow(TestQuota): | ||||
|  | ||||
|         self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.quotas_mock.get.assert_called_once_with(identity_fakes.project_id) | ||||
|         self.compute_quotas_mock.get.assert_called_once_with( | ||||
|             identity_fakes.project_id, | ||||
|         ) | ||||
|         self.volume_quotas_mock.get.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             identity_fakes.project_id, | ||||
|         ) | ||||
|         self.network.get_quota.assert_called_once_with( | ||||
|             identity_fakes.project_id) | ||||
|             identity_fakes.project_id, | ||||
|         ) | ||||
|         self.assertNotCalled(self.network.get_quota_default) | ||||
|  | ||||
|  | ||||
| class TestQuotaList(TestQuota): | ||||
|     """Test cases for quota list command""" | ||||
|  | ||||
|     project = identity_fakes_v3.FakeProject.create_one_project() | ||||
|  | ||||
|     quota_list = network_fakes.FakeQuota.create_one_net_quota() | ||||
|     quota_list1 = compute_fakes.FakeQuota.create_one_comp_quota() | ||||
|     quota_list2 = volume_fakes.FakeQuota.create_one_vol_quota() | ||||
|  | ||||
|     default_quota = network_fakes.FakeQuota.create_one_default_net_quota() | ||||
|     default_quota1 = compute_fakes.FakeQuota.create_one_default_comp_quota() | ||||
|     default_quota2 = volume_fakes.FakeQuota.create_one_default_vol_quota() | ||||
|  | ||||
|     reference_data = (project.id, | ||||
|                       quota_list.floating_ips, | ||||
|                       quota_list.networks, | ||||
|                       quota_list.ports, | ||||
|                       quota_list.rbac_policies, | ||||
|                       quota_list.routers, | ||||
|                       quota_list.security_groups, | ||||
|                       quota_list.security_group_rules, | ||||
|                       quota_list.subnets, | ||||
|                       quota_list.subnet_pools) | ||||
|  | ||||
|     comp_reference_data = (project.id, | ||||
|                            quota_list1.cores, | ||||
|                            quota_list1.fixed_ips, | ||||
|                            quota_list1.injected_files, | ||||
|                            quota_list1.injected_file_content_bytes, | ||||
|                            quota_list1.injected_file_path_bytes, | ||||
|                            quota_list1.instances, | ||||
|                            quota_list1.key_pairs, | ||||
|                            quota_list1.metadata_items, | ||||
|                            quota_list1.ram, | ||||
|                            quota_list1.server_groups, | ||||
|                            quota_list1.server_group_members) | ||||
|  | ||||
|     vol_reference_data = (project.id, | ||||
|                           quota_list2.backups, | ||||
|                           quota_list2.backup_gigabytes, | ||||
|                           quota_list2.gigabytes, | ||||
|                           quota_list2.per_volume_gigabytes, | ||||
|                           quota_list2.snapshots, | ||||
|                           quota_list2.volumes) | ||||
|  | ||||
|     net_column_header = ( | ||||
|         'Project ID', | ||||
|         'Floating IPs', | ||||
|         'Networks', | ||||
|         'Ports', | ||||
|         'RBAC Policies', | ||||
|         'Routers', | ||||
|         'Security Groups', | ||||
|         'Security Group Rules', | ||||
|         'Subnets', | ||||
|         'Subnet Pools' | ||||
|     ) | ||||
|  | ||||
|     comp_column_header = ( | ||||
|         'Project ID', | ||||
|         'Cores', | ||||
|         'Fixed IPs', | ||||
|         'Injected Files', | ||||
|         'Injected File Content Bytes', | ||||
|         'Injected File Path Bytes', | ||||
|         'Instances', | ||||
|         'Key Pairs', | ||||
|         'Metadata Items', | ||||
|         'Ram', | ||||
|         'Server Groups', | ||||
|         'Server Group Members', | ||||
|     ) | ||||
|  | ||||
|     vol_column_header = ( | ||||
|         'Project ID', | ||||
|         'Backups', | ||||
|         'Backup Gigabytes', | ||||
|         'Gigabytes', | ||||
|         'Per Volume Gigabytes', | ||||
|         'Snapshots', | ||||
|         'Volumes', | ||||
|     ) | ||||
|  | ||||
|     def setUp(self): | ||||
|         super(TestQuotaList, self).setUp() | ||||
|  | ||||
|         self.projects_mock.get.return_value = fakes.FakeResource( | ||||
|             None, | ||||
|             copy.deepcopy(identity_fakes.PROJECT), | ||||
|             loaded=True, | ||||
|         ) | ||||
|  | ||||
|         self.identity = self.app.client_manager.identity | ||||
|         self.identity.tenants.list = mock.Mock(return_value=[self.project]) | ||||
|  | ||||
|         self.network = self.app.client_manager.network | ||||
|         self.compute = self.app.client_manager.compute | ||||
|         self.volume = self.app.client_manager.volume | ||||
|  | ||||
|         self.network.get_quota = mock.Mock(return_value=self.quota_list) | ||||
|         self.compute.quotas.get = mock.Mock(return_value=self.quota_list1) | ||||
|         self.volume.quotas.get = mock.Mock(return_value=self.quota_list2) | ||||
|  | ||||
|         self.network.get_quota_default = mock.Mock( | ||||
|             return_value=self.default_quota) | ||||
|         self.compute.quotas.defaults = mock.Mock( | ||||
|             return_value=self.default_quota1) | ||||
|         self.volume.quotas.defaults = mock.Mock( | ||||
|             return_value=self.default_quota2) | ||||
|  | ||||
|         self.cmd = quota.ListQuota(self.app, None) | ||||
|  | ||||
|     def test_quota_list_network(self): | ||||
|         arglist = [ | ||||
|             '--network' | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('network', True) | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.assertEqual(self.net_column_header, columns) | ||||
|  | ||||
|         self.assertEqual(self.reference_data, list(data)[0]) | ||||
|  | ||||
|     def test_quota_list_compute(self): | ||||
|         arglist = [ | ||||
|             '--compute' | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('compute', True) | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.assertEqual(self.comp_column_header, columns) | ||||
|  | ||||
|         self.assertEqual(self.comp_reference_data, list(data)[0]) | ||||
|  | ||||
|     def test_quota_list_volume(self): | ||||
|         arglist = [ | ||||
|             '--volume' | ||||
|         ] | ||||
|         verifylist = [ | ||||
|             ('volume', True) | ||||
|         ] | ||||
|         parsed_args = self.check_parser(self.cmd, arglist, verifylist) | ||||
|  | ||||
|         columns, data = self.cmd.take_action(parsed_args) | ||||
|  | ||||
|         self.assertEqual(self.vol_column_header, columns) | ||||
|  | ||||
|         self.assertEqual(self.vol_reference_data, list(data)[0]) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Dean Troyer
					Dean Troyer