Skip to content

feat: Added two new methods to WindowsService in mfd_host/feature/service/windows.py - #14

Merged
abaczek merged 1 commit into
intel:mainfrom
mkwasile:add_restart_service_windows
Apr 2, 2026
Merged

abaczek merged 1 commit into
intel:mainfrom
mkwasile:add_restart_service_windows

Conversation

@mkwasile

@mkwasile mkwasile commented Apr 1, 2026 •

Copy link
Copy Markdown
Contributor

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>' -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

Copilot AI review requested due to automatic review settings April 1, 2026 13:00

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 via Restart-Service.
  • Added WindowsService.get_service(name) to fetch a service’s .Status and 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.

Comment thread mfd_host/feature/service/windows.py Resolved
Comment thread mfd_host/feature/service/windows.py Resolved
Comment thread mfd_host/feature/service/windows.py Resolved

@abaczek abaczek 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.

generally I agree with copilots comments - at least with the ambiguous get_service(), maybe get_service_status() would be more appropriate

@mkwasile
mkwasile force-pushed the add_restart_service_windows branch from 2fc94a8 to d1ec1b6 Compare April 2, 2026 06:09
@mkwasile

mkwasile commented Apr 2, 2026

Copy link
Copy Markdown
Contributor Author

generally I agree with copilots comments - at least with the ambiguous get_service(), maybe get_service_status() would be more appropriate

Done

@adrianlasota
adrianlasota requested a review from abaczek April 2, 2026 08:00
@mkwasile
mkwasile force-pushed the add_restart_service_windows branch from d1ec1b6 to ff95ac1 Compare April 2, 2026 08:07
adrianlasota
adrianlasota previously approved these changes Apr 2, 2026
adrianlasota
adrianlasota previously approved these changes Apr 2, 2026
@coveralls-official

coveralls-official Bot commented Apr 2, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 94.016% (+0.04%) from 93.972%
when pulling f5adbe9 on mkwasile:add_restart_service_windows
into bff7b32 on intel:main.

@mkwasile
mkwasile force-pushed the add_restart_service_windows branch 2 times, most recently from 4f5fa53 to 4af80ac Compare April 2, 2026 11:13
…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>
@mkwasile mkwasile changed the title [Windows] Add restart_service function feat: Added two new methods to WindowsService in mfd_host/feature/service/windows.py Apr 2, 2026
@mkwasile
mkwasile force-pushed the add_restart_service_windows branch from 4af80ac to f5adbe9 Compare April 2, 2026 11:28
@abaczek
abaczek merged commit 1fb3b9e into intel:main Apr 2, 2026
24 checks passed
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