Skip to content

Commit

Permalink
feat(abr-testing,opentrons): make file command to push desired folder…
Browse files Browse the repository at this point in the history
…s to list of robot ips (#16909)

# Overview
Adds the ability to push one or more folders to one or more roots at
once

## Test Plan and Hands on Testing
Manually tested functionality of command

## Changelog
Added push-folder definition to opentrons makefile

---------

Co-authored-by: rclarke0 <[email protected]>
Co-authored-by: Rhyann Clarke <[email protected]>
  • Loading branch information
3 people authored Nov 21, 2024
1 parent da74897 commit 87c2ffd
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ push:
sleep 1
$(MAKE) -C $(UPDATE_SERVER_DIR) push

.PHONY: push-folder
PUSH_HELPER := abr-testing/abr_testing/tools/make_push.py
push-folder:
$(OT_PYTHON) $(PUSH_HELPER)

.PHONY: push-ot3
push-ot3:
Expand Down
95 changes: 95 additions & 0 deletions abr-testing/abr_testing/tools/make_push.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
"""Push one or more folders to one or more robots."""
import subprocess
import multiprocessing
import json

global folders
# Opentrons folders that can be pushed to robot
folders = [
"abr-testing",
"hardware-testing",
"abr-testing + hardware-testing",
"other",
]


def push_subroutine(cmd: str) -> None:
"""Pushes specified folder to specified robot."""
try:
subprocess.run(cmd)
except Exception:
print("failed to push folder")
raise


def main(folder_to_push: str, robot_to_push: str) -> int:
"""Main process!"""
cmd = "make -C {folder} push-ot3 host={ip}"
robot_ip_path = ""
push_cmd = ""
folder_int = int(folder_to_push)
if folders[folder_int].lower() == "abr-testing + hardware-testing":
if robot_to_push.lower() == "all":
robot_ip_path = input("Path to robot ips: ")
with open(robot_ip_path, "r") as ip_file:
robot_json = json.load(ip_file)
robot_ips_dict = robot_json.get("ip_address_list")
robot_ips = list(robot_ips_dict.keys())
ip_file.close()
else:
robot_ips = [robot_to_push]
for folder_name in folders[:-2]:
# Push abr-testing and hardware-testing folders to all robots
for robot in robot_ips:
print_proc = multiprocessing.Process(
target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",)
)
print_proc.start()
print_proc.join()
push_cmd = cmd.format(folder=folder_name, ip=robot)
process = multiprocessing.Process(
target=push_subroutine, args=(push_cmd,)
)
process.start()
process.join()
print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",))
print_proc.start()
print_proc.join()
else:

if folder_int == (len(folders) - 1):
folder_name = input("Which folder? ")
else:
folder_name = folders[folder_int]
if robot_to_push.lower() == "all":
robot_ip_path = input("Path to robot ips: ")
with open(robot_ip_path, "r") as ip_file:
robot_json = json.load(ip_file)
robot_ips = robot_json.get("ip_address_list")
ip_file.close()
else:
robot_ips = [robot_to_push]

# Push folder to robots
for robot in robot_ips:
print_proc = multiprocessing.Process(
target=print, args=(f"Pushing {folder_name} to {robot}!\n\n",)
)
print_proc.start()
print_proc.join()
push_cmd = cmd.format(folder=folder_name, ip=robot)
process = multiprocessing.Process(target=push_subroutine, args=(push_cmd,))
process.start()
process.join()
print_proc = multiprocessing.Process(target=print, args=("Done!\n\n",))
print_proc.start()
print_proc.join()
return 0


if __name__ == "__main__":
for i, folder in enumerate(folders):
print(f"{i}) {folder}")
folder_to_push = input("Please Select a Folder to Push: ")
robot_to_push = input("Type in robots ip (type all for all): ")
print(main(folder_to_push, robot_to_push))

0 comments on commit 87c2ffd

Please sign in to comment.