diff --git a/src/controller/python/chip/yaml/runner.py b/src/controller/python/chip/yaml/runner.py index fb7a71bd457715..153d21c62584d8 100644 --- a/src/controller/python/chip/yaml/runner.py +++ b/src/controller/python/chip/yaml/runner.py @@ -664,10 +664,9 @@ async def run_action(self, dev_ctrl: ChipDeviceController) -> _ActionResult: if self._command == 'GetCommissionerNodeId': return _ActionResult(status=_ActionStatus.SUCCESS, response=_GetCommissionerNodeIdResult(dev_ctrl.nodeId)) - resp = dev_ctrl.CommissionWithCode(self._setup_payload, self._node_id) - if resp: - return _ActionResult(status=_ActionStatus.SUCCESS, response=None) - else: + try: + dev_ctrl.CommissionWithCode(self._setup_payload, self._node_id) + except ChipStackError: return _ActionResult(status=_ActionStatus.ERROR, response=None) diff --git a/src/controller/python/test/test_scripts/base.py b/src/controller/python/test/test_scripts/base.py index 3f9f76d9101874..cc5a7739ea084c 100644 --- a/src/controller/python/test/test_scripts/base.py +++ b/src/controller/python/test/test_scripts/base.py @@ -38,6 +38,7 @@ import chip.FabricAdmin import chip.interaction_model as IM import chip.native +from chip.exceptions import ChipStackException from chip import ChipDeviceCtrl from chip.ChipStack import ChipStack from chip.crypto import p256keypair @@ -268,7 +269,9 @@ def TestPaseOnly(self, ip: str, setuppin: int, nodeid: int, devCtrl=None): def TestCommissionOnly(self, nodeid: int): self.logger.info( "Commissioning device with id {}".format(nodeid)) - if not self.devCtrl.Commission(nodeid): + try: + self.devCtrl.Commission(nodeid) + except ChipStackException: self.logger.info( "Failed to commission device with id {}".format(str(nodeid))) return False @@ -311,8 +314,10 @@ def TestCommissionFailureOnReport(self, nodeid: int, failAfter: int): def TestCommissioning(self, ip: str, setuppin: int, nodeid: int): self.logger.info("Commissioning device {}".format(ip)) - if not self.devCtrl.CommissionIP(ip, setuppin, nodeid): - self.logger.info( + try: + self.devCtrl.CommissionIP(ip, setuppin, nodeid) + except ChipStackException: + self.logger.exception( "Failed to finish commissioning device {}".format(ip)) return False self.logger.info("Commissioning finished.") @@ -320,8 +325,10 @@ def TestCommissioning(self, ip: str, setuppin: int, nodeid: int): def TestCommissioningWithSetupPayload(self, setupPayload: str, nodeid: int, discoveryType: int = 2): self.logger.info("Commissioning device with setup payload {}".format(setupPayload)) - if not self.devCtrl.CommissionWithCode(setupPayload, nodeid, chip.discovery.DiscoveryType(discoveryType)): - self.logger.info( + try: + self.devCtrl.CommissionWithCode(setupPayload, nodeid, chip.discovery.DiscoveryType(discoveryType)) + except ChipStackException: + self.logger.exception( "Failed to finish commissioning device {}".format(setupPayload)) return False self.logger.info("Commissioning finished.") @@ -783,8 +790,10 @@ async def TestMultiFabric(self, ip: str, setuppin: int, nodeid: int): self.devCtrl2 = self.fabricAdmin2.NewController( self.controllerNodeId, self.paaTrustStorePath) - if not self.devCtrl2.CommissionIP(ip, setuppin, nodeid): - self.logger.info( + try: + self.devCtrl2.CommissionIP(ip, setuppin, nodeid) + except ChipStackException as ex: + self.logger.exception( "Failed to finish key exchange with device {}".format(ip)) return False diff --git a/src/test_driver/openiotsdk/integration-tests/common/utils.py b/src/test_driver/openiotsdk/integration-tests/common/utils.py index 1865cf6274f6ed..da2dcff787de7a 100644 --- a/src/test_driver/openiotsdk/integration-tests/common/utils.py +++ b/src/test_driver/openiotsdk/integration-tests/common/utils.py @@ -92,14 +92,11 @@ def connect_device(devCtrl, setupPayload, commissionableDevice, nodeId=None): pincode = int(setupPayload.attributes['SetUpPINCode']) try: - res = devCtrl.CommissionOnNetwork( + devCtrl.CommissionOnNetwork( nodeId, pincode, filterType=discovery.FilterType.INSTANCE_NAME, filter=commissionableDevice.instanceName) except exceptions.ChipStackError as ex: log.error("Commission discovered device failed {}".format(str(ex))) return None - if not res: - log.info("Commission discovered device failed: %r" % res) - return None return nodeId