Compare commits

..

2 Commits

Author SHA1 Message Date
Josiah Baldwin
df25652ba6 Fixed run_commands parsing return from multiple devices incorrectly 2025-01-08 13:42:39 -08:00
Josiah Baldwin
9668e4d507 Added test for using run_command on multiple nodes 2025-01-08 13:38:49 -08:00
2 changed files with 11 additions and 20 deletions

View File

@@ -1463,6 +1463,7 @@ class Session(object):
result.setdefault(node, {})["complete"] = True
if all(_["complete"] for key, _ in result.items()):
break
continue
elif (event["value"].startswith("Run commands")):
continue
result[node]["result"].append(event["value"])

View File

@@ -187,56 +187,47 @@ async def test_mesh_device(env):
assert r[0].description == "New description", "Description either failed to change, or was changed by a user without permission to do so"
with env.create_agent(mesh.short_meshid) as agent:
with env.create_agent(mesh.short_meshid) as agent,\
env.create_agent(mesh.short_meshid) as agent2:
# Test agent added to device group being propagated correctly
# Create agent isn't so good at waiting for the agent to show in the sessions. Give it a couple seconds to appear.
for i in range(3):
try:
r = await admin_session.list_devices(timeout=10)
print("\ninfo list_devices: {}\n".format(r))
assert len(r) == 1, "Incorrect number of agents connected"
assert len(r) == 2, "Incorrect number of agents connected"
except:
if i == 2:
raise
await asyncio.sleep(1)
else:
break
assert len(await privileged_session.list_devices(timeout=10)) == 1, "Incorrect number of agents connected"
assert len(await privileged_session.list_devices(timeout=10)) == 2, "Incorrect number of agents connected"
assert len(await unprivileged_session.list_devices(timeout=10)) == 0, "Unprivileged account has access to agent it should not"
r = await admin_session.list_devices(details=True, timeout=10)
print("\ninfo list_devices_details: {}\n".format(r))
assert len(r), "No devices found"
assert r[0].mesh is not None, "No mesh found"
assert r[0].mesh.name is not None, "Mesh details not filled correctly"
r = await admin_session.list_devices(group=mesh.name, timeout=10)
print("\ninfo list_devices_group: {}\n".format(r))
assert len(r), "No devices found"
assert r[0].mesh is not None, "No mesh found"
assert r[0].mesh.name is not None, "Mesh details not filled correctly"
r = await admin_session.list_devices(meshid=mesh.meshid, timeout=10)
print("\ninfo list_devices_meshid: {}\n".format(r))
assert len(r), "No devices found"
assert r[0].mesh is not None, "No mesh found"
assert r[0].mesh.name is not None, "Mesh details not filled correctly"
# Test editing device info propagating correctly
assert await admin_session.edit_device(agent.nodeid, name="new_name", description="New Description", tags="device", consent=meshctrl.constants.ConsentFlags.all, timeout=10), "Failed to edit device info"
r = await privileged_session.device_info(agent.nodeid, timeout=10)
print("\ninfo privileged_device_info: {}\n".format(r))
assert r.name == "new_name", "New name did not propagate to other sessions"
assert r.mesh is not None, "No mesh found"
assert r.mesh.name is not None, "Mesh details not filled correctly"
assert (await privileged_session.device_info(agent.nodeid, timeout=10)).name == "new_name", "New name did not propagate to other sessions"
assert await admin_session.edit_device(agent.nodeid, consent=meshctrl.constants.ConsentFlags.none, timeout=10), "Failed to edit device info"
# Test run_commands
r = await admin_session.run_command(agent.nodeid, "ls", timeout=10)
r = await admin_session.run_command([agent.nodeid, agent2.nodeid], "ls", timeout=10)
print("\ninfo run_command: {}\n".format(r))
assert "meshagent" in r[agent.nodeid]["result"], "ls gave incorrect data"
assert "meshagent" in r[agent2.nodeid]["result"], "ls gave incorrect data"
assert "Run commands completed." not in r[agent.nodeid]["result"], "Didn't parse run command ending correctly"
assert "Run commands completed." not in r[agent2.nodeid]["result"], "Didn't parse run command ending correctly"
assert "meshagent" in (await privileged_session.run_command(agent.nodeid, "ls", timeout=10))[agent.nodeid]["result"], "ls gave incorrect data"
# Test run commands with ndividual device permissions
@@ -265,8 +256,7 @@ async def test_mesh_device(env):
# Test getting individual device info
r = await unprivileged_session.device_info(agent.nodeid, timeout=10)
print("\ninfo unprivileged_device_info: {}\n".format(r))
assert r.mesh is None or r.mesh.name is None, "Unprivileged user can see mesh"
print("\ninfo device_info: {}\n".format(r))
# This device info includes the mesh ID of the device, even though the user doesn't have acces to that mesh. That's odd.
# assert r.meshid is None, "Individual device is exposing its meshid"