summaryrefslogtreecommitdiff
path: root/cloudinit/util.py
diff options
context:
space:
mode:
authorJoshua Harlow <harlowja@gmail.com>2016-06-10 14:22:17 -0700
committerJoshua Harlow <harlowja@gmail.com>2016-06-10 14:22:17 -0700
commita8de234ec60c76b7b788513e8111be04ad9205fb (patch)
tree28f16138e108fab6b66a748d9ef697d732c4107a /cloudinit/util.py
parenta3720feb537cb5189bccf4889b601704a4cdf1da (diff)
parent6ada153ebfd9483d76f904dafaa1fc80f61c9205 (diff)
downloadvyos-cloud-init-a8de234ec60c76b7b788513e8111be04ad9205fb.tar.gz
vyos-cloud-init-a8de234ec60c76b7b788513e8111be04ad9205fb.zip
Refactor a large part of the networking code.
Splits off distro specific code into specific files so that other kinds of networking configuration can be written by the various distro(s) that cloud-init supports. It also isolates some of the cloudinit.net code so that it can be more easily used on its own (and incorporated into other projects such as curtin). During this process it adds tests so that the net process can be tested (to some level) so that the format conversion processes can be tested going forward.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r--cloudinit/util.py16
1 files changed, 13 insertions, 3 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py
index d6b80dbe..8873264d 100644
--- a/cloudinit/util.py
+++ b/cloudinit/util.py
@@ -171,7 +171,8 @@ class ProcessExecutionError(IOError):
def __init__(self, stdout=None, stderr=None,
exit_code=None, cmd=None,
- description=None, reason=None):
+ description=None, reason=None,
+ errno=None):
if not cmd:
self.cmd = '-'
else:
@@ -202,6 +203,7 @@ class ProcessExecutionError(IOError):
else:
self.reason = '-'
+ self.errno = errno
message = self.MESSAGE_TMPL % {
'description': self.description,
'cmd': self.cmd,
@@ -1157,7 +1159,14 @@ def find_devs_with(criteria=None, oformat='device',
options.append(path)
cmd = blk_id_cmd + options
# See man blkid for why 2 is added
- (out, _err) = subp(cmd, rcs=[0, 2])
+ try:
+ (out, _err) = subp(cmd, rcs=[0, 2])
+ except ProcessExecutionError as e:
+ if e.errno == errno.ENOENT:
+ # blkid not found...
+ out = ""
+ else:
+ raise
entries = []
for line in out.splitlines():
line = line.strip()
@@ -1706,7 +1715,8 @@ def subp(args, data=None, rcs=None, env=None, capture=True, shell=False,
sp = subprocess.Popen(args, **kws)
(out, err) = sp.communicate(data)
except OSError as e:
- raise ProcessExecutionError(cmd=args, reason=e)
+ raise ProcessExecutionError(cmd=args, reason=e,
+ errno=e.errno)
rc = sp.returncode
if rc not in rcs:
raise ProcessExecutionError(stdout=out, stderr=err,