Skip to content

Commit

Permalink
[vstest]: add dvs_route fixture
Browse files Browse the repository at this point in the history
Signed-off-by: Guohan Lu <lguohan@gmail.com>
  • Loading branch information
lguohan authored and qiluo-msft committed Jun 13, 2021
1 parent 849bdf9 commit a83a2a4
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
15 changes: 11 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
from dvslib.dvs_database import DVSDatabase
from dvslib.dvs_common import PollingConfig, wait_for_result
from dvslib.dvs_acl import DVSAcl
from dvslib.dvs_route import DVSRoute
from dvslib import dvs_vlan
from dvslib import dvs_lag
from dvslib import dvs_mirror
Expand Down Expand Up @@ -1099,7 +1100,7 @@ def getVlanOid(self, vlanId):
vlan_oid = str(k)
break
return vlan_oid

# deps: acl_portchannel, fdb
def getCrmCounterValue(self, key, counter):
counters_db = swsscommon.DBConnector(swsscommon.COUNTERS_DB, self.redis_sock, 0)
Expand Down Expand Up @@ -1462,7 +1463,7 @@ def get_chassis_instance_port_statuses(self):
chassis_container_name = device_info["hostname"] + "." + self.ns

port_info = config["PORT"]

for port, config in port_info.items():
if "admin_status" not in config:
continue
Expand All @@ -1471,13 +1472,13 @@ def get_chassis_instance_port_statuses(self):
instance_to_port_status_map[chassis_container_name] = []

instance_to_port_status_map[chassis_container_name].append((port, config.get("admin_status")))

return instance_to_port_status_map

def handle_chassis_connections(self):
if self.oper != "create":
return

instance_to_port_status_map = self.get_chassis_instance_port_statuses()
for chassis_instance, port_statuses in instance_to_port_status_map.items():
if chassis_instance not in self.dvss:
Expand Down Expand Up @@ -1593,6 +1594,12 @@ def dvs_acl(request, dvs) -> DVSAcl:
dvs.get_state_db(),
dvs.get_counters_db())

@pytest.fixture(scope="class")
def dvs_route(request, dvs) -> DVSRoute:
return DVSRoute(dvs.get_asic_db(),
dvs.get_config_db())


# FIXME: The rest of these also need to be reverted back to normal fixtures to
# appease the linter.
@pytest.yield_fixture(scope="class")
Expand Down
28 changes: 28 additions & 0 deletions tests/dvslib/dvs_route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
from dvslib.dvs_common import wait_for_result

class DVSRoute(object):
def __init__(self, adb, cdb):
self.asic_db = adb
self.config_db = cdb

def check_asicdb_route_entries(self, destinations):
def _access_function():
route_entries = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
route_destinations = [json.loads(route_entry)["dest"]
for route_entry in route_entries]
return (all(destination in route_destinations for destination in destinations), None)

wait_for_result(_access_function)

keys = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")

return [k for k in keys if json.loads(k)['dest'] in destinations]

def check_asicdb_deleted_route_entries(self, destinations):
def _access_function():
route_entries = self.asic_db.get_keys("ASIC_STATE:SAI_OBJECT_TYPE_ROUTE_ENTRY")
route_destinations = [json.loads(route_entry)["dest"] for route_entry in route_entries]
return (all(destination not in route_destinations for destination in destinations), None)

wait_for_result(_access_function)

0 comments on commit a83a2a4

Please sign in to comment.