Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 70 additions & 5 deletions hw_submission_automation/hw_submission_automation.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
python3 hw_submission_automation.py -n test_rng -g 11.latest -p /home/271_RNG_win11_unsigned.hlkx -d 2025-06-24
python3 hw_submission_automation.py submit -n test_rng -g 11.latest -p /home/271_RNG_win11_unsigned.hlkx -d 2025-06-24
python3 hw_submission_automation.py wait_download --input_json result_product_test_blk.json --output_file /path/to/file.signed.zip
python3 hw_submission_automation.py submission_info --input_json result_product_test_blk.json --output_file /path/to/submission_info.json
python3 hw_submission_automation.py submission_info --product_id=13791770662366887 --submission_id=1152921505700160123
"""

import argparse
Expand Down Expand Up @@ -272,6 +274,10 @@ def wait_for_submission(self, product_id: str, submission_id: str) -> str:
"""Wait for submission completion"""
return self._run_sdcm(["--wait", "--productid", product_id, "--submissionid", submission_id])

def submission_info(self, product_id: str, submission_id: str) -> str:
"""Get submission info"""
return self._run_sdcm(["--list=submission", "--productid", product_id, "--submissionid", submission_id])

def download_results(self, product_id: str, submission_id: str, output_file: str) -> str:
"""Download submission results"""
return self._run_sdcm(
Expand Down Expand Up @@ -368,8 +374,8 @@ def parse_arguments():
"action",
nargs="?",
default="submit",
choices=["submit", "wait_download"],
help="Action to perform: submit (default) or wait_download"
choices=["submit", "wait_download", "submission_info"],
help="Action to perform: submit (default), wait_download, submission_info"
)

parser.add_argument(
Expand Down Expand Up @@ -599,7 +605,9 @@ def main_wait_download(args):
print("Error: --output_file is required for download action")
sys.exit(1)

output_file = os.path.abspath(args.output_file)
# output_file = os.path.abspath(args.output_file)
# if script is running in Cygwin environment, os.path.abspath will broke Windows path
output_file = args.output_file

wrapper = SDCMWrapper()
print(f"Waiting for submission with product ID: {args.product_id} and submission ID: {args.submission_id}")
Expand All @@ -614,19 +622,76 @@ def main_wait_download(args):
metadata_file = output_file + "_metadata.json"
wrapper.download_metadata(args.product_id, args.submission_id, metadata_file)

def main_submission_info(args):
print(f"[INFO] Submission info action selected")

input_json_data = None
if args.input_json:
try:
with open(args.input_json, "r") as f:
input_json_data = json.load(f)
print(f"[INFO] Loaded input JSON data from {args.input_json}")
except Exception as e:
print(f"Error: Failed to load input JSON file '{args.input_json}': {e}")
sys.exit(1)
Comment on lines +634 to +636

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Catching a broad Exception is generally discouraged as it can hide unexpected errors. It's better to catch more specific exceptions that you expect to handle, such as FileNotFoundError and json.JSONDecodeError.

Suggested change
except Exception as e:
print(f"Error: Failed to load input JSON file '{args.input_json}': {e}")
sys.exit(1)
except (FileNotFoundError, json.JSONDecodeError) as e:
print(f"Error: Failed to load or parse input JSON file '{args.input_json}': {e}")
sys.exit(1)


if not args.product_id:
if input_json_data and "product_id" in input_json_data:
args.product_id = input_json_data["product_id"]
else:
print("Error: --product_id is required for submission_info action")
sys.exit(1)
if not args.submission_id:
if input_json_data and "submission_id" in input_json_data:
args.submission_id = input_json_data["submission_id"]
else:
print("Error: --submission_id is required for submission_info action")
sys.exit(1)
if not args.output_file:
if input_json_data and "output_file" in input_json_data:
args.output_file = input_json_data["output_file"]
Comment on lines +628 to +652

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This block of code for handling arguments from a JSON file is nearly identical to the one in main_wait_download. To reduce code duplication and improve maintainability, consider extracting this logic into a helper function. The helper could take args and a list of required arguments as parameters, and return the populated args object. This would make the code more DRY (Don't Repeat Yourself).



wrapper = SDCMWrapper()
print(f"Getting information for submission with product ID: {args.product_id} and submission ID: {args.submission_id}")
text_info = wrapper.submission_info(args.product_id, args.submission_id)
print(f"Submission info retrieved")

results = {
"product_id": args.product_id,
"submission_id": args.submission_id,
}
# Simple parsing to find product ID from output, might need adjustment depending on output format
parsing_rules = [
("commit_status", r"\s*commitStatus:\s*(\S+)"),
("name", r"\s*Name:\s*(\S+.*)"),
("type", r"\s*type:\s*(\S+)"),
("step", r"\s*> Step:\s*(\S+)"),
("state", r"\s*> State:\s*(\S+)"),
]
for key, pattern in parsing_rules:
match = re.search(pattern, text_info)
if match:
results[key] = match.group(1)

info_file = args.output_file or slugify(f"Submission_Info_{args.product_id}_{args.submission_id}.json")
with open(info_file, "w") as f:
json.dump(results, f, indent=4)

if __name__ == "__main__":
# Parse command line arguments
args = parse_arguments()

# Check that action is supported
if args.action not in ["submit", "wait_download"]:
if args.action not in ["submit", "submission_info", "wait_download"]:
print(f"Error: Unsupported action '{args.action}'")
print("Supported actions: submit, wait_download")
print("Supported actions: submit, submission_info, wait_download")
sys.exit(1)

# Call appropriate main function based on action
if args.action == "submit":
main_submit(args)
elif args.action == "wait_download":
main_wait_download(args)
elif args.action == "submission_info":
main_submission_info(args)
Loading