Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nlsocket: refactoring #978

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyroute2/ndb/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -750,8 +750,8 @@ def check_sources_started(self, _locals, target, event):
for target in tuple(self.sources.cache):
source = self.sources.remove(target, sync=False)
if source is not None and source.th is not None:
source.shutdown.set()
source.th.join()
self.log.debug(f'closing source {source}')
source.close()
if self._db_cleanup:
self.log.debug('flush DB for the target %s' % target)
self.schema.flush(target)
Expand Down
75 changes: 39 additions & 36 deletions pyroute2/ndb/objects/route.py
Original file line number Diff line number Diff line change
Expand Up @@ -478,45 +478,48 @@ def dump(cls, view):
for record in view.ndb.schema.fetch(req + where, values):
route_id = record[-1]
record = list(record[:-1])
#
# fetch metrics
metrics = tuple(
view.ndb.schema.fetch(
'''
SELECT * FROM metrics WHERE f_route_id = %s
'''
% (plch,),
(route_id,),
if route_id is not None:
#
# fetch metrics
metrics = tuple(
view.ndb.schema.fetch(
'''
SELECT * FROM metrics WHERE f_route_id = %s
'''
% (plch,),
(route_id,),
)
)
)
if metrics:
ret = {}
names = view.ndb.schema.compiled['metrics']['norm_names']
for k, v in zip(names, metrics[0]):
if v is not None and k not in (
'target',
'route_id',
'tflags',
):
ret[k] = v
record.append(json.dumps(ret))
else:
record.append(None)
#
# fetch encap
enc_mpls = tuple(
view.ndb.schema.fetch(
'''
SELECT * FROM enc_mpls WHERE f_route_id = %s
'''
% (plch,),
(route_id,),
if metrics:
ret = {}
names = view.ndb.schema.compiled['metrics']['norm_names']
for k, v in zip(names, metrics[0]):
if v is not None and k not in (
'target',
'route_id',
'tflags',
):
ret[k] = v
record.append(json.dumps(ret))
else:
record.append(None)
#
# fetch encap
enc_mpls = tuple(
view.ndb.schema.fetch(
'''
SELECT * FROM enc_mpls WHERE f_route_id = %s
'''
% (plch,),
(route_id,),
)
)
)
if enc_mpls:
record.append(enc_mpls[0][2])
if enc_mpls:
record.append(enc_mpls[0][2])
else:
record.append(None)
else:
record.append(None)
record.extend((None, None))
yield record

@classmethod
Expand Down
6 changes: 3 additions & 3 deletions pyroute2/ndb/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ def receiver(self):
# The routine exists on an event with error code == 104
#
while self.state.get() != 'stop':
with self.lock:
if self.shutdown.is_set():
break
if self.shutdown.is_set():
break

with self.lock:
if self.nl is not None:
try:
self.nl.close(code=0)
Expand Down
Loading