Skip to content

Commit

Permalink
feat(abr-testing): Added search words for jira tickets (#15596)
Browse files Browse the repository at this point in the history
<!--
Thanks for taking the time to open a pull request! Please make sure
you've read the "Opening Pull Requests" section of our Contributing
Guide:


https://github.com/Opentrons/opentrons/blob/edge/CONTRIBUTING.md#opening-pull-requests

To ensure your code is reviewed quickly and thoroughly, please fill out
the sections below to the best of your ability!
-->

# Overview

Adds more search words for error handling and reformats for clearer
comments.

# Test Plan

<!--
Use this section to describe the steps that you took to test your Pull
Request.
If you did not perform any testing provide justification why.

OT-3 Developers: You should default to testing on actual physical
hardware.
Once again, if you did not perform testing against hardware, justify
why.

Note: It can be helpful to write a test plan before doing development

Example Test Plan (HTTP API Change)

- Verified that new optional argument `dance-party` causes the robot to
flash its lights, move the pipettes,
then home.
- Verified that when you omit the `dance-party` option the robot homes
normally
- Added protocol that uses `dance-party` argument to G-Code Testing
Suite
- Ran protocol that did not use `dance-party` argument and everything
was successful
- Added unit tests to validate that changes to pydantic model are
correct

-->

# Changelog

<!--
List out the changes to the code in this PR. Please try your best to
categorize your changes and describe what has changed and why.

Example changelog:
- Fixed app crash when trying to calibrate an illegal pipette
- Added state to API to track pipette usage
- Updated API docs to mention only two pipettes are supported

IMPORTANT: MAKE SURE ANY BREAKING CHANGES ARE PROPERLY COMMUNICATED
-->

# Review requests

<!--
Describe any requests for your reviewers here.
-->

# Risk assessment

<!--
Carefully go over your pull request and look at the other parts of the
codebase it may affect. Look for the possibility, even if you think it's
small, that your change may affect some other part of the system - for
instance, changing return tip behavior in protocol may also change the
behavior of labware calibration.

Identify the other parts of the system your codebase may affect, so that
in addition to your own review and testing, other people who may not
have the system internalized as much as you can focus their attention
and testing there.
-->
  • Loading branch information
rclarke0 authored Jul 8, 2024
1 parent 66c8a68 commit 12f9095
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 22 deletions.
28 changes: 20 additions & 8 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def create_ticket(
robot: str,
) -> Tuple[str, str]:
"""Create ticket."""
# Check if software version is a field on JIRA, if not replaces with existing version
data = {
"fields": {
"project": {"id": "10273", "key": project_key},
Expand All @@ -73,7 +74,6 @@ def create_ticket(
"parent": {"key": robot},
"priority": {"name": priority},
"components": [{"name": component} for component in components],
"versions": [{"name": affects_versions}],
"description": {
"content": [
{
Expand All @@ -87,6 +87,12 @@ def create_ticket(
# Include other required fields as needed
}
}
available_versions = self.get_project_versions(project_key)
if affects_versions in available_versions:
data["fields"]["versions"] = [{"name": affects_versions}]
print(f"Software version {affects_versions} added.")
else:
print("Software version of robot not in jira releases.")
try:
response = requests.post(
f"{self.url}/rest/api/3/issue",
Expand Down Expand Up @@ -139,6 +145,17 @@ def get_project_issues(self, project_key: str) -> Dict[str, Any]:
response.raise_for_status()
return response.json()

def get_project_versions(self, project_key: str) -> List[str]:
"""Get all project software versions."""
url = f"{self.url}/rest/api/3/project/{project_key}/versions"
headers = {"Accept": "application/json"}
version_list = []
response = requests.request("GET", url, headers=headers, auth=self.auth)
versions = response.json()
for version in versions:
version_list.append(version["name"])
return version_list

def extract_users_from_issues(self, issues: dict) -> Dict[str, Any]:
"""Extract users from issues."""
users = dict()
Expand Down Expand Up @@ -185,20 +202,15 @@ def get_project_components(self, project_id: str) -> List[Dict[str, str]]:
components_list = response.json()
return components_list

def comment(self, comment_str: str, issue_url: str, comment_type: str) -> None:
def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
"""Leave comment on JIRA Ticket."""
comment_url = issue_url + "/comment"
payload = json.dumps(
{
"body": {
"type": "doc",
"version": 1,
"content": [
{
"type": comment_type,
"content": [{"type": "text", "text": comment_str}],
}
],
"content": content_list,
}
}
)
Expand Down
60 changes: 47 additions & 13 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,57 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"""Read log and comment error portion on JIRA ticket."""
for file_name in os.listdir(folder_path):
file_path = os.path.join(folder_path, file_name)
not_found_words = []
print(file_path)
if file_path.endswith(".log"):
with open(file_path) as file:
lines = file.readlines()
word = "error"
words = [
"error",
"traceback",
"error frame encountered",
"did not receive",
"collision_detected",
"fail",
"warning",
"failure",
"homingfail",
"timed out",
"exception",
]
error_lines = ""
for line_index, line in enumerate(lines):
if word in line:
lines_before = max(0, line_index - 20)
lines_after = min(len(lines), line_index + 20)
print("Line Number:", line_index + 1)
error_lines = "".join(lines[lines_before:lines_after])
message = f"Error found in {file_path}"
ticket.comment(error_lines, issue_url, "codeBlock")
break
if len(error_lines) < 1:
message = f"No error found in {file_name}"
ticket.comment(message, issue_url, "paragraph")
for word in words:
content_list = []
for line_index, line in enumerate(lines):
if word in line.lower():
lines_before = max(0, line_index - 10)
lines_after = min(len(lines), line_index + 10)
error_lines = "".join(lines[lines_before:lines_after])
code_lines = {
"type": "codeBlock",
"content": [{"type": "text", "text": error_lines}],
}
content_list.append(code_lines)
num_times = len(content_list)
if num_times == 0:
not_found_words.append(word)
else:
message = f"Key word '{word.upper()}' found in {file_name} {num_times} TIMES."
line_1 = {
"type": "paragraph",
"content": [{"type": "text", "text": message}],
}
content_list.insert(0, line_1)
ticket.comment(content_list, issue_url)
no_word_found_message = (
f"Key words '{not_found_words} were not found in {file_name}."
)
no_word_found_dict = {
"type": "paragraph",
"content": [{"type": "text", "text": no_word_found_message}],
}
content_list.append(no_word_found_dict)
ticket.comment(content_list, issue_url)


def match_error_to_component(
Expand Down Expand Up @@ -282,6 +315,7 @@ def get_run_error_info_from_robot(
project_key = "RABR"
print(robot)
parent_key = project_key + "-" + robot.split("ABR")[1]

# TODO: read board to see if ticket for run id already exists.
# CREATE TICKET
issue_key, raw_issue_url = ticket.create_ticket(
Expand Down
4 changes: 3 additions & 1 deletion abr-testing/abr_testing/tools/abr_scale.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ def get_most_recent_run_and_record(
google_sheet_abr_data.batch_update_cells(runs_and_robots, "A", start_row, "0")
print("Wrote run to ABR-run-data")
# Add LPC to google sheet
google_sheet_lpc = google_sheets_tool.google_sheet(credentials_path, "ABR-LPC", 0)
google_sheet_lpc = google_sheets_tool.google_sheet(
credentials_path, "ABR-LPC", tab_number=0
)
start_row_lpc = google_sheet_lpc.get_index_row() + 1
google_sheet_lpc.batch_update_cells(runs_and_lpc, "A", start_row_lpc, "0")

Expand Down

0 comments on commit 12f9095

Please sign in to comment.