Merge "Use UTF-8 encoding when reading SSH config files"
This commit is contained in:
commit
8346887588
|
@ -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,
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue