Skip to content

Handle missing Portainer snapshots, add API error reporting, and unit tests#6

Merged
skokec merged 2 commits into
masterfrom
codex/fix-portainer-compatibility-issue-07yj8j
May 29, 2026
Merged

Handle missing Portainer snapshots, add API error reporting, and unit tests#6
skokec merged 2 commits into
masterfrom
codex/fix-portainer-compatibility-issue-07yj8j

Conversation

@skokec

@skokec skokec commented May 29, 2026

Copy link
Copy Markdown
Contributor

Motivation

  • Make endpoint/container discovery resilient when Portainer no longer includes Docker snapshots in the endpoint payload.
  • Provide clearer error messages for Portainer API failures and centralize header construction.
  • Add unit tests to guard parsing and error handling behavior.

Description

  • Add PortainerAPIError and helper _raise_for_portainer_error to standardize API error reporting.
  • Introduce _portainer_headers, _container_name, _containers_by_name, and _snapshot_containers helpers to parse containers and names robustly.
  • Update init to fall back to calling /api/endpoints/{id}/docker/containers/json via _fetch_endpoint_containers when snapshots are not present.
  • Use timeout-aware requests and unify header usage; add test_logs.py with unit tests for parsing, fetching, and auth failure behavior.

Testing

  • Ran the new unit test module with python -m unittest test_logs.py.
  • Tests executed: test_parse_endpoints_accepts_missing_snapshots, test_parse_endpoints_reads_legacy_snapshot_containers, test_init_fetches_containers_when_endpoint_snapshots_are_not_returned, and test_init_reports_authentication_failures.
  • All tests passed.

Codex Task

### Motivation

- Portainer LTS responses can omit the `Snapshots` / `DockerSnapshotRaw` fields which caused `parse_endpoints` to raise exceptions during initialization.
- Make endpoint parsing resilient and fall back to the Portainer endpoint proxy for container lists when snapshots are not present.

### Description

- Add container name normalization helpers: `_container_name` and `_containers_by_name` to robustly extract Docker names.
- Add `_snapshot_containers` to safely extract `Snapshots` -> `DockerSnapshotRaw` -> `Containers` when present and update `parse_endpoints` to use it.
- Add `_fetch_endpoint_containers` and update `init` to call the Docker-listing proxy endpoint (`/api/endpoints/<id>/docker/containers/json?all=true`) when snapshots are missing.
- Add unit tests in `test_logs.py` covering missing snapshots, legacy snapshot parsing, and the fallback container fetch.

### Testing

- Ran `python3 -m unittest test_logs.py` which executed 3 tests and passed (`OK`).
- Ran `python3 -m py_compile logs.py test_logs.py` which succeeded with no syntax errors.
@skokec

skokec commented May 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot resolve the merge conflicts in this pull request

Copilot AI commented May 29, 2026

Copy link
Copy Markdown
Contributor

@copilot resolve the merge conflicts in this pull request

Done in d051742 — I merged origin/master into this branch and resolved the conflicts in logs.py and test_logs.py.

@skokec skokec marked this pull request as ready for review May 29, 2026 13:19
Copilot AI review requested due to automatic review settings May 29, 2026 13:19
@skokec skokec merged commit 8b5d160 into master May 29, 2026
Copilot finished work on behalf of skokec May 29, 2026 13:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@skokec skokec deleted the codex/fix-portainer-compatibility-issue-07yj8j branch May 29, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants