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

6 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 01:18 +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, Tuple, 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 def shutdown(self, params: dict, force: bool = False) -> Tuple["Status", dict]: 

18 """ 

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

20 

21 Parameters 

22 ---------- 

23 params: dict 

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

25 force : bool 

26 If True, force stop the Host/VM. 

27 

28 Returns 

29 ------- 

30 result : (Status, dict) 

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

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

33 """ 

34 

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

36 """ 

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

38 

39 Parameters 

40 ---------- 

41 params: dict 

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

43 force : bool 

44 If True, force restart the Host/VM. 

45 

46 Returns 

47 ------- 

48 result : (Status, dict) 

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

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

51 """ 

52 

53 def wait_os_operation(self, params: dict) -> Tuple["Status", dict]: 

54 """ 

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

56 TIMED_OUT when timing out. 

57 

58 Parameters 

59 ---------- 

60 params: dict 

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

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

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

64 

65 Returns 

66 ------- 

67 result : (Status, dict) 

68 A pair of Status and result. 

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

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

71 """