Truncate last_metadata file dumped by cfn-init hook

This patch truncates JSON-dumped metadata file (the default path
should be "/var/cache/heat-cfntools/last_metadata") by cfn-init hook,
and makes sure the file content includes proper metadata only.

Change-Id: I313cc63012134e10165f6bfe09b1096a3cb92cc1
Closes-Bug: #1391072
This commit is contained in:
Xiao Xi LIU 2014-11-10 02:55:42 -06:00
parent 5eb75ccc51
commit cf2cf5b5da

View File

@ -49,7 +49,8 @@ def main(argv=sys.argv, stdin=sys.stdin, stdout=sys.stdout, stderr=sys.stderr):
os.makedirs(LAST_METADATA_DIR, 0o700)
fn = os.path.join(LAST_METADATA_DIR, 'last_metadata')
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY, 0o700), 'w') as f:
with os.fdopen(os.open(fn, os.O_CREAT | os.O_WRONLY | os.O_TRUNC, 0o700),
'w') as f:
json.dump(meta, f)
log.debug('Running %s' % CFN_INIT_CMD)