Coverage for mlos_bench/mlos_bench/services/types/os_ops_type.py: 67%

9 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-21 01:50 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Protocol interface for Host/OS operations.""" 

6 

7from typing import TYPE_CHECKING, Protocol, runtime_checkable 

8 

9if TYPE_CHECKING: 

10 from mlos_bench.environments.status import Status 

11 

12 

13@runtime_checkable 

14class SupportsOSOps(Protocol): 

15 """Protocol interface for Host/OS operations.""" 

16 

17 # pylint: disable=unnecessary-ellipsis 

18 

19 def shutdown(self, params: dict, force: bool = False) -> tuple["Status", dict]: 

20 """ 

21 Initiates a (graceful) shutdown of the Host/VM OS. 

22 

23 Parameters 

24 ---------- 

25 params: dict 

26 Flat dictionary of (key, value) pairs of tunable parameters. 

27 force : bool 

28 If True, force stop the Host/VM. 

29 

30 Returns 

31 ------- 

32 result : (Status, dict) 

33 A pair of Status and result. The result is always {}. 

34 Status is one of {PENDING, SUCCEEDED, FAILED} 

35 """ 

36 ... 

37 

38 def reboot(self, params: dict, force: bool = False) -> tuple["Status", dict]: 

39 """ 

40 Initiates a (graceful) shutdown of the Host/VM OS. 

41 

42 Parameters 

43 ---------- 

44 params: dict 

45 Flat dictionary of (key, value) pairs of tunable parameters. 

46 force : bool 

47 If True, force restart the Host/VM. 

48 

49 Returns 

50 ------- 

51 result : (Status, dict) 

52 A pair of Status and result. The result is always {}. 

53 Status is one of {PENDING, SUCCEEDED, FAILED} 

54 """ 

55 ... 

56 

57 def wait_os_operation(self, params: dict) -> tuple["Status", dict]: 

58 """ 

59 Waits for a pending operation on an OS to resolve to SUCCEEDED or FAILED. Return 

60 TIMED_OUT when timing out. 

61 

62 Parameters 

63 ---------- 

64 params: dict 

65 Flat dictionary of (key, value) pairs of tunable parameters. 

66 Must have the "asyncResultsUrl" key to get the results. 

67 If the key is not present, return Status.PENDING. 

68 

69 Returns 

70 ------- 

71 result : (Status, dict) 

72 A pair of Status and result. 

73 Status is one of {PENDING, SUCCEEDED, FAILED, TIMED_OUT} 

74 Result is info on the operation runtime if SUCCEEDED, otherwise {}. 

75 """ 

76 ...