diff options
author | Scott Moser <smoser@ubuntu.com> | 2013-03-26 15:50:25 -0400 |
---|---|---|
committer | Scott Moser <smoser@ubuntu.com> | 2013-03-26 15:50:25 -0400 |
commit | 19b11d7e269360880d11d883a59b80b2909cee0f (patch) | |
tree | 8c07bef7ecfa749aff05923677a24e6b645ab211 /cloudinit/config/cc_resizefs.py | |
parent | be0041e7c7fd6ce5ffc1c9c54893b715bcab6358 (diff) | |
download | vyos-cloud-init-19b11d7e269360880d11d883a59b80b2909cee0f.tar.gz vyos-cloud-init-19b11d7e269360880d11d883a59b80b2909cee0f.zip |
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
Diffstat (limited to 'cloudinit/config/cc_resizefs.py')
-rw-r--r-- | cloudinit/config/cc_resizefs.py | 27 |
1 files changed, 24 insertions, 3 deletions
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 <http://www.gnu.org/licenses/>. +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 |