Skip to content

CMLDEV-1110: added reload_definitions method to NodeImageDefinitions;…#227

Merged
tmikuska merged 2 commits into
devfrom
CMLDEV-1110-add-reload-definitions-method-to-virl2-client-NodeImageDefinitions
May 18, 2026
Merged

CMLDEV-1110: added reload_definitions method to NodeImageDefinitions;…#227
tmikuska merged 2 commits into
devfrom
CMLDEV-1110-add-reload-definitions-method-to-virl2-client-NodeImageDefinitions

Conversation

@BregaladTaran
Copy link
Copy Markdown
Collaborator

… Included brief test coverage;

url = self._url_for("image_def", definition_id=definition_id)
self._session.delete(url)

def reload_definitions(self) -> dict[str, Any]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Bug (New) - Confidence: 90%] Missing @_requires_version("2.10.0") decorator.

The server endpoint is gated to CML 2.10+ via CMLVersion.V2_10.introduced() in webserver/simple_webserver/api/system.py. Without the decorator, calling this method against a 2.9.x controller produces a generic 404 / HTTPError instead of the codebase's standard FeatureNotSupported exception. Sibling version-gated methods in lab_repository.py (sync_lab_repositories, refresh_lab_repositories, get_lab_repositories, add_lab_repository) all use this pattern.

Suggested change:

from ..utils import _requires_version, get_url_from_template

# ...

@_requires_version("2.10.0")
def reload_definitions(self) -> dict[str, dict[str, list[str]]]:
    ...

Comment thread virl2_client/models/node_image_definition.py
url = self._url_for("image_def", definition_id=definition_id)
self._session.delete(url)

def reload_definitions(self) -> dict[str, Any]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Nit (New) - Confidence: 50%] dict[str, Any] discards the well-defined server response shape.

The server returns DefinitionReportResponse — two fixed top-level keys (node_definitions, image_definitions), each mapping to a dict of unchanged/updated/new/removed/failed lists of strings. A narrower annotation conveys the same shape without introducing new public symbols:

def reload_definitions(self) -> dict[str, dict[str, list[str]]]:
    ...

Other methods on this class are equally loose (dict[str, Any] / list[dict[str, Any]]), so this is optional polish for consistency.

Comment thread tests/test_node_image_definitions.py Outdated

report = defs.reload_definitions()
assert report == expected_report
assert session.put.mock_calls[0].args[0] == "reload_definitions"
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

[Nit (New) - Confidence: 40%] Test hard-codes "reload_definitions" instead of going through _url_for("reload_defs") / _URL_TEMPLATES. Renaming the template key without updating the URL would not be caught here.

This matches the existing pattern in this file though (other tests don't assert on the URL at all), so optional.

@tmikuska
Copy link
Copy Markdown
Collaborator

AI-Assisted Code Review Summary

This review was performed by an LLM. All comments — especially line numbers, suggested code, and version/permission claims — should be verified by a human before acting on them.

Linked Jira: CMLDEV-1110

Scope check

Tight, focused PR (2 files, +63 / −0). Cross-checked against the server-side endpoint in the simple monorepo (webserver/simple_webserver/api/system.py:685-731): URL (reload_definitions), HTTP verb (PUT), and response shape (DefinitionReportResponse) all match. The example payload in the test faithfully reflects the server schema.

Two server-side constraints aren't reflected on the client:

  • Endpoint is annotated CMLVersion.V2_10.introduced() — CML 2.10+ only.
  • Endpoint is gated by IsAdminPermDepends — admin only.

Major (should fix)

  • virl2_client/models/node_image_definition.py:317reload_definitions is missing @_requires_version("2.10.0"). Without it, older controllers raise a generic 404 instead of the standard FeatureNotSupported. (See inline comment.)

Minor (negligible / nits)

  • virl2_client/models/node_image_definition.py:319 — Docstring should mention the CML >= 2.10 requirement and the admin-only access constraint. (See inline comment.)
  • virl2_client/models/node_image_definition.py:317 — Return type dict[str, Any] discards the well-defined response shape; consider dict[str, dict[str, list[str]]] for slightly stronger typing without introducing new public symbols. Other methods on the class are equally loose, so this is optional. (See inline comment.)
  • tests/test_node_image_definitions.py:323 — Test hard-codes the URL string instead of going through _url_for. Matches the existing pattern, optional. (See inline comment.)

Things done well

  • Verb/path/response shape all match the authoritative server contract.
  • Test follows the tests/AGENTS.md conventions (LLM-generated note, reST docstring, plain MagicMock, single behavior per test).
  • Example response in the test matches the server's make_def_report_error output format for the failed entry, which is a nice touch.
  • URL template centralized in _URL_TEMPLATES, consistent with the rest of the class.

Confidence percentages reflect certainty: lower values may be false positives. Origin column: New = introduced by this PR, Pre-existing = already in the codebase (consider fixing opportunistically). All findings here are New.

Per PR #227 review:
- Decorate reload_definitions with @_requires_version("2.10.0") so older
  controllers raise FeatureNotSupported instead of bubbling up an HTTPError
  for a missing route. The server endpoint is annotated
  CMLVersion.V2_10.introduced() and gated by IsAdminPermDepends.
- Surface the version floor and admin-only requirement in the docstring.
- Tighten return type from dict[str, Any] to dict[str, dict[str, list[str]]],
  mirroring the server's DefinitionReportResponse shape.
- Anchor the test URL assertion to _URL_TEMPLATES["reload_defs"] so renaming
  the template key would surface a failure.
@tmikuska tmikuska merged commit 768dcf8 into dev May 18, 2026
5 checks passed
@tmikuska tmikuska deleted the CMLDEV-1110-add-reload-definitions-method-to-virl2-client-NodeImageDefinitions branch May 18, 2026 08:20
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