|
35 | 35 |
|
36 | 36 | from glance.api import policy
|
37 | 37 | from glance.common import wsgi
|
| 38 | +from glance import context |
| 39 | +import glance.db as db_api |
38 | 40 | from glance.quota import keystone as ks_quota
|
39 | 41 | from glance.tests import functional
|
40 | 42 | from glance.tests.functional import ft_utils as func_utils
|
@@ -4549,6 +4551,61 @@ def test_uploading_methods(self):
|
4549 | 4551 | # Make sure we can still import.
|
4550 | 4552 | self._create_and_import(stores=['store1'])
|
4551 | 4553 |
|
| 4554 | + def test_image_count_total_with_delayed_delete(self): |
| 4555 | + self.config(delayed_delete=True) |
| 4556 | + self.set_limit({'image_size_total': 100, |
| 4557 | + 'image_stage_total': 10, |
| 4558 | + 'image_count_total': 1, |
| 4559 | + 'image_count_uploading': 10}) |
| 4560 | + self.start_server() |
| 4561 | + # Create an image |
| 4562 | + image_id = self._create_and_upload() |
| 4563 | + # Make sure we can not create any more images. |
| 4564 | + resp = self._create() |
| 4565 | + self.assertEqual(413, resp.status_code) |
| 4566 | + |
| 4567 | + # Delete one image, which should put us under quota |
| 4568 | + self.api_delete('/v2/images/%s' % image_id) |
| 4569 | + |
| 4570 | + # Verify image is in pending_delete state |
| 4571 | + image = self._get_pending_delete_image(image_id) |
| 4572 | + self.assertEqual('pending_delete', image['status']) |
| 4573 | + |
| 4574 | + # Now we can create that image |
| 4575 | + self._create() |
| 4576 | + |
| 4577 | + def test_image_size_total_with_delayed_delete(self): |
| 4578 | + self.config(delayed_delete=True) |
| 4579 | + self.set_limit({'image_size_total': 6, |
| 4580 | + 'image_stage_total': 10, |
| 4581 | + 'image_count_total': 10, |
| 4582 | + 'image_count_uploading': 1}) |
| 4583 | + self.start_server() |
| 4584 | + # Create an image |
| 4585 | + image_id = self._create_and_upload( |
| 4586 | + data_iter=test_utils.FakeData(8 * units.Mi)) |
| 4587 | + # Make sure we can not upload any more images. |
| 4588 | + self._create_and_upload(expected_code=413) |
| 4589 | + |
| 4590 | + # Delete one image, which should put us under quota |
| 4591 | + self.api_delete('/v2/images/%s' % image_id) |
| 4592 | + |
| 4593 | + # Verify image is in pending_delete state |
| 4594 | + image = self._get_pending_delete_image(image_id) |
| 4595 | + self.assertEqual('pending_delete', image['status']) |
| 4596 | + |
| 4597 | + # Now we can create that image |
| 4598 | + self._create_and_upload() |
| 4599 | + |
| 4600 | + def _get_pending_delete_image(self, image_id): |
| 4601 | + # In Glance V2, there is no way to get the 'pending_delete' image from |
| 4602 | + # API. So we get the image from db here for testing. |
| 4603 | + # Clean the session cache first to avoid connecting to the old db data. |
| 4604 | + admin_context = context.get_admin_context(show_deleted=True) |
| 4605 | + db_api.get_api()._FACADE = None |
| 4606 | + image = db_api.get_api().image_get(admin_context, image_id) |
| 4607 | + return image |
| 4608 | + |
4552 | 4609 |
|
4553 | 4610 | class TestStoreWeight(functional.SynchronousAPIBase):
|
4554 | 4611 | def setUp(self):
|
|
0 commit comments