示例#1
0
    def test_all_ready_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._reconnect = asynctest.CoroutineMock()
        p2._reconnect = asynctest.CoroutineMock()
        p3._reconnect = asynctest.CoroutineMock()

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

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

        assert m.all_ready() is True
示例#2
0
    def test_refresh_already_refreshing(self):
        m = plugin.PluginManager()
        m.is_refreshing = True

        assert len(m.plugins) == 0
        m.refresh()
        assert len(m.plugins) == 0
示例#3
0
    def test_register_duplicate_plugin_id_both_active(self, mock_version,
                                                      mock_metadata):
        """Plugins with the same Plugin ID are registered. Both are considered active,
        so Synse should keep the cached Plugin instance.
        """

        m = plugin.PluginManager()
        p = plugin.Plugin(
            {
                'id': 'foo',
                'tag': 'foo'
            },
            {},
            client.PluginClientV3('foo', 'tcp'),
        )
        m.plugins = {'123': p}

        plugin_id = m.register('localhost:5432', 'tcp')
        assert plugin_id == '123'
        # Ensure nothing new was added to the manager.
        assert len(m.plugins) == 1
        assert m.plugins[plugin_id].active is True
        assert m.plugins[plugin_id].disabled is False

        # Since the plugins are both active, Synse keeps the existing one, so
        # the object ID of the cached Plugin should not have changed from the
        # seed value.
        assert id(m.plugins[plugin_id]) == id(p)

        mock_metadata.assert_called_once()
        mock_version.assert_called_once()
示例#4
0
    def test_discover_one_address_found(self, mock_discover):
        m = plugin.PluginManager()
        found = m.discover()

        assert len(found) == 1
        assert ('localhost:5001', 'tcp') in found
        mock_discover.assert_called_once()
示例#5
0
    def test_register_duplicate_id_existing_disabled_new_address_changed(
            self, mock_version, mock_metadata):  # noqa
        """Plugins with the same Plugin ID are registered. The cached plugin is disabled and has
        a different address than the new plugin, which is active. Synse should replace the cached
        disabled instance with the new active one.
        """

        m = plugin.PluginManager()
        p = plugin.Plugin(
            {
                'id': '123',
                'tag': 'foo'
            },
            {},
            client.PluginClientV3('somewhere:6789', 'tcp'),
        )
        p.disabled = True
        m.plugins = {'123': p}

        plugin_id = m.register('localhost:5432', 'tcp')
        assert plugin_id == '123'
        assert len(m.plugins) == 1
        assert m.plugins[plugin_id].active is True
        assert m.plugins[plugin_id].disabled is False

        # Since the seed plugin is disabled, the registration process should replace
        # the old Plugin instance with the newly created one, which should no longer
        # be disabled. This will be a new instance, so new object ID.
        assert id(m.plugins[plugin_id]) != id(p)

        mock_metadata.assert_called_once()
        mock_version.assert_called_once()
示例#6
0
    def test_has_plugins_one(self):
        m = plugin.PluginManager()
        m.plugins = {
            '1': 'placeholder',
        }

        assert m.has_plugins() is True
示例#7
0
    def test_refresh_discover_fail(self, mock_refresh, mock_register, mock_discover):
        m = plugin.PluginManager()
        m.refresh()

        mock_discover.assert_called_once()
        mock_register.assert_called_once_with(address='localhost:5001', protocol='tcp')
        mock_refresh.assert_has_calls([])
示例#8
0
    def test_refresh_discover_ok(self, mock_refresh, mock_register, mock_discover):
        m = plugin.PluginManager()
        m.refresh()

        mock_discover.assert_called_once()
        mock_register.assert_called_once_with(address='localhost:5001', protocol='tcp')
        # empty because register is mocked, so nothing gets added to manager
        mock_refresh.assert_has_calls([])
示例#9
0
    def test_refresh_new_plugin(self, mock_refresh, register_mock, load_mock):
        m = plugin.PluginManager()
        m.refresh()

        load_mock.assert_called_once()
        register_mock.assert_called_once_with(address='localhost:5001', protocol='tcp')
        # empty because register is mocked, so nothing gets added to manager
        mock_refresh.assert_has_calls([])
示例#10
0
    def test_get_plugin_found(self):
        m = plugin.PluginManager()
        m.plugins = {
            '1': 'placeholder',
        }

        result = m.get('1')
        assert result is not None
        assert result == 'placeholder'
示例#11
0
    def test_refresh_client_create_error(self, mock_refresh, mock_register, mock_load):
        m = plugin.PluginManager()

        with pytest.raises(synse_errors.ClientCreateError):
            m.refresh()

        mock_load.assert_called_once()
        mock_register.assert_called_once_with(address='localhost:5001', protocol='tcp')
        mock_refresh.assert_not_called()
示例#12
0
    def test_bucket_plugins_no_config(self, simple_plugin):
        m = plugin.PluginManager()
        m.plugins[simple_plugin.id] = simple_plugin

        existing, new, removed = m.bucket_plugins([])
        assert len(existing) == 0
        assert len(new) == 0
        assert len(removed) == 1

        assert simple_plugin in removed
示例#13
0
    def test_refresh_existing_plugin(self, mock_refresh, load_mock, simple_plugin):
        m = plugin.PluginManager()
        m.plugins[simple_plugin.id] = simple_plugin
        simple_plugin.disabled = True

        m.refresh()

        assert simple_plugin.disabled is False
        load_mock.assert_called_once()
        mock_refresh.assert_has_calls([])
示例#14
0
    def test_register_success(self, mock_version, mock_metadata):
        m = plugin.PluginManager()

        plugin_id = m.register('localhost:5432', 'tcp')
        assert plugin_id == '123'
        assert len(m.plugins) == 1
        assert m.plugins[plugin_id].active is True

        mock_metadata.assert_called_once()
        mock_version.assert_called_once()
示例#15
0
    def test_register_fail_metadata_call(self, mock_metadata):
        m = plugin.PluginManager()

        with pytest.raises(RpcError):
            m.register('localhost:5432', 'tcp')

        # Ensure nothing was added to the manager.
        assert len(m.plugins) == 0

        mock_metadata.assert_called_once()
示例#16
0
    def test_register_fail_client_create(self, mock_init):
        m = plugin.PluginManager()

        with pytest.raises(synse_errors.ClientCreateError):
            m.register('localhost:5432', 'tcp')

        # Ensure nothing was added to the manager.
        assert len(m.plugins) == 0

        mock_init.assert_called_once()
示例#17
0
    def test_refresh_removed_plugin(self, mock_refresh, load_mock, simple_plugin):
        m = plugin.PluginManager()
        m.plugins[simple_plugin.id] = simple_plugin
        simple_plugin.cancel_tasks = mock.MagicMock()
        assert simple_plugin.disabled is False

        m.refresh()

        assert simple_plugin.disabled is True
        load_mock.assert_called_once()
        simple_plugin.cancel_tasks.assert_called_once()
        mock_refresh.assert_has_calls([])
示例#18
0
    def test_iterate_has_plugins(self):
        m = plugin.PluginManager()
        m.plugins = {
            '1': 'placeholder',
            '2': 'placeholder',
            '3': 'placeholder',
            '4': 'placeholder',
        }

        assert isinstance(m, Iterable)
        assert 4 == len(list(m))

        # Ensure we iterate over the plugin dict values.
        for item in m:
            assert item == 'placeholder'
示例#19
0
    def test_bucket_plugins_no_plugins(self):
        m = plugin.PluginManager()
        assert len(m.plugins) == 0

        existing, new, removed = m.bucket_plugins([
            ('localhost:5001', 'tcp'),
            ('localhost:5002', 'tcp'),
            ('localhost:5003', 'tcp'),
        ])
        assert len(existing) == 0
        assert len(removed) == 0
        assert len(new) == 3

        assert ('localhost:5001', 'tcp') in new
        assert ('localhost:5002', 'tcp') in new
        assert ('localhost:5003', 'tcp') in new
示例#20
0
    def test_register_duplicate_plugin_id(self, mock_version, mock_metadata):
        m = plugin.PluginManager()
        m.plugins = {
            '123': plugin.Plugin(
                {'id': 'foo', 'tag': 'foo'},
                {},
                client.PluginClientV3('foo', 'tcp'),
            ),
        }

        plugin_id = m.register('localhost:5432', 'tcp')
        assert plugin_id == '123'
        # Ensure nothing new was added to the manager.
        assert len(m.plugins) == 1

        mock_metadata.assert_called_once()
        mock_version.assert_called_once()
示例#21
0
    def test_bucket_plugins(self):
        p1 = plugin.Plugin(
            client=client.PluginClientV3('localhost:5001', 'tcp'),
            version={},
            info={
                'tag': 'test/foo',
                'id': '123',
                'vcs': 'https://github.com/vapor-ware/synse-server',
            },
        )
        p2 = plugin.Plugin(
            client=client.PluginClientV3('localhost:5002', 'tcp'),
            version={},
            info={
                'tag': 'test/bar',
                'id': '456',
                'vcs': 'https://github.com/vapor-ware/synse-server',
            },
        )
        p1._reconnect = asynctest.CoroutineMock
        p2._reconnect = asynctest.CoroutineMock

        m = plugin.PluginManager()
        m.plugins[p1.id] = p1
        m.plugins[p2.id] = p2

        existing, new, removed = m.bucket_plugins([
            ('localhost:5001', 'tcp'),
            ('localhost:5003', 'tcp'),
        ])
        assert len(existing) == 1
        assert len(new) == 1
        assert len(removed) == 1

        assert ('localhost:5003', 'tcp') in new
        assert p1 in existing
        assert p2 in removed
示例#22
0
 def test_all_ready_true_no_plugins(self):
     m = plugin.PluginManager()
     assert m.all_ready() is True
示例#23
0
    def test_get_plugin_not_found(self):
        m = plugin.PluginManager()

        result = m.get('1')
        assert result is None
示例#24
0
 def test_load_tcp_one(self):
     m = plugin.PluginManager()
     loaded = m.load()
     assert len(loaded) == 1
示例#25
0
 def test_load_unix_multi(self):
     m = plugin.PluginManager()
     loaded = m.load()
     assert len(loaded) == 3
示例#26
0
 def test_load_tcp_and_unix(self):
     m = plugin.PluginManager()
     loaded = m.load()
     assert len(loaded) == 6
示例#27
0
    def test_discover_no_addresses_found(self, mock_discover):
        m = plugin.PluginManager()
        found = m.discover()

        assert len(found) == 0
        mock_discover.assert_called_once()
示例#28
0
    def test_discover_fail_kubernetes_discovery(self, mock_discover):
        m = plugin.PluginManager()
        found = m.discover()

        assert len(found) == 0
        mock_discover.assert_called_once()
示例#29
0
    def test_refresh_no_addresses(self):
        m = plugin.PluginManager()

        assert len(m.plugins) == 0
        m.refresh()
        assert len(m.plugins) == 0
示例#30
0
    def test_has_no_plugins(self):
        m = plugin.PluginManager()

        assert m.has_plugins() is False