|
15 | 15 | # under the License.
|
16 | 16 |
|
17 | 17 | import mock
|
| 18 | +from oslo_limit import fixture as limit_fixture |
18 | 19 | from oslo_utils.fixture import uuidsentinel as uuids
|
19 | 20 | import webob
|
20 | 21 |
|
21 | 22 | from nova.api.openstack.compute import quota_sets as quotas_v21
|
22 | 23 | from nova.db import constants as db_const
|
23 | 24 | from nova import exception
|
| 25 | +from nova.limit import local as local_limit |
24 | 26 | from nova import objects
|
25 | 27 | from nova import quota
|
26 | 28 | from nova import test
|
@@ -868,3 +870,176 @@ def test_user_quotas_delete(self, mock_destroy_all_by_user):
|
868 | 870 | class UnifiedLimitsQuotaSetsTest(NoopQuotaSetsTest):
|
869 | 871 | quota_driver = "nova.quota.UnifiedLimitsDriver"
|
870 | 872 | expected_detail = {'in_use': -1, 'limit': -1, 'reserved': 0}
|
| 873 | + |
| 874 | + def setUp(self): |
| 875 | + super(UnifiedLimitsQuotaSetsTest, self).setUp() |
| 876 | + reglimits = {local_limit.SERVER_METADATA_ITEMS: 128, |
| 877 | + local_limit.INJECTED_FILES: 5, |
| 878 | + local_limit.INJECTED_FILES_CONTENT: 10 * 1024, |
| 879 | + local_limit.INJECTED_FILES_PATH: 255, |
| 880 | + local_limit.KEY_PAIRS: 100, |
| 881 | + local_limit.SERVER_GROUPS: 12, |
| 882 | + local_limit.SERVER_GROUP_MEMBERS: 10} |
| 883 | + self.useFixture(limit_fixture.LimitFixture(reglimits, {})) |
| 884 | + |
| 885 | + def test_show_v21(self): |
| 886 | + req = fakes.HTTPRequest.blank("") |
| 887 | + response = self.controller.show(req, uuids.project_id) |
| 888 | + expected_response = { |
| 889 | + 'quota_set': { |
| 890 | + 'id': uuids.project_id, |
| 891 | + 'cores': -1, |
| 892 | + 'fixed_ips': -1, |
| 893 | + 'floating_ips': -1, |
| 894 | + 'injected_file_content_bytes': 10240, |
| 895 | + 'injected_file_path_bytes': 255, |
| 896 | + 'injected_files': 5, |
| 897 | + 'instances': -1, |
| 898 | + 'key_pairs': 100, |
| 899 | + 'metadata_items': 128, |
| 900 | + 'ram': -1, |
| 901 | + 'security_group_rules': -1, |
| 902 | + 'security_groups': -1, |
| 903 | + 'server_group_members': 10, |
| 904 | + 'server_groups': 12, |
| 905 | + } |
| 906 | + } |
| 907 | + self.assertEqual(expected_response, response) |
| 908 | + |
| 909 | + def test_show_v257(self): |
| 910 | + req = fakes.HTTPRequest.blank("", version='2.57') |
| 911 | + response = self.controller.show(req, uuids.project_id) |
| 912 | + expected_response = { |
| 913 | + 'quota_set': { |
| 914 | + 'id': uuids.project_id, |
| 915 | + 'cores': -1, |
| 916 | + 'instances': -1, |
| 917 | + 'key_pairs': 100, |
| 918 | + 'metadata_items': 128, |
| 919 | + 'ram': -1, |
| 920 | + 'server_group_members': 10, |
| 921 | + 'server_groups': 12}} |
| 922 | + self.assertEqual(expected_response, response) |
| 923 | + |
| 924 | + @mock.patch.object(objects.InstanceGroupList, "get_counts") |
| 925 | + def test_detail_v21(self, mock_count): |
| 926 | + mock_count.return_value = {'project': {'server_groups': 9}} |
| 927 | + req = fakes.HTTPRequest.blank("") |
| 928 | + response = self.controller.detail(req, uuids.project_id) |
| 929 | + expected_response = { |
| 930 | + 'quota_set': { |
| 931 | + 'id': uuids.project_id, |
| 932 | + 'cores': self.expected_detail, |
| 933 | + 'fixed_ips': self.expected_detail, |
| 934 | + 'floating_ips': self.expected_detail, |
| 935 | + 'injected_file_content_bytes': { |
| 936 | + 'in_use': 0, 'limit': 10240, 'reserved': 0}, |
| 937 | + 'injected_file_path_bytes': { |
| 938 | + 'in_use': 0, 'limit': 255, 'reserved': 0}, |
| 939 | + 'injected_files': { |
| 940 | + 'in_use': 0, 'limit': 5, 'reserved': 0}, |
| 941 | + 'instances': self.expected_detail, |
| 942 | + 'key_pairs': { |
| 943 | + 'in_use': 0, 'limit': 100, 'reserved': 0}, |
| 944 | + 'metadata_items': { |
| 945 | + 'in_use': 0, 'limit': 128, 'reserved': 0}, |
| 946 | + 'ram': self.expected_detail, |
| 947 | + 'security_group_rules': self.expected_detail, |
| 948 | + 'security_groups': self.expected_detail, |
| 949 | + 'server_group_members': { |
| 950 | + 'in_use': 0, 'limit': 10, 'reserved': 0}, |
| 951 | + 'server_groups': { |
| 952 | + 'in_use': 9, 'limit': 12, 'reserved': 0}, |
| 953 | + } |
| 954 | + } |
| 955 | + self.assertEqual(expected_response, response) |
| 956 | + |
| 957 | + @mock.patch.object(objects.InstanceGroupList, "get_counts") |
| 958 | + def test_detail_v21_user(self, mock_count): |
| 959 | + mock_count.return_value = {'project': {'server_groups': 9}} |
| 960 | + req = fakes.HTTPRequest.blank("?user_id=42") |
| 961 | + response = self.controller.detail(req, uuids.project_id) |
| 962 | + expected_response = { |
| 963 | + 'quota_set': { |
| 964 | + 'id': uuids.project_id, |
| 965 | + 'cores': self.expected_detail, |
| 966 | + 'fixed_ips': self.expected_detail, |
| 967 | + 'floating_ips': self.expected_detail, |
| 968 | + 'injected_file_content_bytes': { |
| 969 | + 'in_use': 0, 'limit': 10240, 'reserved': 0}, |
| 970 | + 'injected_file_path_bytes': { |
| 971 | + 'in_use': 0, 'limit': 255, 'reserved': 0}, |
| 972 | + 'injected_files': { |
| 973 | + 'in_use': 0, 'limit': 5, 'reserved': 0}, |
| 974 | + 'instances': self.expected_detail, |
| 975 | + 'key_pairs': { |
| 976 | + 'in_use': 0, 'limit': 100, 'reserved': 0}, |
| 977 | + 'metadata_items': { |
| 978 | + 'in_use': 0, 'limit': 128, 'reserved': 0}, |
| 979 | + 'ram': self.expected_detail, |
| 980 | + 'security_group_rules': self.expected_detail, |
| 981 | + 'security_groups': self.expected_detail, |
| 982 | + 'server_group_members': { |
| 983 | + 'in_use': 0, 'limit': 10, 'reserved': 0}, |
| 984 | + 'server_groups': { |
| 985 | + 'in_use': 9, 'limit': 12, 'reserved': 0}, |
| 986 | + } |
| 987 | + } |
| 988 | + self.assertEqual(expected_response, response) |
| 989 | + |
| 990 | + @mock.patch.object(objects.Quotas, "create_limit") |
| 991 | + def test_update_v21(self, mock_create): |
| 992 | + req = fakes.HTTPRequest.blank("") |
| 993 | + # TODO(johngarbutt) still need to implement get_settable_quotas |
| 994 | + body = {'quota_set': {'server_groups': 2}} |
| 995 | + response = self.controller.update(req, uuids.project_id, body=body) |
| 996 | + expected_response = { |
| 997 | + 'quota_set': { |
| 998 | + 'cores': -1, |
| 999 | + 'fixed_ips': -1, |
| 1000 | + 'floating_ips': -1, |
| 1001 | + 'injected_file_content_bytes': 10240, |
| 1002 | + 'injected_file_path_bytes': 255, |
| 1003 | + 'injected_files': 5, |
| 1004 | + 'instances': -1, |
| 1005 | + 'key_pairs': 100, |
| 1006 | + 'metadata_items': 128, |
| 1007 | + 'ram': -1, |
| 1008 | + 'security_group_rules': -1, |
| 1009 | + 'security_groups': -1, |
| 1010 | + 'server_group_members': 10, |
| 1011 | + 'server_groups': 12, |
| 1012 | + } |
| 1013 | + } |
| 1014 | + self.assertEqual(expected_response, response) |
| 1015 | + mock_create.assert_called_once_with(req.environ['nova.context'], |
| 1016 | + uuids.project_id, "server_groups", |
| 1017 | + 2, user_id=None) |
| 1018 | + |
| 1019 | + @mock.patch.object(objects.Quotas, "create_limit") |
| 1020 | + def test_update_v21_user(self, mock_create): |
| 1021 | + req = fakes.HTTPRequest.blank("?user_id=42") |
| 1022 | + body = {'quota_set': {'key_pairs': 52}} |
| 1023 | + response = self.controller.update(req, uuids.project_id, body=body) |
| 1024 | + expected_response = { |
| 1025 | + 'quota_set': { |
| 1026 | + 'cores': -1, |
| 1027 | + 'fixed_ips': -1, |
| 1028 | + 'floating_ips': -1, |
| 1029 | + 'injected_file_content_bytes': 10240, |
| 1030 | + 'injected_file_path_bytes': 255, |
| 1031 | + 'injected_files': 5, |
| 1032 | + 'instances': -1, |
| 1033 | + 'key_pairs': 100, |
| 1034 | + 'metadata_items': 128, |
| 1035 | + 'ram': -1, |
| 1036 | + 'security_group_rules': -1, |
| 1037 | + 'security_groups': -1, |
| 1038 | + 'server_group_members': 10, |
| 1039 | + 'server_groups': 12, |
| 1040 | + } |
| 1041 | + } |
| 1042 | + self.assertEqual(expected_response, response) |
| 1043 | + mock_create.assert_called_once_with(req.environ['nova.context'], |
| 1044 | + uuids.project_id, "key_pairs", 52, |
| 1045 | + user_id="42") |
0 commit comments