~harlowja/cloud-init/cloud-init-net-refactor

« back to all changes in this revision

Viewing changes to cloudinit/util.py

  • Committer: Joshua Harlow
  • Date: 2016-05-19 21:26:30 UTC
  • mfrom: (1215.1.18 cloud-init)
  • Revision ID: harlowja@gmail.com-20160519212630-b2l2fsshopo50fdk
RemergeĀ againstĀ head/master

Show diffs side-by-side

added added

removed removed

Lines of Context:
171
171
 
172
172
    def __init__(self, stdout=None, stderr=None,
173
173
                 exit_code=None, cmd=None,
174
 
                 description=None, reason=None):
 
174
                 description=None, reason=None,
 
175
                 errno=None):
175
176
        if not cmd:
176
177
            self.cmd = '-'
177
178
        else:
202
203
        else:
203
204
            self.reason = '-'
204
205
 
 
206
        self.errno = errno
205
207
        message = self.MESSAGE_TMPL % {
206
208
            'description': self.description,
207
209
            'cmd': self.cmd,
1147
1149
        options.append(path)
1148
1150
    cmd = blk_id_cmd + options
1149
1151
    # See man blkid for why 2 is added
1150
 
    (out, _err) = subp(cmd, rcs=[0, 2])
 
1152
    try:
 
1153
        (out, _err) = subp(cmd, rcs=[0, 2])
 
1154
    except ProcessExecutionError as e:
 
1155
        if e.errno == errno.ENOENT:
 
1156
            # blkid not found...
 
1157
            out = ""
 
1158
        else:
 
1159
            raise
1151
1160
    entries = []
1152
1161
    for line in out.splitlines():
1153
1162
        line = line.strip()
1696
1705
        sp = subprocess.Popen(args, **kws)
1697
1706
        (out, err) = sp.communicate(data)
1698
1707
    except OSError as e:
1699
 
        raise ProcessExecutionError(cmd=args, reason=e)
 
1708
        raise ProcessExecutionError(cmd=args, reason=e,
 
1709
                                    errno=e.errno)
1700
1710
    rc = sp.returncode
1701
1711
    if rc not in rcs:
1702
1712
        raise ProcessExecutionError(stdout=out, stderr=err,