Skip to content

Commit

Permalink
feat(hardware-testing): Store file containing output from git describ…
Browse files Browse the repository at this point in the history
…e to serve as QC versioning (#12402)

* create temporary file on OT3 storing operator's pushed monorepo git hash

* use git description instead of hash; adds python method for reading description file

* adds description to a few production scripts

* wip: moving logic to script so it's in one place

* works

* consolidate hardware-testing push commands into single push-ot3

* linting!

* don't append list if no files were modified
  • Loading branch information
andySigler authored Apr 5, 2023
1 parent 15e8a6f commit 605f348
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 15 deletions.
1 change: 1 addition & 0 deletions hardware-testing/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.pulled-data/*
*.tar.gz
*.zip
.hardware-testing-description
ot3-firmware/
18 changes: 10 additions & 8 deletions hardware-testing/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ push-plot-webpage-ot3:
scp -r hardware_testing/tools/plot root@$(host):/data
$(call move-plot-webpage-ot3,$(host),$(br_ssh_key),$(ssh_opts))

.PHONY: push-description-ot3
push-description-ot3:
$(python) -c "from hardware_testing.data import create_git_description_file; create_git_description_file()"
scp ./.hardware-testing-description root@$(host):/data/.hardware-testing-description

.PHONY: restart
restart:
$(call restart-service,$(host),$(br_ssh_key),$(ssh_opts),"opentrons-robot-server")
Expand All @@ -145,14 +150,11 @@ push-no-restart-ot3: sdist Pipfile.lock
$(call push-python-sdist,$(host),,$(ssh_opts),$(sdist_file),/opt/opentrons-robot-server,"hardware_testing")

.PHONY: push-ot3
push-ot3: push-no-restart-ot3 restart-ot3
push-ot3: push-no-restart-ot3 push-plot-webpage-ot3 push-description-ot3

.PHONY: push-all
push-all: clean wheel push-no-restart push-plot-webpage

.PHONY: push-all-ot3
push-all-ot3: push-ot3 push-plot-webpage-ot3

.PHONY: term
term:
ssh -i $(br_ssh_key) $(ssh_opts) root@$(host)
Expand Down Expand Up @@ -194,11 +196,11 @@ endef

.PHONY: sync-sw-ot3
sync-sw-ot3:
cd ../hardware && $(MAKE) push-no-restart-ot3 host=$(host)
cd ../api && $(MAKE) push-no-restart-ot3 host=$(host)
cd ../shared-data && $(MAKE) all push-no-restart-ot3 host=$(host)
cd ../hardware && $(MAKE) push-ot3 host=$(host)
cd ../api && $(MAKE) push-ot3 host=$(host)
cd ../shared-data && $(MAKE) all push-ot3 host=$(host)
cd ../robot-server && $(MAKE) push-ot3 host=$(host)
cd ../hardware-testing && $(MAKE) push-all-ot3 host=$(host)
cd ../hardware-testing && $(MAKE) push-ot3 host=$(host)

.PHONY: sync-fw-ot3
sync-fw-ot3:
Expand Down
42 changes: 41 additions & 1 deletion hardware-testing/hardware_testing/data/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,50 @@
from datetime import datetime
import os
from pathlib import Path
from subprocess import check_output
from time import time
from typing import Tuple

from opentrons.config import infer_config_base_dir
from opentrons.config import infer_config_base_dir, IS_ROBOT

GIT_DESCRIBE_NAME = ".hardware-testing-description"


def _git(*args: str) -> str:
return check_output(["git"] + list(args)).decode("utf-8").strip()


def _build_git_description_string() -> str:
if IS_ROBOT:
raise RuntimeError("unable to run git describe on robot")
description = _git("describe")
mods = _git("ls-files", "-m").replace("\n", ", ")
if not mods:
return description
return f"{description} [{mods}]"


def get_git_description() -> str:
"""Get git description file."""
if IS_ROBOT:
file_path = infer_config_base_dir() / GIT_DESCRIBE_NAME
if not file_path.exists():
return "unknown"
with open(file_path, "r") as f:
return f.read().strip()
else:
return _build_git_description_string()


def create_git_description_file() -> str:
"""Create git description file."""
if IS_ROBOT:
raise RuntimeError("unable to create git description file on robot")
contents = _build_git_description_string()
file_path = infer_config_base_dir() / GIT_DESCRIBE_NAME
with open(GIT_DESCRIBE_NAME, "w+") as f:
f.write(contents)
return str(file_path)


def get_testing_data_directory() -> Path:
Expand Down
13 changes: 10 additions & 3 deletions hardware-testing/hardware_testing/gravimetric/execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from opentrons.protocol_api import ProtocolContext, InstrumentContext, Well, Labware

from hardware_testing.data import create_run_id_and_start_time, ui
from hardware_testing.data import create_run_id_and_start_time, ui, get_git_description
from hardware_testing.opentrons_api.types import OT3Mount, Point
from hardware_testing.opentrons_api.helpers_ot3 import clear_pipette_ul_per_mm

Expand Down Expand Up @@ -283,6 +283,13 @@ def _record_measurement_and_store(m_type: MeasurementType) -> MeasurementData:
return volume_aspirate, volume_dispense


def _get_operator_name(is_simulating: bool) -> str:
if not is_simulating:
return input("OPERATOR name:").strip()
else:
return "simulation"


def run(ctx: ProtocolContext, cfg: config.GravimetricConfig) -> None:
"""Run."""
run_id, start_time = create_run_id_and_start_time()
Expand Down Expand Up @@ -342,8 +349,8 @@ def _drop_tip() -> None:
ui.print_header("CREATE TEST-REPORT")
test_report = report.create_csv_test_report(test_volumes, cfg, run_id=run_id)
test_report.set_tag(pipette_tag)
test_report.set_operator("unknown")
test_report.set_version("unknown")
test_report.set_operator(_get_operator_name(ctx.is_simulating()))
test_report.set_version(get_git_description())
report.store_serial_numbers(
test_report,
robot="ot3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import asyncio
from pathlib import Path

from hardware_testing.data import ui
from hardware_testing.data import ui, get_git_description
from hardware_testing.data.csv_report import RESULTS_OVERVIEW_TITLE
from hardware_testing.opentrons_api import helpers_ot3

Expand All @@ -23,10 +23,9 @@ async def _main(cfg: TestConfig) -> None:
else:
robot_id = "ot3-simulated-A01"
operator = "simulation"
software_version = "unknown" # FIXME: figure out what this should be
report.set_tag(robot_id)
report.set_operator(operator)
report.set_version(software_version)
report.set_version(get_git_description())

# BUILD API
api = await helpers_ot3.build_async_ot3_hardware_api(
Expand Down

0 comments on commit 605f348

Please sign in to comment.