Skip to content

Commit

Permalink
Supporting hosted agent pools for release pipeline (#477)
Browse files Browse the repository at this point in the history
* Supporting hosted agent pools.
* Fix bugs in DPS discovery test
  • Loading branch information
digimaun authored Dec 15, 2021
1 parent 9d2f677 commit b154107
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
29 changes: 20 additions & 9 deletions .azure-devops/create-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@ parameters:
- name: variableGroup
type: string
default: 'aziotcli_test_primary'
- name: vmImage
- name: buildAgentPoolVar
type: string
default: 'BuildAgentPool'
- name: buildAgentVmImageVar
type: string
default: 'BuildAgentVmImage'
- name: testAgentVmImage
type: string
default: 'ubuntu-18.04'
values:
Expand All @@ -21,6 +27,9 @@ parameters:
- '3.6.x'
- '3.8.x'
- '3.9.x'
- name: stageForPublish
type: boolean
default: false
- name: pythonVersionTestRun
type: string
default: '3.8.x'
Expand Down Expand Up @@ -55,8 +64,8 @@ stages:

- job: 'Build_Publish_Azure_IoT_CLI_Extension'
pool:
vmImage: ${{ parameters.vmImage }}

name: $[variables.${{ parameters.buildAgentPoolVar }}]
vmImage: $[variables.${{ parameters.buildAgentVmImageVar }}]
steps:
- task: UsePythonVersion@0
inputs:
Expand All @@ -69,7 +78,7 @@ stages:

- job: 'Build_Publish_Azure_CLI_Test_SDK'
pool:
vmImage: ${{ parameters.vmImage }}
vmImage: ${{ parameters.testAgentVmImage }}

steps:
- task: UsePythonVersion@0
Expand All @@ -94,9 +103,10 @@ stages:

- stage: 'test'
displayName: 'Run tests'
pool:
vmImage: ${{ parameters.vmImage }}
dependsOn: build
condition: succeeded()
pool:
vmImage: ${{ parameters.testAgentVmImage }}
jobs:
- job: 'testCentral'
displayName: 'Test IoT Central'
Expand Down Expand Up @@ -171,16 +181,17 @@ stages:

- stage: 'release'
displayName: 'Stage GitHub release'
dependsOn: [build, test]
condition: and(succeeded(), eq(variables.OfficialBuild, 'true'))
dependsOn: build
condition: and(succeeded(), eq(${{ parameters.stageForPublish }}, 'true'))
jobs:
- deployment: 'StageGitHub'
displayName: 'Stage CLI extension on GitHub'
environment: 'production'

- job: 'Calculate_Sha_And_Create_Release'
pool:
vmImage: 'windows-2019'
name: $[variables.${{ parameters.buildAgentPoolVar }}]
vmImage: $[variables.${{ parameters.buildAgentVmImageVar }}]
variables:
CLIVersion: $[ stageDependencies.build.recordVersion.outputs['setupVersion.CLIVersion'] ]
ReleaseTitle: $[ stageDependencies.build.recordVersion.outputs['setupVersion.ReleaseTitle'] ]
Expand Down
38 changes: 17 additions & 21 deletions azext_iot/tests/dps/core/test_dps_discovery_int.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,11 @@
# --------------------------------------------------------------------------------------------

from azext_iot.dps.providers.discovery import DPSDiscovery
from azure.cli.testsdk import LiveScenarioTest
from azext_iot.tests.dps import IoTDPSLiveScenarioTest
from azext_iot.tests.settings import Setting
import os

dps = os.environ.get("azext_iot_testdps")
dps_rg = os.environ.get("azext_iot_testrg")


class TestDPSDiscovery(LiveScenarioTest):
class TestDPSDiscovery(IoTDPSLiveScenarioTest):
def __init__(self, test_case):
super(TestDPSDiscovery, self).__init__(test_case)
self.cmd_shell = Setting()
Expand All @@ -23,19 +19,19 @@ def __init__(self, test_case):
def test_dps_discovery(self):
discovery = DPSDiscovery(self.cmd_shell)

resource = discovery.find_resource(resource_name=dps)
assert resource.name == dps
resource = discovery.find_resource(resource_name=self.entity_dps_name)
assert resource.name == self.entity_dps_name

auto_policy = discovery.find_policy(resource_name=dps, rg=dps_rg).as_dict()
auto_policy = discovery.find_policy(resource_name=self.entity_dps_name, rg=self.entity_rg).as_dict()
assert auto_policy

# Assumption - Test DPS includes the vanilla provisioningserviceowner policy
desired_policy = discovery.find_policy(
resource_name=dps, rg=dps_rg, policy_name=self.desired_policy_name
resource_name=self.entity_dps_name, rg=self.entity_rg, policy_name=self.desired_policy_name
).as_dict()
assert desired_policy["key_name"] == self.desired_policy_name

policies = discovery.get_policies(resource_name=dps, rg=dps_rg)
policies = discovery.get_policies(resource_name=self.entity_dps_name, rg=self.entity_rg)
assert len(policies)

# Example for leveraging discovery to build cstring for every policy on target IotHub
Expand All @@ -46,23 +42,23 @@ def test_dps_discovery(self):
assert sub_hubs

filtered_sub_hubs = [
hub for hub in sub_hubs if hub.as_dict()["name"] == dps
hub for hub in sub_hubs if hub.as_dict()["name"] == self.entity_dps_name
]
assert filtered_sub_hubs

rg_hubs = discovery.get_resources(rg=dps_rg)
rg_hubs = discovery.get_resources(rg=self.entity_rg)
assert rg_hubs

filtered_rg_hubs = [hub for hub in rg_hubs if hub.as_dict()["name"] == dps]
filtered_rg_hubs = [hub for hub in rg_hubs if hub.as_dict()["name"] == self.entity_dps_name]
assert filtered_rg_hubs

assert len(rg_hubs) <= len(sub_hubs)

def test_dps_targets(self):
discovery = DPSDiscovery(self.cmd_shell)

auto_target = discovery.get_target(resource_name=dps)
assert_target(auto_target, rg=dps_rg)
auto_target = discovery.get_target(resource_name=self.entity_dps_name)
assert_target(auto_target, rg=self.entity_rg)
connection_string = auto_target["cs"]

cs_target1 = discovery.get_target_by_cstring(connection_string)
Expand All @@ -71,19 +67,19 @@ def test_dps_targets(self):
cs_target2 = discovery.get_target(resource_name=None, login=connection_string)
assert_target(cs_target2, True)

auto_target = discovery.get_target(resource_name=dps, resource_group_name=dps_rg)
assert_target(auto_target, rg=dps_rg)
auto_target = discovery.get_target(resource_name=self.entity_dps_name, resource_group_name=self.entity_rg)
assert_target(auto_target, rg=self.entity_rg)

sub_targets = discovery.get_targets()
[assert_target(tar) for tar in sub_targets]

rg_targets = discovery.get_targets(resource_group_name=dps_rg)
[assert_target(tar, rg=dps_rg) for tar in rg_targets]
rg_targets = discovery.get_targets(resource_group_name=self.entity_rg)
[assert_target(tar, rg=self.entity_rg) for tar in rg_targets]

assert len(rg_targets) <= len(sub_targets)


def assert_target(target: dict, by_cstring=False, include_events=False, **kwargs):
def assert_target(target: dict, by_cstring=False, **kwargs):
assert target["cs"]
assert target["policy"]
assert target["primarykey"]
Expand Down

0 comments on commit b154107

Please sign in to comment.