Coverage for mlos_bench/mlos_bench/tests/services/remote/azure/conftest.py: 100%

26 statements  

« 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""" 

6Configuration test fixtures for azure_vm_services in mlos_bench. 

7""" 

8 

9from unittest.mock import patch 

10 

11import pytest 

12 

13from mlos_bench.services.config_persistence import ConfigPersistenceService 

14from mlos_bench.services.remote.azure import ( 

15 AzureAuthService, 

16 AzureNetworkService, 

17 AzureVMService, 

18 AzureFileShareService, 

19) 

20 

21# pylint: disable=redefined-outer-name 

22 

23 

24@pytest.fixture 

25def config_persistence_service() -> ConfigPersistenceService: 

26 """ 

27 Test fixture for ConfigPersistenceService. 

28 """ 

29 return ConfigPersistenceService() 

30 

31 

32@pytest.fixture 

33def azure_auth_service(config_persistence_service: ConfigPersistenceService, 

34 monkeypatch: pytest.MonkeyPatch) -> AzureAuthService: 

35 """ 

36 Creates a dummy AzureAuthService for tests that require it. 

37 """ 

38 auth = AzureAuthService(config={}, global_config={}, parent=config_persistence_service) 

39 monkeypatch.setattr(auth, "get_access_token", lambda: "TEST_TOKEN") 

40 return auth 

41 

42 

43@pytest.fixture 

44def azure_network_service(azure_auth_service: AzureAuthService) -> AzureNetworkService: 

45 """ 

46 Creates a dummy Azure VM service for tests that require it. 

47 """ 

48 return AzureNetworkService(config={ 

49 "deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc", 

50 "subscription": "TEST_SUB", 

51 "resourceGroup": "TEST_RG", 

52 "deploymentTemplateParameters": { 

53 "location": "westus2", 

54 }, 

55 "pollInterval": 1, 

56 "pollTimeout": 2 

57 }, global_config={ 

58 "deploymentName": "TEST_DEPLOYMENT-VNET", 

59 "vnetName": "test-vnet", # Should come from the upper-level config 

60 }, parent=azure_auth_service) 

61 

62 

63@pytest.fixture 

64def azure_vm_service(azure_auth_service: AzureAuthService) -> AzureVMService: 

65 """ 

66 Creates a dummy Azure VM service for tests that require it. 

67 """ 

68 return AzureVMService(config={ 

69 "deploymentTemplatePath": "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc", 

70 "subscription": "TEST_SUB", 

71 "resourceGroup": "TEST_RG", 

72 "deploymentTemplateParameters": { 

73 "location": "westus2", 

74 }, 

75 "pollInterval": 1, 

76 "pollTimeout": 2 

77 }, global_config={ 

78 "deploymentName": "TEST_DEPLOYMENT-VM", 

79 "vmName": "test-vm", # Should come from the upper-level config 

80 }, parent=azure_auth_service) 

81 

82 

83@pytest.fixture 

84def azure_vm_service_remote_exec_only(azure_auth_service: AzureAuthService) -> AzureVMService: 

85 """ 

86 Creates a dummy Azure VM service with no deployment template. 

87 """ 

88 return AzureVMService(config={ 

89 "subscription": "TEST_SUB", 

90 "resourceGroup": "TEST_RG", 

91 "pollInterval": 1, 

92 "pollTimeout": 2, 

93 }, global_config={ 

94 "vmName": "test-vm", # Should come from the upper-level config 

95 }, parent=azure_auth_service) 

96 

97 

98@pytest.fixture 

99def azure_fileshare(config_persistence_service: ConfigPersistenceService) -> AzureFileShareService: 

100 """ 

101 Creates a dummy AzureFileShareService for tests that require it. 

102 """ 

103 with patch("mlos_bench.services.remote.azure.azure_fileshare.ShareClient"): 

104 return AzureFileShareService(config={ 

105 "storageAccountName": "TEST_ACCOUNT_NAME", 

106 "storageFileShareName": "TEST_FS_NAME", 

107 "storageAccountKey": "TEST_ACCOUNT_KEY" 

108 }, global_config={}, parent=config_persistence_service)