Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migration to check firewall meets min version #2386

Merged
merged 5 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.4.3"
16 changes: 10 additions & 6 deletions api_app/api/routes/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,35 @@ async def migrate_database(resources_repo=Depends(get_repository(ResourceReposit
resource_migration=Depends(get_repository(ResourceMigration))):
try:
migrations = list()
logging.info("PR 1030.")
logging.info("PR 1030")
resources_repo.rename_field_name('resourceTemplateName', 'templateName')
resources_repo.rename_field_name('resourceTemplateVersion', 'templateVersion')
resources_repo.rename_field_name('resourceTemplateParameters', 'properties')
migrations.append(Migration(issueNumber="PR 1030", status="Executed"))

logging.info("PR 1031.")
logging.info("PR 1031")
resources_repo.rename_field_name('workspaceType', 'templateName')
resources_repo.rename_field_name('workspaceServiceType', 'templateName')
resources_repo.rename_field_name('userResourceType', 'templateName')
migrations.append(Migration(issueNumber="PR 1031", status="Executed"))

logging.info("PR 1717. - Shared services")
logging.info("PR 1717 - Shared services")
migration_status = "Executed" if shared_services_migration.deleteDuplicatedSharedServices() else "Skipped"
migrations.append(Migration(issueNumber="PR 1717", status=migration_status))

logging.info("PR 1726. - Authentication needs to be in properties so we can update them")
logging.info("PR 1726 - Authentication needs to be in properties so we can update them")
migration_status = "Executed" if workspace_migration.moveAuthInformationToProperties() else "Skipped"
migrations.append(Migration(issueNumber="PR 1726", status=migration_status))

logging.info("#1406 - Extra field to support UI")
logging.info("PR 1406 - Extra field to support UI")
num_rows = resource_migration.add_deployment_status_field(operations_repo)
migrations.append(Migration(issueNumber="1406", status=f'Updated {num_rows} resource objects'))

logging.info("PR 2371 - Validate min firewall version")
shared_services_migration.checkMinFirewallVersion()
migrations.append(Migration(issueNumber="2371", status='Firewall version meets requirement'))

return MigrationOutList(migrations=migrations)
except Exception as e:
logging.error(f"Failed to migrate database: {e}")
logging.error("Failed to migrate database: %s", e)
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail=str(e))
15 changes: 15 additions & 0 deletions api_app/db/migrations/shared_services.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,18 @@ def deleteDuplicatedSharedServices(self) -> bool:
migrated = True

return migrated

def checkMinFirewallVersion(self) -> bool:
template_name = 'tre-shared-service-firewall'
min_template_version = semantic_version.Version('0.4.0')

resource = self.query(query=f'SELECT * FROM c WHERE c.resourceType = "shared-service" \
AND c.templateName = "{template_name}" AND {IS_OPERATING_SHARED_SERVICE}')

template_version = semantic_version.Version(resource[0]["templateVersion"])

if (template_version < min_template_version):
raise ValueError(f"{template_name} deployed version ({template_version}) is below minimum ({min_template_version})!",
"Go to https://github.com/microsoft/AzureTRE/blob/main/CHANGELOG.md, and review release 0.5.0 for more info.")

return True
6 changes: 5 additions & 1 deletion api_app/tests_ma/test_api/test_routes/test_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,13 @@ def _prepare(self, app, admin_user):
@ patch("api.routes.migrations.ResourceRepository.rename_field_name")
@ patch("api.routes.migrations.SharedServiceMigration.deleteDuplicatedSharedServices")
@ patch("api.routes.migrations.WorkspaceMigration.moveAuthInformationToProperties")
async def test_post_migrations_returns_202_on_successful(self, workspace_migration, shared_services_migration, rename_field, add_deployment_field, _, logging, client, app):
@ patch("api.routes.migrations.SharedServiceMigration.checkMinFirewallVersion")
async def test_post_migrations_returns_202_on_successful(self, check_min_firewall_version, workspace_migration,
shared_services_migration, rename_field,
add_deployment_field, _, logging, client, app):
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))

check_min_firewall_version.assert_called_once()
shared_services_migration.assert_called_once()
workspace_migration.assert_called_once()
rename_field.assert_called()
Expand Down