зеркало из https://github.com/microsoft/lisa.git
fix who -b issue on Ubuntu 14.04
who -b doesn't return value in first boot on Ubuntu 14.04. Use uptime -s to get boot time. uptime -s doesn't exists on some centos version, so it's not default command.
This commit is contained in:
Родитель
b96cb62789
Коммит
5043793336
|
@ -10,6 +10,7 @@ from .modinfo import Modinfo
|
|||
from .ntttcp import Ntttcp
|
||||
from .reboot import Reboot
|
||||
from .uname import Uname
|
||||
from .uptime import Uptime
|
||||
from .who import Who
|
||||
|
||||
__all__ = [
|
||||
|
@ -25,5 +26,6 @@ __all__ = [
|
|||
"Ntttcp",
|
||||
"Reboot",
|
||||
"Uname",
|
||||
"Uptime",
|
||||
"Who",
|
||||
]
|
||||
|
|
|
@ -8,6 +8,7 @@ from lisa.util.perf_timer import create_timer
|
|||
from lisa.util.process import ExecutableResult
|
||||
|
||||
from .date import Date
|
||||
from .uptime import Uptime
|
||||
from .who import Who
|
||||
|
||||
|
||||
|
@ -26,7 +27,14 @@ class Reboot(Tool):
|
|||
def reboot(self) -> None:
|
||||
who = self.node.tools[Who]
|
||||
timer = create_timer()
|
||||
last_boot_time = who.last_boot()
|
||||
|
||||
# who -b doesn't return correct content in Ubuntu 14.04, but uptime works.
|
||||
# uptime has no -s parameter in some distros, so not use is as default.
|
||||
try:
|
||||
last_boot_time = who.last_boot()
|
||||
except Exception:
|
||||
uptime = self.node.tools[Uptime]
|
||||
last_boot_time = uptime.since_time()
|
||||
current_boot_time = last_boot_time
|
||||
|
||||
# who -b returns time without seconds.
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
from datetime import datetime
|
||||
|
||||
from dateutil.parser import parser
|
||||
|
||||
from lisa.executable import Tool
|
||||
from lisa.util import LisaException
|
||||
|
||||
|
||||
class Uptime(Tool):
|
||||
@property
|
||||
def command(self) -> str:
|
||||
return "uptime"
|
||||
|
||||
def _check_exists(self) -> bool:
|
||||
return True
|
||||
|
||||
def since_time(self, no_error_log: bool = True) -> datetime:
|
||||
command_result = self.run("-s", no_error_log=no_error_log)
|
||||
if command_result.exit_code != 0:
|
||||
raise LisaException(
|
||||
f"get unexpected non-zero exit code {command_result.exit_code}"
|
||||
)
|
||||
return parser().parse(command_result.stdout)
|
Загрузка…
Ссылка в новой задаче