Skip to content

Commit d528865

Browse files
committed
[Python] Adjust tests to use new commissioning error handling
1 parent 32bb422 commit d528865

File tree

3 files changed

+20
-14
lines changed

3 files changed

+20
-14
lines changed

src/controller/python/chip/yaml/runner.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -664,10 +664,10 @@ async def run_action(self, dev_ctrl: ChipDeviceController) -> _ActionResult:
664664
if self._command == 'GetCommissionerNodeId':
665665
return _ActionResult(status=_ActionStatus.SUCCESS, response=_GetCommissionerNodeIdResult(dev_ctrl.nodeId))
666666

667-
resp = dev_ctrl.CommissionWithCode(self._setup_payload, self._node_id)
668-
if resp:
667+
try:
668+
dev_ctrl.CommissionWithCode(self._setup_payload, self._node_id)
669669
return _ActionResult(status=_ActionStatus.SUCCESS, response=None)
670-
else:
670+
except ChipStackError:
671671
return _ActionResult(status=_ActionStatus.ERROR, response=None)
672672

673673

src/controller/python/test/test_scripts/base.py

+16-7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from chip import ChipDeviceCtrl
4242
from chip.ChipStack import ChipStack
4343
from chip.crypto import p256keypair
44+
from chip.exceptions import ChipStackException
4445
from chip.utils import CommissioningBuildingBlocks
4546
from cirque_restart_remote_device import restartRemoteDevice
4647
from ecdsa import NIST256p
@@ -268,7 +269,9 @@ def TestPaseOnly(self, ip: str, setuppin: int, nodeid: int, devCtrl=None):
268269
def TestCommissionOnly(self, nodeid: int):
269270
self.logger.info(
270271
"Commissioning device with id {}".format(nodeid))
271-
if not self.devCtrl.Commission(nodeid):
272+
try:
273+
self.devCtrl.Commission(nodeid)
274+
except ChipStackException:
272275
self.logger.info(
273276
"Failed to commission device with id {}".format(str(nodeid)))
274277
return False
@@ -311,17 +314,21 @@ def TestCommissionFailureOnReport(self, nodeid: int, failAfter: int):
311314

312315
def TestCommissioning(self, ip: str, setuppin: int, nodeid: int):
313316
self.logger.info("Commissioning device {}".format(ip))
314-
if not self.devCtrl.CommissionIP(ip, setuppin, nodeid):
315-
self.logger.info(
317+
try:
318+
self.devCtrl.CommissionIP(ip, setuppin, nodeid)
319+
except ChipStackException:
320+
self.logger.exception(
316321
"Failed to finish commissioning device {}".format(ip))
317322
return False
318323
self.logger.info("Commissioning finished.")
319324
return True
320325

321326
def TestCommissioningWithSetupPayload(self, setupPayload: str, nodeid: int, discoveryType: int = 2):
322327
self.logger.info("Commissioning device with setup payload {}".format(setupPayload))
323-
if not self.devCtrl.CommissionWithCode(setupPayload, nodeid, chip.discovery.DiscoveryType(discoveryType)):
324-
self.logger.info(
328+
try:
329+
self.devCtrl.CommissionWithCode(setupPayload, nodeid, chip.discovery.DiscoveryType(discoveryType))
330+
except ChipStackException:
331+
self.logger.exception(
325332
"Failed to finish commissioning device {}".format(setupPayload))
326333
return False
327334
self.logger.info("Commissioning finished.")
@@ -783,8 +790,10 @@ async def TestMultiFabric(self, ip: str, setuppin: int, nodeid: int):
783790
self.devCtrl2 = self.fabricAdmin2.NewController(
784791
self.controllerNodeId, self.paaTrustStorePath)
785792

786-
if not self.devCtrl2.CommissionIP(ip, setuppin, nodeid):
787-
self.logger.info(
793+
try:
794+
self.devCtrl2.CommissionIP(ip, setuppin, nodeid)
795+
except ChipStackException:
796+
self.logger.exception(
788797
"Failed to finish key exchange with device {}".format(ip))
789798
return False
790799

src/test_driver/openiotsdk/integration-tests/common/utils.py

+1-4
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,11 @@ def connect_device(devCtrl, setupPayload, commissionableDevice, nodeId=None):
9292

9393
pincode = int(setupPayload.attributes['SetUpPINCode'])
9494
try:
95-
res = devCtrl.CommissionOnNetwork(
95+
devCtrl.CommissionOnNetwork(
9696
nodeId, pincode, filterType=discovery.FilterType.INSTANCE_NAME, filter=commissionableDevice.instanceName)
9797
except exceptions.ChipStackError as ex:
9898
log.error("Commission discovered device failed {}".format(str(ex)))
9999
return None
100-
if not res:
101-
log.info("Commission discovered device failed: %r" % res)
102-
return None
103100
return nodeId
104101

105102

0 commit comments

Comments
 (0)