From f68abf9b0e3e2ba206c560c19db321c6f88670f1 Mon Sep 17 00:00:00 2001 From: Alvaro Lopez Garcia Date: Fri, 2 Dec 2011 14:18:38 +0100 Subject: Fixes bug 723235 The XML templates have been converted into properties, thus we can compare the mtime of the XML templates (libvirt and cpuinfo) each time they are needed, checking if they have been modified and reloading them. Added a function to read cached files. Change-Id: I6cf0229c6435300e73f9d9a6b10b0bf9bf144a55 --- nova/tests/test_utils.py | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'nova/tests') diff --git a/nova/tests/test_utils.py b/nova/tests/test_utils.py index 15ac0dc2d..d2b122121 100644 --- a/nova/tests/test_utils.py +++ b/nova/tests/test_utils.py @@ -14,6 +14,8 @@ # License for the specific language governing permissions and limitations # under the License. +import __builtin__ +import mox import datetime import os import tempfile @@ -330,6 +332,33 @@ class GenericUtilsTestCase(test.TestCase): actual_url = "http://%s:%d" % (FLAGS.glance_host, FLAGS.glance_port) self.assertEqual(generated_url, actual_url) + def test_read_cached_file(self): + self.mox.StubOutWithMock(os.path, "getmtime") + os.path.getmtime(mox.IgnoreArg()).AndReturn(1) + self.mox.ReplayAll() + + cache_data = {"data": 1123, "mtime": 1} + data = utils.read_cached_file("/this/is/a/fake", cache_data) + self.assertEqual(cache_data["data"], data) + + def test_read_modified_cached_file(self): + self.mox.StubOutWithMock(os.path, "getmtime") + self.mox.StubOutWithMock(__builtin__, 'open') + + os.path.getmtime(mox.IgnoreArg()).AndReturn(2) + + fake_contents = "lorem ipsum" + fake_file = self.mox.CreateMockAnything() + fake_file.read().AndReturn(fake_contents) + __builtin__.open(mox.IgnoreArg()).AndReturn(fake_file) + + self.mox.ReplayAll() + cache_data = {"data": 1123, "mtime": 1} + data = utils.read_cached_file("/this/is/a/fake", cache_data) + self.mox.VerifyAll() + self.mox.UnsetStubs() + self.assertEqual(data, fake_contents) + class IsUUIDLikeTestCase(test.TestCase): def assertUUIDLike(self, val, expected): -- cgit