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

25 statements  

« prev     ^ index     » next       coverage.py v7.6.7, created at 2024-11-22 01:18 +0000

1# 

2# Copyright (c) Microsoft Corporation. 

3# Licensed under the MIT License. 

4# 

5"""Configuration test fixtures for azure_vm_services in mlos_bench.""" 

6 

7from unittest.mock import patch 

8 

9import pytest 

10 

11from mlos_bench.services.config_persistence import ConfigPersistenceService 

12from mlos_bench.services.remote.azure import ( 

13 AzureAuthService, 

14 AzureFileShareService, 

15 AzureNetworkService, 

16 AzureVMService, 

17) 

18 

19# pylint: disable=redefined-outer-name 

20 

21 

22@pytest.fixture 

23def config_persistence_service() -> ConfigPersistenceService: 

24 """Test fixture for ConfigPersistenceService.""" 

25 return ConfigPersistenceService() 

26 

27 

28@pytest.fixture 

29def azure_auth_service( 

30 config_persistence_service: ConfigPersistenceService, 

31 monkeypatch: pytest.MonkeyPatch, 

32) -> AzureAuthService: 

33 """Creates a dummy AzureAuthService for tests that require it.""" 

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

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

36 return auth 

37 

38 

39@pytest.fixture 

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

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

42 return AzureNetworkService( 

43 config={ 

44 "deploymentTemplatePath": ( 

45 "services/remote/azure/arm-templates/azuredeploy-ubuntu-vm.jsonc" 

46 ), 

47 "subscription": "TEST_SUB", 

48 "resourceGroup": "TEST_RG", 

49 "deploymentTemplateParameters": { 

50 "location": "westus2", 

51 }, 

52 "pollInterval": 1, 

53 "pollTimeout": 2, 

54 }, 

55 global_config={ 

56 "deploymentName": "TEST_DEPLOYMENT-VNET", 

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

58 }, 

59 parent=azure_auth_service, 

60 ) 

61 

62 

63@pytest.fixture 

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

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

66 return AzureVMService( 

67 config={ 

68 "deploymentTemplatePath": ( 

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

70 ), 

71 "subscription": "TEST_SUB", 

72 "resourceGroup": "TEST_RG", 

73 "deploymentTemplateParameters": { 

74 "location": "westus2", 

75 }, 

76 "pollInterval": 1, 

77 "pollTimeout": 2, 

78 }, 

79 global_config={ 

80 "deploymentName": "TEST_DEPLOYMENT-VM", 

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

82 }, 

83 parent=azure_auth_service, 

84 ) 

85 

86 

87@pytest.fixture 

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

89 """Creates a dummy Azure VM service with no deployment template.""" 

90 return AzureVMService( 

91 config={ 

92 "subscription": "TEST_SUB", 

93 "resourceGroup": "TEST_RG", 

94 "pollInterval": 1, 

95 "pollTimeout": 2, 

96 }, 

97 global_config={ 

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

99 }, 

100 parent=azure_auth_service, 

101 ) 

102 

103 

104@pytest.fixture 

105def azure_fileshare(azure_auth_service: AzureAuthService) -> AzureFileShareService: 

106 """Creates a dummy AzureFileShareService for tests that require it.""" 

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

108 return AzureFileShareService( 

109 config={ 

110 "storageAccountName": "TEST_ACCOUNT_NAME", 

111 "storageFileShareName": "TEST_FS_NAME", 

112 "storageAccountKey": "TEST_ACCOUNT_KEY", 

113 }, 

114 global_config={}, 

115 parent=azure_auth_service, 

116 )