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

5 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 00:44 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Protocol interface for Service types that provide helper functions to run scripts on 

6a remote host OS. 

7""" 

8 

9from typing import TYPE_CHECKING, Iterable, Protocol, Tuple, runtime_checkable 

10 

11if TYPE_CHECKING: 

12 from mlos_bench.environments.status import Status 

13 

14 

15@runtime_checkable 

16class SupportsRemoteExec(Protocol): 

17 """Protocol interface for Service types that provide helper functions to run scripts 

18 on a remote host OS. 

19 """ 

20 

21 def remote_exec( 

22 self, 

23 script: Iterable[str], 

24 config: dict, 

25 env_params: dict, 

26 ) -> Tuple["Status", dict]: 

27 """ 

28 Run a command on remote host OS. 

29 

30 Parameters 

31 ---------- 

32 script : Iterable[str] 

33 A list of lines to execute as a script on a remote VM. 

34 config : dict 

35 Flat dictionary of (key, value) pairs of parameters. 

36 They usually come from `const_args` and `tunable_params` 

37 properties of the Environment. 

38 env_params : dict 

39 Parameters to pass as *shell* environment variables into the script. 

40 This is usually a subset of `config` with some possible conversions. 

41 

42 Returns 

43 ------- 

44 result : (Status, dict) 

45 A pair of Status and result. 

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

47 """ 

48 

49 def get_remote_exec_results(self, config: dict) -> Tuple["Status", dict]: 

50 """ 

51 Get the results of the asynchronously running command. 

52 

53 Parameters 

54 ---------- 

55 config : dict 

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

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

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

59 

60 Returns 

61 ------- 

62 result : (Status, dict) 

63 A pair of Status and result. 

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

65 """