Make caching work when cloud name is None
All of the other keys are coerced to strings through some method but a cloud name of None with no namespace produces a TypeError because sequence 0 is not a string when joined. Change-Id: I78d0e6daedfe3cf1a0db5f606c21af803450f018
This commit is contained in:
parent
1cb9b2094a
commit
f57433929a
|
@ -295,7 +295,7 @@ class OpenStackCloud(object):
|
|||
kwargs_key = ','.join(
|
||||
['%s:%s' % (k, kwargs[k]) for k in kw_keys if k != 'cache'])
|
||||
ans = "_".join(
|
||||
[name_key, fname, arg_key, kwargs_key])
|
||||
[str(name_key), fname, arg_key, kwargs_key])
|
||||
return ans
|
||||
return generate_key
|
||||
|
||||
|
|
|
@ -361,3 +361,24 @@ class TestMemoryCache(base.TestCase):
|
|||
glance_mock.images.update.assert_called_with(**args)
|
||||
fake_image_dict = meta.obj_to_dict(fake_image)
|
||||
self.assertEqual([fake_image_dict], self.cloud.list_images())
|
||||
|
||||
@mock.patch.object(shade.OpenStackCloud, 'glance_client')
|
||||
def test_cache_no_cloud_name(self, glance_mock):
|
||||
class FakeImage(dict):
|
||||
id = 1
|
||||
status = 'active'
|
||||
name = 'None Test Image'
|
||||
fi = FakeImage(id=FakeImage.id, status=FakeImage.status,
|
||||
name=FakeImage.name)
|
||||
glance_mock.images.list.return_value = [fi]
|
||||
self.cloud.name = None
|
||||
self.assertEqual([fi], [dict(x) for x in self.cloud.list_images()])
|
||||
# Now test that the list was cached
|
||||
fi2 = FakeImage(id=2, status=FakeImage.status, name=FakeImage.name)
|
||||
fi2.id = 2
|
||||
glance_mock.images.list.return_value = [fi, fi2]
|
||||
self.assertEqual([fi], [dict(x) for x in self.cloud.list_images()])
|
||||
# Invalidation too
|
||||
self.cloud.list_images.invalidate(self.cloud)
|
||||
self.assertEqual(
|
||||
[fi, fi2], [dict(x) for x in self.cloud.list_images()])
|
||||
|
|
Loading…
Reference in New Issue