Skip to content

Commit

Permalink
[vstest/nhg]: use dvs_route fixture to make test_nhg more robust
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <[email protected]>
  • Loading branch information
lguohan committed Feb 17, 2021
1 parent d407bc8 commit 20ee836
Showing 1 changed file with 10 additions and 19 deletions.
29 changes: 10 additions & 19 deletions tests/test_nhg.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


class TestNextHopGroup(object):
def test_route_nhg(self, dvs, testlog):
def test_route_nhg(self, dvs, dvs_route, testlog):
config_db = dvs.get_config_db()
fvs = {"NULL": "NULL"}
config_db.create_entry("INTERFACE", "Ethernet0", fvs)
Expand All @@ -35,32 +35,23 @@ def test_route_nhg(self, dvs, testlog):
assert dvs.servers[1].runcmd("ip link set up dev eth0") == 0
assert dvs.servers[2].runcmd("ip link set up dev eth0") == 0

rtprefix = "2.2.2.0/24"

app_db = dvs.get_app_db()
ps = swsscommon.ProducerStateTable(app_db.db_connection, "ROUTE_TABLE")

asic_db = dvs.get_asic_db()
asic_routes_count = len(asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY"))

dvs_route.check_asicdb_deleted_route_entries([rtprefix])

fvs = swsscommon.FieldValuePairs([("nexthop","10.0.0.1,10.0.0.3,10.0.0.5"), ("ifname", "Ethernet0,Ethernet4,Ethernet8")])
ps.set("2.2.2.0/24", fvs)
ps.set(rtprefix, fvs)

# check if route was propagated to ASIC DB

asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY", asic_routes_count + 1)
keys = asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")

found_route = False
for k in keys:
rt_key = json.loads(k)

if rt_key['dest'] == "2.2.2.0/24":
found_route = True
break

assert found_route
rtkeys = dvs_route.check_asicdb_route_entries([rtprefix])

# assert the route points to next hop group
fvs = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY", k)
fvs = asic_db.get_entry("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY", rtkeys[0])

nhgid = fvs["SAI_ROUTE_ENTRY_ATTR_NEXT_HOP_ID"]

Expand Down Expand Up @@ -112,10 +103,10 @@ def test_route_nhg(self, dvs, testlog):
assert fvs["SAI_NEXT_HOP_GROUP_MEMBER_ATTR_NEXT_HOP_GROUP_ID"] == nhgid

# Remove route 2.2.2.0/24
ps._del("2.2.2.0/24")
ps._del(rtprefix)

# Wait for route 2.2.2.0/24 to be removed
asic_db.wait_for_n_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY", asic_routes_count)
dvs_route.check_asicdb_deleted_route_entries([rtprefix])

def test_route_nhg_exhaust(self, dvs, testlog):
"""
Expand Down

0 comments on commit 20ee836

Please sign in to comment.