Fix tests failing due to missing .env file and logging issue with resource processor (#4208)

This commit is contained in:
Marcus Robinson 2024-12-18 09:04:13 +00:00 коммит произвёл GitHub
Родитель beea683cd6
Коммит 5e9d1b9dfb
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
9 изменённых файлов: 39 добавлений и 22 удалений

Просмотреть файл

@ -32,8 +32,10 @@ BUG FIXES:
- Create policy to allow all user to configure color profiles to remove auth dialog. ([#4184](https://github.com/microsoft/AzureTRE/pull/4184))
- Pre configure VS code option to prevent script failure ([#4185](https://github.com/microsoft/AzureTRE/pull/4185))
- Enable symlinks to work on Linux VM shared storage ([#4180](https://github.com/microsoft/AzureTRE/issues/4180))
- Fix failing tests, .env missing and storage logs ([#4207](https://github.com/microsoft/AzureTRE/issues/4207))
- Unable to delete virtual machines, add skip_shutdown_and_force_delete = true ([#4135](https://github.com/microsoft/AzureTRE/issues/4135))
COMPONENTS:
## 0.19.1

Просмотреть файл

@ -1 +1 @@
__version__ = "0.20.0"
__version__ = "0.20.1"

Просмотреть файл

@ -1,12 +1,11 @@
from typing import List
import warnings
from starlette.config import Config
from _version import __version__
try:
config = Config('.env')
# Workaround needed until FastAPI uses Starlette >= 3.7.1
except FileNotFoundError:
config = Config()
warnings.filterwarnings("ignore", message="Config file '.env' not found.")
config = Config('.env')
# API settings
API_PREFIX = "/api"

Просмотреть файл

@ -66,7 +66,7 @@ class WorkspaceRepository(ResourceRepository):
return parse_obj_as(Workspace, workspaces[0])
# Remove this method once not using last 4 digits for naming - https://github.com/microsoft/AzureTRE/issues/3666
async def is_worksapce_storage_account_available(self, workspace_id: str) -> bool:
async def is_workspace_storage_account_available(self, workspace_id: str) -> bool:
storage_client = StorageManagementClient(credentials.get_credential(), config.SUBSCRIPTION_ID)
# check for storage account with last 4 digits of workspace_id
availability_result = storage_client.storage_accounts.check_name_availability(
@ -81,7 +81,7 @@ class WorkspaceRepository(ResourceRepository):
full_workspace_id = str(uuid.uuid4())
# Ensure workspace with last four digits of ID does not already exist - remove when https://github.com/microsoft/AzureTRE/issues/3666 is resolved
while not await self.is_worksapce_storage_account_available(full_workspace_id):
while not await self.is_workspace_storage_account_available(full_workspace_id):
full_workspace_id = str(uuid.uuid4())
template = await self.validate_input_against_template(workspace_input.templateName, workspace_input, ResourceType.Workspace, user_roles)

Просмотреть файл

@ -232,7 +232,7 @@ class CostService:
else:
c = ["UsageDate", "ResourceGroup", "Tag", "Currency"]
df = df.groupby(c).agg({'PreTaxCost': sum})
df = df.groupby(c).agg({'PreTaxCost': 'sum'})
# reset index and reorder columns
df.reset_index(inplace=True)

Просмотреть файл

@ -98,7 +98,7 @@ async def test_get_workspace_by_id_queries_db(workspace_repo, workspace):
@pytest.mark.asyncio
@patch('db.repositories.workspaces.generate_new_cidr')
@patch('db.repositories.workspaces.WorkspaceRepository.validate_input_against_template')
@patch('db.repositories.workspaces.WorkspaceRepository.is_worksapce_storage_account_available')
@patch('db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available')
@patch('core.config.RESOURCE_LOCATION', "useast2")
@patch('core.config.TRE_ID', "9876")
async def test_create_workspace_item_creates_a_workspace_with_the_right_values(mock_is_workspace_storage_account_available, validate_input_mock, new_cidr_mock, workspace_repo, basic_workspace_request, basic_resource_template):
@ -168,7 +168,7 @@ async def test_get_address_space_based_on_size_with_large_address_space(workspac
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository.validate_input_against_template')
@patch('db.repositories.workspaces.WorkspaceRepository.is_worksapce_storage_account_available')
@patch('db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available')
@patch('core.config.RESOURCE_LOCATION', "useast2")
@patch('core.config.TRE_ID', "9876")
@patch('core.config.CORE_ADDRESS_SPACE', "10.1.0.0/22")
@ -189,7 +189,7 @@ async def test_create_workspace_item_creates_a_workspace_with_custom_address_spa
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository.validate_input_against_template')
@patch('db.repositories.workspaces.WorkspaceRepository.is_worksapce_storage_account_available')
@patch('db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available')
@patch('core.config.RESOURCE_LOCATION', "useast2")
@patch('core.config.TRE_ID', "9876")
@patch('core.config.CORE_ADDRESS_SPACE', "10.1.0.0/22")
@ -260,7 +260,7 @@ async def test_get_address_space_based_on_size_with_address_space_and_address_sp
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository.validate_input_against_template')
@patch('db.repositories.workspaces.WorkspaceRepository.is_worksapce_storage_account_available')
@patch('db.repositories.workspaces.WorkspaceRepository.is_workspace_storage_account_available')
async def test_create_workspace_item_raises_value_error_if_template_is_invalid(mock_is_workspace_storage_account_available, validate_input_mock, workspace_repo, basic_workspace_request):
workspace_input = basic_workspace_request
@ -298,27 +298,31 @@ def test_workspace_owner_is_not_overwritten_if_present_in_workspace_properties(w
assert workspace_repo.get_workspace_owner(dictToTest, not_expected_object_id) == "Expected"
@patch('azure.mgmt.storage.StorageManagementClient')
async def test_is_worksapce_storage_account_available_when_name_available(mock_storage_client):
@pytest.mark.asyncio
@patch('db.repositories.workspaces.StorageManagementClient')
async def test_is_workspace_storage_account_available_when_name_available(mock_storage_client):
workspace_id = "workspace1234"
mock_storage_client.return_value = MagicMock()
mock_storage_client.return_value.storage_accounts.check_name_availability.return_value = AsyncMock()
mock_storage_client.return_value.storage_accounts.check_name_availability.return_value.name_available = True
workspace_repo = WorkspaceRepository()
result = await workspace_repo.is_workspace_with_last_4_id(workspace_id)
result = await workspace_repo.is_workspace_storage_account_available(workspace_id)
mock_storage_client.return_value.storage_accounts.check_name_availability.assert_called_once_with({"name": f"stgws{workspace_id[-4:]}"})
assert result is False
assert result is True
@patch('azure.mgmt.storage.StorageManagementClient')
async def test_is_worksapce_storage_account_available_when_name_not_available(mock_storage_client):
@pytest.mark.asyncio
@patch('db.repositories.workspaces.StorageManagementClient')
async def test_is_workspace_storage_account_available_when_name_not_available(mock_storage_client):
workspace_id = "workspace1234"
mock_storage_client.return_value = MagicMock()
mock_storage_client.return_value.storage_accounts.check_name_availability.return_value = AsyncMock()
mock_storage_client.return_value.storage_accounts.check_name_availability.return_value.name_available = False
workspace_repo = WorkspaceRepository()
result = await workspace_repo.is_workspace_with_last_4_id(workspace_id)
result = await workspace_repo.is_workspace_storage_account_available(workspace_id)
mock_storage_client.return_value.storage_accounts.check_name_availability.assert_called_once_with({"name": f"stgws{workspace_id[-4:]}"})
assert result is True
assert result is False

Просмотреть файл

@ -21,6 +21,7 @@ def clear_lru_cache():
CostService.cache_clear()
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -63,6 +64,7 @@ async def test_query_tre_costs_with_granularity_none_returns_correct_cost_report
assert cost_report.workspaces[1].costs[1].currency == "USD"
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -165,6 +167,7 @@ def __get_daily_cost_management_query_result():
return query_result
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -201,6 +204,7 @@ async def test_query_tre_costs_with_granularity_none_and_missing_costs_data_retu
assert len(cost_report.workspaces[1].costs) == 0
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -229,6 +233,7 @@ async def test_query_tre_costs_for_unsupported_subscription_raises_subscription_
"guy22", GranularityEnum.none, datetime.now(), datetime.now(), workspace_repo_mock, shared_service_repo_mock)
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -267,6 +272,7 @@ async def test_query_tre_costs_with_granularity_daily_and_missing_costs_data_ret
assert len(cost_report.workspaces[1].costs) == 0
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -333,6 +339,7 @@ async def test_query_tre_costs_with_dates_set_as_none_calls_client_with_month_to
assert query_definition.timeframe == TimeframeType.MONTH_TO_DATE
@pytest.mark.asyncio
@patch('db.repositories.workspaces.WorkspaceRepository')
@patch('db.repositories.shared_services.SharedServiceRepository')
@patch('services.cost_service.CostManagementClient')
@ -442,6 +449,7 @@ def __set_user_resource_repo_mock_return_value(user_resource_repo_mock):
])
@pytest.mark.asyncio
@patch('db.repositories.user_resources.UserResourceRepository')
@patch('db.repositories.workspace_services.WorkspaceServiceRepository')
@patch('db.repositories.workspaces.WorkspaceRepository')
@ -497,6 +505,7 @@ async def test_query_tre_workspace_costs_with_granularity_none_returns_correct_w
assert workspace_cost_report.workspace_services[1].user_resources[1].costs[0].cost == 4.1
@pytest.mark.asyncio
@patch('db.repositories.user_resources.UserResourceRepository')
@patch('db.repositories.workspace_services.WorkspaceServiceRepository')
@patch('db.repositories.workspaces.WorkspaceRepository')

Просмотреть файл

@ -1 +1 @@
__version__ = "0.10.0"
__version__ = "0.10.1"

Просмотреть файл

@ -100,6 +100,9 @@ def chunk_log_output(output: str, chunk_size: int = 30000):
Split the log output into smaller chunks and prefix each chunk with [Log chunk X of Y].
"""
total_chunks = (len(output) + chunk_size - 1) // chunk_size # Calculate total number of chunks
if total_chunks == 1:
yield output
return
for i in range(0, len(output), chunk_size):
current_chunk = i // chunk_size + 1
prefix = f"[Log chunk {current_chunk} of {total_chunks}] "