Skip to content
Closed
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
54 changes: 54 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -777,10 +777,64 @@ def add_neighbor(self, interface, ip, mac):
time.sleep(1)

def remove_neighbor(self, interface, ip):
"""
Removes a neighbor from the device. This method will wait 1 second
to allow redis updates to propagate.
"""
tbl = swsscommon.ProducerStateTable(self.pdb, "NEIGH_TABLE")
tbl._del(interface + ":" + ip)
time.sleep(1)

def add_route(self, prefix, nexthop):
"""
Adds a route from nexthop to prefix. This method will wait 1 second
to allow redis updates to propagate.
"""
self.runcmd("ip route add " + prefix + " via " + nexthop)
time.sleep(1)

def update_route(self, prefix, nexthop):
"""
Adds a route from nexthop to prefix, overwriting an existing route
to prefix. This method will wait 1 second to allow redis updates
to propagate.
"""
self.runcmd("ip route change " + prefix + " via " + nexthop)
time.sleep(1)

def add_route_ecmp(self, prefix, nexthops):
"""
Adds an ecmp route from any of the provided nexthops to prefix.
This method will wait 1 second to allow redis updates to propagate.
"""
cmd = ""
for nexthop in nexthops:
cmd += " nexthop via " + nexthop

self.runcmd("ip route add " + prefix + cmd)
time.sleep(1)

def update_route_ecmp(self, prefix, nexthops):
"""
Adds an ecmp route from any of the provided nexthops to prefix,
overwriting an existing ecmp route to prefix. This method will wait
1 second to allow redis updates to propagate.
"""
cmd = ""
for nexthop in nexthops:
cmd += " nexthop via " + nexthop

self.runcmd("ip route change " + prefix + cmd)
time.sleep(1)

def remove_route(self, prefix):
"""
Removes a route to prefix. This method will wait 1 second to allow
redis updates to propagate.
"""
self.runcmd("ip route del " + prefix)
time.sleep(1)

def setup_db(self):
self.pdb = swsscommon.DBConnector(0, self.redis_sock, 0)
self.adb = swsscommon.DBConnector(1, self.redis_sock, 0)
Expand Down
116 changes: 114 additions & 2 deletions tests/test_warm_reboot.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,121 @@ def ping_new_ips(dvs):
dvs.runcmd(['sh', '-c', "ping -c 1 -W 0 -q {}.0.0.{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)])
dvs.runcmd(['sh', '-c', "ping6 -c 1 -W 0 -q {}00::{} > /dev/null 2>&1".format(i*4,j+NUM_NEIGH_PER_INTF+2)])


def create_mirror_session(dvs, name, src, dst, gre, dscp, ttl, queue):
"""
Creates a mirror session. This method will wait 1 second to allow
redis updates to propagate.
"""
tbl = swsscommon.Table(dvs.cdb, "MIRROR_SESSION")
fvs = swsscommon.FieldValuePairs([("src_ip", src),
("dst_ip", dst),
("gre_type", gre),
("dscp", dscp),
("ttl", ttl),
("queue", queue)])
tbl.set(name, fvs)
time.sleep(1)


def remove_mirror_session(dvs, name):
"""
Deletes a mirror session. This method will wait 1 second to allow
redis updates to propagate.
"""
tbl = swsscommon.Table(dvs.cdb, "MIRROR_SESSION")
tbl._del(name)
time.sleep(1)


def get_mirror_session_state(dvs, name):
"""
Gets the current state of a mirror session. This method will cause
your test to fail if the given mirror session does not exist.

Example output:
{
"src_ip": "10.0.0.0",
"dst_ip": "192.168.1.1",
...
}
"""
tbl = swsscommon.Table(dvs.sdb, "MIRROR_SESSION_TABLE")
(status, fvs) = tbl.get(name)
assert status
assert len(fvs) > 0
return {fv[0]: fv[1] for fv in fvs}


class TestWarmReboot(object):
def test_MirrorSessionWarmReboot(self, dvs, testlog):
"""
This test verifies that mirror session monitor ports are not
changed after warm reboot.
"""

# Setup the virtual switch
dvs.setup_db()
dvs.runcmd("config warm_restart enable swss")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I suggest moving warm restart setting close to swss restart.


# Setup neighbors for the test
dvs.set_interface_status("Ethernet12", "up")
dvs.set_interface_status("Ethernet16", "up")
dvs.set_interface_status("Ethernet20", "up")

dvs.add_ip_address("Ethernet12", "10.0.0.0/31")
dvs.add_ip_address("Ethernet16", "11.0.0.0/31")
dvs.add_ip_address("Ethernet20", "12.0.0.0/31")

dvs.add_neighbor("Ethernet12", "10.0.0.1", "02:04:06:08:10:12")
dvs.add_neighbor("Ethernet16", "11.0.0.1", "03:04:06:08:10:12")
dvs.add_neighbor("Ethernet20", "12.0.0.1", "04:04:06:08:10:12")

# Set test_session1 monitor port as Ethernet12
dvs.add_route("2.2.2.2", "10.0.0.1")
create_mirror_session(dvs, "test_session1", "1.1.1.1", "2.2.2.2", "0x6558", "8", "100", "0")

# Set test_session2 monitor port as Ethernet16
dvs.update_route_ecmp("2.2.2.2", ["11.0.0.1", "10.0.0.1"])
create_mirror_session(dvs, "test_session2", "1.1.1.1", "2.2.2.2", "0x6558", "8", "100", "0")

# Set test_session3 monitor port as Ethernet20
dvs.update_route_ecmp("2.2.2.2", ["12.0.0.1", "11.0.0.1", "10.0.0.1"])
create_mirror_session(dvs, "test_session3", "1.1.1.1", "2.2.2.2", "0x6558", "8", "100", "0")

test_session1_mp = get_mirror_session_state(dvs, "test_session1")["monitor_port"]
test_session2_mp = get_mirror_session_state(dvs, "test_session2")["monitor_port"]
test_session3_mp = get_mirror_session_state(dvs, "test_session3")["monitor_port"]

# Perform the warm reboot
dvs.stop_swss()
dvs.start_swss()
time.sleep(5)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

is sleep 5 seconds enough? You could polling "show warm_restart state" and wait until orchagent is reconciled. That would take lot longer than 5 seconds though.


# Verify that all monitor ports are still the same after warm reboot
assert test_session1_mp == get_mirror_session_state(dvs, "test_session1")["monitor_port"]
assert test_session2_mp == get_mirror_session_state(dvs, "test_session2")["monitor_port"]
assert test_session3_mp == get_mirror_session_state(dvs, "test_session3")["monitor_port"]

# Teardown the mirror sessions and routes
remove_mirror_session(dvs, "test_session1")
remove_mirror_session(dvs, "test_session2")
remove_mirror_session(dvs, "test_session3")

dvs.remove_route("2.2.2.2")

dvs.remove_neighbor("Ethernet12", "10.0.0.1")
dvs.remove_neighbor("Ethernet16", "11.0.0.1")
dvs.remove_neighbor("Ethernet20", "12.0.0.1")

dvs.remove_ip_address("Ethernet12", "10.0.0.0/31")
dvs.remove_ip_address("Ethernet16", "11.0.0.0/31")
dvs.remove_ip_address("Ethernet20", "12.0.0.0/31")

dvs.set_interface_status("Ethernet12", "down")
dvs.set_interface_status("Ethernet16", "down")
dvs.set_interface_status("Ethernet20", "down")

def test_PortSyncdWarmRestart(self, dvs, testlog):

conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -325,7 +439,6 @@ def test_PortSyncdWarmRestart(self, dvs, testlog):
intf_tbl._del("Ethernet20")
time.sleep(2)


def test_VlanMgrdWarmRestart(self, dvs, testlog):

conf_db = swsscommon.DBConnector(swsscommon.CONFIG_DB, dvs.redis_sock, 0)
Expand Down Expand Up @@ -815,7 +928,6 @@ def test_swss_neighbor_syncup(self, dvs, testlog):
intf_tbl._del("{}".format(intfs[1]))
time.sleep(2)


# TODO: The condition of warm restart readiness check is still under discussion.
def test_OrchagentWarmRestartReadyCheck(self, dvs, testlog):

Expand Down