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

8 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 Service types that provide helper functions to run scripts on 

6a remote host OS. 

7""" 

8 

9from collections.abc import Iterable 

10from typing import TYPE_CHECKING, Protocol, runtime_checkable 

11 

12if TYPE_CHECKING: 

13 from mlos_bench.environments.status import Status 

14 

15 

16@runtime_checkable 

17class SupportsRemoteExec(Protocol): 

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

19 on a remote host OS. 

20 """ 

21 

22 # pylint: disable=unnecessary-ellipsis 

23 

24 def remote_exec( 

25 self, 

26 script: Iterable[str], 

27 config: dict, 

28 env_params: dict, 

29 ) -> tuple["Status", dict]: 

30 """ 

31 Run a command on remote host OS. 

32 

33 Parameters 

34 ---------- 

35 script : Iterable[str] 

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

37 config : dict 

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

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

40 properties of the Environment. 

41 env_params : dict 

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

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

44 

45 Returns 

46 ------- 

47 result : (Status, dict) 

48 A pair of Status and result. 

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

50 """ 

51 ... 

52 

53 def get_remote_exec_results(self, config: dict) -> tuple["Status", dict]: 

54 """ 

55 Get the results of the asynchronously running command. 

56 

57 Parameters 

58 ---------- 

59 config : dict 

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

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

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

63 

64 Returns 

65 ------- 

66 result : (Status, dict) 

67 A pair of Status and result. 

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

69 """ 

70 ...