diff --git a/tobiko/shell/ssh/_config.py b/tobiko/shell/ssh/_config.py index a9b746bf3..0e75ccac1 100644 --- a/tobiko/shell/ssh/_config.py +++ b/tobiko/shell/ssh/_config.py @@ -16,6 +16,7 @@ from __future__ import absolute_import import collections +import io import os import typing # noqa import urllib @@ -75,9 +76,15 @@ class SSHConfigFixture(tobiko.SharedFixture): config_file = tobiko.tobiko_config_path(config_file) if os.path.exists(config_file): LOG.debug("Parsing %r config file...", config_file) - with open(config_file) as f: - self.config.parse(f) - LOG.debug("File %r parsed.", config_file) + try: + with io.open(config_file, 'rt', + encoding="utf-8") as f: + self.config.parse(f) + except Exception as ex: + LOG.exception(f"Error parsing '{config_file}' SSH config " + f"file: {ex}") + else: + LOG.debug("File %r parsed.", config_file) def lookup(self, host: typing.Optional[str] = None, diff --git a/tobiko/tests/unit/shell/test_ssh.py b/tobiko/tests/unit/shell/test_ssh.py index d32e331b8..0ab48a8cc 100644 --- a/tobiko/tests/unit/shell/test_ssh.py +++ b/tobiko/tests/unit/shell/test_ssh.py @@ -15,6 +15,7 @@ # under the License. from __future__ import absolute_import +import io import os import mock @@ -61,7 +62,8 @@ class SSHClientFixtureTest(unit.TobikoUnitTest): for ssh_config_file in CONF.tobiko.ssh.config_files: ssh_config_file = tobiko.tobiko_config_path(ssh_config_file) if os.path.exists(ssh_config_file): - with open(ssh_config_file) as f: + with io.open(ssh_config_file, 'rt', + encoding="utf-8") as f: ssh_config.parse(f) expected_host_config = ssh_config.lookup(fixture.host) expected_host_config.pop('include', None)