Skip to content

Commit 4e7e772

Browse files
authored
[dvs] Refactor VLAN tests to use dvslib (#1241)
- Refactor tests to use polling interface - Refactor redundant testing methods - Reenable unstable tests Signed-off-by: Danny Allen <[email protected]>
1 parent eea6815 commit 4e7e772

File tree

3 files changed

+427
-700
lines changed

3 files changed

+427
-700
lines changed

tests/conftest.py

+3
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,9 @@ def get_asic_db(self):
947947
db.default_acl_tables = self.asicdb.default_acl_tables
948948
db.default_acl_entries = self.asicdb.default_acl_entries
949949
db.port_name_map = self.asicdb.portnamemap
950+
db.default_vlan_id = self.asicdb.default_vlan_id
951+
db.port_to_id_map = self.asicdb.portoidmap
952+
db.hostif_name_map = self.asicdb.hostifnamemap
950953
self.asic_db = db
951954

952955
return self.asic_db

tests/dvslib/dvs_database.py

+38-1
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,43 @@ def _access_function():
121121

122122
return wait_for_result(_access_function, polling_config)
123123

124+
def wait_for_field_match(self,
125+
table_name,
126+
key,
127+
expected_fields,
128+
polling_config=DEFAULT_POLLING_CONFIG):
129+
"""
130+
Checks if the provided fields are contained in the entry stored
131+
at `key` in the specified table. This method will wait for the
132+
fields to exist.
133+
134+
NOTE: We suggest you only use this function if:
135+
1) the entry already exists, and
136+
2) you expect certain fields to change
137+
138+
Otherwise, it is more efficient to use `wait_for_entry` and check
139+
for the expected fields after the entry has been retrieved.
140+
141+
Args:
142+
table_name (str): The name of the table where the entry is
143+
stored.
144+
key (str): The key that maps to the entry being checked.
145+
expected_fields (dict): The fields and their values we expect
146+
to see in the entry.
147+
polling_config (PollingConfig): The parameters to use to poll
148+
the db.
149+
150+
Returns:
151+
Dict[str, str]: The entry stored at `key`. If no entry is found,
152+
then an empty Dict will be returned.
153+
"""
154+
155+
def _access_function():
156+
fv_pairs = self.get_entry(table_name, key)
157+
return (expected_fields.items() <= fv_pairs.items(), fv_pairs)
158+
159+
return wait_for_result(_access_function, polling_config)
160+
124161
def wait_for_empty_entry(self,
125162
table_name,
126163
key,
@@ -141,7 +178,7 @@ def wait_for_empty_entry(self,
141178

142179
def _access_function():
143180
fv_pairs = self.get_entry(table_name, key)
144-
return (not fv_pairs, fv_pairs)
181+
return (not bool(fv_pairs), fv_pairs)
145182

146183
return wait_for_result(_access_function, polling_config)
147184

0 commit comments

Comments
 (0)