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