diff --git a/pyroute2/ndb/source.py b/pyroute2/ndb/source.py index e068322d2..a8c4a2c15 100644 --- a/pyroute2/ndb/source.py +++ b/pyroute2/ndb/source.py @@ -7,10 +7,21 @@ starts with one local RTNL source names `localhost`:: >>> ndb = NDB() - >>> ndb.sources.details() - {'kind': u'local', u'nlm_generator': 1, 'target': u'localhost'} + >>> ndb.sources.summary().format("json") + [ + { + "name": "localhost", + "spec": "{'target': 'localhost', 'nlm_generator': 1}", + "state": "running" + }, + { + "name": "localhost/nsmanager", + "spec": "{'target': 'localhost/nsmanager'}", + "state": "running" + } + ] >>> ndb.sources['localhost'] - [running] + [running] The `localhost` RTNL source starts an additional async cache thread. The `nlm_generator` option means that instead of collections the @@ -18,7 +29,7 @@ consume memory regardless of the RTNL objects number:: >>> ndb.sources['localhost'].nl.link('dump') - + See also: :ref:`iproute` @@ -180,6 +191,12 @@ def __init__(self, ndb, **spec): self.ndb.task_manager.db_add_nl_source(self.target, self.kind, spec) self.load_sql() + @classmethod + def _count(cls, view): + return view.ndb.task_manager.db_fetchone( + "SELECT count(*) FROM %s" % view.table + ) + @property def must_restart(self): if self.max_errors < 0 or self.errors_counter <= self.max_errors: diff --git a/tests/test_linux/test_ndb/test_sources.py b/tests/test_linux/test_ndb/test_sources.py index c53be96af..25177df97 100644 --- a/tests/test_linux/test_ndb/test_sources.py +++ b/tests/test_linux/test_ndb/test_sources.py @@ -38,6 +38,7 @@ def test_multiple_sources(context): assert len(list(ndb.neighbours.dump())) assert len(list(ndb.addresses.dump())) assert len(list(ndb.routes.dump())) + assert len(ndb.sources) == len(sources) # here NDB() gets closed #