Skip to content

Conversation

@vprysiaz
Copy link
Collaborator

…ections

@tmikuska tmikuska requested review from tmikuska and virlos November 21, 2025 18:56
except KeyError:
raise PyatsDeviceNotFound(node_label)

node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop()
node = self._lab.get_node_by_label(node_label)

node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop()

# will raise API error inside if console does not exist for device
node.console_key(console_number)
Copy link
Collaborator

Choose a reason for hiding this comment

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

you don't want to store and use the key? what's the reason of calling it then? I'd let it fail later

Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, let it fail on connect if the console cannot get actually connected

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it is just a simple way how to verify that console with this number exists. we do not have API for getting list of available consoles. so calling this api raises error like "console 5 does not exist". if this console does not exist then we can not use it for pyats as well

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

as virlos said - "let it fail on connect". I am removing this check at all here. just replacing serial number in connection string

pattern = rf"({re.escape(node_label)})/\d+"
new_console_cfg = f"/{console_number}"

new_connect_command = re.sub(pattern, rf"\1{new_console_cfg}", old_connect_command)
Copy link
Collaborator

Choose a reason for hiding this comment

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

wouldn't this work?

Suggested change
new_connect_command = re.sub(pattern, rf"\1{new_console_cfg}", old_connect_command)
new_connect_command = re.sub(pattern, rf"\1/{console_number}", old_connect_command)

Copy link
Collaborator

@tmikuska tmikuska Nov 21, 2025

Choose a reason for hiding this comment

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

I believe that the original console number is always 0, so a simpler replace command should work as well, e.g.,

pyats_device.connections["a"]["command"] = pyats_device.connections["a"]["command"][:-1] + console_number

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

it will work for sure. I just tried to make it robust. who knows how connect command will look like in future. but for now I will use your approach

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

since virlos is ok with that - applying this suggestion

@tmikuska tmikuska changed the base branch from main to dev November 21, 2025 19:37
@tmikuska tmikuska force-pushed the CMLDEV-12-Add-possibility-to-enable-pyats-on-different-console branch from ab65bf3 to e00ddee Compare November 21, 2025 19:53
@tmikuska
Copy link
Collaborator

I rebased this from dev and changed the target branch to the same.

node: Node = [node for node in self._lab.nodes()if node.label == node_label].pop()

# will raise API error inside if console does not exist for device
node.console_key(console_number)
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, let it fail on connect if the console cannot get actually connected

new_console_cfg = f"/{console_number}"

new_connect_command = re.sub(
pattern, rf"\1{new_console_cfg}", old_connect_command
Copy link
Collaborator

Choose a reason for hiding this comment

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

you should rather check that the console number is 0-3, and only change the last character. No need to use regex here

"""
Switch to different serial console that is used to execute PyAts commands
should be executed after sync_testbed
and re-executed after every sync_testbed call.
Copy link
Collaborator

Choose a reason for hiding this comment

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

speaking of - if you use console 0, then switch to console 1 using this method, will the next command perhaps reuse the connection it already has established with console 0? Maybe coordinate with the other ticket about closing an existing connection if the connection number does not match.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

if you keep older connection open then it will still use console 0.

@tmikuska tmikuska force-pushed the dev branch 2 times, most recently from b9d320f to bb8b0fa Compare December 2, 2025 03:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants