summaryrefslogtreecommitdiff
path: root/ironic/drivers/modules/image_cache.py
diff options
context:
space:
mode:
authorVictor Sergeyev <vsergeyev@mirantis.com>2014-12-30 13:50:27 +0200
committerVictor Sergeyev <vsergeyev@mirantis.com>2015-05-06 11:51:44 +0300
commit70062322a240353989babeddfb904b487a42d668 (patch)
treeb914ca4a6c2a9df5f79f14a7abdc5c716dc128c5 /ironic/drivers/modules/image_cache.py
parent1961523996f1f0a88f2e3871c902dd7426ba25f5 (diff)
downloadironic-70062322a240353989babeddfb904b487a42d668.tar.gz
Run tests in py34 environment
A lot of fixes to be compatible with python 3: - fix encoding/decoding errors - fix issues with comparison - use `reload`, `reraise`, ext. modules from six - use items() instead of iteritems() - add a new file with py3 specific test requirements - drop passing the arbitrary arguments to object.__new__ method. See bug [1] for more details. - add a workaround to bug in `mock` library - add py33 and py34 test environment to tox.ini [1] http://bugs.python.org/issue1683368 Change-Id: I90936cb6b6eaaf4b5e1ce67732caec3c8bdc1cc2
Diffstat (limited to 'ironic/drivers/modules/image_cache.py')
-rw-r--r--ironic/drivers/modules/image_cache.py8
1 files changed, 5 insertions, 3 deletions
diff --git a/ironic/drivers/modules/image_cache.py b/ironic/drivers/modules/image_cache.py
index 618ae25d8..ceecd6059 100644
--- a/ironic/drivers/modules/image_cache.py
+++ b/ironic/drivers/modules/image_cache.py
@@ -26,6 +26,7 @@ import uuid
from oslo_concurrency import lockutils
from oslo_config import cfg
from oslo_log import log as logging
+import six
from ironic.common import exception
from ironic.common.glance_service import service_utils
@@ -107,8 +108,9 @@ class ImageCache(object):
else:
# NOTE(vdrok): Doing conversion of href in case it's unicode
# string, UUID cannot be generated for unicode strings on python 2.
+ href_encoded = href.encode('utf-8') if six.PY2 else href
master_file_name = str(uuid.uuid5(uuid.NAMESPACE_URL,
- href.encode('utf-8')))
+ href_encoded))
master_path = os.path.join(self.master_dir, master_file_name)
if CONF.parallel_image_downloads:
@@ -281,7 +283,7 @@ class ImageCache(object):
"threshold %(expected)d"),
{'dir': self.master_dir, 'actual': total_size,
'expected': self._cache_size})
- return max(amount, 0)
+ return max(amount, 0) if amount is not None else 0
def _find_candidates_for_deletion(master_dir):
@@ -379,7 +381,7 @@ def cleanup(priority):
"""Decorator method for adding cleanup priority to a class."""
def _add_property_to_class_func(cls):
_cache_cleanup_list.append((priority, cls))
- _cache_cleanup_list.sort(reverse=True)
+ _cache_cleanup_list.sort(reverse=True, key=lambda tuple_: tuple_[0])
return cls
return _add_property_to_class_func