Skip to content

Commit

Permalink
feat: add plugin manager util for checking all plugins active
Browse files Browse the repository at this point in the history
  • Loading branch information
edaniszewski committed Feb 5, 2020
1 parent bb040d6 commit bc5dc7c
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
9 changes: 9 additions & 0 deletions synse_server/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,15 @@ def refresh(self) -> None:
elapsed_time=time.time() - start,
)

def all_active(self) -> bool:
"""Check to see if all registered plugins are active.
If a single plugin is inactive, this returns False. If no plugins are
registered, this returns True. In such a case, it is up to the caller to
perform additional checks for number of registered plugins.
"""
return all(plugin.active for plugin in self)


# A module-level instance of the plugin manager. This makes it easier to use
# the manager in various places, without having to initialize a new instance.
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/test_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,46 @@ def test_get_plugin_found(self):
assert result is not None
assert result == 'placeholder'

def test_all_active_true_no_plugins(self):
m = plugin.PluginManager()
assert m.all_active() is True

def test_all_active_true_has_plugins(self):
p1 = plugin.Plugin({'id': '1', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))
p2 = plugin.Plugin({'id': '2', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))
p3 = plugin.Plugin({'id': '3', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))

p1.mark_active()
p2.mark_active()
p3.mark_active()

m = plugin.PluginManager()
m.plugins = {
'1': p1,
'2': p2,
'3': p3,
}

assert m.all_active() is True

def test_all_active_false_has_plugins(self):
p1 = plugin.Plugin({'id': '1', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))
p2 = plugin.Plugin({'id': '2', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))
p3 = plugin.Plugin({'id': '3', 'tag': 'foo'}, {}, client.PluginClientV3('foo', 'tcp'))

p1.mark_active()
p2.mark_inactive()
p3.mark_active()

m = plugin.PluginManager()
m.plugins = {
'1': p1,
'2': p2,
'3': p3,
}

assert m.all_active() is False

def test_register_fail_metadata_call(self, mocker):
# Mock test data
mock_metadata = mocker.patch(
Expand Down

0 comments on commit bc5dc7c

Please sign in to comment.