Handle missing Portainer snapshots, add API error reporting, and unit tests#6
Merged
Merged
Conversation
### 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.
Contributor
Author
|
@copilot resolve the merge conflicts in this pull request |
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
Description
PortainerAPIErrorand helper_raise_for_portainer_errorto standardize API error reporting._portainer_headers,_container_name,_containers_by_name, and_snapshot_containershelpers to parse containers and names robustly.initto fall back to calling/api/endpoints/{id}/docker/containers/jsonvia_fetch_endpoint_containerswhen snapshots are not present.test_logs.pywith unit tests for parsing, fetching, and auth failure behavior.Testing
python -m unittest test_logs.py.test_parse_endpoints_accepts_missing_snapshots,test_parse_endpoints_reads_legacy_snapshot_containers,test_init_fetches_containers_when_endpoint_snapshots_are_not_returned, andtest_init_reports_authentication_failures.Codex Task