|
| 1 | +# Licensed under the Apache License, Version 2.0 (the "License"); you may |
| 2 | +# not use this file except in compliance with the License. You may obtain |
| 3 | +# a copy of the License at |
| 4 | +# |
| 5 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 6 | +# |
| 7 | +# Unless required by applicable law or agreed to in writing, software |
| 8 | +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT |
| 9 | +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 10 | +# License for the specific language governing permissions and limitations |
| 11 | +# under the License. |
| 12 | + |
| 13 | +import uuid |
| 14 | + |
| 15 | +from openstackclient.tests.functional.image import base |
| 16 | + |
| 17 | + |
| 18 | +class CacheTests(base.BaseImageTests): |
| 19 | + """Functional tests for Cache commands""" |
| 20 | + |
| 21 | + def test_cached_image(self): |
| 22 | + """Test cached image operations including queue and clear""" |
| 23 | + # Create test image |
| 24 | + name = uuid.uuid4().hex |
| 25 | + output = self.openstack( |
| 26 | + f'image create {name}', |
| 27 | + parse_output=True, |
| 28 | + ) |
| 29 | + image_id = output["id"] |
| 30 | + self.assertOutput(name, output['name']) |
| 31 | + |
| 32 | + # Register cleanup for created image |
| 33 | + self.addCleanup( |
| 34 | + self.openstack, 'cached image delete ' + image_id, fail_ok=True |
| 35 | + ) |
| 36 | + self.addCleanup(self.openstack, 'image delete ' + image_id) |
| 37 | + |
| 38 | + # Queue image for caching |
| 39 | + self.openstack('cached image queue ' + image_id) |
| 40 | + |
| 41 | + # Verify queuing worked |
| 42 | + cache_output = self.openstack('cached image list', parse_output=True) |
| 43 | + self.assertIsInstance(cache_output, list) |
| 44 | + image_ids = [img['ID'] for img in cache_output] |
| 45 | + self.assertIn(image_id, image_ids) |
| 46 | + |
| 47 | + # Clear cached images |
| 48 | + self.openstack('cached image clear') |
| 49 | + |
| 50 | + # Verify clearing worked |
| 51 | + output = self.openstack('cached image list', parse_output=True) |
| 52 | + if output: |
| 53 | + image_ids = [img['ID'] for img in output] |
| 54 | + self.assertNotIn(image_id, image_ids) |
0 commit comments