diff options
author | Jenkins <jenkins@review.openstack.org> | 2014-06-18 04:15:30 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2014-06-18 04:15:30 +0000 |
commit | 269c841b472f2f83fc4001f22db8e04f4248f453 (patch) | |
tree | 4d0dcc97ff33080c1f74ccdb7a40f342771f6d87 /heat_cfntools | |
parent | 0fab4170ffa33dc1628f50972fa21862d844a618 (diff) | |
parent | 5f7025558cf468792d1c18605667888a5d775b36 (diff) | |
download | heat-cfntools-269c841b472f2f83fc4001f22db8e04f4248f453.tar.gz |
Merge "Add res_last_path to store last metadata of a resource"
Diffstat (limited to 'heat_cfntools')
-rw-r--r-- | heat_cfntools/cfntools/cfn_helper.py | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/heat_cfntools/cfntools/cfn_helper.py b/heat_cfntools/cfntools/cfn_helper.py index 4085a43..a7d5e3b 100644 --- a/heat_cfntools/cfntools/cfn_helper.py +++ b/heat_cfntools/cfntools/cfn_helper.py @@ -22,7 +22,6 @@ import atexit import ConfigParser import errno import grp -import hashlib import json import logging import os @@ -1118,6 +1117,11 @@ class Metadata(object): True -- success False -- error """ + if self.resource is not None: + res_last_path = last_path + '_' + self.resource + else: + res_last_path = last_path + if meta_str: self._data = meta_str else: @@ -1137,7 +1141,7 @@ class Metadata(object): # cached metadata or the logic below could re-run a stale # cfn-init-data fd = None - for filepath in [last_path, default_path]: + for filepath in [res_last_path, last_path, default_path]: try: fd = open(filepath) except IOError: @@ -1160,18 +1164,21 @@ class Metadata(object): else: self._metadata = self._data - cm = hashlib.md5(json.dumps(self._metadata)) - current_md5 = cm.hexdigest() - old_md5 = None + last_data = "" + for metadata_file in [res_last_path, last_path]: + try: + with open(metadata_file) as lm: + try: + last_data = json.load(lm) + except ValueError: + pass + lm.close() + except IOError: + LOG.warn("Unable to open local metadata : %s" % + metadata_file) + continue - try: - with open(last_path) as lm: - om = hashlib.md5() - om.update(lm.read()) - old_md5 = om.hexdigest() - except Exception: - pass - if old_md5 != current_md5: + if self._metadata != last_data: self._has_changed = True # if cache dir does not exist try to create it @@ -1191,6 +1198,9 @@ class Metadata(object): os.chmod(cf.name, 0o600) cf.write(json.dumps(self._metadata)) os.rename(cf.name, last_path) + cf.close() + if res_last_path != last_path: + shutil.copy(last_path, res_last_path) return True |