Skip to content

Commit 38400fd

Browse files
authored
Network find speedup (#747)
* Skip getting device's status if not necessay This fix adds an additional flag that speeds up the network find avoiding to always getting data from sqpoller to detect devices' status. Signed-off-by: Claudio Usai <[email protected]> * Update tests, handle corner case for internal flag in device get Signed-off-by: Claudio Usai <[email protected]> * Update with suggestions Signed-off-by: Claudio Usai <[email protected]> * Update tests Signed-off-by: Claudio Usai <[email protected]>
1 parent 765d0cb commit 38400fd

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

suzieq/engines/pandas/device.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ def get(self, **kwargs):
2525
status = kwargs.pop('status', '')
2626
os_version = kwargs.pop('version', '')
2727
os = kwargs.get('os', '')
28+
ignore_neverpoll = kwargs.pop('ignore_neverpoll', False)
2829

2930
addnl_fields = []
3031
fields = self.schema.get_display_fields(columns)
@@ -49,11 +50,13 @@ def get(self, **kwargs):
4950
if view == 'latest' and 'status' in df.columns:
5051
df['status'] = np.where(df.active, df['status'], 'dead')
5152

52-
poller_df = self._get_table_sqobj('sqPoller').get(
53-
namespace=kwargs.get('namespace', []),
54-
hostname=kwargs.get('hostname', []),
55-
service='device',
56-
columns='namespace hostname status timestamp'.split())
53+
poller_df = pd.DataFrame()
54+
if not ignore_neverpoll:
55+
poller_df = self._get_table_sqobj('sqPoller').get(
56+
namespace=kwargs.get('namespace', []),
57+
hostname=kwargs.get('hostname', []),
58+
service='device',
59+
columns='namespace hostname status timestamp'.split())
5760

5861
if not poller_df.empty:
5962
# Identify the address to namespace/hostname mapping

suzieq/engines/pandas/interfaces.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -544,7 +544,8 @@ def _add_portmode(self, df: pd.DataFrame, **kwargs):
544544

545545
devdf = self._get_table_sqobj('device') \
546546
.get(namespace=namespace, hostname=hostname,
547-
columns=['namespace', 'hostname', 'os', 'status', 'vendor'])
547+
columns=['namespace', 'hostname', 'os'],
548+
ignore_neverpoll=True)
548549

549550
pm_df = pd.DataFrame({'namespace': [], 'hostname': [],
550551
'ifname': [], 'portmode': []})

suzieq/sqobjects/device.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def __init__(self, **kwargs):
1212
super().__init__(table='device', **kwargs)
1313
self._valid_get_args = ['namespace', 'hostname', 'columns', 'os',
1414
'vendor', 'model', 'status', 'version',
15-
'query_str']
15+
'query_str', 'ignore_neverpoll']
1616
self._valid_arg_vals = {
1717
'status': ['alive', 'dead', 'neverpoll',
1818
'!alive', '!dead', '!neverpoll']

tests/integration/test_rest.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,6 +573,9 @@ def test_rest_arg_consistency(service, verb):
573573

574574
valid_args = set(arglist)
575575

576+
if service == 'device':
577+
valid_args.remove('ignore_neverpoll')
578+
576579
# In the tests below, we warn when we don't have the exact
577580
# {service}_{verb} REST function, which prevents us from picking the
578581
# correct set of args.
@@ -692,6 +695,8 @@ def test_routes_sqobj_consistency():
692695
args_to_match = get_args_to_match(sqobj, route.verbs)
693696
args_to_match = {a for a in args_to_match
694697
if a not in common_args.union(top_args)}
698+
if table == 'device':
699+
args_to_match.remove('ignore_neverpoll')
695700
if args_to_match != query_params:
696701
assert False, (f'different query params for {table}: expected '
697702
f'{args_to_match}. Got {query_params}')

0 commit comments

Comments
 (0)