def get_cached_image(context, instance): base_disk_path = pathutils.base_disk_path(instance) for disk_format in constants.ALL_DISK_FORMATS: test_path = base_disk_path + '.' + disk_format.lower() if os.path.exists(test_path): return test_path sync = utils.synchronized(base_disk_path) synchronized_fetch_image = sync(_fetch_image) disk_path = synchronized_fetch_image(context, instance, base_disk_path) return disk_path
def test_base_disk_path(self, mock_base_disk, mock_join): pathutils.base_disk_path(self._instance) self.assertEqual(1, mock_base_disk.call_count) self.assertEqual(1, mock_join.call_count)