From 67fe09104cb347c03ea608c72a1382e8ea252b1d Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 5 Apr 2012 00:08:42 -0400 Subject: move the reading of the cmdline cloud-config url to cloud-init.py The reason for moving this from cloudinit/__init__.py was that it was running too late there. The cloudinit.parsed_cfgs variable was already filled by cloud-init.py's reading of cloud config. I'm sure I had done this so that it would not have to re-parse configs. I think the right way to handle this is to move that logic back to cloudinit/__init__.py and add some function like 'reread_configs()' that would re-read all releavent cofnigs and re-setup logging. That seemed more error prone at the moment, with limited time. --- cloud-init.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index 9e0a0405..db620502 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -28,6 +28,7 @@ import cloudinit.CloudConfig as CC import cloudinit.DataSource as ds import cloudinit.netinfo as netinfo import time +import traceback import logging import errno import os @@ -67,6 +68,26 @@ def main(): warn("unable to open /proc/uptime\n") uptime = "na" + cmdline_msg = None + cmdline_exc = None + if cmd == "start": + target = "%s.d/%s" % (cloudinit.system_config, + "91_kernel_cmdline_url.cfg") + if os.path.exists(target): + cmdline_msg = "cmdline: %s existed" % target + else: + try: + (key, url, content) = cloudinit.get_cmdline_url() + if key and content: + util.write_file(target, content, mode=0600) + cmdline_msg = ("cmdline: wrote %s from %s, %s" % + (target, key, url)) + elif key: + cmdline_msg = ("cmdline: %s, %s had no cloud-config" % + (key, url)) + except Exception: + cmdline_exc = traceback.format_exc() + try: cfg = cloudinit.get_base_cfg(cfg_path) except Exception as e: @@ -86,6 +107,11 @@ def main(): cloudinit.logging_set_from_cfg(cfg) log = logging.getLogger() + if cmdline_exc: + log.warn(cmdline_exc) + elif cmdline_msg: + log.debug(cmdline_msg) + try: cloudinit.initfs() except Exception as e: -- cgit v1.2.3 From c1656161cc88e05f02afb1806545dd5cc7acc227 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 5 Apr 2012 00:16:52 -0400 Subject: improve exception message --- cloud-init.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index db620502..ac98e562 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -86,7 +86,9 @@ def main(): cmdline_msg = ("cmdline: %s, %s had no cloud-config" % (key, url)) except Exception: - cmdline_exc = traceback.format_exc() + cmdline_exc = "%s\n%s\n" % (traceback.format_exc() + "cmdline token was %s=%s" % (key, url)) + warn(cmdline_exc) try: cfg = cloudinit.get_base_cfg(cfg_path) @@ -108,7 +110,7 @@ def main(): log = logging.getLogger() if cmdline_exc: - log.warn(cmdline_exc) + log.debug(cmdline_exc) elif cmdline_msg: log.debug(cmdline_msg) -- cgit v1.2.3 From 5295dabadb8248543b2224f608371fec5e177f12 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 5 Apr 2012 00:20:32 -0400 Subject: syntax error fix --- cloud-init.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index ac98e562..855b38e0 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -86,7 +86,7 @@ def main(): cmdline_msg = ("cmdline: %s, %s had no cloud-config" % (key, url)) except Exception: - cmdline_exc = "%s\n%s\n" % (traceback.format_exc() + cmdline_exc = "%s\n%s\n" % (traceback.format_exc(), "cmdline token was %s=%s" % (key, url)) warn(cmdline_exc) -- cgit v1.2.3 From 9258ae52432ab73acef139e38b930faba4858bc8 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 5 Apr 2012 00:25:02 -0400 Subject: revert improved exception printing, as it was broken --- cloud-init.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index 855b38e0..08be1e0c 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -86,8 +86,7 @@ def main(): cmdline_msg = ("cmdline: %s, %s had no cloud-config" % (key, url)) except Exception: - cmdline_exc = "%s\n%s\n" % (traceback.format_exc(), - "cmdline token was %s=%s" % (key, url)) + cmdline_exc = traceback.format_exc() warn(cmdline_exc) try: -- cgit v1.2.3 From 6d62fe860f55faf2d7b0b6216c11305e114c5214 Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Thu, 5 Apr 2012 00:30:28 -0400 Subject: add a better exception message --- cloud-init.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'cloud-init.py') diff --git a/cloud-init.py b/cloud-init.py index 08be1e0c..3261e3f3 100755 --- a/cloud-init.py +++ b/cloud-init.py @@ -76,8 +76,10 @@ def main(): if os.path.exists(target): cmdline_msg = "cmdline: %s existed" % target else: + cmdline=util.get_cmdline() try: - (key, url, content) = cloudinit.get_cmdline_url() + (key, url, content) = cloudinit.get_cmdline_url( + cmdline=cmdline) if key and content: util.write_file(target, content, mode=0600) cmdline_msg = ("cmdline: wrote %s from %s, %s" % @@ -86,7 +88,8 @@ def main(): cmdline_msg = ("cmdline: %s, %s had no cloud-config" % (key, url)) except Exception: - cmdline_exc = traceback.format_exc() + cmdline_exc = ("cmdline: '%s' raised exception\n%s" % + (cmdline, traceback.format_exc())) warn(cmdline_exc) try: -- cgit v1.2.3