Repository navigation
feat: Added two new methods to WindowsService in mfd_host/feature/service/windows.py - #14
Conversation
There was a problem hiding this comment.
Pull request overview
Adds Windows service management helpers to the Service feature, enabling callers to restart a Windows service and query its current status via PowerShell, with corresponding unit tests to validate command construction, logging, and error propagation.
Changes:
- Added
WindowsService.restart_service(name)to restart a service viaRestart-Service. - Added
WindowsService.get_service(name)to fetch a service’s.Statusand return a stripped status string. - Introduced unit tests validating PowerShell command execution, MODULE_DEBUG logging, and exception propagation.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| mfd_host/feature/service/windows.py | Adds new Windows service operations implemented via _connection.execute_powershell. |
| tests/unit/test_mfd_host/test_feature/test_service/test_windows.py | Adds unit tests for the new Windows service operations. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
abaczek
left a comment
There was a problem hiding this comment.
generally I agree with copilots comments - at least with the ambiguous get_service(), maybe get_service_status() would be more appropriate
2fc94a8 to
d1ec1b6
Compare
Done |
d1ec1b6 to
ff95ac1
Compare
ff95ac1 to
03044d5
Compare
4f5fa53 to
4af80ac
Compare
…vice/windows.py:
- "restart_service(name: str) -> None": Restarts a Windows service by name
using the PowerShell `Restart-Service -Name '<name>' -Force` command.
- "get_service_status(name: str) -> str": Retrieves the current status of a Windows
service by name using the PowerShell `(Get-Service -Name '<name>').Status`
command, returning the stripped status string (e.g. "Running", "Stopped").
Both methods log at MODULE_DEBUG level and delegate execution to
`_connection.execute_powershell` with `expected_return_codes={0}`.
Unit tests added in tests/unit/test_mfd_host/test_feature/test_service/test_windows.py
covering the following scenarios:
- restart_service: successful call with correct PowerShell command
- restart_service: MODULE_DEBUG log message emitted
- restart_service: RuntimeError propagates on connection failure
- get_service_status: successful call with correct PowerShell command and stripped return value
- get_service_status: "Stopped" status correctly stripped of trailing newline
- get_service_status: MODULE_DEBUG log message emitted
- get_service_status: RuntimeError propagates on connection failure
Signed-off-by: mwasile <marek.wasilewski@intel.com>
4af80ac to
f5adbe9
Compare
feat: Added two new methods to WindowsService in mfd_host/feature/service/windows.py:
"restart_service(name: str) -> None": Restarts a Windows service by name using the PowerShell
Restart-Service -Name '<name>' -Forcecommand."get_service_status(name: str) -> str": Retrieves the current status of a Windows service by name using the PowerShell
(Get-Service -Name '<name>').Statuscommand, returning the stripped status string (e.g. "Running", "Stopped").Both methods log at MODULE_DEBUG level and delegate execution to
_connection.execute_powershellwithexpected_return_codes={0}.Unit tests added in tests/unit/test_mfd_host/test_feature/test_service/test_windows.py covering the following scenarios:
restart_service: successful call with correct PowerShell command
restart_service: MODULE_DEBUG log message emitted
restart_service: RuntimeError propagates on connection failure
get_service_status: successful call with correct PowerShell command and stripped return value
get_service_status: "Stopped" status correctly stripped of trailing newline
get_service_status: MODULE_DEBUG log message emitted
get_service_status: RuntimeError propagates on connection failure