|
6 | 6 | import webbrowser
|
7 | 7 | import argparse
|
8 | 8 | from typing import List, Tuple
|
9 |
| -from abr_testing.data_collection import read_robot_logs, abr_google_drive, get_run_logs |
10 |
| - |
11 |
| - |
12 |
| -def get_error_runs_from_robot(ip: str) -> List[str]: |
13 |
| - """Get runs that have errors from robot.""" |
14 |
| - error_run_ids = [] |
15 |
| - response = requests.get( |
16 |
| - f"http://{ip}:31950/runs", headers={"opentrons-version": "3"} |
17 |
| - ) |
18 |
| - run_data = response.json() |
19 |
| - run_list = run_data["data"] |
20 |
| - for run in run_list: |
21 |
| - run_id = run["id"] |
22 |
| - num_of_errors = len(run["errors"]) |
23 |
| - if not run["current"] and num_of_errors > 0: |
24 |
| - error_run_ids.append(run_id) |
25 |
| - return error_run_ids |
26 |
| - |
27 |
| - |
28 |
| -def get_error_info_from_robot( |
29 |
| - ip: str, one_run: str, storage_directory: str |
30 |
| -) -> Tuple[str, str, str, List[str], str, str]: |
31 |
| - """Get error information from robot to fill out ticket.""" |
32 |
| - description = dict() |
33 |
| - # get run information |
34 |
| - results = get_run_logs.get_run_data(one_run, ip) |
35 |
| - # save run information to local directory as .json file |
36 |
| - saved_file_path = read_robot_logs.save_run_log_to_json( |
37 |
| - ip, results, storage_directory |
38 |
| - ) |
39 |
| - |
40 |
| - # Error Printout |
41 |
| - ( |
42 |
| - num_of_errors, |
43 |
| - error_type, |
44 |
| - error_code, |
45 |
| - error_instrument, |
46 |
| - error_level, |
47 |
| - ) = read_robot_logs.get_error_info(results) |
48 |
| - # JIRA Ticket Fields |
49 |
| - failure_level = "Level " + str(error_level) + " Failure" |
50 |
| - components = [failure_level, "Flex-RABR"] |
51 |
| - affects_version = results["API_Version"] |
52 |
| - parent = results.get("robot_name", "") |
53 |
| - print(parent) |
54 |
| - summary = parent + "_" + str(one_run) + "_" + str(error_code) + "_" + error_type |
55 |
| - # Description of error |
56 |
| - description["protocol_name"] = results["protocol"]["metadata"].get( |
57 |
| - "protocolName", "" |
58 |
| - ) |
59 |
| - description["error"] = " ".join([error_code, error_type, error_instrument]) |
60 |
| - description["protocol_step"] = list(results["commands"])[-1] |
61 |
| - description["right_mount"] = results.get("right", "No attachment") |
62 |
| - description["left_mount"] = results.get("left", "No attachment") |
63 |
| - description["gripper"] = results.get("extension", "No attachment") |
64 |
| - all_modules = abr_google_drive.get_modules(results) |
65 |
| - whole_description = {**description, **all_modules} |
66 |
| - whole_description_str = ( |
67 |
| - "{" |
68 |
| - + "\n".join("{!r}: {!r},".format(k, v) for k, v in whole_description.items()) |
69 |
| - + "}" |
70 |
| - ) |
71 |
| - |
72 |
| - return ( |
73 |
| - summary, |
74 |
| - parent, |
75 |
| - affects_version, |
76 |
| - components, |
77 |
| - whole_description_str, |
78 |
| - saved_file_path, |
79 |
| - ) |
80 | 9 |
|
81 | 10 |
|
82 | 11 | class JiraTicket:
|
@@ -193,20 +122,6 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None
|
193 | 122 | if __name__ == "__main__":
|
194 | 123 | """Create ticket for specified robot."""
|
195 | 124 | parser = argparse.ArgumentParser(description="Pulls run logs from ABR robots.")
|
196 |
| - parser.add_argument( |
197 |
| - "storage_directory", |
198 |
| - metavar="STORAGE_DIRECTORY", |
199 |
| - type=str, |
200 |
| - nargs=1, |
201 |
| - help="Path to long term storage directory for run logs.", |
202 |
| - ) |
203 |
| - parser.add_argument( |
204 |
| - "robot_ip", |
205 |
| - metavar="ROBOT_IP", |
206 |
| - type=str, |
207 |
| - nargs=1, |
208 |
| - help="IP address of robot as string.", |
209 |
| - ) |
210 | 125 | parser.add_argument(
|
211 | 126 | "jira_api_token",
|
212 | 127 | metavar="JIRA_API_TOKEN",
|
@@ -238,38 +153,9 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None
|
238 | 153 | help="JIRA Board ID. RABR is 217",
|
239 | 154 | )
|
240 | 155 | args = parser.parse_args()
|
241 |
| - storage_directory = args.storage_directory[0] |
242 |
| - ip = args.robot_ip[0] |
243 | 156 | url = "https://opentrons.atlassian.net"
|
244 | 157 | api_token = args.jira_api_token[0]
|
245 | 158 | email = args.email[0]
|
246 | 159 | board_id = args.board_id[0]
|
247 | 160 | reporter_id = args.reporter_id[0]
|
248 | 161 | ticket = JiraTicket(url, api_token, email)
|
249 |
| - error_runs = get_error_runs_from_robot(ip) |
250 |
| - one_run = error_runs[-1] # Most recent run with error. |
251 |
| - ( |
252 |
| - summary, |
253 |
| - robot, |
254 |
| - affects_version, |
255 |
| - components, |
256 |
| - whole_description_str, |
257 |
| - saved_file_path, |
258 |
| - ) = get_error_info_from_robot(ip, one_run, storage_directory) |
259 |
| - print(f"Making ticket for run: {one_run} on robot {robot}.") |
260 |
| - # TODO: make argument or see if I can get rid of with using board_id. |
261 |
| - project_key = "RABR" |
262 |
| - parent_key = project_key + "-" + robot[-1] |
263 |
| - issue_url, issue_key = ticket.create_ticket( |
264 |
| - summary, |
265 |
| - whole_description_str, |
266 |
| - project_key, |
267 |
| - reporter_id, |
268 |
| - "Bug", |
269 |
| - "Medium", |
270 |
| - components, |
271 |
| - affects_version, |
272 |
| - parent_key, |
273 |
| - ) |
274 |
| - ticket.open_issue(issue_key) |
275 |
| - ticket.post_attachment_to_ticket(issue_key, saved_file_path) |
0 commit comments