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

Never sort port lists during rendering #90

Merged
merged 1 commit into from
Jan 25, 2017
Merged
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion fake_switches/cisco/cisco_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,15 @@ def get_default_ports():
Port("FastEthernet0/1"),
Port("FastEthernet0/2"),
Port("FastEthernet0/3"),
Port("FastEthernet0/4")
Port("FastEthernet0/4"),
Port("FastEthernet0/5"),
Port("FastEthernet0/6"),
Port("FastEthernet0/7"),
Port("FastEthernet0/8"),
Port("FastEthernet0/9"),
Port("FastEthernet0/10"),
Port("FastEthernet0/11"),
Port("FastEthernet0/12")
]


Expand Down
6 changes: 3 additions & 3 deletions fake_switches/cisco/command_processor/enabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def do_show(self, *args):
self.write_line("VLAN Name Status Ports")
self.write_line("---- -------------------------------- --------- -------------------------------")
for vlan in sorted(self.switch_configuration.vlans, key=lambda v: v.number):
ports = [port.get_subname(length=2) for port in self.switch_configuration.ports
ports = [port.get_subname(length=2) for port in self.switch_configuration.get_physical_ports()
if port.access_vlan == vlan.number or (vlan.number == 1 and port.access_vlan is None)]
self.write_line("%-4s %-32s %s%s" % (
vlan.number,
Expand Down Expand Up @@ -136,7 +136,7 @@ def do_show(self, *args):
self.write_line("% Invalid input detected at '^' marker.")
self.write_line("")
else:
if_list = sorted(self.switch_configuration.ports, key=lambda e: ("a" if isinstance(e, VlanPort) else "b") + e.name)
if_list = self.switch_configuration.get_vlan_ports() + self.switch_configuration.get_physical_ports()
if if_list:
for interface in if_list:
self.write_line("%s is down, line protocol is down" % interface.name)
Expand Down Expand Up @@ -199,7 +199,7 @@ def show_run(self):
]
for vlan in self.switch_configuration.vlans:
all_data = all_data + build_running_vlan(vlan) + ["!"]
for interface in sorted(self.switch_configuration.ports, key=lambda e: ("b" if isinstance(e, VlanPort) else "a") + e.name):
for interface in self.switch_configuration.get_physical_ports() + self.switch_configuration.get_vlan_ports():
all_data = all_data + build_running_interface(interface) + ["!"]
if self.switch_configuration.static_routes:
for route in self.switch_configuration.static_routes:
Expand Down
42 changes: 37 additions & 5 deletions tests/cisco/test_cisco_switch_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def test_show_vlan_brief(self, t):
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12")
Copy link
Contributor

Choose a reason for hiding this comment

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

are you sure there's not an auto wrapping here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is, based on terminal width, which we dont support right now. If you set your terminal to super large, you will get the above result.

I'm happy with the compromise for now.
other than that is assume a 80x24 terminal and always wrap, even on larger terminals.

Copy link
Contributor

Choose a reason for hiding this comment

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

It may be a good idea for the future to always wrap at 80 as the idea is to test applications that should expect a line wrap in what the switch returns. But I don't think this is part of this review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good remark. Will address in an upcoming change.

Copy link
Contributor

Choose a reason for hiding this comment

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

Buuuuuut.... that's not how we assumed stuff up to now, this is made for testing automated tools, these tools usually use a defined screen size and may want to test with multiple lines in the port list

Copy link
Contributor

Choose a reason for hiding this comment

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

I've created an issue to reflect this behavior #97

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Why an issue? Why introduce an inconsistency?

To my knowledge we already wrap to 80 chars everywhere

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! Then, if we already wrap to 80 chars everywhere, it must be taken care of in this review.

t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
Expand All @@ -218,7 +218,7 @@ def test_show_vlan(self, t):
t.readln("")
t.readln("VLAN Name Status Ports")
t.readln("---- -------------------------------- --------- -------------------------------")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4")
t.readln("1 default active Fa0/2, Fa0/3, Fa0/4, Fa0/5, Fa0/6, Fa0/7, Fa0/8, Fa0/9, Fa0/10, Fa0/11, Fa0/12")
t.readln("123 VLAN123 active Fa0/1")
t.readln("2222 your-name-is-way-too-long-for-th active")
t.readln("3333 some-name active")
Expand Down Expand Up @@ -824,7 +824,7 @@ def test_removing_ip_address(self, t):
configuring(t, do="no interface vlan 2999")

@with_protocol
def test_show_ip_interfaces(self, t):
def test_show_ip_interface(self, t):
enable(t)

create_vlan(t, "1000")
Expand Down Expand Up @@ -865,6 +865,22 @@ def test_show_ip_interfaces(self, t):
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/4 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/5 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/6 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/7 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/8 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/9 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/10 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/11 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.readln("FastEthernet0/12 is down, line protocol is down")
t.readln(" Internet protocol processing disabled")
t.read("my_switch#")

t.write("show ip interface vlan 4000")
Expand Down Expand Up @@ -1041,6 +1057,22 @@ def test_full_running_config_and_pipe_begin_support(self, t):
t.readln("!")
t.readln("interface FastEthernet0/4")
t.readln("!")
t.readln("interface FastEthernet0/5")
t.readln("!")
t.readln("interface FastEthernet0/6")
t.readln("!")
t.readln("interface FastEthernet0/7")
t.readln("!")
t.readln("interface FastEthernet0/8")
t.readln("!")
t.readln("interface FastEthernet0/9")
t.readln("!")
t.readln("interface FastEthernet0/10")
t.readln("!")
t.readln("interface FastEthernet0/11")
t.readln("!")
t.readln("interface FastEthernet0/12")
t.readln("!")
t.readln("interface Vlan1000")
t.readln(" no ip address")
t.readln("!")
Expand Down Expand Up @@ -1344,7 +1376,7 @@ def test_show_version(self, t):
t.readln("Processor board ID FOC1530X2F7")
t.readln("Last reset from power-on")
t.readln("0 Virtual Ethernet interfaces")
t.readln("4 Gigabit Ethernet interfaces")
t.readln("12 Gigabit Ethernet interfaces")
t.readln("The password-recovery mechanism is enabled.")
t.readln("")
t.readln("512K bytes of flash-simulated non-volatile configuration memory.")
Expand All @@ -1366,7 +1398,7 @@ def test_show_version(self, t):
t.readln("")
t.readln("Switch Ports Model SW Version SW Image")
t.readln("------ ----- ----- ---------- ----------")
t.readln("* 1 4 WS-C3750G-24TS-1U 12.2(58)SE2 C3750-IPSERVICESK9-M")
t.readln("* 1 12 WS-C3750G-24TS-1U 12.2(58)SE2 C3750-IPSERVICESK9-M")
t.readln("")
t.readln("")
t.readln("Configuration register is 0xF")
Expand Down