Skip to content

Commit

Permalink
[dvs] Refactor VLAN tests to use dvslib (#1241)
Browse files Browse the repository at this point in the history
- Refactor tests to use polling interface
- Refactor redundant testing methods
- Reenable unstable tests

Signed-off-by: Danny Allen <daall@microsoft.com>
  • Loading branch information
daall committed Apr 8, 2020
1 parent eea6815 commit 4e7e772
Show file tree
Hide file tree
Showing 3 changed files with 427 additions and 700 deletions.
3 changes: 3 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,9 @@ def get_asic_db(self):
db.default_acl_tables = self.asicdb.default_acl_tables
db.default_acl_entries = self.asicdb.default_acl_entries
db.port_name_map = self.asicdb.portnamemap
db.default_vlan_id = self.asicdb.default_vlan_id
db.port_to_id_map = self.asicdb.portoidmap
db.hostif_name_map = self.asicdb.hostifnamemap
self.asic_db = db

return self.asic_db
Expand Down
39 changes: 38 additions & 1 deletion tests/dvslib/dvs_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,43 @@ def _access_function():

return wait_for_result(_access_function, polling_config)

def wait_for_field_match(self,
table_name,
key,
expected_fields,
polling_config=DEFAULT_POLLING_CONFIG):
"""
Checks if the provided fields are contained in the entry stored
at `key` in the specified table. This method will wait for the
fields to exist.
NOTE: We suggest you only use this function if:
1) the entry already exists, and
2) you expect certain fields to change
Otherwise, it is more efficient to use `wait_for_entry` and check
for the expected fields after the entry has been retrieved.
Args:
table_name (str): The name of the table where the entry is
stored.
key (str): The key that maps to the entry being checked.
expected_fields (dict): The fields and their values we expect
to see in the entry.
polling_config (PollingConfig): The parameters to use to poll
the db.
Returns:
Dict[str, str]: The entry stored at `key`. If no entry is found,
then an empty Dict will be returned.
"""

def _access_function():
fv_pairs = self.get_entry(table_name, key)
return (expected_fields.items() <= fv_pairs.items(), fv_pairs)

return wait_for_result(_access_function, polling_config)

def wait_for_empty_entry(self,
table_name,
key,
Expand All @@ -141,7 +178,7 @@ def wait_for_empty_entry(self,

def _access_function():
fv_pairs = self.get_entry(table_name, key)
return (not fv_pairs, fv_pairs)
return (not bool(fv_pairs), fv_pairs)

return wait_for_result(_access_function, polling_config)

Expand Down
Loading

0 comments on commit 4e7e772

Please sign in to comment.