Skip to content

Fix dynamic service templates not applied during device discovery#19286

Open
Florent4C wants to merge 1 commit intolibrenms:masterfrom
Florent4C:fix-dynamic-service-template-discovery
Open

Fix dynamic service templates not applied during device discovery#19286
Florent4C wants to merge 1 commit intolibrenms:masterfrom
Florent4C:fix-dynamic-service-template-discovery

Conversation

@Florent4C
Copy link

Summary

  • Dynamic service templates are not automatically applied to newly
    discovered devices during the discovery process
  • The applyDeviceAll() method (called from Services::discover())
    never calls updateDevices() to refresh the pivot table before
    checking device membership, causing new devices to be silently skipped
  • The UI "Apply" button (apply() method) already handles this
    correctly — this fix aligns the discovery path with the same behavior

Steps to reproduce

  1. Create a dynamic service template with a rule (e.g. os in iosxr,iosxe)
  2. Enable discover_services_templates
  3. Add a new device matching the rule
  4. Wait for discovery to run
  5. No service is created — manual "Apply" from the UI is required

Fix

Call updateDevices() for dynamic templates in applyDeviceAll()
before calling applyDevice(), so the pivot table is up to date
when the device membership check runs.

Test plan

  • Add a device matching a dynamic service template rule
  • Run discovery (lnms device:discover <hostname>)
  • Verify the service is automatically created without manual "Apply"
  • Verify existing static and device-group templates still work

When a new device is discovered, applyDeviceAll() iterates all service templates and calls applyDevice() for each. However, for dynamic templates, updateDevices() was never called to refresh the pivot table before checking device membership. This caused new devices matching dynamic rules to be silently skipped.

The apply() method (used by the UI "Apply" button) already calls updateDevices() before processing. This fix adds the same call in the discovery path (applyDeviceAll), ensuring dynamic templates are consistently applied to newly discovered devices.

Please give a short description what your pull request is for

DO NOT DELETE THE UNDERLYING TEXT

Please note

Please read this information carefully. You can run ./lnms dev:check to check your code before submitting.

  • [ X] Have you followed our code guidelines?
  • If my Pull Request does some changes/fixes/enhancements in the WebUI, I have inserted a screenshot of it.
  • If my Pull Request makes discovery/polling/yaml changes, I have added/updated test data.

Testers

If you would like to test this pull request then please run: ./scripts/github-apply <pr_id>, i.e ./scripts/github-apply 5926
After you are done testing, you can remove the changes with ./scripts/github-remove. If there are schema changes, you can ask on discord how to revert.

When a new device is discovered, applyDeviceAll() iterates all service
templates and calls applyDevice() for each. However, for dynamic
templates, updateDevices() was never called to refresh the pivot table
before checking device membership. This caused new devices matching
dynamic rules to be silently skipped.

The apply() method (used by the UI "Apply" button) already calls
updateDevices() before processing. This fix adds the same call in the
discovery path (applyDeviceAll), ensuring dynamic templates are
consistently applied to newly discovered devices.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

2 participants