Skip to content

change: when possible (REST allows it), always power cycle the control host#1002

Merged
p-gentili merged 4 commits intomainfrom
always-reboot-control-host
Apr 8, 2026
Merged

change: when possible (REST allows it), always power cycle the control host#1002
p-gentili merged 4 commits intomainfrom
always-reboot-control-host

Conversation

@p-gentili
Copy link
Copy Markdown
Contributor

@p-gentili p-gentili commented Apr 6, 2026

Description

We currently power cycle the control host only if not reachable, because it might be a disruptive operation with a live system. After introducing a poweroff API though, this action becomes safe to do every time, making sure we always test with a clean system.

  1. Move power cycling logic to a central place, common to all devices
  2. Move all control host related logic into a dedicated class

Resolved issues

Resolves https://warthogs.atlassian.net/browse/ZAP-1446

Documentation

N/A

Web service API changes

N/A

Tests

Fallback (online):

2026-04-06 16:49:40,398 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Running pre-provision hook
2026-04-06 16:49:40,398 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Attempt to power cycle the control host.
2026-04-06 16:49:40,402 hp-pro-sff-400-g9-desktop-pc-c30464 WARNING: DEVICE CONNECTOR: The REST API is not available on 192.168.68.59, falling back to SSH-based control host check
2026-04-06 16:49:40,409 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: BEGIN provision
2026-04-06 16:49:40,409 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Provisioning device
...

Fallback (offline):

2026-04-06 16:49:52,051 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Running pre-provision hook
2026-04-06 16:49:52,052 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Attempt to power cycle the control host.
2026-04-06 16:50:02,062 hp-pro-sff-400-g9-desktop-pc-c30464 WARNING: DEVICE CONNECTOR: The REST API is not available on 192.168.68.59, falling back to SSH-based control host check
2026-04-06 16:50:05,069 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Running control host reboot script
2026-04-06 16:50:05,069 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 1"
2026-04-06 16:50:05,071 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 2"
2026-04-06 16:50:05,073 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 3"
2026-04-06 16:50:05,075 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Waiting for control host 192.168.68.59 to come back online (timeout: 300 seconds)
2026-04-06 16:53:27,160 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: BEGIN provision
2026-04-06 16:53:27,160 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Provisioning device

REST poweroff + power cycle:

2026-04-06 16:55:19,956 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Running pre-provision hook
2026-04-06 16:55:19,956 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Attempt to power cycle the control host.
2026-04-06 16:55:50,216 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Running control host reboot script
2026-04-06 16:55:50,216 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 1"
2026-04-06 16:55:50,218 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 2"
2026-04-06 16:55:50,220 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Executing: echo "reboot_cmd 3"
2026-04-06 16:55:50,221 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Waiting for the REST API on control host 192.168.68.59
2026-04-06 16:57:07,575 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: BEGIN provision
2026-04-06 16:57:07,575 hp-pro-sff-400-g9-desktop-pc-c30464 INFO: DEVICE CONNECTOR: Provisioning device

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 6, 2026

Codecov Report

❌ Patch coverage is 98.31933% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 75.24%. Comparing base (9c80d85) to head (b282df4).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1002      +/-   ##
==========================================
+ Coverage   75.00%   75.24%   +0.23%     
==========================================
  Files         109      110       +1     
  Lines       10746    10756      +10     
  Branches      899      898       -1     
==========================================
+ Hits         8060     8093      +33     
+ Misses       2500     2467      -33     
- Partials      186      196      +10     
Flag Coverage Δ *Carryforward flag
agent 74.72% <ø> (ø)
cli 90.40% <ø> (ø) Carriedforward from d973a93
device 62.52% <98.31%> (+0.53%) ⬆️
server 88.09% <ø> (ø) Carriedforward from d973a93

*This pull request uses carry forward flags. Click here to find out more.

Components Coverage Δ
Agent 74.72% <ø> (ø)
CLI 90.40% <ø> (ø)
Common ∅ <ø> (∅)
Device Connectors 62.52% <98.31%> (+0.53%) ⬆️
Server 88.09% <ø> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@p-gentili p-gentili requested a review from Copilot April 6, 2026 14:59
@p-gentili p-gentili marked this pull request as ready for review April 6, 2026 14:59
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR centralizes “control host” handling by introducing a DefaultControlHost helper and updating device connectors/tests to use it, enabling an “always power cycle when REST supports it” pre-provision behavior.

Changes:

  • Added DefaultControlHost (REST health check/poweroff + SSH fallback + reboot script execution) and rewired DefaultDevice.pre_provision_hook() to delegate to it.
  • Removed Zapper-specific REST readiness helpers (wait_ready, REST health check) and updated tests accordingly.
  • Simplified MuxPi/Zapper code paths that previously waited for the Zapper REST API before proceeding.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
device-connectors/src/testflinger_device_connectors/devices/init.py Adds DefaultControlHost and updates DefaultDevice.pre_provision_hook() to power-cycle via REST when available.
device-connectors/tests/test_devices.py Updates unit tests to target DefaultControlHost + new power-cycle / SSH fallback behavior.
device-connectors/src/testflinger_device_connectors/devices/tests/test_devices.py Updates DefaultDevice-related tests to use DefaultControlHost.wait_online/offline.
device-connectors/src/testflinger_device_connectors/devices/zapper/init.py Removes Zapper REST readiness helpers and removes the “cannot reach REST API” guard from provision.
device-connectors/src/testflinger_device_connectors/devices/zapper/tests/test_zapper.py Updates tests to validate DefaultControlHost REST health check and removes wait_ready expectations from Zapper flows.
device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/init.py Removes connector-specific pre_provision_hook override so it relies on the default centralized behavior.
device-connectors/src/testflinger_device_connectors/devices/zapper_kvm/tests/test_zapper_kvm.py Removes tests for the deleted pre_provision_hook override.
device-connectors/src/testflinger_device_connectors/devices/muxpi/muxpi.py Removes Zapper REST readiness wait from the zapper-based provisioning path.
device-connectors/src/testflinger_device_connectors/devices/muxpi/tests/test_muxpi.py Updates tests to stop asserting a Zapper REST readiness wait.
Comments suppressed due to low confidence (1)

device-connectors/src/testflinger_device_connectors/devices/zapper/init.py:156

  • ZapperConnector.provision no longer checks that the control host REST API is reachable before starting provisioning. If DefaultDevice.pre_provision_hook() falls back to SSH (or if the power-cycle is skipped), the subsequent _api_post/_api_get calls can fail with raw requests exceptions instead of a clear ProvisioningError. Consider reintroducing a readiness check using DefaultControlHost(control_host).wait_ready(...) and converting TimeoutError/ConnectionError into a ProvisioningError with a helpful message.
    def provision(self, args):
        """Provision device when the command is invoked."""
        super().provision(args)

        with open(args.job_data, encoding="utf-8") as job_json:
            self.job_data = json.load(job_json)

        logger.info("BEGIN provision")
        logger.info("Provisioning device")

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread device-connectors/tests/test_devices.py
Comment thread device-connectors/src/testflinger_device_connectors/devices/muxpi/muxpi.py Outdated
@p-gentili p-gentili requested a review from amalinowski75 April 6, 2026 15:21
amalinowski75
amalinowski75 previously approved these changes Apr 7, 2026
Copy link
Copy Markdown

@amalinowski75 amalinowski75 left a comment

Choose a reason for hiding this comment

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

Looks good. I left only one comment and it'w probably not valid :)

@p-gentili p-gentili merged commit fe8b98a into main Apr 8, 2026
17 checks passed
@p-gentili p-gentili deleted the always-reboot-control-host branch April 8, 2026 08:06
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.

4 participants