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

test: separate instance lifecycle tests from init #402

Merged
merged 2 commits into from
Oct 3, 2024
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
17 changes: 0 additions & 17 deletions azext_edge/tests/edge/init/int/test_init_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,23 +239,6 @@ def assert_aio_instance(
assert expected_custom_location in tree
assert "azure-iot-operations-platform" in tree

# list failed to return collection response YAY
instance_rg_list = run(f"az iot ops list -g {resource_group}")
assert instance_name in [inst["name"] for inst in instance_rg_list]
instance_sub_list = run("az iot ops list")
assert instance_name in [inst["name"] for inst in instance_sub_list]

# update - ultimate sadness
description = generate_random_string()
tags = f"{generate_random_string()}={generate_random_string()}"
instance_update = run(
f"az iot ops update -n {instance_name} -g {resource_group} --description {description} "
f"--tags {tags}"
)
assert instance_update["properties"]["description"] == description
tag_key, tag_value = tags.split("=")
assert instance_update["tags"][tag_key] == tag_value


def assert_broker_args(
instance_name: str,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# coding=utf-8
# ----------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License file in the project root for license information.
# ----------------------------------------------------------------------------------------------

from azure.cli.core.azclierror import CLIInternalError
import pytest
from knack.log import get_logger

from ....generators import generate_random_string
from ....helpers import run

logger = get_logger(__name__)


@pytest.fixture(scope="function")
def instance_test_setup(settings):
from ....settings import EnvironmentVariables
settings.add_to_config(EnvironmentVariables.rg.value)
settings.add_to_config(EnvironmentVariables.instance.value)
if not all([settings.env.azext_edge_instance, settings.env.azext_edge_rg]):
raise AssertionError(
"Cannot run instance tests without an instance and resource group. "
f"Current settings:\n {settings}"
)

yield {
"resourceGroup": settings.env.azext_edge_rg,
"instanceName": settings.env.azext_edge_instance
}


def test_aio_instance(instance_test_setup, tracked_resources):
resource_group = instance_test_setup["resourceGroup"]
instance_name = instance_test_setup["instanceName"]
try:
instance_rg_list = run(f"az iot ops list -g {resource_group}")
assert instance_name in [inst["name"] for inst in instance_rg_list]
except CLIInternalError:
logger.error(f"Possible bad instance in resource group {resource_group}")

try:
instance_sub_list = run("az iot ops list")
assert instance_name in [inst["name"] for inst in instance_sub_list]
except CLIInternalError:
sub = run("az account show").get("id", "current")
logger.error(f"Possible bad instance in subscription `{sub}`.")

tree = run(f"az iot ops show -n {instance_name} -g {resource_group} --tree")
assert "azure-iot-operations-platform" in tree
# instance name should be one of the resources
assert instance_name in tree

# create random resource to ensure it shows up in show tree
aep_name = generate_random_string(force_lower=True)
aep = run(
f"az iot ops asset endpoint create opcua -n {aep_name} -g {resource_group} "
f"--instance {instance_name} --target-address opc.tcp://opcplc-000000.azure-iot-operations:50000"
)
tracked_resources.append(aep["id"])
tree = run(f"az iot ops show -n {instance_name} -g {resource_group} --tree")
assert aep_name in tree

instance_show = run(f"az iot ops show -n {instance_name} -g {resource_group}")
if instance_show.get("properties", {}).get("provisioningState") != "Succeeded":
pytest.skip("Cannot update instance that is not ready.")

# update - ultimate sadness
description = generate_random_string()
tags = f"{generate_random_string()}={generate_random_string()}"
instance_update = run(
f"az iot ops update -n {instance_name} -g {resource_group} --description {description} "
f"--tags {tags}"
)
assert instance_update["properties"]["description"] == description
tag_key, tag_value = tags.split("=")
assert instance_update["tags"][tag_key] == tag_value