Skip to content

Commit b44ee2b

Browse files
committed
dps
1 parent 4f8f7c5 commit b44ee2b

1 file changed

Lines changed: 21 additions & 39 deletions

File tree

azext_iot/tests/dps/core/test_dps_linked_hub_int.py

Lines changed: 21 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
cli = EmbeddedCLI()
2020

2121

22-
def _find_gwv2_hub(rg):
23-
"""Find a GWv2 hub in the RG"""
24-
hubs = cli.invoke(f"iot hub list -g {rg}").as_json()
25-
for hub in hubs:
26-
if hub.get("properties", {}).get("deviceHostName"):
27-
return hub
28-
return None
22+
def _require_gwv2_hub(provisioned_hub):
23+
"""Return the provisioned hub resource, skipping if it is not a GWv2 (TLS 1.3) hub."""
24+
hub = cli.invoke(f"iot hub show -n {provisioned_hub['name']}").as_json()
25+
if not hub.get("properties", {}).get("deviceHostName"):
26+
pytest.skip("Provisioned hub is not GWv2 — TLS 1.3 linked-hub tests require a GWv2 hub")
27+
return hub
2928

3029

3130
def _cleanup_linked_hub(dps_name, rg, linked_hub_name):
@@ -35,14 +34,12 @@ def _cleanup_linked_hub(dps_name, rg, linked_hub_name):
3534
)
3635

3736

38-
def test_linked_hub_create_auto_hostname(provisioned_iot_dps_no_hub_module):
37+
def test_linked_hub_create_auto_hostname(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
3938
"""On a GWv2 hub, auto (default) should resolve to the device hostname."""
4039
dps_name = provisioned_iot_dps_no_hub_module["name"]
4140
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
4241

43-
gwv2_hub = _find_gwv2_hub(dps_rg)
44-
if not gwv2_hub:
45-
pytest.skip("No GWv2 hub available in resource group for TLS 1.3 testing")
42+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
4643

4744
hub_name = gwv2_hub["name"]
4845
device_hostname = gwv2_hub["properties"]["deviceHostName"]
@@ -64,14 +61,12 @@ def test_linked_hub_create_auto_hostname(provisioned_iot_dps_no_hub_module):
6461
_cleanup_linked_hub(dps_name, dps_rg, device_hostname)
6562

6663

67-
def test_linked_hub_create_classic_hostname(provisioned_iot_dps_no_hub_module):
64+
def test_linked_hub_create_classic_hostname(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
6865
"""Create linked hub with explicit classic hostname type."""
6966
dps_name = provisioned_iot_dps_no_hub_module["name"]
7067
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
7168

72-
gwv2_hub = _find_gwv2_hub(dps_rg)
73-
if not gwv2_hub:
74-
pytest.skip("No GWv2 hub available in resource group")
69+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
7570

7671
hub_name = gwv2_hub["name"]
7772
classic_hostname = gwv2_hub["properties"]["hostName"]
@@ -93,14 +88,12 @@ def test_linked_hub_create_classic_hostname(provisioned_iot_dps_no_hub_module):
9388
_cleanup_linked_hub(dps_name, dps_rg, classic_hostname)
9489

9590

96-
def test_linked_hub_create_device_hostname(provisioned_iot_dps_no_hub_module):
91+
def test_linked_hub_create_device_hostname(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
9792
"""Create linked hub with explicit device hostname type on a GWv2 hub."""
9893
dps_name = provisioned_iot_dps_no_hub_module["name"]
9994
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
10095

101-
gwv2_hub = _find_gwv2_hub(dps_rg)
102-
if not gwv2_hub:
103-
pytest.skip("No GWv2 hub available in resource group")
96+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
10497

10598
hub_name = gwv2_hub["name"]
10699
device_hostname = gwv2_hub["properties"]["deviceHostName"]
@@ -122,17 +115,12 @@ def test_linked_hub_create_device_hostname(provisioned_iot_dps_no_hub_module):
122115
_cleanup_linked_hub(dps_name, dps_rg, device_hostname)
123116

124117

125-
def test_hub_show_returns_tls13_hostnames(provisioned_iot_dps_no_hub_module):
118+
def test_hub_show_returns_tls13_hostnames(provisioned_only_iot_hubs_session):
126119
"""Verify hub show returns TLS 1.3 hostname properties for GWv2 hubs."""
127-
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
128-
129-
gwv2_hub = _find_gwv2_hub(dps_rg)
130-
if not gwv2_hub:
131-
pytest.skip("No GWv2 hub available in resource group")
120+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
132121

133122
hub_name = gwv2_hub["name"]
134-
result = cli.invoke(f"iot hub show -n {hub_name}").as_json()
135-
props = result["properties"]
123+
props = gwv2_hub["properties"]
136124

137125
assert props.get("hostName"), "hostName (classic) should be present"
138126
assert props.get("deviceHostName"), "deviceHostName should be present for GWv2 hub"
@@ -145,14 +133,12 @@ def test_hub_show_returns_tls13_hostnames(provisioned_iot_dps_no_hub_module):
145133
assert hub_name in props["serviceHostName"]
146134

147135

148-
def test_linked_hub_list_shows_hostname(provisioned_iot_dps_no_hub_module):
136+
def test_linked_hub_list_shows_hostname(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
149137
"""Verify linked hub list returns the correct hostname after linking."""
150138
dps_name = provisioned_iot_dps_no_hub_module["name"]
151139
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
152140

153-
gwv2_hub = _find_gwv2_hub(dps_rg)
154-
if not gwv2_hub:
155-
pytest.skip("No GWv2 hub available in resource group")
141+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
156142

157143
hub_name = gwv2_hub["name"]
158144
device_hostname = gwv2_hub["properties"]["deviceHostName"]
@@ -174,16 +160,14 @@ def test_linked_hub_list_shows_hostname(provisioned_iot_dps_no_hub_module):
174160
_cleanup_linked_hub(dps_name, dps_rg, device_hostname)
175161

176162

177-
def test_linked_hub_update_combined_migration(provisioned_iot_dps_no_hub_module):
163+
def test_linked_hub_update_combined_migration(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
178164
"""Migrate a hub link from KeyBased + classic endpoint to
179165
SystemAssigned + device endpoint in a single update call.
180166
"""
181167
dps_name = provisioned_iot_dps_no_hub_module["name"]
182168
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
183169

184-
gwv2_hub = _find_gwv2_hub(dps_rg)
185-
if not gwv2_hub:
186-
pytest.skip("No GWv2 hub available in resource group")
170+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
187171

188172
hub_name = gwv2_hub["name"]
189173
classic_hostname = gwv2_hub["properties"]["hostName"]
@@ -231,14 +215,12 @@ def test_linked_hub_update_combined_migration(provisioned_iot_dps_no_hub_module)
231215
_cleanup_linked_hub(dps_name, dps_rg, hostname)
232216

233217

234-
def test_linked_hub_create_keybased_then_switch_to_mi(provisioned_iot_dps_no_hub_module):
218+
def test_linked_hub_create_keybased_then_switch_to_mi(provisioned_iot_dps_no_hub_module, provisioned_only_iot_hubs_session):
235219
"""KeyBased create -> auth-only SystemAssigned swap (no hostname change)."""
236220
dps_name = provisioned_iot_dps_no_hub_module["name"]
237221
dps_rg = provisioned_iot_dps_no_hub_module["resourceGroup"]
238222

239-
gwv2_hub = _find_gwv2_hub(dps_rg)
240-
if not gwv2_hub:
241-
pytest.skip("No GWv2 hub available in resource group")
223+
gwv2_hub = _require_gwv2_hub(provisioned_only_iot_hubs_session)
242224

243225
hub_name = gwv2_hub["name"]
244226
device_hostname = gwv2_hub["properties"]["deviceHostName"]

0 commit comments

Comments
 (0)