From 19b11d7e269360880d11d883a59b80b2909cee0f Mon Sep 17 00:00:00 2001 From: Scott Moser Date: Tue, 26 Mar 2013 15:50:25 -0400 Subject: handle errors in cc_reizefs better Now, errors will not be so annoying if the device doesn't exist. Specifically, if there is no device in a container, only debug messages will be logged. LP: #1160462 --- cloudinit/config/cc_resizefs.py | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'cloudinit') diff --git a/cloudinit/config/cc_resizefs.py b/cloudinit/config/cc_resizefs.py index 51dead2f..b4ee16b2 100644 --- a/cloudinit/config/cc_resizefs.py +++ b/cloudinit/config/cc_resizefs.py @@ -18,6 +18,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . +import errno import os import stat import time @@ -75,9 +76,29 @@ def handle(name, cfg, _cloud, log, args): (devpth, fs_type, mount_point) = result # Ensure the path is a block device. - if not stat.S_ISBLK(os.stat(devpth).st_mode): - log.debug("The %s device which was found for mount point %s for %s " - "is not a block device" % (devpth, mount_point, resize_what)) + info = "dev=%s mnt_point=%s path=%s" % (devpth, mount_point, resize_what) + log.debug("resize_info: %s" % info) + + try: + statret = os.stat(devpth) + except OSError as exc: + if util.is_container() and exc.errno == errno.ENOENT: + log.debug("Device '%s' did not exist in container. " + "cannot resize: %s" % (devpth, info)) + elif exc.errno == errno.ENOENT: + log.warn("Device '%s' did not exist. cannot resize: %s" % + (devpth, info)) + else: + raise exc + return + + if not stat.S_ISBLK(statret.st_mode): + if util.is_container(): + log.debug("device '%s' not a block device in container." + " cannot resize: %s" % (devpth, info)) + else: + log.warn("device '%s' not a block device. cannot resize: %s" % + (devpth, info)) return resizer = None -- cgit v1.2.3