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
This commit is contained in:
Steven Dake 2013-02-26 17:38:30 -07:00
parent 7dace2f835
commit 737cc26570
4 changed files with 22 additions and 30 deletions

View File

@ -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())

View File

@ -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)

View File

@ -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()

View File

@ -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()