Skip to content

Commit

Permalink
Merge branch 'main' into 2829-delete-review-vms-on-cancel
Browse files Browse the repository at this point in the history
  • Loading branch information
yuvalyaron authored Jan 30, 2023
2 parents 199d17c + e0b282a commit 6ce7147
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 35 deletions.
38 changes: 28 additions & 10 deletions .github/workflows/build_docs.yml
Original file line number Diff line number Diff line change
@@ -1,21 +1,39 @@
---
name: Publish docs via Github Pages

on: # yamllint disable-line rule:truthy
name: Deploy Documentation
on:
workflow_dispatch:
release:
types: [published]
push:
branches: [main]
paths:
- 'docs/**'

- mkdocs.yml
branches:
- main
jobs:
build:
name: Deploy docs
deploy:
name: Deploy Documentation
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Checkout main
uses: actions/checkout@v3
with:
fetch-depth: 0
persist-credentials: true
- uses: actions/setup-python@v4
with:
python-version: 3.x
- run: pip install -r docs/requirements.txt
- run: mkdocs gh-deploy --strict --force
- name: Install Dependencies
run: |
pip install -r docs/requirements.txt
- name: Configure Git User
# Required by mike for the commit it does to the gh-pages branch
run: |
git config user.name "ci-docs"
git config user.email "ci-docs@dummy.com"
- name: Deploy the latest documents from new release
if: ${{ github.event_name == 'release' }}
run: mike deploy --push --update-aliases "${GITHUB_REF#refs/*/}" latest-release
- name: Deploy the development docs
if: ${{ github.event_name != 'release' }}
run: mike deploy --push develop
1 change: 1 addition & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ mkdocs
mkdocs-material
mkdocs-material-extensions
mkdocstrings
mike
8 changes: 7 additions & 1 deletion e2e_tests/airlock/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,15 @@ async def wait_for_status(
200,
)
current_status = request_result[strings.AIRLOCK_REQUEST][strings.AIRLOCK_REQUEST_STATUS]
if (current_status == request_status or is_final_status(current_status)):

if (current_status == request_status):
break

if (is_final_status(current_status)):
status = request_result[strings.AIRLOCK_REQUEST].get(strings.AIRLOCK_REQUEST_STATUS_MESSAGE)
LOGGER.error(f"Airlock request ended with unexpected status: {current_status}. reason: {status}")
raise Exception("Airlock request unexpected status.")

LOGGER.info(f"Waiting for request status: {request_status}, current status is {current_status}")
await asyncio.sleep(5)

Expand Down
1 change: 1 addition & 0 deletions e2e_tests/airlock/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@

AIRLOCK_REQUEST = "airlockRequest"
AIRLOCK_REQUEST_STATUS = "status"
AIRLOCK_REQUEST_STATUS_MESSAGE = "statusMessage"
21 changes: 13 additions & 8 deletions e2e_tests/helpers.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from json import JSONDecodeError

import asyncio
from typing import Optional
from typing import List, Optional
from contextlib import asynccontextmanager
from httpx import AsyncClient, Timeout
from httpx import AsyncClient, Timeout, Response
import logging
from starlette import status

Expand Down Expand Up @@ -56,8 +56,8 @@ async def get_shared_service_by_name(template_name: str, verify, token) -> Optio
auth_headers = get_auth_header(token)

response = await client.get(full_endpoint, headers=auth_headers, timeout=TIMEOUT)
assert_status(response, [status.HTTP_200_OK], "Failed to get shared services")
LOGGER.info(f'RESPONSE: {response}')
assert (response.status_code == status.HTTP_200_OK), "Request to get shared services failed"

shared_service_list = response.json()["sharedServices"]

Expand Down Expand Up @@ -95,11 +95,11 @@ async def check_aad_auth_redirect(endpoint, verify) -> None:
except Exception:
LOGGER.exception("Generic execption in http request.")

assert (response.status_code == status.HTTP_302_FOUND)
assert_status(response, [status.HTTP_302_FOUND])
assert response.has_redirect_location

location = response.headers["Location"]
LOGGER.info("Returned redirect URL: %s", location)
LOGGER.info(f"Returned redirect URL: {location}")

valid_redirection_contains = ["login", "microsoftonline", "oauth2", "authorize"]
assert all(word in location for word in valid_redirection_contains), "Redirect URL doesn't apper to be valid"
Expand All @@ -123,9 +123,14 @@ async def get_admin_token(verify) -> str:
try:
responseJson = response.json()
except JSONDecodeError:
assert False, "Failed to parse response as JSON: {} {}".format(response.status_code, response.content)
assert False, f"Failed to parse response as JSON. status_code: {response.status_code}, content: {response.content}"

assert "access_token" in responseJson, "Failed to get access_token: {}".format(response.content)
assert "access_token" in responseJson, f"Failed to get access_token. content: {response.content}"
token = responseJson["access_token"]
assert token is not None, "Token not returned"
return token if (response.status_code == status.HTTP_200_OK) else None
return token if (response.status_code == status.HTTP_200_OK) else ""


def assert_status(response: Response, expected_status: List[int] = [200], message_prefix: str = "Unexpected HTTP Status"):
assert response.status_code in expected_status, \
f"{message_prefix}. Expected: {expected_status}. Actual: {response.status_code}. Response text: {response.text}"
15 changes: 5 additions & 10 deletions e2e_tests/resources/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import logging
from httpx import AsyncClient, Timeout
from starlette import status
from e2e_tests.helpers import get_auth_header, get_full_endpoint
from e2e_tests.helpers import assert_status, get_auth_header, get_full_endpoint
from e2e_tests.resources.deployment import delete_done, install_done, patch_done

from resources import strings
Expand All @@ -17,9 +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)

LOGGER.info(f'RESPONSE Status code: {response.status_code}')
assert (response.status_code == status.HTTP_200_OK), f"Get for endpoint {full_endpoint} failed"
assert_status(response, [status.HTTP_202_ACCEPTED], f"Failed to GET {full_endpoint}")

return response.json()

Expand All @@ -38,8 +36,7 @@ async def post_resource(payload, endpoint, access_token, verify, method="POST",
check_method = patch_done
response = await client.patch(full_endpoint, headers=auth_headers, json=payload, timeout=TIMEOUT)

LOGGER.info(f'RESPONSE Status code: {response.status_code}')
assert (response.status_code == status.HTTP_202_ACCEPTED), f"Request failed with response {response.status_code} and content {response.content}"
assert_status(response, [status.HTTP_202_ACCEPTED], "The resource couldn't be sent")

resource_path = response.json()["operation"]["resourcePath"]
resource_id = response.json()["operation"]["resourceId"]
Expand All @@ -62,15 +59,13 @@ async def disable_and_delete_resource(endpoint, access_token, verify):
# disable
payload = {"isEnabled": False}
response = await client.patch(full_endpoint, headers=auth_headers, json=payload, timeout=TIMEOUT)
LOGGER.info(f'RESPONSE Status code: {response.status_code}')
assert (response.status_code == status.HTTP_202_ACCEPTED), "Disable resource failed"
assert_status(response, [status.HTTP_202_ACCEPTED], "The resource couldn't be disabled")
operation_endpoint = response.headers["Location"]
await wait_for(patch_done, client, operation_endpoint, auth_headers, [strings.RESOURCE_STATUS_UPDATING_FAILED])

# delete
response = await client.delete(full_endpoint, headers=auth_headers, timeout=TIMEOUT)
LOGGER.info(f'RESPONSE Status code: {response.status_code}')
assert (response.status_code == status.HTTP_200_OK), "The resource couldn't be deleted"
assert_status(response, [status.HTTP_200_OK], "The resource couldn't be deleted")

resource_id = response.json()["operation"]["resourceId"]
operation_endpoint = response.headers["Location"]
Expand Down
4 changes: 2 additions & 2 deletions e2e_tests/test_shared_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from starlette import status

import config
from helpers import get_auth_header, get_template
from helpers import assert_status, get_auth_header, get_template
from resources import strings
from helpers import get_admin_token

Expand Down Expand Up @@ -34,4 +34,4 @@ async def test_get_shared_service_templates(template_name, verify) -> None:
async def test_get_shared_service_template(template_name, verify) -> None:
admin_token = await get_admin_token(verify)
async with get_template(template_name, strings.API_SHARED_SERVICE_TEMPLATES, admin_token, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} failed"
assert_status(response, [status.HTTP_200_OK], f"Failed to GET template: {template_name}")
5 changes: 3 additions & 2 deletions e2e_tests/test_workspace_service_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from starlette import status

import config
from helpers import get_auth_header, get_template
from helpers import assert_status, get_auth_header, get_template
from resources import strings
from helpers import get_admin_token

Expand Down Expand Up @@ -35,6 +35,7 @@ async def test_get_workspace_service_template(template_name, verify) -> None:
admin_token = await get_admin_token(verify)
async with get_template(template_name, strings.API_WORKSPACE_SERVICE_TEMPLATES, admin_token, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} failed"
assert_status(response, [status.HTTP_200_OK], f"Failed to GET {template_name}")


@pytest.mark.smoke
Expand All @@ -58,4 +59,4 @@ async def test_create_workspace_service_templates(verify) -> None:
admin_token = await get_admin_token(verify)
response = await client.post(f"https://{config.TRE_ID}.{config.RESOURCE_LOCATION}.cloudapp.azure.com{strings.API_WORKSPACE_SERVICE_TEMPLATES}", headers=get_auth_header(admin_token), json=payload)

assert (response.status_code == status.HTTP_201_CREATED or response.status_code == status.HTTP_409_CONFLICT), "The workspace service template creation service returned unexpected response."
assert_status(response, [status.HTTP_201_CREATED, status.HTTP_409_CONFLICT], "Failed to create workspace service template")
4 changes: 2 additions & 2 deletions e2e_tests/test_workspace_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from starlette import status

import config
from helpers import get_auth_header, get_template
from helpers import assert_status, get_auth_header, get_template
from resources import strings
from helpers import get_admin_token

Expand Down Expand Up @@ -33,4 +33,4 @@ async def test_get_workspace_templates(template_name, verify) -> None:
async def test_get_workspace_template(template_name, verify) -> None:
admin_token = await get_admin_token(verify)
async with get_template(template_name, strings.API_WORKSPACE_TEMPLATES, admin_token, verify) as response:
assert (response.status_code == status.HTTP_200_OK), f"GET Request for {template_name} creation failed"
assert_status(response, [status.HTTP_200_OK], f"Failed to GET template: {template_name}")
8 changes: 8 additions & 0 deletions mkdocs-overrides/main.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
{% extends "base.html" %}

{% block outdated %}
You're not viewing the latest version.
<a href="{{ '../' ~ base_url }}">
<strong>Click here to go to latest.</strong>
</a>
</script>
{% endblock %}

{% block analytics %}
<script type="text/javascript">
(function(c,l,a,r,i,t,y){
Expand Down
4 changes: 4 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ theme:
features:
- navigation.instant
- navigation.indexes
extra:
version:
provider: mike
default: latest-release

plugins:
- search
Expand Down

0 comments on commit 6ce7147

Please sign in to comment.