Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(system-server,robot-server,api): add ability to enable OEM Mode when setting enableOEMMode advanced setting. #14832

Merged
merged 12 commits into from
Apr 12, 2024

Conversation

vegano1
Copy link
Contributor

@vegano1 vegano1 commented Apr 8, 2024

Overview

We need to change the splash screen in user space, this is managed by the systems service opentrons-loading.service. This pull request in oe-core (Opentrons/oe-core#143) adds the mechanism to change the splash screen via the /var/lib/opentrons-system-server/system.env file. This pull request adds the endpoint and hooks it up to the robot-server to allow the OEM Mode to be enabled/disabled when the enableOEMMode feature flag is changed via the /system/settings POST request.

Closes: PLAT-275 PLAT-276

Test Plan

  • Build and test oe-core and buildroot builds on the Flex and OT-2
  • Make sure that the robot-server and system-server startup regardless of the value of enableOEMMode
  • Make sure we can change the oem_mode_enabled flag in the system.env via PUT /system/oem_mode/enable.
  • Make sure that we change the sysem.env file when the enableOEMMode advanced flag is set via POST /system/settings.
  • Make sure that we return a non-200 error code if PUT /system/oem_mode/enable fails for whatever reason.
  • Make sure that we DONT set the enableOEMMode advanced setting if PUT /system/oem_mode/enable fails.

Changelog

  • add aiohttp==3.8.1 to the robot-server so we can make async HTTP requests
  • add /system/oem_mode/enable endpoint to enable/disable OEM Mode by changing the system.env
  • add oem_mode_enabled and oem_mode_splash_custom system server config flags
  • add oem_mode_enabled helper function to feature_flags.py
  • add save_settings method to system-server settings so we can save the SystemServerSettings to a system.env
  • use the /system/oem_mode/enable endpoint when the enableOEMMode advanced settings flag is changed.

Review requests

  • Does the approach make sense of having the /system/oem_mode/enable request get triggered from the robot-server.
  • Ideally, the set_oem_mode_request is not just some floating function, this should be an HTTPClient that encapsulates HTTP requests to local endpoints. This might need to be added at a different time.
  • I haven't done HTTP API's in a while, so feedback is appreciated.

Risk assessment

  • low, should only affect enableOEMMOde advanced setting for the Flex and OT-2

Copy link

codecov bot commented Apr 8, 2024

Codecov Report

Attention: Patch coverage is 47.72727% with 23 lines in your changes are missing coverage. Please review.

Project coverage is 67.49%. Comparing base (8f50b08) to head (b0adf34).
Report is 10 commits behind head on edge.

❗ Current head b0adf34 differs from pull request most recent head 6c068d5. Consider uploading reports for the commit 6c068d5 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             edge   #14832      +/-   ##
==========================================
- Coverage   67.50%   67.49%   -0.02%     
==========================================
  Files        2521     2525       +4     
  Lines       72090    72124      +34     
  Branches     9311     9311              
==========================================
+ Hits        48666    48677      +11     
- Misses      21228    21251      +23     
  Partials     2196     2196              
Flag Coverage Δ
system-server 91.41% <47.72%> (-4.64%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
api/src/opentrons/config/feature_flags.py 100.00% <ø> (ø)
...er/robot_server/service/legacy/routers/settings.py 100.00% <ø> (ø)
system-server/system_server/settings/__init__.py 100.00% <100.00%> (ø)
...m-server/system_server/system/oem_mode/__init__.py 100.00% <100.00%> (ø)
...tem-server/system_server/system/oem_mode/models.py 100.00% <100.00%> (ø)
system-server/system_server/system/router.py 100.00% <100.00%> (ø)
...rver/system_server/system/oem_mode/dependencies.py 0.00% <0.00%> (ø)
...tem-server/system_server/system/oem_mode/router.py 42.85% <42.85%> (ø)
system-server/system_server/settings/settings.py 63.63% <35.29%> (-31.82%) ⬇️

@vegano1 vegano1 changed the title feat(robot-server,) feat(system-server,robot-server,api): add ability to enable OEM Mode when setting enableOEMMode advanced setting. Apr 8, 2024
@@ -76,3 +76,8 @@ def enable_error_recovery_experiments() -> bool:
return advs.get_setting_with_env_overload(
"enableErrorRecoveryExperiments", RobotTypeEnum.FLEX
)

def oem_mode_enabled() -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks good but perhaps this should be passed robot type instead of assume it. We've had problems with feature flags before where we assume type in the past and had to correct it, like with enable_door_safety_switch. If this is passed an OT-2 robot type I'd expect we'd just raise an error, or do nothing at all?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this should do nothing on the OT2, since all the logic that deals with OEM mode is on the client side.

Copy link
Contributor

Choose a reason for hiding this comment

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

If this is unused in the current build (and is not planned to be used) should we simply removed it all together?

@vegano1 vegano1 marked this pull request as ready for review April 10, 2024 22:16
@vegano1 vegano1 requested review from a team as code owners April 10, 2024 22:16
Copy link
Contributor

@CaseyBatten CaseyBatten left a comment

Choose a reason for hiding this comment

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

Overall everything looks good so far from my perspective. The justification for the odd coupling order (enabled OEM: client -> robot server -> system server, upload image: client -> system server) of the robot server, system server and client for file writing makes sense given actions occurring. However, we may want to note this decision for future divisions of labor between the system and robot servers to more cleanly separate the order of operations if any similar features are developed in the future.

Comment on lines 92 to +99
try:
# send request to system server if this is the enableOEMMode setting
if update.id == "enableOEMMode" and robot_type == RobotTypeEnum.FLEX:
resp = await set_oem_mode_request(update.value)
if resp != 200:
# TODO: raise correct error here
raise Exception(f"Something went wrong setting OEM Mode. err: {resp}")

Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed, the except handlers for the raised Exception below here are probably sufficient for the error response we'd want, so this should be okay.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

correct

@@ -76,3 +76,8 @@ def enable_error_recovery_experiments() -> bool:
return advs.get_setting_with_env_overload(
"enableErrorRecoveryExperiments", RobotTypeEnum.FLEX
)

def oem_mode_enabled() -> bool:
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is unused in the current build (and is not planned to be used) should we simply removed it all together?

Comment on lines +80 to +84
def save_settings(settings: SystemServerSettings) -> bool:
"""Save the settings to the dotenv file."""
env_path = Environment().dot_env_path
env_path = env_path or f"{settings.persistence_directory}/system.env"
prefix = settings.Config.env_prefix
Copy link
Contributor

Choose a reason for hiding this comment

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

As discussed the decision to have the system server responsible for this persistence file write is justified.

@vegano1 vegano1 merged commit 437e074 into edge Apr 12, 2024
23 checks passed
@vegano1 vegano1 deleted the PLAT-276-add-oem-mode-endpoint branch April 12, 2024 19:28
Carlos-fernandez pushed a commit that referenced this pull request May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants