-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Creating friendly functions for establishing new controllers on existing or new fabrics #37009
Open
j-ororke
wants to merge
8
commits into
project-chip:master
Choose a base branch
from
j-ororke:add_friendly_funct_fabcon
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+143
−0
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a108642
Creating friendly functions to resolve issue 465:
j-ororke 89c27a6
Restyled by autopep8
restyled-commits a236d08
Updating to resolve comments:
j-ororke 17820f5
Restyled by autopep8
restyled-commits 2de9b9c
Updating TC_CreateNewController python test module:
j-ororke ce75f81
Update CertificateAuthority.py
j-ororke ad93629
Updating CertificateAuthority and TC_CreateNewController modules:
j-ororke 5539578
Update src/python_testing/TC_CreateNewController.py
j-ororke File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
# | ||
# Copyright (c) 2025 Project CHIP Authors | ||
# All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
|
||
# See https://github.com/project-chip/connectedhomeip/blob/master/docs/testing/python.md#defining-the-ci-test-arguments | ||
# for details about the block below. | ||
# | ||
# === BEGIN CI TEST ARGUMENTS === | ||
# test-runner-runs: | ||
# run1: | ||
# app: ${ALL_CLUSTERS_APP} | ||
# app-args: --discriminator 1234 --passcode 20202021 --KVS kvs1 | ||
# script-args: > | ||
# --storage-path admin_storage.json | ||
# --discriminator 1234 | ||
# --passcode 20202021 | ||
# --endpoint 1 | ||
# --commissioning-method on-network | ||
# factory-reset: true | ||
# quiet: true | ||
# === END CI TEST ARGUMENTS === | ||
|
||
import asyncio | ||
|
||
from chip.testing.matter_testing import MatterBaseTest, TestStep, async_test_body, default_matter_test_main | ||
from mobly import asserts | ||
|
||
|
||
class TC_CreateNewController(MatterBaseTest): | ||
# Using get_code and a modified version of setup_class_helper functions from chip.testing.basic_composition module | ||
def get_code(self, dev_ctrl): | ||
created_codes = [] | ||
for idx, discriminator in enumerate(self.matter_test_config.discriminators): | ||
created_codes.append(dev_ctrl.CreateManualCode(discriminator, self.matter_test_config.setup_passcodes[idx])) | ||
|
||
setup_codes = self.matter_test_config.qr_code_content + self.matter_test_config.manual_code + created_codes | ||
if not setup_codes: | ||
return None | ||
asserts.assert_equal(len(setup_codes), 1, | ||
"Require exactly one of either --qr-code, --manual-code or (--discriminator and --passcode).") | ||
return setup_codes[0] | ||
|
||
async def setup_class_helper(self, allow_pase: bool = True): | ||
dev_ctrl = self.default_controller | ||
self.problems = [] | ||
|
||
node_id = self.dut_node_id | ||
|
||
task_list = [] | ||
if allow_pase and self.get_code(dev_ctrl): | ||
setup_code = self.get_code(dev_ctrl) | ||
pase_future = dev_ctrl.EstablishPASESession(setup_code, self.dut_node_id) | ||
task_list.append(asyncio.create_task(pase_future)) | ||
|
||
case_future = dev_ctrl.GetConnectedDevice(nodeid=node_id, allowPASE=False) | ||
task_list.append(asyncio.create_task(case_future)) | ||
|
||
for task in task_list: | ||
asyncio.ensure_future(task) | ||
|
||
done, pending = await asyncio.wait(task_list, return_when=asyncio.FIRST_COMPLETED) | ||
|
||
for task in pending: | ||
try: | ||
task.cancel() | ||
await task | ||
except asyncio.CancelledError: | ||
pass | ||
|
||
wildcard_read = (await dev_ctrl.Read(node_id, [()])) | ||
|
||
# ======= State kept for use by all tests ======= | ||
# All endpoints in "full object" indexing format | ||
self.endpoints = wildcard_read.attributes | ||
|
||
def steps_TC_CreateNewController(self) -> list[TestStep]: | ||
return [ | ||
TestStep(1, "Commissioning, already done", is_commissioning=True), | ||
TestStep(2, "Checking create new controller on new fabric"), | ||
TestStep(3, "Remove new fabric from TH to verify it can be removed after creation"), | ||
TestStep(4, "Checking create new controller on existing fabric"), | ||
TestStep(5, "Remove fabric from TH to verify it can be removed after creation") | ||
] | ||
|
||
def TC_TestAttrAvail(self) -> list[str]: | ||
return ["RVCOPSTATE.S"] | ||
|
||
@async_test_body | ||
async def setup_class(self): | ||
super().setup_class() | ||
await self.setup_class_helper() | ||
|
||
# ======= START OF ACTUAL TESTS ======= | ||
@async_test_body | ||
async def test_TC_CreateNewController(self): | ||
self.step(1) | ||
self.endpoint = self.get_endpoint() | ||
asserts.assert_false(self.endpoint is None, "--endpoint <endpoint> must be included on the command line in.") | ||
self.th1 = self.default_controller | ||
|
||
self.step(2) | ||
self.th2 = self.certificate_authority_manager.create_new_controller(fabric_Id=self.th1.fabricId + 1, ca_List=1, node_Id=2) | ||
|
||
self.step(3) | ||
self.th2.Shutdown() | ||
|
||
self.step(4) | ||
self.th3 = self.certificate_authority_manager.create_new_controller(ca_List=0, new_Fabric=False, node_Id=2) | ||
|
||
self.step(5) | ||
self.th3.Shutdown() | ||
|
||
|
||
if __name__ == "__main__": | ||
default_matter_test_main() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not totally sure this is right place for this - this is now part of the certificate authority manager class, but it's creating a controller. I think this might be better off as a standalone helper function somewhere.
@andy31415 - thoughts? I'm open to being overruled.