loguserdata: prevent shadowing of arguments and globals

cleaning this up for bug 1154641

Change-Id: I95271bdeba1bba29e78af79de4e2173d07750e4f
Signed-off-by: Angus Salkeld <asalkeld@redhat.com>
changes/99/24399/1
Angus Salkeld 10 years ago
parent a492c6e04f
commit fbea931550

@ -1,13 +1,15 @@
#!/usr/bin/env python
import sys
import os
import subprocess
import datetime
import pkg_resources
import os
import subprocess
import sys
from distutils.version import LooseVersion
path = '/var/lib/heat-cfntools'
VAR_PATH = '/var/lib/heat-cfntools'
def chk_ci_version():
@ -15,45 +17,45 @@ def chk_ci_version():
return v >= LooseVersion('0.6.0')
def create_log(path):
fd = os.open(path, os.O_WRONLY | os.O_CREAT, 0600)
def create_log(log_path):
fd = os.open(log_path, os.O_WRONLY | os.O_CREAT, 0600)
return os.fdopen(fd, 'w')
def call(args, log):
log.write('%s\n' % ' '.join(args))
log.flush()
p = subprocess.Popen(args, stdout=log, stderr=log)
def call(args, logger):
logger.write('%s\n' % ' '.join(args))
logger.flush()
p = subprocess.Popen(args, stdout=logger, stderr=logger)
p.wait()
return p.returncode
def main(log):
def main(logger):
if not chk_ci_version():
# pre 0.6.0 - user data executed via cloudinit, not this helper
log.write('Unable to log provisioning, need a newer version of'
' cloud-init\n')
logger.write('Unable to log provisioning, need a newer version of'
' cloud-init\n')
return -1
userdata_path = os.path.join(path, 'cfn-userdata')
userdata_path = os.path.join(VAR_PATH, 'cfn-userdata')
os.chmod(userdata_path, 0700)
log.write('Provision began: %s\n' % datetime.datetime.now())
log.flush()
returncode = call([userdata_path], log)
log.write('Provision done: %s\n' % datetime.datetime.now())
logger.write('Provision began: %s\n' % datetime.datetime.now())
logger.flush()
returncode = call([userdata_path], logger)
logger.write('Provision done: %s\n' % datetime.datetime.now())
if returncode:
return returncode
if __name__ == '__main__':
with create_log('/var/log/heat-provision.log') as log:
returncode = main(log)
if returncode:
code = main(log)
if code:
log.write('Provision failed')
sys.exit(returncode)
sys.exit(code)
userdata_path = os.path.join(path, 'provision-finished')
with create_log(userdata_path) as log:
provision_log = os.path.join(VAR_PATH, 'provision-finished')
with create_log(provision_log) as log:
log.write('%s\n' % datetime.datetime.now())

Loading…
Cancel
Save