Skip to content

Commit

Permalink
feat (hardware-testing): add JIRA functionality to testing scripts (#…
Browse files Browse the repository at this point in the history
…16013)

<!--
Thanks for taking the time to open a Pull Request (PR)! 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

GitHub provides robust markdown to format your PR. Links, diagrams,
pictures, and videos along with text formatting make it possible to
create a rich and informative PR. For more information on GitHub
markdown, see:


https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax

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

# Overview

This pull request adds a few new features to existing hardware testing
scripts and a small bug fix.

## Test Plan and Hands on Testing

I ran every new script on robots while initiating errors and trying to
break them. All changes to the jira_tool script work with every current
references of the script.

## Changelog

First, the speed_accel_profile script can now post results and raw data
to Jira and print a summary of the test outside of Jira. Next, in the
"gripper_and_zmount_move" you can now change the distance, log results,
and post results to a Jira ticket. Both of these script changes required
a few small changes and additions to the jira_tool script. Also, both of
these scripts can be used without Jira integration and outside of ABR.
Lastly, a bug in the abr_robot_error script that prevented LPC data from
being collected was fixed.

## Review requests

Checking message statements and if some functions should be defined in
different scripts.

## Risk assessment

Not much, this only affects ABR and hardware testing scripts. 
<!--
- Indicate the level of attention this PR needs.
- Provide context to guide reviewers.
- Discuss trade-offs, coupling, and side effects.
- 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 may also change the
behavior of labware calibration.
- How do your unit tests and on hands on testing mitigate this PR's
risks and the risk of future regressions?
- Especially in high risk PRs, explain how you know your testing is
enough.
-->
  • Loading branch information
nbshiland authored Aug 19, 2024
1 parent 177001f commit 322109a
Show file tree
Hide file tree
Showing 4 changed files with 360 additions and 57 deletions.
35 changes: 30 additions & 5 deletions abr-testing/abr_testing/automation/jira_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,14 +174,16 @@ def post_attachment_to_ticket(self, issue_id: str, attachment_path: str) -> None
"file": (attachment_path, open(attachment_path, "rb"), "application-type")
}
JSON_headers = {"Accept": "application/json", "X-Atlassian-Token": "no-check"}
attachment_url = f"{self.url}/rest/api/3/issue/{issue_id}/attachments"
try:
response = requests.post(
f"{self.url}/rest/api/3/issue/{issue_id}/attachments",
response = requests.request(
"POST",
attachment_url,
headers=JSON_headers,
auth=self.auth,
files=file,
)
print(f"File: {attachment_path} posted to ticket {issue_id}")
print(f"File: {attachment_path} posted to ticket {issue_id}.")
except json.JSONDecodeError:
error_message = str(response.content)
print(f"JSON decoding error occurred. Response content: {error_message}.")
Expand Down Expand Up @@ -257,9 +259,9 @@ def get_project_components(self, project_id: str) -> List[Dict[str, str]]:
components_list = response.json()
return components_list

def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
def comment(self, content_list: List[Dict[str, Any]], issue_key: str) -> None:
"""Leave comment on JIRA Ticket."""
comment_url = issue_url + "/comment"
comment_url = f"{self.url}/rest/api/3/issue/{issue_key}/comment"
payload = json.dumps(
{
"body": {
Expand All @@ -273,6 +275,29 @@ def comment(self, content_list: List[Dict[str, Any]], issue_url: str) -> None:
"POST", comment_url, data=payload, headers=self.headers, auth=self.auth
)

def format_jira_comment(self, comment_info: Any) -> List[Dict[str, Any]]:
"""Formats a string input to work with the "comment" function."""
content_list: List = []
line_1 = {
"type": "paragraph",
"content": [{"type": "text", "text": comment_info}],
}
content_list.insert(0, line_1)
return content_list

def get_ticket(self) -> str:
"""Gets and confirms jira ticket number."""
while True:
issue_key = input("Ticket Key: ")
url = f"{self.url}/rest/api/3/issue/{issue_key}"
headers = {"Accept": "application/json"}
response = requests.request("GET", url, headers=headers, auth=self.auth)
if str(response) == "<Response [200]>":
break
else:
print("Please input a valid JIRA Key")
return issue_key


if __name__ == "__main__":
"""Create ticket for specified robot."""
Expand Down
37 changes: 21 additions & 16 deletions abr-testing/abr_testing/data_collection/abr_robot_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"content": [{"type": "text", "text": message}],
}
content_list.insert(0, line_1)
ticket.comment(content_list, issue_url)
ticket.comment(content_list, issue_key)
no_word_found_message = (
f"Key words '{not_found_words} were not found in {file_name}."
)
Expand All @@ -209,7 +209,7 @@ def read_each_log(folder_path: str, issue_url: str) -> None:
"content": [{"type": "text", "text": no_word_found_message}],
}
content_list.append(no_word_found_dict)
ticket.comment(content_list, issue_url)
ticket.comment(content_list, issue_key)


def match_error_to_component(
Expand Down Expand Up @@ -383,21 +383,26 @@ def get_run_error_info_from_robot(
errored_labware_dict["Slot"] = labware["location"].get("slotName", "")
errored_labware_dict["Labware Type"] = labware.get("definitionUri", "")
offset_id = labware.get("offsetId", "")
for lpc in lpc_dict:
if lpc.get("id", "") == offset_id:
errored_labware_dict["X"] = lpc["vector"].get("x", "")
errored_labware_dict["Y"] = lpc["vector"].get("y", "")
errored_labware_dict["Z"] = lpc["vector"].get("z", "")
errored_labware_dict["Module"] = lpc["location"].get(
"moduleModel", ""
)
errored_labware_dict["Adapter"] = lpc["location"].get(
"definitionUri", ""
)
if offset_id == "":
labware_slot = errored_labware_dict["Slot"]
lpc_message = f"The current LPC coords found at {labware_slot} are (0, 0, 0). \
Please confirm with the ABR-LPC sheet and re-LPC."
else:
for lpc in lpc_dict:
if lpc.get("id", "") == offset_id:
errored_labware_dict["X"] = lpc["vector"].get("x", "")
errored_labware_dict["Y"] = lpc["vector"].get("y", "")
errored_labware_dict["Z"] = lpc["vector"].get("z", "")
errored_labware_dict["Module"] = lpc["location"].get(
"moduleModel", ""
)
errored_labware_dict["Adapter"] = lpc["location"].get(
"definitionUri", ""
)

lpc_message = compare_lpc_to_historical_data(
errored_labware_dict, parent, storage_directory
)
lpc_message = compare_lpc_to_historical_data(
errored_labware_dict, parent, storage_directory
)

description["protocol_step"] = protocol_step
description["right_mount"] = results.get("right", "No attachment")
Expand Down
Loading

0 comments on commit 322109a

Please sign in to comment.