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

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

@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.

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