Skip to content

Commit bb07e26

Browse files
committed
fix: pytest and e2e issue
1 parent 17d03ac commit bb07e26

2 files changed

Lines changed: 21 additions & 22 deletions

File tree

tests/e2e/test_driver_netmiko.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ def test_netmiko_exec_on_linux_ssh():
5454

5555
result = rpc.execute(req)
5656

57-
assert target.command in result
58-
assert "netpulse-e2e" in result[target.command]
57+
res = next(x for x in result if x.command == target.command)
58+
assert "netpulse-e2e" in res.output
5959

6060

6161
def test_netmiko_exec_on_srlinux(monkeypatch):
@@ -87,9 +87,9 @@ def test_netmiko_exec_on_srlinux(monkeypatch):
8787
except Exception as exc:
8888
pytest.skip(f"SR Linux auth/connection failed: {exc}")
8989

90-
assert target.command in result
91-
assert isinstance(result[target.command], str)
92-
assert result[target.command].strip()
90+
res = next(x for x in result if x.command == target.command)
91+
assert isinstance(res.output, str)
92+
assert res.output.strip()
9393

9494

9595
def test_netmiko_config_on_srlinux(monkeypatch):
@@ -126,7 +126,7 @@ def test_netmiko_config_on_srlinux(monkeypatch):
126126
pytest.skip(f"SR Linux auth/connection failed: {exc}")
127127

128128
assert isinstance(result, list)
129-
assert result and all(isinstance(item, str) for item in result)
129+
assert result and all(isinstance(res.output, str) for res in result)
130130

131131

132132
def test_netmiko_reuses_persisted_session(monkeypatch):
@@ -175,8 +175,8 @@ def spy_set(cls, session, conn_args):
175175
command=cmd,
176176
)
177177
result = rpc.execute(req)
178-
assert cmd in result
179-
assert "reuse" in result[cmd]
178+
res = next(x for x in result if x.command == cmd)
179+
assert "reuse" in res.output
180180

181181
non_none_sets = [s for s in set_calls if s]
182182
assert len(non_none_sets) == 1, "persisted session should be set once"
@@ -219,14 +219,14 @@ def test_api_exec_netmiko_pinned(node_worker, api_server, wait_for_job):
219219

220220
assert resp.status_code == 201, resp.text
221221
body = resp.json()
222-
job = body["data"]
222+
job = body
223223
assert job["queue"] == f"HostQ_{target.host}"
224224

225225
finished = wait_for_job(job_id=job["id"])
226226
assert finished["status"] == "finished"
227227
result = finished["result"]["retval"]
228-
assert cmd in result
229-
assert "api-netmiko-e2e" in result[cmd]
228+
res = next(x for x in result if x["command"] == cmd)
229+
assert "api-netmiko-e2e" in res["output"]
230230

231231

232232
def test_api_netmiko_srl_render_and_parse(node_worker, api_server, wait_for_job):
@@ -271,15 +271,14 @@ def test_api_netmiko_srl_render_and_parse(node_worker, api_server, wait_for_job)
271271
pytest.skip(f"API unreachable at {API_BASE}: {exc}")
272272

273273
assert resp.status_code == 201, resp.text
274-
job = resp.json()["data"]
274+
job = resp.json()
275275
assert job["queue"] == f"HostQ_{target.host}"
276276

277277
finished = wait_for_job(job_id=job["id"], timeout=120)
278278
assert finished["status"] == "finished"
279279
retval = finished["result"]["retval"]
280-
assert isinstance(retval, dict) and retval, "expected parsed output keyed by command"
281-
rendered_cmd = next(iter(retval.keys()))
282-
parsed = retval[rendered_cmd]
280+
res_dict = retval[0]
281+
parsed = res_dict.get("parsed")
283282
assert isinstance(parsed, list), "TextFSM parser should return a list of records"
284283

285284

@@ -328,7 +327,7 @@ def test_api_netmiko_srl_bulk_exec(node_worker, api_server, wait_for_job):
328327
timeout=15,
329328
)
330329
assert resp.status_code == 201, resp.text
331-
body = resp.json()["data"]
330+
body = resp.json()
332331
succeeded = body["succeeded"]
333332
failed = body["failed"]
334333

@@ -339,6 +338,6 @@ def test_api_netmiko_srl_bulk_exec(node_worker, api_server, wait_for_job):
339338
finished = wait_for_job(job_id=job["id"], timeout=120)
340339
assert finished["status"] == "finished"
341340
retval = finished["result"]["retval"]
342-
assert isinstance(retval, dict) and retval, "expected command output per host"
343-
# Since bulk returns list in order, ensure each job got output for the issued command.
344-
assert cmd in retval
341+
res_dict = next((x for x in retval if x["command"] == cmd), None)
342+
assert res_dict is not None, "expected command output per host"
343+
assert res_dict["output"]

tests/e2e/test_driver_paramiko.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def test_paramiko_file_transfer_upload_and_download(tmp_path):
132132
),
133133
)
134134
upload_result = rpc.execute(upload_req)
135-
res = next(x for x in upload_result if "file_transfer_upload" in x.command)
135+
res = next(x for x in upload_result if x.command.startswith("upload"))
136136
assert res.exit_status == 0
137137

138138
download_path = tmp_path / "paramiko-download.txt"
@@ -149,7 +149,7 @@ def test_paramiko_file_transfer_upload_and_download(tmp_path):
149149
),
150150
)
151151
download_result = rpc.execute(download_req)
152-
res = next(x for x in download_result if "file_transfer_download" in x.command)
152+
res = next(x for x in download_result if x.command.startswith("download"))
153153
assert res.exit_status == 0
154154
assert download_path.read_text() == upload_payload
155155

@@ -187,7 +187,7 @@ def test_api_exec_paramiko_fifo(fifo_worker, api_server, wait_for_job):
187187

188188
assert resp.status_code == 201, resp.text
189189
body = resp.json()
190-
job = body["data"]
190+
job = body
191191
assert job["queue"] == "FifoQ"
192192

193193
finished = wait_for_job(job_id=job["id"])

0 commit comments

Comments
 (0)