Coverage for mlos_bench/mlos_bench/tests/services/remote/mock/mock_vm_service.py: 100%

10 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"""A collection Service functions for mocking managing VMs.""" 

6 

7from collections.abc import Callable 

8from typing import Any 

9 

10from mlos_bench.services.base_service import Service 

11from mlos_bench.services.types.host_ops_type import SupportsHostOps 

12from mlos_bench.services.types.host_provisioner_type import SupportsHostProvisioning 

13from mlos_bench.services.types.os_ops_type import SupportsOSOps 

14from mlos_bench.tests.services.remote.mock import mock_operation 

15 

16 

17class MockVMService(Service, SupportsHostProvisioning, SupportsHostOps, SupportsOSOps): 

18 """Mock VM service for testing.""" 

19 

20 # pylint: disable=too-many-ancestors 

21 

22 def __init__( 

23 self, 

24 config: dict[str, Any] | None = None, 

25 global_config: dict[str, Any] | None = None, 

26 parent: Service | None = None, 

27 methods: dict[str, Callable] | list[Callable] | None = None, 

28 ): 

29 """ 

30 Create a new instance of mock VM services proxy. 

31 

32 Parameters 

33 ---------- 

34 config : dict 

35 Free-format dictionary that contains the benchmark environment 

36 configuration. 

37 global_config : dict 

38 Free-format dictionary of global parameters. 

39 parent : Service 

40 Parent service that can provide mixin functions. 

41 """ 

42 super().__init__( 

43 config, 

44 global_config, 

45 parent, 

46 self.merge_methods( 

47 methods, 

48 { 

49 name: mock_operation 

50 for name in ( 

51 # SupportsHostProvisioning: 

52 "wait_host_deployment", 

53 "provision_host", 

54 "deprovision_host", 

55 "deallocate_host", 

56 # SupportsHostOps: 

57 "start_host", 

58 "stop_host", 

59 "restart_host", 

60 "wait_host_operation", 

61 # SupportsOsOps: 

62 "shutdown", 

63 "reboot", 

64 "wait_os_operation", 

65 ) 

66 }, 

67 ), 

68 )