Commit 4444e963 authored by Jérome Perrin's avatar Jérome Perrin

format: fix callAndRead for python3

Fixes the following error:

    Traceback (most recent call last):
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/cli/entry.py", line 305, in run_subcommand
        result = cmd.run(parsed_args)
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/cli/command.py", line 56, in run
        return self.take_action(parsed_args)
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/cli/format.py", line 128, in take_action
        do_format(conf=conf)
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/format.py", line 1396, in do_format
        create_tap=conf.create_tap)
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/format.py", line 655, in format
        partition.address_list.append(self.interface.addIPv6Address())
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/format.py", line 1223, in addIPv6Address
        if self._addSystemAddress(addr, netmask, tap=tap):
      File "/opt/slapos/eggs/slapos.core-1.7.9-py3.7.egg/slapos/format.py", line 1086, in _addSystemAddress
        for l in result.split('\n'):
    TypeError: a bytes-like object is required, not 'str'
parent 5ea9b36b
Pipeline #22605 passed with stage
in 0 seconds
...@@ -150,9 +150,12 @@ def getPublicIPv4Address(): ...@@ -150,9 +150,12 @@ def getPublicIPv4Address():
return ipv4 return ipv4
def callAndRead(argument_list, raise_on_error=True): def callAndRead(argument_list, raise_on_error=True):
popen = subprocess.Popen(argument_list, popen = subprocess.Popen(
stdout=subprocess.PIPE, argument_list,
stderr=subprocess.STDOUT) stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
)
result = popen.communicate()[0] result = popen.communicate()[0]
if raise_on_error and popen.returncode != 0: if raise_on_error and popen.returncode != 0:
raise ValueError('Issue while invoking %r, result was:\n%s' % ( raise ValueError('Issue while invoking %r, result was:\n%s' % (
......
...@@ -950,5 +950,9 @@ class TestFormatConfig(SlapformatMixin): ...@@ -950,5 +950,9 @@ class TestFormatConfig(SlapformatMixin):
# TODO add more tests with config file # TODO add more tests with config file
if __name__ == '__main__':
unittest.main() class TestCallAndRead(unittest.TestCase):
def test_callAndRead(self):
self.assertEqual(
slapos.format.callAndRead(['echo', 'hello']),
(0, 'hello\n'))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment