Merge "image: make sure the target for "clear_cache" is valid"
This commit is contained in:
commit
d0718dce12
@ -101,7 +101,7 @@ class Proxy(proxy.Proxy):
|
||||
cache = self._get_resource(_cache.Cache, None)
|
||||
return cache.queue(self, image_id)
|
||||
|
||||
def clear_cache(self, target):
|
||||
def clear_cache(self, target='both'):
|
||||
"""Clear all images from cache, queue or both
|
||||
|
||||
:param target: Specify which target you want to clear
|
||||
|
@ -62,8 +62,12 @@ class Cache(resource.Resource):
|
||||
:returns: The server response
|
||||
"""
|
||||
headers = {}
|
||||
if target != "both":
|
||||
if target in ('cache', 'queue'):
|
||||
headers = {'x-image-cache-clear-target': target}
|
||||
elif target != "both":
|
||||
raise exceptions.InvalidRequest(
|
||||
'Target must be "cache", "queue" or "both".'
|
||||
)
|
||||
response = session.delete(self.base_path, headers=headers)
|
||||
exceptions.raise_from_response(response)
|
||||
return response
|
||||
|
@ -69,5 +69,22 @@ class TestCache(base.TestCase):
|
||||
session = mock.Mock()
|
||||
session.delete = mock.Mock()
|
||||
|
||||
sot.clear(session)
|
||||
session.delete.assert_called_with('/cache', headers={})
|
||||
|
||||
sot.clear(session, 'both')
|
||||
session.delete.assert_called_with('/cache', headers={})
|
||||
|
||||
sot.clear(session, 'cache')
|
||||
session.delete.assert_called_with(
|
||||
'/cache', headers={'x-image-cache-clear-target': 'cache'}
|
||||
)
|
||||
|
||||
sot.clear(session, 'queue')
|
||||
session.delete.assert_called_with(
|
||||
'/cache', headers={'x-image-cache-clear-target': 'queue'}
|
||||
)
|
||||
|
||||
self.assertRaises(
|
||||
exceptions.InvalidRequest, sot.clear, session, 'invalid'
|
||||
)
|
||||
|
@ -982,3 +982,12 @@ class TestCache(TestImageProxy):
|
||||
expected_args=[self.proxy, 'both'],
|
||||
)
|
||||
mock_get_resource.assert_called_once_with(_cache.Cache, None)
|
||||
|
||||
mock_get_resource.reset_mock()
|
||||
self._verify(
|
||||
"openstack.image.v2.cache.Cache.clear",
|
||||
self.proxy.clear_cache,
|
||||
method_args=[],
|
||||
expected_args=[self.proxy, 'both'],
|
||||
)
|
||||
mock_get_resource.assert_called_once_with(_cache.Cache, None)
|
||||
|
Loading…
Reference in New Issue
Block a user