99 wait_for_device_id ,
1010)
1111from utils .logger import get_logger
12+ from utils .memfault_ota import (
13+ delete_device_if_exists ,
14+ enable_server_side_developer_mode ,
15+ load_memfault_credentials ,
16+ )
1217from utils .nrf_cloud_device import delete_if_exists , onboard
1318from utils .nrf_cloud_provision import install_device_credentials
1419from utils .uart import Uart
@@ -27,35 +32,56 @@ def test_cloud_connect_after_provisioning(
2732 """Provision credentials on a fresh device, onboard to nRF Cloud, and connect."""
2833 dut = cloud_connect_dut
2934 expected_device_id = load_expected_device_id (test_config )
35+ memfault_env = load_memfault_credentials (test_config )
36+ device_id : str | None = None
3037
31- logger .info ("Phase 1/5 - Wait for device ID in boot log" )
32- device_id = assert_dut_device_id (
33- wait_for_device_id (dut .uart , timeout = 30 ),
34- expected_device_id ,
35- )
36-
37- logger .info ("Phase 2/5 - Confirm device boots without nRF Cloud credentials" )
38- dut .uart .wait_for_substring (MISSING_CREDENTIALS_LOG , timeout = 300 )
38+ try :
39+ logger .info ("Phase 1/5 - Wait for device ID in boot log" )
40+ device_id = assert_dut_device_id (
41+ wait_for_device_id (dut .uart , timeout = 30 ),
42+ expected_device_id ,
43+ )
3944
40- logger .info (
41- "Phase 3/5 - Remove only the configured DUT from nRF Cloud if already registered"
42- )
43- delete_if_exists (device_id , expected_device_id )
45+ logger .info ("Phase 2/5 - Confirm device boots without nRF Cloud credentials" )
46+ dut .uart .wait_for_substring (MISSING_CREDENTIALS_LOG , timeout = 60 )
4447
45- logger .info ("Phase 4/5 - Install credentials and onboard using onboard.csv" )
46- dut .uart .stop ()
47- try :
48- onboard_csv = install_device_credentials (
49- work_dir = nrf_cloud_env ["work_dir" ],
50- device_id = device_id ,
51- serial_port = dut .serial_port ,
52- ca_cert = nrf_cloud_env ["ca_cert" ],
53- ca_key = nrf_cloud_env ["ca_key" ],
48+ logger .info (
49+ "Phase 3/5 - Remove only the configured DUT from nRF Cloud if already registered"
5450 )
55- onboard (str (onboard_csv ))
56- finally :
57- dut .uart = Uart (dut .serial_port , log_path = dut .serial_log )
58- nrfutil_reset (dut .segger_sn )
51+ delete_if_exists (device_id , expected_device_id )
5952
60- logger .info ("Phase 5/5 - Wait for nRF Cloud connection in serial log" )
61- dut .uart .wait_for_substring (CLOUD_CONNECTED_LOG , timeout = 900 )
53+ logger .info ("Phase 4/5 - Install credentials and onboard using onboard.csv" )
54+ dut .uart .stop ()
55+ try :
56+ onboard_csv = install_device_credentials (
57+ work_dir = nrf_cloud_env ["work_dir" ],
58+ device_id = device_id ,
59+ serial_port = dut .serial_port ,
60+ ca_cert = nrf_cloud_env ["ca_cert" ],
61+ ca_key = nrf_cloud_env ["ca_key" ],
62+ segger_sn = dut .segger_sn ,
63+ )
64+ onboard (str (onboard_csv ))
65+ finally :
66+ dut .uart = Uart (dut .serial_port , log_path = dut .serial_log )
67+ nrfutil_reset (dut .segger_sn )
68+
69+ logger .info ("Phase 5/5 - Wait for nRF Cloud connection in serial log" )
70+ dut .uart .wait_for_substring (CLOUD_CONNECTED_LOG , timeout = 120 )
71+ enable_server_side_developer_mode (memfault_env , device_id )
72+ finally :
73+ if device_id is not None :
74+ try :
75+ delete_if_exists (device_id , expected_device_id )
76+ except RuntimeError as exc :
77+ logger .warning (
78+ "Failed to delete DUT from nRF Cloud during cleanup: %s" ,
79+ exc ,
80+ )
81+ try :
82+ delete_device_if_exists (memfault_env , device_id , expected_device_id )
83+ except RuntimeError as exc :
84+ logger .warning (
85+ "Failed to delete DUT from Memfault during cleanup: %s" ,
86+ exc ,
87+ )
0 commit comments