Skip to content

Commit

Permalink
Fix blktap error mapping in python3
Browse files Browse the repository at this point in the history
```
    def _errmsg(self):
        output = map(str.rstrip, self._p.stderr)
        return "; ".join(output)
```

rstrip is only compatible with str but stderr field uses bytes type
instead of str in python3, so we use `universal_newlines` on subprocess.Popen
to fix this problem.

Signed-off-by: Ronan Abhamon <[email protected]>
  • Loading branch information
Wescoeur committed Jul 5, 2023
1 parent a30cb16 commit 0501fca
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions drivers/blktap2.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ def _call(cls, args, quiet=False, input=None):
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True)
close_fds=True,
universal_newlines=True)
if input:
p.stdin.write(input)
p.stdin.close()
Expand Down Expand Up @@ -246,7 +247,7 @@ def _pread(cls, args, quiet=False, input=None):
output = tapctl.stdout.readline().rstrip()

tapctl._wait(quiet)
return output.decode()
return output

@staticmethod
def _maybe(opt, parm):
Expand All @@ -265,16 +266,15 @@ def __list(cls, minor=None, pid=None, _type=None, path=None):
tapctl = cls._call(args, True)

for stdout_line in tapctl.stdout:
decoded_line = stdout_line.decode()
# FIXME: tap-ctl writes error messages to stdout and
# confuses this parser
if decoded_line == "blktap kernel module not installed\n":
if stdout_line == "blktap kernel module not installed\n":
# This isn't pretty but (a) neither is confusing stdout/stderr
# and at least causes the error to describe the fix
raise Exception("blktap kernel module not installed: try 'modprobe blktap'")
row = {}

for field in decoded_line.rstrip().split(' ', 3):
for field in stdout_line.rstrip().split(' ', 3):
bits = field.split('=')
if len(bits) == 2:
key, val = field.split('=')
Expand Down

0 comments on commit 0501fca

Please sign in to comment.