Coverage for mlos_bench/mlos_bench/tests/services/remote/mock/mock_vm_service.py: 100%
9 statements
« prev ^ index » next coverage.py v7.6.9, created at 2024-12-20 00:44 +0000
« 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"""A collection Service functions for mocking managing VMs."""
7from typing import Any, Callable, Dict, List, Optional, Union
9from mlos_bench.services.base_service import Service
10from mlos_bench.services.types.host_ops_type import SupportsHostOps
11from mlos_bench.services.types.host_provisioner_type import SupportsHostProvisioning
12from mlos_bench.services.types.os_ops_type import SupportsOSOps
13from mlos_bench.tests.services.remote.mock import mock_operation
16class MockVMService(Service, SupportsHostProvisioning, SupportsHostOps, SupportsOSOps):
17 """Mock VM service for testing."""
19 def __init__(
20 self,
21 config: Optional[Dict[str, Any]] = None,
22 global_config: Optional[Dict[str, Any]] = None,
23 parent: Optional[Service] = None,
24 methods: Union[Dict[str, Callable], List[Callable], None] = None,
25 ):
26 """
27 Create a new instance of mock VM services proxy.
29 Parameters
30 ----------
31 config : dict
32 Free-format dictionary that contains the benchmark environment
33 configuration.
34 global_config : dict
35 Free-format dictionary of global parameters.
36 parent : Service
37 Parent service that can provide mixin functions.
38 """
39 super().__init__(
40 config,
41 global_config,
42 parent,
43 self.merge_methods(
44 methods,
45 {
46 name: mock_operation
47 for name in (
48 # SupportsHostProvisioning:
49 "wait_host_deployment",
50 "provision_host",
51 "deprovision_host",
52 "deallocate_host",
53 # SupportsHostOps:
54 "start_host",
55 "stop_host",
56 "restart_host",
57 "wait_host_operation",
58 # SupportsOsOps:
59 "shutdown",
60 "reboot",
61 "wait_os_operation",
62 )
63 },
64 ),
65 )