Skip to content
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
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1681,6 +1681,23 @@ def wait_for_user_input(self,
logging.info("========= EOF on STDIN =========")
return None

def create_new_controller_on_new_fabric(self, nodeid: int = 2, vendorid: bytes = 0xFFF1, fabricid: int = 1):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes for 0xFFF1 does not look like the correct type for vendorid. Something is mismatched here

"""
Create new fabric and controller for commissioning
"""
new_cert_auth = self.certificate_authority_manager.NewCertificateAuthority()
new_fabric_admin = new_cert_auth.NewFabricAdmin(vendorId=vendorid, fabricId=fabricid)
new_controller = new_fabric_admin.NewController(nodeId=nodeid)
return new_controller

def create_new_controller_on_existing_fabric(self, nodeid: int = 2):
Copy link
Contributor

@andy31415 andy31415 Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thinking aloud (feedback please?) could we combine these so that we do not have 2 verbose variants? It seems to me we have generally the same function, except we either use the current fabric or create a new one.

So maybe some signature like:

@dataclass
class NewFabricInfo:
    vendorId: int = 0xFFF1
    fabricId: int = 1

def new_controller(self, nodeid: int = 2, new_fabric: Optional[NewFabricInfo] = None):
    if new_fabric is not None:
        fabric_admin = ....
    else:
        fabric_admin = ...
    return fabric_admin.NewController(nodeId=nodeId)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also fine. I didn't think too hard about it when I created the issue other than "this code is yucky, let's make it less yucky in some way"

"""
Create new controller on an already established fabric
"""
current_fabric_admin = self.certificate_authority_manager.activeCaList[0].adminList[0]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aside for the comment above, I wonder about the syntax here: this is restricted to activeCaList[0] only (why are we not supporting other indices?) and also it seems to replace a one-liner (albeit a very long one liner....) like self.certificate_authority_manager.activeCaList[0].adminList[0].NewController(nodeid)

why do we place this on MatterBaseTest class? this is a class with over 1500 lines of code already ... that is not good for maintainability. How about having certificate_authority_manager have these methods? then instead of self.new_controller(....) I call self.certificate_authority_manager.create_controller(....) in some form of arguments. Likely we then control with activeCaList we use ... we could even have a union of existingCa vs NewCa.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

activeCaList[0] is where the default contoller is created. So 0 should be a default, but yeah, it would be good to be able to create ex. new controller on new fabric index 1, second controller on that newly created fabric.

new_controller = current_fabric_admin.NewController(nodeId=nodeid)
return new_controller


def generate_mobly_test_config(matter_test_config: MatterTestConfig):
test_run_config = TestRunConfig()
Expand Down
Loading