Skip to content

Commit ef95d32

Browse files
authored
[dvs] Convert sflow and speed tests to use dvslib (sonic-net#1382)
Signed-off-by: Danny Allen <[email protected]>
1 parent 6b1aa37 commit ef95d32

File tree

3 files changed

+200
-320
lines changed

3 files changed

+200
-320
lines changed

tests/dvslib/dvs_database.py

+74-3
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,54 @@ def __access_function():
119119

120120
return result
121121

122-
def wait_for_field_match(
122+
def wait_for_fields(
123123
self,
124124
table_name: str,
125125
key: str,
126-
expected_fields: Dict[str, str],
126+
expected_fields: List[str],
127127
polling_config: PollingConfig = DEFAULT_POLLING_CONFIG
128128
) -> Dict[str, str]:
129129
"""Wait for the entry stored at `key` to have the specified fields and retrieve it.
130130
131131
This method is useful if you only care about a subset of the fields stored in the
132132
specified entry.
133133
134+
Args:
135+
table_name: The name of the table where the entry is stored.
136+
key: The key that maps to the entry being checked.
137+
expected_fields: The fields that we expect to see in the entry.
138+
polling_config: The parameters to use to poll the db.
139+
140+
Returns:
141+
The entry stored at `key`. If no entry is found, then an empty Dict is returned.
142+
"""
143+
def __access_function():
144+
fv_pairs = self.get_entry(table_name, key)
145+
return (all(field in fv_pairs for field in expected_fields), fv_pairs)
146+
147+
status, result = wait_for_result(
148+
__access_function,
149+
self._disable_strict_polling(polling_config))
150+
151+
if not status:
152+
assert not polling_config.strict, \
153+
f"Expected fields not found: expected={expected_fields}, \
154+
received={result}, key=\"{key}\", table=\"{table_name}\""
155+
156+
return result
157+
158+
def wait_for_field_match(
159+
self,
160+
table_name: str,
161+
key: str,
162+
expected_fields: Dict[str, str],
163+
polling_config: PollingConfig = DEFAULT_POLLING_CONFIG
164+
) -> Dict[str, str]:
165+
"""Wait for the entry stored at `key` to have the specified field/value pairs and retrieve it.
166+
167+
This method is useful if you only care about the contents of a subset of the fields stored in the
168+
specified entry.
169+
134170
Args:
135171
table_name: The name of the table where the entry is stored.
136172
key: The key that maps to the entry being checked.
@@ -150,7 +186,42 @@ def __access_function():
150186

151187
if not status:
152188
assert not polling_config.strict, \
153-
f"Expected fields not found: expected={expected_fields}, \
189+
f"Expected field/value pairs not found: expected={expected_fields}, \
190+
received={result}, key=\"{key}\", table=\"{table_name}\""
191+
192+
return result
193+
194+
def wait_for_field_negative_match(
195+
self,
196+
table_name: str,
197+
key: str,
198+
old_fields: Dict[str, str],
199+
polling_config: PollingConfig = DEFAULT_POLLING_CONFIG
200+
) -> Dict[str, str]:
201+
"""Wait for the entry stored at `key` to have different field/value pairs than the ones specified.
202+
203+
This method is useful if you expect some field to change, but you don't know their exact values.
204+
205+
Args:
206+
table_name: The name of the table where the entry is stored.
207+
key: The key that maps to the entry being checked.
208+
old_fields: The original field/value pairs we expect to change.
209+
polling_config: The parameters to use to poll the db.
210+
211+
Returns:
212+
The entry stored at `key`. If no entry is found, then an empty Dict is returned.
213+
"""
214+
def __access_function():
215+
fv_pairs = self.get_entry(table_name, key)
216+
return (all(k in fv_pairs and fv_pairs[k] != v for k, v in old_fields.items()), fv_pairs)
217+
218+
status, result = wait_for_result(
219+
__access_function,
220+
self._disable_strict_polling(polling_config))
221+
222+
if not status:
223+
assert not polling_config.strict, \
224+
f"Did not expect field/values to match, but they did: provided={old_fields}, \
154225
received={result}, key=\"{key}\", table=\"{table_name}\""
155226

156227
return result

0 commit comments

Comments
 (0)