Use UTF-8 encoding when reading SSH config files
This prevents configuration errors with Python 3.6 Change-Id: Ife61beb1d8bd5378f39ab58c1ee3956cc26316da
This commit is contained in:
parent
770f3dab17
commit
4b6d86e6a6
|
@ -16,6 +16,7 @@
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
import collections
|
import collections
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
import typing # noqa
|
import typing # noqa
|
||||||
import urllib
|
import urllib
|
||||||
|
@ -75,9 +76,15 @@ class SSHConfigFixture(tobiko.SharedFixture):
|
||||||
config_file = tobiko.tobiko_config_path(config_file)
|
config_file = tobiko.tobiko_config_path(config_file)
|
||||||
if os.path.exists(config_file):
|
if os.path.exists(config_file):
|
||||||
LOG.debug("Parsing %r config file...", config_file)
|
LOG.debug("Parsing %r config file...", config_file)
|
||||||
with open(config_file) as f:
|
try:
|
||||||
self.config.parse(f)
|
with io.open(config_file, 'rt',
|
||||||
LOG.debug("File %r parsed.", config_file)
|
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,
|
def lookup(self,
|
||||||
host: typing.Optional[str] = None,
|
host: typing.Optional[str] = None,
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
# under the License.
|
# under the License.
|
||||||
from __future__ import absolute_import
|
from __future__ import absolute_import
|
||||||
|
|
||||||
|
import io
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
@ -61,7 +62,8 @@ class SSHClientFixtureTest(unit.TobikoUnitTest):
|
||||||
for ssh_config_file in CONF.tobiko.ssh.config_files:
|
for ssh_config_file in CONF.tobiko.ssh.config_files:
|
||||||
ssh_config_file = tobiko.tobiko_config_path(ssh_config_file)
|
ssh_config_file = tobiko.tobiko_config_path(ssh_config_file)
|
||||||
if os.path.exists(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)
|
ssh_config.parse(f)
|
||||||
expected_host_config = ssh_config.lookup(fixture.host)
|
expected_host_config = ssh_config.lookup(fixture.host)
|
||||||
expected_host_config.pop('include', None)
|
expected_host_config.pop('include', None)
|
||||||
|
|
Loading…
Reference in New Issue