Skip to content

[Smartswitch] Host container differentiation for sensor commands#604

Merged
judyjoseph merged 4 commits intosonic-net:masterfrom
gpunathilell:host_docker
Nov 3, 2025
Merged

[Smartswitch] Host container differentiation for sensor commands#604
judyjoseph merged 4 commits intosonic-net:masterfrom
gpunathilell:host_docker

Conversation

@gpunathilell
Copy link
Contributor

@gpunathilell gpunathilell commented Oct 6, 2025

Description

Differentiate commands being executed in host and container seperately for some smartswitch specific functions,
sensord commands can only be executed inside hte pmon docker container, so these commands need to differentiate between host and container execution

Motivation and Context

This is done because these functions are called from inside the pmon docker during chassis command execution and from the host directly during reboot command execution

How Has This Been Tested?

tests/module_base_test.py::TestModuleBase::test_module_base PASSED       [  2%]
tests/module_base_test.py::TestModuleBase::test_is_container_detection PASSED [  2%]
tests/module_base_test.py::TestModuleBase::test_sensors PASSED           [  2%]
tests/module_base_test.py::TestModuleBase::test_pci_entry_state_db PASSED [  2%]
tests/module_base_test.py::TestModuleBase::test_file_operation_lock PASSED [  2%]
tests/module_base_test.py::TestModuleBase::test_pci_operation_lock PASSED [  2%]
tests/module_base_test.py::TestModuleBase::test_sensord_operation_lock PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_handle_pci_removal PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_handle_pci_rescan PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_handle_sensor_removal PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_handle_sensor_addition PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_module_pre_shutdown PASSED [  3%]
tests/module_base_test.py::TestModuleBase::test_module_post_startup PASSED [  3%]

Manual test with:
reboot -d DPU0
and config chassis modules startup DPU0

Additional Information (Optional)

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@gpunathilell gpunathilell marked this pull request as ready for review October 17, 2025 17:39
@gpunathilell
Copy link
Contributor Author

@vvolam and @rameshraghupathy please review

Copy link
Contributor

Copilot AI left a comment

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 adds host/container differentiation for sensor commands in ModuleBase class for smartswitch functionality. The changes enable sensord commands to be executed properly both when called from within the pmon docker container and when called from the host system during different operations.

  • Introduces host detection mechanism using the presence of /.dockerenv file
  • Modifies sensor handling methods to use subprocess calls with docker exec when running on host
  • Updates command execution to differentiate between host and container environments

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
sonic_platform_base/module_base.py Adds _is_host() method and modifies sensor removal/addition methods to use subprocess calls with docker exec prefixes when running on host
tests/module_base_test.py Updates test cases to cover both host and container execution scenarios with proper mocking of subprocess calls

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@mssonicbld
Copy link
Collaborator

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@mssonicbld
Copy link
Collaborator

Cherry-pick PR to msft-202506: Azure/sonic-platform-common.msft#111

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants