Skip to content

fix(upgrade): correct upgrader RPC method names (prepare/appendData/execute) - #2

Merged
widgetii merged 1 commit into
masterfrom
fix/upgrader-method-names
Sep 26, 2026
Merged

widgetii merged 1 commit into
masterfrom
fix/upgrader-method-names

Conversation

@widgetii

Copy link
Copy Markdown
Member

upgrade_firmware() drove upgrader.start → upgrader.send → upgrader.execute,
but the hunter daemon's actual RPC upgrade handlers — reversed on a Zenointel
GK7205V510 camera — are upgrader.prepare → upgrader.appendData →
upgrader.execute
(the same handlers the web /cgi-bin/upgrader.cgi bridges
to). As written, a real flash would fail at the first call with RPC 405
(method not allowed) instead of upgrading.

Changes:

  • Method strings corrected and lifted into const.py (UPGRADER_STATE/PREPARE/APPEND/EXECUTE); firmware_state() uses UPGRADER_STATE.
  • tests/test_dahua.py::TestFirmware updated to the new names (30 passing).
  • Docstring expanded: the method names are from firmware but the JSON param names (Type / Offset+Length) are not byte-proven, and this is still mock-only / never run on hardware / confirm-guarded.

Context: read-only upgrader.getState on a live SD-2N-4G returns result:false
(not a 405), i.e. the namespace exists; the exact param names remain a bench
task. Part of the Zenointel OpenIPC-transition work.

…/execute

upgrade_firmware() drove `upgrader.start` -> `upgrader.send` -> `upgrader.execute`,
but the hunter daemon's actual RPC handlers (reversed on a Zenointel GK7205
camera) are `upgrader.prepare` -> `upgrader.appendData` -> `upgrader.execute`. As
written it would fail at the first call with RPC 405 (method not allowed) rather
than flashing. Method strings are now named constants in const.py; firmware_state
uses UPGRADER_STATE. Tests updated to the corrected names.

Still mock-only / never run on hardware and confirm-guarded: the method names are
from firmware but the JSON param names (Type / Offset+Length) are not byte-proven
(docstring flags this).
@qodo-free-for-open-source-projects

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can type 'qodo, fix this' on a finding and the fix lands right on your PR

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@qodo-free-for-open-source-projects

Copy link
Copy Markdown

PR Summary by Qodo

Correct firmware upgrader RPC method names

🐞 Bug fix 🧪 Tests 📝 Documentation 🕐 10-20 Minutes

Grey Divider

AI Description

• Correct firmware upgrade RPC flow to prepare, appendData, and execute handlers.
• Centralize upgrader method names and route state checks through shared constants.
• Align mock coverage and document hardware-validation and firmware-package safety constraints.
Diagram

sequenceDiagram
    actor User as Operator
    participant Client as DahuaClient
    participant File as Firmware Package
    participant DHIP as DHIP Transport
    participant Hunter as hunter upgrader
    User->>Client: firmware_state()
    Client->>DHIP: upgrader.getState
    DHIP->>Hunter: Read upgrade state
    User->>Client: upgrade_firmware()
    alt confirm is false
        Client-->>User: Raise ValueError
    else confirm is true
        Client->>DHIP: upgrader.prepare
        DHIP->>Hunter: Prepare upgrade
        loop Each firmware chunk
            Client->>File: Read chunk
            Client->>DHIP: upgrader.appendData
            DHIP->>Hunter: Append chunk
        end
        Client->>DHIP: upgrader.execute
        DHIP->>Hunter: Execute upgrade
    end
Loading
High-Level Assessment

The direct correction is the appropriate approach because the handler names were recovered from the target firmware and match the web upgrader bridge. Centralizing them prevents future string drift across state and upgrade operations. Runtime fallback to the invalid legacy names or routing through the CGI bridge would add ambiguity and transport complexity to a destructive, hardware-sensitive operation.

Files changed (3) +35 / -15

Bug fix (2) +31 / -11
client.pyUse corrected upgrader handlers throughout the firmware flow +19/-11

Use corrected upgrader handlers throughout the firmware flow

• Routes state, preparation, chunk upload, response validation, and execution through centralized upgrader constants. Expands the upgrade documentation to identify the expected package format and emphasize that parameter names and real-hardware flashing remain unverified.

dahua/client.py

const.pyDefine firmware upgrader RPC constants +12/-0

Define firmware upgrader RPC constants

• Adds constants for getState, prepare, appendData, and execute. Documents their firmware-derived origin and the remaining uncertainty around JSON parameter names.

dahua/const.py

Tests (1) +4 / -4
test_dahua.pyAlign firmware mocks with corrected RPC methods +4/-4

Align firmware mocks with corrected RPC methods

• Updates the fake server handlers and orchestration assertions to expect upgrader.prepare and three upgrader.appendData calls before execution.

tests/test_dahua.py

@widgetii
widgetii merged commit 2d25671 into master Sep 26, 2026
6 checks passed
@widgetii
widgetii deleted the fix/upgrader-method-names branch September 26, 2026 12:16
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.

1 participant