Skip to content

Commit

Permalink
Migrate reviewDecision of Airlock Reviews (#3152)
Browse files Browse the repository at this point in the history
* add migration for airlock reviewDecision value

* add 'update_review_decision_values' to the migrations test

* update PR number

* match issue number to PR number

* update changelog

* fix wrong expected status in e2e
  • Loading branch information
yuvalyaron committed Jan 31, 2023
1 parent 35b486b commit 3eca584
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ENHANCEMENTS:

BUG FIXES:
* Reauth CLI if TRE endpoint has changed [#3137](https://github.com/microsoft/AzureTRE/pull/3137)
* Added Migration for Airlock requests that were created prior to version 0.5.0 ([#3152](https://github.com/microsoft/AzureTRE/pull/3152))

COMPONENTS:

Expand Down
2 changes: 1 addition & 1 deletion api_app/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.11.0"
__version__ = "0.11.1"
6 changes: 5 additions & 1 deletion api_app/api/routes/migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ async def migrate_database(resources_repo=Depends(get_repository(ResourceReposit

logging.info("PR 2883 - Support multiple reviewer VMs per Airlock request")
num_updated = await airlock_migration.change_review_resources_to_dict()
migrations.append(Migration(issueNumber="XXXX", status=f'Updated {num_updated} airlock requests with new reviewUserResources format'))
migrations.append(Migration(issueNumber="2883", status=f'Updated {num_updated} airlock requests with new reviewUserResources format'))

logging.info("PR 3152 - Migrate reviewDecision of Airlock Reviews")
num_updated = await airlock_migration.update_review_decision_values()
migrations.append(Migration(issueNumber="3152", status=f'Updated {num_updated} airlock requests with new reviewDecision value'))

return MigrationOutList(migrations=migrations)
except Exception as e:
Expand Down
26 changes: 26 additions & 0 deletions api_app/db/migrations/airlock.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from azure.cosmos.aio import CosmosClient
from resources import strings
from db.repositories.airlock_requests import AirlockRequestRepository


Expand Down Expand Up @@ -52,3 +53,28 @@ async def change_review_resources_to_dict(self) -> int:
num_updated += 1

return num_updated

async def update_review_decision_values(self) -> int:
num_updated = 0
for request in await self.query('SELECT * FROM c WHERE ARRAY_LENGTH(c.reviews) > 0'):
request_changed = False

for review in request['reviews']:
old_decision = review['reviewDecision']
new_decision = old_decision

if old_decision == 'approval_in_progress':
new_decision = strings.AIRLOCK_REVIEW_DECISION_APPROVED

if old_decision == 'rejection_in_progress':
new_decision = strings.AIRLOCK_REVIEW_DECISION_REJECTED

if new_decision != old_decision:
request_changed = True
review['reviewDecision'] = new_decision

if request_changed:
await self.update_item_dict(request)
num_updated += 1

return num_updated
4 changes: 3 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 @@ -44,7 +44,8 @@ def _prepare(self, app, admin_user):
@ patch("api.routes.migrations.AirlockMigration.add_created_by_and_rename_in_history")
@ patch("api.routes.migrations.AirlockMigration.rename_field_name")
@ patch("api.routes.migrations.AirlockMigration.change_review_resources_to_dict")
async def test_post_migrations_returns_202_on_successful(self, change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
@ patch("api.routes.migrations.AirlockMigration.update_review_decision_values")
async def test_post_migrations_returns_202_on_successful(self, update_review_decision_values, change_review_resources_to_dict, airlock_rename_field, add_created_by_and_rename_in_history,
check_min_firewall_version, workspace_migration, shared_services_migration,
rename_field, add_deployment_field, archive_history, _, logging, client, app):
response = await client.post(app.url_path_for(strings.API_MIGRATE_DATABASE))
Expand All @@ -57,6 +58,7 @@ async def test_post_migrations_returns_202_on_successful(self, change_review_res
add_created_by_and_rename_in_history.assert_called_once()
airlock_rename_field.assert_called()
change_review_resources_to_dict.assert_called_once()
update_review_decision_values.assert_called_once()
archive_history.assert_called_once()
logging.assert_called()
assert response.status_code == status.HTTP_202_ACCEPTED
Expand Down
2 changes: 1 addition & 1 deletion devops/scripts/migrate_state_store.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# This script migrates the Cosmos database based on any breaking changes that have occurred.
# Cosmos is behind a private network, so we call the /migrate endpoint of the API
# Cosmos is behind a private network, so we call the /migrations endpoint of the API

set -o errexit
set -o pipefail
Expand Down
2 changes: 1 addition & 1 deletion e2e_tests/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ async def get_resource(endpoint, access_token, verify):
auth_headers = get_auth_header(access_token)

response = await client.get(full_endpoint, headers=auth_headers, timeout=TIMEOUT)
assert_status(response, [status.HTTP_202_ACCEPTED], f"Failed to GET {full_endpoint}")
assert_status(response, [status.HTTP_200_OK], f"Failed to GET {full_endpoint}")

return response.json()

Expand Down

0 comments on commit 3eca584

Please sign in to comment.