Skip to content
This repository has been archived by the owner on Dec 16, 2017. It is now read-only.

Commit

Permalink
better detection of cloud-init finished during container creation
Browse files Browse the repository at this point in the history
Merge of Mike McCracken's work from better_cloud_init_finished
branch with minor updates to point to correct file location and
not be fatal on init errors.

Signed-off-by: Adam Stokes <adam.stokes@ubuntu.com>
  • Loading branch information
Adam Stokes committed Nov 11, 2014
1 parent e880b90 commit f20bb56
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions cloudinstall/single_install.py
Expand Up @@ -16,8 +16,7 @@

import logging
import os
import sys

import json
import time
from cloudinstall.config import Config
from cloudinstall.installbase import InstallBase
Expand Down Expand Up @@ -71,14 +70,32 @@ def create_container_and_wait(self):
tries = tries + 1

def cloud_init_finished(self):
""" checks the log to see if cloud-init finished
"""checks cloud-init result.json in container to find out status
returns True if cloud-init finished with no errors, False if
it's not done yet, and raises an exception if it had errors.
"""
log_file = os.path.join(self.container_abspath,
'rootfs/var/log/cloud-init-output.log')
out = utils.get_command_output('sudo tail -n1 {0}'.format(log_file))
if 'finished at' in out['output']:
return True
return False
result_json = os.path.join(self.container_abspath,
'rootfs/var/lib/cloud/data/result.json')
if not os.path.isfile(result_json):
return False

result_json = utils.slurp(result_json)
log.debug("Cloud-init finished: {}".format(result_json))

if result_json == '':
return False

ret = json.loads(result_json)
errors = ret['v1']['errors']
if len(errors):
log.error("Container cloud-init finished with "
"errors: {}".format(errors))
# FIXME: Log errors for now, don't be fatal as the main
# error is coming from a pollinate command unable
# to run which doesn't seem to effect the installer.
# raise Exception("Container cloud-init returned errors")
return True

def copy_installdata_and_set_perms(self):
""" copies install data and sets permissions on files/dirs
Expand Down

2 comments on commit f20bb56

@mikemccracken
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did you use the copy under rootfs instead of the one in /run in the container?
the cloud-init docs suggested that the /run symlink was better, to guarantee you aren't getting a stale copy from a previous run of the container

@adam-stokes
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my tests that directory never contained the results.json file. Does it get removed automatically after cloud-init is finished?

Please sign in to comment.