From 737cc26570e194f691de71a7372f33a75a32e8c2 Mon Sep 17 00:00:00 2001 From: Steven Dake Date: Tue, 26 Feb 2013 17:38:30 -0700 Subject: [PATCH] Put heat data files in /var/lib/heat-cfntools The /var/lib/heat-cfntools directory should be owned by the heat-cfntools package for whichever distro it is included. This avoids the problem of heat writing to directories owned by cloud-init. For the moment, the part handler will continue to write to /var/lib/cloud/data to be removed at a later date. Change-Id: I70b714c70ed146d4f6807850d6e7264c6a4624cd Fixes: Bug #1105806 --- heat/cloudinit/loguserdata.py | 11 +++-------- heat/cloudinit/part-handler.py | 11 +++++++++++ heat/tests/functional/util.py | 6 +++--- heat/tests/test_loguserdata.py | 24 +++++------------------- 4 files changed, 22 insertions(+), 30 deletions(-) diff --git a/heat/cloudinit/loguserdata.py b/heat/cloudinit/loguserdata.py index c1dff070ff..69b33b507f 100644 --- a/heat/cloudinit/loguserdata.py +++ b/heat/cloudinit/loguserdata.py @@ -8,7 +8,7 @@ import pkg_resources from distutils.version import LooseVersion import errno -path = '/var/lib/cloud/data' +path = '/var/lib/heat-cfntools' def chk_ci_version(): @@ -47,12 +47,6 @@ def main(log): if returncode: return returncode - try: - os.makedirs('/var/lib/heat', 0700) - except OSError as e: - if e.errno != errno.EEXIST: - raise - if __name__ == '__main__': with create_log('/var/log/heat-provision.log') as log: @@ -61,5 +55,6 @@ if __name__ == '__main__': log.write('Provision failed') sys.exit(returncode) - with create_log('/var/lib/heat/provision-finished') as log: + userdata_path = os.path.join(path, 'provision-finished') + with create_log(userdata_path) as log: log.write('%s\n' % datetime.datetime.now()) diff --git a/heat/cloudinit/part-handler.py b/heat/cloudinit/part-handler.py index 978566c771..138d6d5862 100644 --- a/heat/cloudinit/part-handler.py +++ b/heat/cloudinit/part-handler.py @@ -1,5 +1,6 @@ #part-handler +import os import datetime @@ -9,7 +10,13 @@ def list_types(): def handle_part(data, ctype, filename, payload): if ctype == "__begin__": + try: + os.makedirs('/var/lib/heat-cfntools', 0700) + except OSError as e: + if e.errno != errno.EEXIST: + raise return + if ctype == "__end__": return @@ -18,5 +25,9 @@ def handle_part(data, ctype, filename, payload): log.write('%s filename:%s, ctype:%s\n' % (timestamp, filename, ctype)) if ctype == 'text/x-cfninitdata': + with open('/var/lib/heat-cfntools/%s' % filename, 'w') as f: + f.write(payload) + + # TODO(sdake) hopefully temporary until users move to heat-cfntools-1.3 with open('/var/lib/cloud/data/%s' % filename, 'w') as f: f.write(payload) diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index 43059ebae7..73dc024ced 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -140,7 +140,7 @@ class Instance(object): tries = 0 while True: try: - self.sftp.stat('/var/lib/cloud/instance/boot-finished') + self.sftp.stat('/var/lib/heat-cfntools/boot-finished') except IOError, e: tries += 1 if e.errno == errno.ENOENT: @@ -219,7 +219,7 @@ class Instance(object): tries = 0 while True: try: - self.sftp.stat('/var/lib/heat/provision-finished') + self.sftp.stat('/var/lib/heat-cfntools/provision-finished') except paramiko.SSHException as e: print e except IOError as e: @@ -258,7 +258,7 @@ class Instance(object): stack = parser.Stack(None, 'test', template, params) parsed_t = stack.resolve_static_data(t) - remote_file = self.sftp.open('/var/lib/cloud/data/cfn-userdata') + remote_file = self.sftp.open('/var/lib/heat-cfntools/cfn-userdata') remote_file_list = remote_file.read().split('\n') remote_file_list_u = map(unicode, remote_file_list) remote_file.close() diff --git a/heat/tests/test_loguserdata.py b/heat/tests/test_loguserdata.py index c78e3f7bce..0fce0e1519 100644 --- a/heat/tests/test_loguserdata.py +++ b/heat/tests/test_loguserdata.py @@ -48,7 +48,6 @@ class LoguserdataTest(unittest.TestCase): self.m.StubOutWithMock(pkg_resources, 'get_distribution') self.m.StubOutWithMock(subprocess, 'Popen') self.m.StubOutWithMock(os, 'chmod') - self.m.StubOutWithMock(os, 'makedirs') def tearDown(self): self.m.UnsetStubs() @@ -108,14 +107,13 @@ class LoguserdataTest(unittest.TestCase): log = StringIO.StringIO() pkg_resources.get_distribution('cloud-init').AndReturn( FakeCiVersion('0.7.0')) - os.chmod('/var/lib/cloud/data/cfn-userdata', 0700).AndReturn(None) + + os.chmod('/var/lib/heat-cfntools/cfn-userdata', 0700).AndReturn(None) subprocess.Popen( - ['/var/lib/cloud/data/cfn-userdata'], + ['/var/lib/heat-cfntools/cfn-userdata'], stderr=log, stdout=log).AndReturn(FakePOpen(0)) - os.makedirs('/var/lib/heat', 0700).AndReturn(None) - self.m.ReplayAll() loguserdata.main(log) self.m.VerifyAll() @@ -132,26 +130,14 @@ class LoguserdataTest(unittest.TestCase): pkg_resources.get_distribution('cloud-init').AndReturn( FakeCiVersion('0.7.0')) - os.chmod('/var/lib/cloud/data/cfn-userdata', 0700).AndReturn(None) + os.chmod('/var/lib/heat-cfntools/cfn-userdata', 0700).AndReturn(None) subprocess.Popen( - ['/var/lib/cloud/data/cfn-userdata'], + ['/var/lib/heat-cfntools/cfn-userdata'], stderr=log, stdout=log).AndReturn(FakePOpen(-2)) - #fail on create directories - pkg_resources.get_distribution('cloud-init').AndReturn( - FakeCiVersion('0.7.0')) - - os.chmod('/var/lib/cloud/data/cfn-userdata', 0700).AndReturn(None) - subprocess.Popen( - ['/var/lib/cloud/data/cfn-userdata'], - stderr=log, - stdout=log).AndReturn(FakePOpen(0)) - os.makedirs('/var/lib/heat', 0700).AndRaise(OSError()) - self.m.ReplayAll() self.assertEqual(-1, loguserdata.main(log)) self.assertEqual(-2, loguserdata.main(log)) - self.assertRaises(OSError, loguserdata.main, log) self.m.VerifyAll()