Skip to content

Commit

Permalink
Update service.py
Browse files Browse the repository at this point in the history
  • Loading branch information
SRIKKANTH committed Jan 3, 2025
1 parent 4a92ce3 commit 712e9f8
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions lisa/base_tools/service.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.
import re
from enum import Enum
from time import sleep
from typing import Optional, Type
from enum import Enum

from lisa import schema
from lisa.executable import ExecutableResult, Tool
from lisa.tools.powershell import PowerShell
from lisa.util import (
LisaException,
UnsupportedDistroException,
create_timer,
filter_ansi_escape,
find_group_in_lines,
create_timer,
)


Expand Down Expand Up @@ -270,18 +269,18 @@ def _check_service_running(self, name: str) -> bool:
return self._get_status(name) == WindowsServiceStatus.RUNNING

def _get_status(self, name: str = "") -> WindowsServiceStatus:
service_status = self.node.tools[PowerShell].run_cmdlet(
f"Get-Service {name}",
force_run=True,
output_json=True,
fail_on_error=False,
)
if not service_status:
raise LisaException(f"service '{name}' does not exist")
return WindowsServiceStatus(service_status["Status"])
try:
service_status = self.node.tools[PowerShell].run_cmdlet(
f"Get-Service {name}", force_run=True, output_json=True
)
return WindowsServiceStatus(int(service_status["Status"]))
except LisaException as identifier:
if "Cannot find any service with service name" in str(identifier):
raise LisaException(f"service '{name}' does not exist")
raise identifier

def _is_service_inactive(self, name: str) -> bool:
return self._get_status(name) == WindowsServiceStatus.STOPPED
return self._get_status(name) == WindowsServiceStatus.PAUSED

def _wait_for_service(self, name: str, status: WindowsServiceStatus) -> None:
timeout = 60
Expand All @@ -295,5 +294,6 @@ def _wait_for_service(self, name: str, status: WindowsServiceStatus) -> None:

if timeout < timer.elapsed():
raise LisaException(
f"service '{name}' still in '{current_service_status}' state after '{timeout}' seconds" # noqa: E501
f"service '{name}' still in '{current_service_status}' state"
f"after '{timeout}' seconds"
)

0 comments on commit 712e9f8

Please sign in to comment.