Skip to content

Enabling the restapi_sidecar container to update sonic-restapi.yang - #25484

Closed
mramezani95 wants to merge 2 commits into
sonic-net:masterfrom
mramezani95:mramezani/restapi_sidecar_sync_yang
Closed

mramezani95 wants to merge 2 commits into
sonic-net:masterfrom
mramezani95:mramezani/restapi_sidecar_sync_yang

Conversation

@mramezani95

Copy link
Copy Markdown
Contributor

Why I did it

#25450 updated sonic-restapi.yang. This PR enables restapi_sidecar to correctly update this file on SONiC devices.

Work item tracking
  • Microsoft ADO (number only): 36761447

How I did it

  1. Added a SyncItem for sonic-restapi.yang. If IS_V1_ENABLED is true, sonic-restapi.yang is updated to the old version (prior to Allowing wildcard client cert CNs in restapi's YANG model #25450). If IS_V1_ENABLED is false, sonic-restapi.yang is updated to the new version.
  2. Updated current tests and added additional tests for this scenario in test_systemd_stub.py.

How to verify it

Run the tests in test_systemd_stub.py:

dockers/docker-restapi-sidecar/cli-plugin-tests$ pytest -v
================================================================== test session starts ==================================================================
platform linux -- Python 3.11.2, pytest-7.2.1, pluggy-1.0.0+repack -- /usr/bin/python3
cachedir: .pytest_cache
rootdir: /sonic, configfile: pytest.ini
plugins: pyfakefs-5.10.2, cov-4.0.0
collected 40 items                                                                                                                                      

test_systemd_stub.py::test_sync_no_change_fast_path PASSED                                                                                        [  2%]
test_systemd_stub.py::test_sync_updates_v1 PASSED                                                                                                 [  5%]
test_systemd_stub.py::test_sync_updates_not_v1 PASSED                                                                                             [  7%]
test_systemd_stub.py::test_sync_updates_and_post_actions PASSED                                                                                   [ 10%]
test_systemd_stub.py::test_sync_missing_src_returns_false PASSED                                                                                  [ 12%]
test_systemd_stub.py::test_main_once_exits_zero_and_disables_post_actions PASSED                                                                  [ 15%]
test_systemd_stub.py::test_env_controls_restapi_src_false PASSED                                                                                  [ 17%]
test_systemd_stub.py::test_env_controls_restapi_src_true PASSED                                                                                   [ 20%]
test_systemd_stub.py::test_env_controls_restapi_src_default PASSED                                                                                [ 22%]
test_systemd_stub.py::test_post_copy_actions_match_sync_items PASSED                                                                              [ 25%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20231110.19-202311] PASSED                                                         [ 27%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20240510.25-202405] PASSED                                                         [ 30%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20241110.22-202411] PASSED                                                         [ 32%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20250510.04-202505] PASSED                                                         [ 35%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20251110.01-202511] PASSED                                                         [ 37%]
test_systemd_stub.py::test_branch_detection_from_version[20231110.19-202311] PASSED                                                               [ 40%]
test_systemd_stub.py::test_branch_detection_from_version[20240510.25-2024050] PASSED                                                              [ 42%]
test_systemd_stub.py::test_branch_detection_from_version[20241110.22-202411] PASSED                                                               [ 45%]
test_systemd_stub.py::test_branch_detection_from_version[20250510.04-202505] PASSED                                                               [ 47%]
test_systemd_stub.py::test_branch_detection_from_version[20251110.01-202511] PASSED                                                               [ 50%]
test_systemd_stub.py::test_branch_detection_from_version[20241110.kw.24-202411] PASSED                                                            [ 52%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20241110.kw.24-202411] PASSED                                                      [ 55%]
test_systemd_stub.py::test_branch_detection_from_version[20240510.25-2024051] PASSED                                                              [ 57%]
test_systemd_stub.py::test_branch_detection_from_version[SONiC.20231120.abc.123-202311] PASSED                                                    [ 60%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[SONiC.master.921927-18199d73f] PASSED                                             [ 62%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[master.921927-18199d73f] PASSED                                                   [ 65%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[SONiC.internal.135691748-dbb8d29985] PASSED                                       [ 67%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[internal.135691748-dbb8d29985] PASSED                                             [ 70%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[private-build-1.0] PASSED                                                         [ 72%]
test_systemd_stub.py::test_unsupported_branches_exit_with_error[unknown-format] PASSED                                                            [ 75%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202311-False] PASSED                                                                     [ 77%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202405-False] PASSED                                                                     [ 80%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202411-False] PASSED                                                                     [ 82%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202505-False] PASSED                                                                     [ 85%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202511-False] PASSED                                                                     [ 87%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202311-True] PASSED                                                                      [ 90%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202405-True] PASSED                                                                      [ 92%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202411-True] PASSED                                                                      [ 95%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202505-True] PASSED                                                                      [ 97%]
test_systemd_stub.py::test_per_branch_files_with_v1_flag[202511-True] PASSED                                                                      [100%]

================================================================== 40 passed in 0.07s ===================================================================

Which release branch to backport (provide reason below if selected)

  • 202305
  • 202311
  • 202405
  • 202411
  • 202505
  • 202511

Tested branch (Please provide the tested image version)

  • [master]

Description for the changelog

Enabling the restapi_sidecar container to update sonic-restapi.yang.

Link to config_db schema for YANG module changes

N/A

Signed-off-by: Mahdi Ramezani <mramezani@microsoft.com>
@mramezani95
mramezani95 requested a review from lguohan as a code owner February 13, 2026 02:57
Copilot AI review requested due to automatic review settings February 13, 2026 02:57
@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld

Copy link
Copy Markdown
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

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.

Pull request overview

This PR updates the docker-restapi-sidecar sync logic so the sidecar container can manage the on-host sonic-restapi.yang version in /usr/local/yang-models/, selecting the appropriate model depending on whether IS_V1_ENABLED is set.

Changes:

  • Add a new SyncItem to copy sonic-restapi.yang onto the host, choosing v1 vs non-v1 source based on IS_V1_ENABLED.
  • Introduce v1 and non-v1 sonic-restapi.yang payloads in systemd_scripts/ for the sidecar image to publish.
  • Update and extend test_systemd_stub.py to validate v1 vs non-v1 sync behavior.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
dockers/docker-restapi-sidecar/systemd_stub.py Adds syncing of sonic-restapi.yang to /usr/local/yang-models/ with v1/non-v1 source selection.
dockers/docker-restapi-sidecar/systemd_scripts/sonic-restapi.yang Adds the “new” YANG model payload (wildcard CN support).
dockers/docker-restapi-sidecar/systemd_scripts/v1/sonic-restapi.yang Adds the “old” YANG model payload intended for v1-enabled behavior.
dockers/docker-restapi-sidecar/cli-plugin-tests/test_systemd_stub.py Adds fixtures and tests to validate v1 vs non-v1 sync of both restapi.sh and sonic-restapi.yang.

Comment thread dockers/docker-restapi-sidecar/systemd_scripts/sonic-restapi.yang
@maipbui

maipbui commented Feb 13, 2026

Copy link
Copy Markdown
Contributor

POST_COPY_ACTIONS = {

is there any post copy actions needed?


Refers to: dockers/docker-restapi-sidecar/systemd_stub.py:91 in b44d83b. [](commit_id = b44d83b, deletion_comment = False)

@mramezani95

Copy link
Copy Markdown
Contributor Author

POST_COPY_ACTIONS = {

is there any post copy actions needed?

Refers to: dockers/docker-restapi-sidecar/systemd_stub.py:91 in b44d83b. [](commit_id = b44d83b, deletion_comment = False)

Not for the YANG file. As soon as the file is replaced, the changes take effect.

@mramezani95

Copy link
Copy Markdown
Contributor Author

Closing this pull request since we decided to implement a different solution.

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.

4 participants