Skip to content

Commit

Permalink
Various tests (Ingress, Traffic, Dapr, Env) (Azure#87)
Browse files Browse the repository at this point in the history
* Added env tests.

* Added ingress tests.

* Added ingress traffic tests.

* Fixed small issue.

* Added remove test for dapr components.

* Removed live_only from containerapp commands. Added recordings.

* Removed live_only from env commands.

* Removed sleep 60 since we use poll for delete anyways.

* Wrote better dapr-component tests. Fixed old tests that required live only.

Co-authored-by: Haroon Feisal <[email protected]>
  • Loading branch information
runefa and Haroon Feisal authored May 5, 2022
1 parent 1b8c7e0 commit 40ca5b9
Show file tree
Hide file tree
Showing 15 changed files with 39,212 additions and 21 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,24 @@
import unittest

from azure.cli.testsdk.scenario_tests import AllowLargeResponse
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, live_only)
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck)


TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))

@live_only()
class ContainerappIdentityTests(ScenarioTest):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_identity_e2e(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
ca_name = self.create_random_name(prefix='containerapp', length=24)
user_identity_name = self.create_random_name(prefix='containerapp', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

self.cmd('containerapp env create -g {} -n {}'.format(resource_group, env_name))
logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

Expand Down Expand Up @@ -63,12 +66,16 @@ def test_containerapp_identity_e2e(self, resource_group):
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus")
@ResourceGroupPreparer(location="canadacentral")
def test_containerapp_identity_system(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
ca_name = self.create_random_name(prefix='containerapp', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {}'.format(resource_group, env_name))
self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

Expand All @@ -95,14 +102,18 @@ def test_containerapp_identity_system(self, resource_group):
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
@ResourceGroupPreparer(location="westeurope")
def test_containerapp_identity_user(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
ca_name = self.create_random_name(prefix='containerapp', length=24)
user_identity_name1 = self.create_random_name(prefix='containerapp-user1', length=24)
user_identity_name2 = self.create_random_name(prefix='containerapp-user2', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {}'.format(resource_group, env_name))
self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

Expand Down Expand Up @@ -149,16 +160,19 @@ def test_containerapp_identity_user(self, resource_group):
])


@live_only()
class ContainerappEnvStorageTests(ScenarioTest):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_env_storage(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
storage_name = self.create_random_name(prefix='storage', length=24)
shares_name = self.create_random_name(prefix='share', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

self.cmd('containerapp env create -g {} -n {}'.format(resource_group, env_name))
logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

Expand Down Expand Up @@ -188,3 +202,105 @@ def test_containerapp_env_storage(self, resource_group):
self.cmd('containerapp env storage list -g {} -n {}'.format(resource_group, env_name), checks=[
JMESPathCheck('length(@)', 0),
])


class ContainerappIngressTests(ScenarioTest):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_ingress_e2e(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
ca_name = self.create_random_name(prefix='containerapp', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

while containerapp_env["properties"]["provisioningState"].lower() == "waiting":
time.sleep(5)
containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

self.cmd('containerapp create -g {} -n {} --environment {} --ingress external --target-port 80'.format(resource_group, ca_name, env_name))

self.cmd('containerapp ingress show -g {} -n {}'.format(resource_group, ca_name, env_name), checks=[
JMESPathCheck('external', True),
JMESPathCheck('targetPort', 80),
])

self.cmd('containerapp ingress disable -g {} -n {}'.format(resource_group, ca_name, env_name))

containerapp_def = self.cmd('containerapp show -g {} -n {}'.format(resource_group, ca_name)).get_output_in_json()

self.assertEqual("fqdn" in containerapp_def["properties"]["configuration"], False)

self.cmd('containerapp ingress enable -g {} -n {} --type internal --target-port 81 --allow-insecure --transport http2'.format(resource_group, ca_name, env_name))

self.cmd('containerapp ingress show -g {} -n {}'.format(resource_group, ca_name, env_name), checks=[
JMESPathCheck('external', False),
JMESPathCheck('targetPort', 81),
JMESPathCheck('allowInsecure', True),
JMESPathCheck('transport', "Http2"),
])

self.cmd('containerapp ingress show -g {} -n {}'.format(resource_group, ca_name, env_name), checks=[
JMESPathCheck('external', False),
JMESPathCheck('targetPort', 81),
JMESPathCheck('allowInsecure', True),
JMESPathCheck('transport', "Http2"),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="eastus2")
def test_containerapp_ingress_traffic_e2e(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-env', length=24)
ca_name = self.create_random_name(prefix='containerapp', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

while containerapp_env["properties"]["provisioningState"].lower() == "waiting":
time.sleep(5)
containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

self.cmd('containerapp create -g {} -n {} --environment {} --ingress external --target-port 80'.format(resource_group, ca_name, env_name))

self.cmd('containerapp ingress show -g {} -n {}'.format(resource_group, ca_name), checks=[
JMESPathCheck('external', True),
JMESPathCheck('targetPort', 80),
])

self.cmd('containerapp ingress traffic set -g {} -n {} --traffic-weight latest=100'.format(resource_group, ca_name), checks=[
JMESPathCheck('[0].latestRevision', True),
JMESPathCheck('[0].weight', 100),
])

self.cmd('containerapp update -g {} -n {} --cpu 1.0 --memory 2Gi'.format(resource_group, ca_name))

revisions_list = self.cmd('containerapp revision list -g {} -n {}'.format(resource_group, ca_name)).get_output_in_json()

self.cmd('containerapp ingress traffic set -g {} -n {} --traffic-weight latest=50 {}=50'.format(resource_group, ca_name, revisions_list[0]["name"]), checks=[
JMESPathCheck('[0].latestRevision', True),
JMESPathCheck('[0].weight', 50),
JMESPathCheck('[1].revisionName', revisions_list[0]["name"]),
JMESPathCheck('[1].weight', 50),
])

self.cmd('containerapp ingress traffic show -g {} -n {}'.format(resource_group, ca_name), checks=[
JMESPathCheck('[0].latestRevision', True),
JMESPathCheck('[0].weight', 50),
JMESPathCheck('[1].revisionName', revisions_list[0]["name"]),
JMESPathCheck('[1].weight', 50),
])

revisions_list = self.cmd('containerapp revision list -g {} -n {}'.format(resource_group, ca_name)).get_output_in_json()

for revision in revisions_list:
self.assertEqual(revision["properties"]["trafficWeight"], 50)
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# --------------------------------------------------------------------------------------------

import os
import time
import yaml

from azure.cli.testsdk.scenario_tests import AllowLargeResponse
from azure.cli.testsdk import (ScenarioTest, ResourceGroupPreparer, JMESPathCheck, live_only)

TEST_DIR = os.path.abspath(os.path.join(os.path.abspath(__file__), '..'))

class ContainerappEnvScenarioTest(ScenarioTest):
@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="northeurope")
def test_containerapp_env_e2e(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-e2e-env', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

while containerapp_env["properties"]["provisioningState"].lower() == "waiting":
time.sleep(5)
containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

self.cmd('containerapp env list -g {}'.format(resource_group), checks=[
JMESPathCheck('length(@)', 1),
JMESPathCheck('[0].name', env_name),
])

self.cmd('containerapp env show -n {} -g {}'.format(env_name, resource_group), checks=[
JMESPathCheck('name', env_name),
])

# Sleep in case containerapp create takes a while
self.cmd('containerapp env delete -g {} -n {} --yes'.format(resource_group, env_name))

# Sleep in case env delete takes a while
self.cmd('containerapp env list -g {}'.format(resource_group), checks=[
JMESPathCheck('length(@)', 0),
])

@AllowLargeResponse(8192)
@ResourceGroupPreparer(location="northeurope")
def test_containerapp_env_dapr_components(self, resource_group):
env_name = self.create_random_name(prefix='containerapp-e2e-env', length=24)
dapr_comp_name = self.create_random_name(prefix='dapr-component', length=24)
logs_workspace_name = self.create_random_name(prefix='containerapp-env', length=24)

logs_workspace_id = self.cmd('monitor log-analytics workspace create -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["customerId"]
logs_workspace_key = self.cmd('monitor log-analytics workspace get-shared-keys -g {} -n {}'.format(resource_group, logs_workspace_name)).get_output_in_json()["primarySharedKey"]

self.cmd('containerapp env create -g {} -n {} --logs-workspace-id {} --logs-workspace-key {}'.format(resource_group, env_name, logs_workspace_id, logs_workspace_key))

import tempfile

file_ref, dapr_file = tempfile.mkstemp(suffix=".yml")

dapr_yaml = """
name: statestore
componentType: state.azure.blobstorage
version: v1
metadata:
- name: accountName
secretRef: storage-account-name
secrets:
- name: storage-account-name
value: storage-account-name
"""

daprloaded = yaml.safe_load(dapr_yaml)

with open(dapr_file, 'w') as outfile:
yaml.dump(daprloaded, outfile, default_flow_style=False)

containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

while containerapp_env["properties"]["provisioningState"].lower() == "waiting":
time.sleep(5)
containerapp_env = self.cmd('containerapp env show -g {} -n {}'.format(resource_group, env_name)).get_output_in_json()

self.cmd('containerapp env dapr-component set -n {} -g {} --dapr-component-name {} --yaml {}'.format(env_name, resource_group, dapr_comp_name, dapr_file.replace(os.sep, os.sep + os.sep)), checks=[
JMESPathCheck('name', dapr_comp_name),
])

os.close(file_ref)

self.cmd('containerapp env dapr-component list -n {} -g {}'.format(env_name, resource_group), checks=[
JMESPathCheck('length(@)', 1),
JMESPathCheck('[0].name', dapr_comp_name),
])

self.cmd('containerapp env dapr-component show -n {} -g {} --dapr-component-name {}'.format(env_name, resource_group, dapr_comp_name), checks=[
JMESPathCheck('name', dapr_comp_name),
JMESPathCheck('properties.version', 'v1'),
JMESPathCheck('properties.secrets[0].name', 'storage-account-name'),
JMESPathCheck('properties.metadata[0].name', 'accountName'),
JMESPathCheck('properties.metadata[0].secretRef', 'storage-account-name'),
])

self.cmd('containerapp env dapr-component remove -n {} -g {} --dapr-component-name {}'.format(env_name, resource_group, dapr_comp_name))

self.cmd('containerapp env dapr-component list -n {} -g {}'.format(env_name, resource_group), checks=[
JMESPathCheck('length(@)', 0),
])
Loading

0 comments on commit 40ca5b9

Please sign in to comment.