Coverage for mlos_bench/mlos_bench/services/types/host_ops_type.py: 64%

11 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/VM boot 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 SupportsHostOps(Protocol): 

15 """Protocol interface for Host/VM boot operations.""" 

16 

17 # pylint: disable=unnecessary-ellipsis 

18 

19 def start_host(self, params: dict) -> tuple["Status", dict]: 

20 """ 

21 Start a Host/VM. 

22 

23 Parameters 

24 ---------- 

25 params : dict 

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

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 

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

37 """ 

38 Stops the Host/VM by initiating a (graceful) shutdown. 

39 

40 Parameters 

41 ---------- 

42 params : dict 

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

44 force : bool 

45 If True, force stop the Host/VM. 

46 

47 Returns 

48 ------- 

49 result : (Status, dict) 

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

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

52 """ 

53 ... 

54 

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

56 """ 

57 Restarts the host by initiating a (graceful) shutdown. 

58 

59 Parameters 

60 ---------- 

61 params : dict 

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

63 force : bool 

64 If True, force restart the Host/VM. 

65 

66 Returns 

67 ------- 

68 result : (Status, dict) 

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

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

71 """ 

72 ... 

73 

74 def wait_host_operation(self, params: dict) -> tuple["Status", dict]: 

75 """ 

76 Waits for a pending operation on a Host/VM to resolve to SUCCEEDED or FAILED. 

77 Return TIMED_OUT when timing out. 

78 

79 Parameters 

80 ---------- 

81 params: dict 

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

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

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

85 

86 Returns 

87 ------- 

88 result : (Status, dict) 

89 A pair of Status and result. 

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

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

92 """ 

93 ...