Add support for glance cache

Change-Id: I539807d329b9529580b298cc96172c3a120950e1
This commit is contained in:
Mridula Joshi 2023-01-10 12:21:26 +00:00
parent 9ea832d660
commit c0e8027e83
5 changed files with 101 additions and 0 deletions

View File

@ -15,6 +15,7 @@ import time
import warnings
from openstack import exceptions
from openstack.image.v2 import cache as _cache
from openstack.image.v2 import image as _image
from openstack.image.v2 import member as _member
from openstack.image.v2 import metadef_namespace as _metadef_namespace
@ -50,6 +51,7 @@ def _get_name_and_filename(name, image_format):
class Proxy(proxy.Proxy):
_resource_registry = {
"cache": _cache.Cache,
"image": _image.Image,
"image_member": _member.Member,
"metadef_namespace": _metadef_namespace.MetadefNamespace,
@ -72,6 +74,10 @@ class Proxy(proxy.Proxy):
_SHADE_IMAGE_SHA256_KEY = 'owner_specified.shade.sha256'
_SHADE_IMAGE_OBJECT_KEY = 'owner_specified.shade.object'
# ====== CACHE MANAGEMENT======
def get_image_cache(self):
return self._get(_cache.Cache, requires_id=False)
# ====== IMAGES ======
def create_image(
self,

View File

@ -0,0 +1,33 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack import resource
class CachedImage(resource.Resource):
image_id = resource.Body('image_id')
hits = resource.Body('hits')
last_accessed = resource.Body('last_accessed')
last_modified = resource.Body('last_modified')
size = resource.Body('size')
class Cache(resource.Resource):
base_path = '/cache'
allow_fetch = True
_max_microversion = '2.14'
cached_images = resource.Body('cached_images', type=list,
list_type=CachedImage)
queued_images = resource.Body('queued_images', type=list)

View File

@ -0,0 +1,45 @@
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from openstack.image.v2 import cache
from openstack.tests.unit import base
EXAMPLE = {
'cached_images': [
{'hits': 0,
'image_id': '1a56983c-f71f-490b-a7ac-6b321a18935a',
'last_accessed': 1671699579.444378,
'last_modified': 1671699579.444378,
'size': 0},
],
'queued_images': [
'3a4560a1-e585-443e-9b39-553b46ec92d1',
'6f99bf80-2ee6-47cf-acfe-1f1fabb7e810'
]
}
class TestCache(base.TestCase):
def test_basic(self):
sot = cache.Cache()
self.assertIsNone(sot.resource_key)
self.assertEqual('/cache', sot.base_path)
self.assertTrue(sot.allow_fetch)
def test_make_it(self):
sot = cache.Cache(**EXAMPLE)
self.assertEqual(
[cache.CachedImage(**e) for e in EXAMPLE['cached_images']],
sot.cached_images,
)
self.assertEqual(EXAMPLE['queued_images'], sot.queued_images)

View File

@ -17,6 +17,7 @@ import requests
from openstack import exceptions
from openstack.image.v2 import _proxy
from openstack.image.v2 import cache as _cache
from openstack.image.v2 import image as _image
from openstack.image.v2 import member as _member
from openstack.image.v2 import metadef_namespace as _metadef_namespace
@ -882,3 +883,15 @@ class TestMetadefSchema(TestImageProxy):
'requires_id': False,
},
)
class TestCache(TestImageProxy):
def test_image_cache_get(self):
self._verify(
"openstack.proxy.Proxy._get",
self.proxy.get_image_cache,
expected_args=[_cache.Cache],
expected_kwargs={
'requires_id': False
},
)

View File

@ -0,0 +1,4 @@
---
features:
- |
Add support for glance Cache API.