Skip to content

Commit

Permalink
[test]: Enforce fake port-channel interfaces carrier up (#905)
Browse files Browse the repository at this point in the history
After switching to FRR, routes cannot be inserted if the
interface is not connected, or 'carrier down'. Thus, it
is mandatory to force the interface carrier up.

Signed-off-by: Shu0T1an ChenG <shuche@microsoft.com>
  • Loading branch information
Shuotian Cheng committed May 22, 2019
1 parent 2e3b946 commit f437f9f
Showing 1 changed file with 31 additions and 25 deletions.
56 changes: 31 additions & 25 deletions tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def setup_db(self, dvs):
self.cdb = swsscommon.DBConnector(4, dvs.redis_sock, 0)
self.sdb = swsscommon.DBConnector(6, dvs.redis_sock, 0)

def set_interface_status(self, interface, admin_status):
def set_interface_status(self, dvs, interface, admin_status):
if interface.startswith("PortChannel"):
tbl_name = "PORTCHANNEL"
elif interface.startswith("Vlan"):
Expand All @@ -27,6 +27,12 @@ def set_interface_status(self, interface, admin_status):
tbl.set(interface, fvs)
time.sleep(1)

# when using FRR, route cannot be inserted if the neighbor is not
# connected. thus it is mandatory to force the interface up manually
if interface.startswith("PortChannel"):
dvs.runcmd("bash -c 'echo " + ("1" if admin_status == "up" else "0") +\
" > /sys/class/net/" + interface + "/carrier'")

def add_ip_address(self, interface, ip):
if interface.startswith("PortChannel"):
tbl_name = "PORTCHANNEL_INTERFACE"
Expand Down Expand Up @@ -118,7 +124,7 @@ def test_MirrorAddRemove(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring up Ethernet16
self.set_interface_status("Ethernet16", "up")
self.set_interface_status(dvs, "Ethernet16", "up")
assert self.get_mirror_session_state(session)["status"] == "inactive"

# add IP address to Ethernet16
Expand Down Expand Up @@ -183,7 +189,7 @@ def test_MirrorAddRemove(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring down Ethernet16
self.set_interface_status("Ethernet16", "down")
self.set_interface_status(dvs, "Ethernet16", "down")
assert self.get_mirror_session_state(session)["status"] == "inactive"

# remove mirror session
Expand Down Expand Up @@ -253,8 +259,8 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog):
self.create_vlan_member("6", "Ethernet4")

# bring up vlan and member
self.set_interface_status("Vlan6", "up")
self.set_interface_status("Ethernet4", "up")
self.set_interface_status(dvs, "Vlan6", "up")
self.set_interface_status(dvs, "Ethernet4", "up")

# add ip address to vlan 6
self.add_ip_address("Vlan6", "6.6.6.0/24")
Expand Down Expand Up @@ -325,8 +331,8 @@ def test_MirrorToVlanAddRemove(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring down vlan and member
self.set_interface_status("Ethernet4", "down")
self.set_interface_status("Vlan6", "down")
self.set_interface_status(dvs, "Ethernet4", "down")
self.set_interface_status(dvs, "Vlan6", "down")

# remove vlan member; remove vlan
self.remove_vlan_member("6", "Ethernet4")
Expand Down Expand Up @@ -390,8 +396,8 @@ def test_MirrorToLagAddRemove(self, dvs, testlog):
self.create_port_channel_member("008", "Ethernet88")

# bring up port channel and port channel member
self.set_interface_status("PortChannel008", "up")
self.set_interface_status("Ethernet88", "up")
self.set_interface_status(dvs, "PortChannel008", "up")
self.set_interface_status(dvs, "Ethernet88", "up")

# add ip address to port channel 008
self.add_ip_address("PortChannel008", "11.11.11.0/24")
Expand Down Expand Up @@ -422,8 +428,8 @@ def test_MirrorToLagAddRemove(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring down port channel and port channel member
self.set_interface_status("PortChannel008", "down")
self.set_interface_status("Ethernet88", "down")
self.set_interface_status(dvs, "PortChannel008", "down")
self.set_interface_status(dvs, "Ethernet88", "down")

# remove port channel member; remove port channel
self.remove_port_channel_member("008", "Ethernet88")
Expand Down Expand Up @@ -458,7 +464,7 @@ def test_MirrorDestMoveVlan(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring up port; add ip; add neighbor; add route
self.set_interface_status("Ethernet32", "up")
self.set_interface_status(dvs, "Ethernet32", "up")
self.add_ip_address("Ethernet32", "80.0.0.0/31")
self.add_neighbor("Ethernet32", "80.0.0.1", "02:04:06:08:10:12")
self.add_route(dvs, "8.8.0.0/16", "80.0.0.1")
Expand All @@ -479,8 +485,8 @@ def test_MirrorDestMoveVlan(self, dvs, testlog):
# create vlan; create vlan member; bring up vlan and member
self.create_vlan(dvs, "9")
self.create_vlan_member("9", "Ethernet48")
self.set_interface_status("Vlan9", "up")
self.set_interface_status("Ethernet48", "up")
self.set_interface_status(dvs, "Vlan9", "up")
self.set_interface_status(dvs, "Ethernet48", "up")
assert self.get_mirror_session_state(session)["status"] == "active"

# add ip address to vlan 9
Expand Down Expand Up @@ -539,16 +545,16 @@ def test_MirrorDestMoveVlan(self, dvs, testlog):
assert fv[1] == "false"

# bring down vlan and member; remove vlan member; remove vlan
self.set_interface_status("Ethernet48", "down")
self.set_interface_status("Vlan9", "down")
self.set_interface_status(dvs, "Ethernet48", "down")
self.set_interface_status(dvs, "Vlan9", "down")
self.remove_vlan_member("9", "Ethernet48")
self.remove_vlan("9")

# remove route; remove neighbor; remove ip; bring down port
self.remove_route(dvs, "8.8.8.0/24")
self.remove_neighbor("Ethernet32", "80.0.0.1")
self.remove_ip_address("Ethernet32", "80.0.0.0/31")
self.set_interface_status("Ethernet32", "down")
self.set_interface_status(dvs, "Ethernet32", "down")

# remove mirror session
self.remove_mirror_session(session)
Expand Down Expand Up @@ -576,7 +582,7 @@ def test_MirrorDestMoveLag(self, dvs, testlog):
assert self.get_mirror_session_state(session)["status"] == "inactive"

# bring up port; add ip; add neighbor; add route
self.set_interface_status("Ethernet64", "up")
self.set_interface_status(dvs, "Ethernet64", "up")
self.add_ip_address("Ethernet64", "100.0.0.0/31")
self.add_neighbor("Ethernet64", "100.0.0.1", "02:04:06:08:10:12")
self.add_route(dvs, "13.13.0.0/16", "100.0.0.1")
Expand All @@ -597,8 +603,8 @@ def test_MirrorDestMoveLag(self, dvs, testlog):
# create port channel; create port channel member; bring up
self.create_port_channel(dvs, "080")
self.create_port_channel_member("080", "Ethernet32")
self.set_interface_status("PortChannel080", "up")
self.set_interface_status("Ethernet32", "up")
self.set_interface_status(dvs, "PortChannel080", "up")
self.set_interface_status(dvs, "Ethernet32", "up")

# add ip address to port channel 080; create neighbor to port channel 080
self.add_ip_address("PortChannel080", "200.0.0.0/31")
Expand Down Expand Up @@ -663,8 +669,8 @@ def test_MirrorDestMoveLag(self, dvs, testlog):
self.remove_ip_address("PortChannel080", "200.0.0.0/31")

# bring down; remove port channel member; remove port channel
self.set_interface_status("Ethernet32", "down")
self.set_interface_status("PortChannel080", "down")
self.set_interface_status(dvs, "Ethernet32", "down")
self.set_interface_status(dvs, "PortChannel080", "down")
self.remove_port_channel_member("080", "Ethernet32")
self.remove_port_channel(dvs, "080")
assert self.get_mirror_session_state(session)["status"] == "active"
Expand All @@ -673,7 +679,7 @@ def test_MirrorDestMoveLag(self, dvs, testlog):
self.remove_route(dvs, "13.13.0.0/16")
self.remove_neighbor("Ethernet64", "100.0.0.1")
self.remove_ip_address("Ethernet64", "100.0.0.0/31")
self.set_interface_status("Ethernet64", "down")
self.set_interface_status(dvs, "Ethernet64", "down")
assert self.get_mirror_session_state(session)["status"] == "inactive"

# remove mirror session
Expand Down Expand Up @@ -719,7 +725,7 @@ def test_AclBindMirror(self, dvs, testlog):
acl_rule = "MIRROR_RULE"

# bring up port; assign ip; create neighbor; create route
self.set_interface_status("Ethernet32", "up")
self.set_interface_status(dvs, "Ethernet32", "up")
self.add_ip_address("Ethernet32", "20.0.0.0/31")
self.add_neighbor("Ethernet32", "20.0.0.1", "02:04:06:08:10:12")
self.add_route(dvs, "4.4.4.4", "20.0.0.1")
Expand Down Expand Up @@ -788,4 +794,4 @@ def test_AclBindMirror(self, dvs, testlog):
self.remove_route(dvs, "4.4.4.4")
self.remove_neighbor("Ethernet32", "20.0.0.1")
self.remove_ip_address("Ethernet32", "20.0.0.0/31")
self.set_interface_status("Ethernet32", "down")
self.set_interface_status(dvs, "Ethernet32", "down")

0 comments on commit f437f9f

Please sign in to comment.