|
13 | 13 | # License for the specific language governing permissions and limitations
|
14 | 14 | # under the License.
|
15 | 15 | import copy
|
| 16 | +import mock |
16 | 17 | import webob
|
17 | 18 |
|
18 | 19 | from nova.api.openstack.compute import quota_classes \
|
19 | 20 | as quota_classes_v21
|
20 | 21 | from nova import exception
|
| 22 | +from nova import objects |
21 | 23 | from nova import test
|
22 | 24 | from nova.tests.unit.api.openstack import fakes
|
23 | 25 |
|
@@ -156,3 +158,107 @@ def setUp(self):
|
156 | 158 | for resource in quota_classes_v21.FILTERED_QUOTAS_2_57:
|
157 | 159 | self.quota_resources.pop(resource, None)
|
158 | 160 | self.filtered_quotas.extend(quota_classes_v21.FILTERED_QUOTAS_2_57)
|
| 161 | + |
| 162 | + |
| 163 | +class NoopQuotaClassesTest(test.NoDBTestCase): |
| 164 | + quota_driver = "nova.quota.NoopQuotaDriver" |
| 165 | + |
| 166 | + def setUp(self): |
| 167 | + super(NoopQuotaClassesTest, self).setUp() |
| 168 | + self.flags(driver=self.quota_driver, group="quota") |
| 169 | + self.controller = quota_classes_v21.QuotaClassSetsController() |
| 170 | + |
| 171 | + def test_show_v21(self): |
| 172 | + req = fakes.HTTPRequest.blank("") |
| 173 | + response = self.controller.show(req, "test_class") |
| 174 | + expected_response = { |
| 175 | + 'quota_class_set': { |
| 176 | + 'id': 'test_class', |
| 177 | + 'cores': -1, |
| 178 | + 'fixed_ips': -1, |
| 179 | + 'floating_ips': -1, |
| 180 | + 'injected_file_content_bytes': -1, |
| 181 | + 'injected_file_path_bytes': -1, |
| 182 | + 'injected_files': -1, |
| 183 | + 'instances': -1, |
| 184 | + 'key_pairs': -1, |
| 185 | + 'metadata_items': -1, |
| 186 | + 'ram': -1, |
| 187 | + 'security_group_rules': -1, |
| 188 | + 'security_groups': -1 |
| 189 | + } |
| 190 | + } |
| 191 | + self.assertEqual(expected_response, response) |
| 192 | + |
| 193 | + def test_show_v257(self): |
| 194 | + req = fakes.HTTPRequest.blank("", version='2.57') |
| 195 | + response = self.controller.show(req, "default") |
| 196 | + expected_response = { |
| 197 | + 'quota_class_set': { |
| 198 | + 'id': 'default', |
| 199 | + 'cores': -1, |
| 200 | + 'instances': -1, |
| 201 | + 'key_pairs': -1, |
| 202 | + 'metadata_items': -1, |
| 203 | + 'ram': -1, |
| 204 | + 'server_group_members': -1, |
| 205 | + 'server_groups': -1, |
| 206 | + } |
| 207 | + } |
| 208 | + self.assertEqual(expected_response, response) |
| 209 | + |
| 210 | + def test_update_v21_still_rejects_badrequests(self): |
| 211 | + req = fakes.HTTPRequest.blank("") |
| 212 | + body = {'quota_class_set': {'instances': 50, 'cores': 50, |
| 213 | + 'ram': 51200, 'unsupported': 12}} |
| 214 | + self.assertRaises(exception.ValidationError, self.controller.update, |
| 215 | + req, 'test_class', body=body) |
| 216 | + |
| 217 | + @mock.patch.object(objects.Quotas, "update_class") |
| 218 | + def test_update_v21(self, mock_update): |
| 219 | + req = fakes.HTTPRequest.blank("") |
| 220 | + body = {'quota_class_set': {'ram': 51200}} |
| 221 | + response = self.controller.update(req, 'default', body=body) |
| 222 | + expected_response = { |
| 223 | + 'quota_class_set': { |
| 224 | + 'cores': -1, |
| 225 | + 'fixed_ips': -1, |
| 226 | + 'floating_ips': -1, |
| 227 | + 'injected_file_content_bytes': -1, |
| 228 | + 'injected_file_path_bytes': -1, |
| 229 | + 'injected_files': -1, |
| 230 | + 'instances': -1, |
| 231 | + 'key_pairs': -1, |
| 232 | + 'metadata_items': -1, |
| 233 | + 'ram': -1, |
| 234 | + 'security_group_rules': -1, |
| 235 | + 'security_groups': -1 |
| 236 | + } |
| 237 | + } |
| 238 | + self.assertEqual(expected_response, response) |
| 239 | + mock_update.assert_called_once_with(req.environ['nova.context'], |
| 240 | + "default", "ram", 51200) |
| 241 | + |
| 242 | + @mock.patch.object(objects.Quotas, "update_class") |
| 243 | + def test_update_v257(self, mock_update): |
| 244 | + req = fakes.HTTPRequest.blank("", version='2.57') |
| 245 | + body = {'quota_class_set': {'ram': 51200}} |
| 246 | + response = self.controller.update(req, 'default', body=body) |
| 247 | + expected_response = { |
| 248 | + 'quota_class_set': { |
| 249 | + 'cores': -1, |
| 250 | + 'instances': -1, |
| 251 | + 'key_pairs': -1, |
| 252 | + 'metadata_items': -1, |
| 253 | + 'ram': -1, |
| 254 | + 'server_group_members': -1, |
| 255 | + 'server_groups': -1, |
| 256 | + } |
| 257 | + } |
| 258 | + self.assertEqual(expected_response, response) |
| 259 | + mock_update.assert_called_once_with(req.environ['nova.context'], |
| 260 | + "default", "ram", 51200) |
| 261 | + |
| 262 | + |
| 263 | +class UnifiedLimitsQuotaClassesTest(NoopQuotaClassesTest): |
| 264 | + quota_driver = "nova.quota.UnifiedLimitsDriver" |
0 commit comments