Skip to content

Commit

Permalink
[dvs] Stabilize sub-port tests (#1254)
Browse files Browse the repository at this point in the history
Signed-off-by: Danny Allen <daall@microsoft.com>
  • Loading branch information
daall committed Apr 12, 2020
1 parent 327605a commit 25097d2
Show file tree
Hide file tree
Showing 2 changed files with 134 additions and 107 deletions.
64 changes: 57 additions & 7 deletions tests/dvslib/dvs_database.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,8 @@ def wait_for_field_match(self,
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.
Note:
This method does not check for an exact match.
Args:
table_name (str): The name of the table where the entry is
Expand All @@ -154,7 +150,7 @@ def wait_for_field_match(self,

def _access_function():
fv_pairs = self.get_entry(table_name, key)
return (expected_fields.items() <= fv_pairs.items(), fv_pairs)
return (all(fv_pairs.get(k) == v for k, v in expected_fields.items()), fv_pairs)

return wait_for_result(_access_function, polling_config)

Expand Down Expand Up @@ -208,3 +204,57 @@ def _access_function():
return (len(keys) == num_keys, keys)

return wait_for_result(_access_function, polling_config)

def wait_for_matching_keys(self,
table_name,
expected_keys,
polling_config=DEFAULT_POLLING_CONFIG):
"""
Checks if the specified keys exist in the table. This method
will wait for the keys to exist.
Args:
table_name (str): The name of the table from which to fetch
the keys.
expected_keys (List[str]): The keys we expect to see in the
table.
polling_config (PollingConfig): The parameters to use to poll
the db.
Returns:
List[str]: The keys stored in the table. If no keys are found,
then an empty List will be returned.
"""

def _access_function():
keys = self.get_keys(table_name)
return (all(key in keys for key in expected_keys), keys)

return wait_for_result(_access_function, polling_config)

def wait_for_deleted_keys(self,
table_name,
deleted_keys,
polling_config=DEFAULT_POLLING_CONFIG):
"""
Checks if the specified keys no longer exist in the table. This
method will wait for the keys to be deleted.
Args:
table_name (str): The name of the table from which to fetch
the keys.
deleted_keys (List[str]): The keys we expect to be removed from
the table.
polling_config (PollingConfig): The parameters to use to poll
the db.
Returns:
List[str]: The keys stored in the table. If no keys are found,
then an empty List will be returned.
"""

def _access_function():
keys = self.get_keys(table_name)
return (all(key not in keys for key in deleted_keys), keys)

return wait_for_result(_access_function, polling_config)
Loading

0 comments on commit 25097d2

Please sign in to comment.