fix: call list endpoint on every poll cycle to advance pre-change job state - #11
Open
noppanut15 wants to merge 2 commits into
Open
fix: call list endpoint on every poll cycle to advance pre-change job state#11noppanut15 wants to merge 2 commits into
noppanut15 wants to merge 2 commits into
Conversation
… state
The single-job GET (/api/v1/analyze/jobs/prechangeAnalysis/{job_id})
does not reflect live state — the backend only advances a job when the
list endpoint (GET /api/v1/analyze/jobs/prechangeAnalysis) is called.
This is required for both transitions:
submitted → running: without the list call, the job never starts
running → completed: without the list call, the job never finishes
This matches the behaviour observed in Postman: calling the list
endpoint immediately causes the single-job GET to return the updated
status on the next request.
The list endpoint is called on every poll iteration to mimic what the
GUI's pre-change list page does on each load. Its result is discarded;
the single-job GET is still used for the actual status check so we
avoid iterating potentially many jobs on every cycle.
The wait_prechange_analysis() polling loop now calls the list endpoint on every iteration. Add LIST_PATH / PRECHANGE_LIST_PATH routes (returning an empty entries list) to all affected test labs so they don't 404.
Contributor
Author
|
FYI: The PR description has been updated with ND 4.3 testing. |
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.
Problem
nac-analytics nd prechangewould hang indefinitely at:The job would never complete unless the user manually opened the pre-change analysis page in the Nexus Dashboard GUI. For example, even after waiting for more than 25 mins, the tool was still stuck at
Waiting for pre-change analysis..., but once the GUI page was opened, the tool would resume and finish within ~15 seconds. (the next the poll interval)Affected ND Version
Root Cause
The polling loop in
wait_prechange_analysis()was exclusively calling the single-job GET endpoint:The Nexus Dashboard backend does not advance a job's state in response to this endpoint alone. Advancing job state requires the list endpoint to be called (mimics what GUI does):
This was confirmed manually via Postman. The list endpoint is required for both transitions:
analysisStatussubmitted→runningrunning→completedOpening the GUI's pre-change list page fires this exact request on every page load, which is why the CLI would unblock whenever the user navigated to the GUI.
Fix
Added
list_prechange_analyses()which calls the list endpoint with the same query parameters the GUI uses. It is called on every poll iteration inwait_prechange_analysis()before the single-job GET. The list response is discarded — the single-job GET is still used for the actual status check, so we avoid iterating potentially many jobs on every cycle.Testing
Verified end-to-end against a real Nexus Dashboard instance, both version 4.2(1) and 4.3(1), with
plan.json— the job progressed through both transitions and completed successfully without any GUI interaction:All 218 unit tests pass. Ruff clean.
Changes
nac_analytics/products/nexus_dashboard/client.py— addedlist_prechange_analyses()and called it on every poll cycle inwait_prechange_analysis()tests/unit/test_prechange.py— addedLIST_PATH/LIST_RESPONSEconstants and registered the list route in all polling test labstests/unit/test_cli_commands.py— addedPRECHANGE_LIST_PATHand registered the list route inbuild_lab()