Skip to content

Commit 447a174

Browse files
jingfelixacerv
authored andcommitted
ssh: add support for known_hosts
Reviewed-by: Andrea Cervesato <andrea.cervesato@suse.com> Signed-off-by: jingfelix <jingfelix@outlook.com> Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com> Closes: #42
1 parent 515a505 commit 447a174

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

libkirk/ssh.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def __init__(self) -> None:
7474
self._password = None
7575
self._key_file = None
7676
self._sudo = False
77+
self._known_hosts = None
7778
self._session_sem = None
7879
self._stop = False
7980
self._conn = None
@@ -94,6 +95,7 @@ def config_help(self) -> dict:
9495
"key_file": "private key location",
9596
"reset_cmd": "command to reset the remote SUT",
9697
"sudo": "use sudo to access to root shell (default: 0)",
98+
"known_hosts": "path to custom known_hosts file (optional)",
9799
}
98100

99101
async def _reset(self, iobuffer: IOBuffer = None) -> None:
@@ -161,6 +163,7 @@ def setup(self, **kwargs: dict) -> None:
161163
self._user = kwargs.get("user", "root")
162164
self._password = kwargs.get("password", None)
163165
self._key_file = kwargs.get("key_file", None)
166+
self._known_hosts = kwargs.get("known_hosts", None)
164167

165168
try:
166169
self._port = int(kwargs.get("port", "22"))
@@ -196,13 +199,15 @@ async def communicate(self, iobuffer: IOBuffer = None) -> None:
196199
host=self._host,
197200
port=self._port,
198201
username=self._user,
199-
client_keys=[priv_key])
202+
client_keys=[priv_key],
203+
known_hosts=self._known_hosts)
200204
else:
201205
self._conn = await asyncssh.connect(
202206
host=self._host,
203207
port=self._port,
204208
username=self._user,
205-
password=self._password)
209+
password=self._password,
210+
known_hosts=self._known_hosts)
206211

207212
# read maximum number of sessions and limit `run_command`
208213
# concurrent calls to that by using a semaphore
@@ -225,7 +230,8 @@ async def stop(self, iobuffer: IOBuffer = None) -> None:
225230
self._stop = True
226231
try:
227232
if self._channels:
228-
self._logger.info("Killing %d process(es)", len(self._channels))
233+
self._logger.info("Killing %d process(es)",
234+
len(self._channels))
229235

230236
for proc in self._channels:
231237
proc.kill()

0 commit comments

Comments
 (0)