Beispiel #1
0
 def test_plugin_bad_uninstall(self, *args):
     pm = PluginManager(self.base_dir,
                        self.instance,
                        self.fake_service,
                        lister_fn=self.list_plugins)
     pm.start()
     res = pm.uninstall(self.get_test_plugin_path('plugin1'))
     assert not res["installed"]
Beispiel #2
0
    def test_load_plugin_enabled(self, *args):
        plugin_url = self.get_test_plugin_path('plugin1')
        plugin_id = self.get_test_id('plugin1')
        db_plugin = PluginData(name="plugin1",
                               description="x",
                               enabled=True,
                               app_url=plugin_url,
                               machine=self.instance)
        install_dir = self.base_dir / "plugins" / plugin_id
        venv_dir = self.base_dir / "venv" / plugin_id

        db_plugin.save(force_insert=True)
        shutil.copytree(plugin_url, str(install_dir))

        VirtualEnvManager(venv_dir).install(install_dir / "requirements.txt")

        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()

        expected = {
            "name": "plugin1",
            "description": "description",
            "id": plugin_id,
            "enabled": True,
            "installed": True,
            "active": True,
            "remote_url": plugin_url,
        }
        assert pm.plugin_state(plugin_url) == expected

        pm.stop()
Beispiel #3
0
    def test_plugin_listing(self, *args):
        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()

        expected = [{
            "name": "plugin1",
            "description": "description",
            "id": self.get_test_id('plugin1'),
            "enabled": False,
            "installed": False,
            "active": False,
            "remote_url": self.get_test_plugin_path('plugin1'),
        }]

        assert pm.list() == expected
Beispiel #4
0
def handle_messaging_plugin_install():
    machine_id = get_machine_id()
    base_path = get_config_path()
    plugins_db = PluginsDatabase(os.path.join(base_path, "db"))
    plugin_manager = PluginManager(base_path)

    plugins_db.start()

    git_plugin = GitPlugin(MESSAGING_PLUGIN_URL, "WeaveServer", "Messaging")
    plugin_manager.install(git_plugin)

    token = "app-token-" + str(uuid4())
    instance_data = WeaveEnvInstanceData(machine_id=machine_id,
                                         app_token=token)
    plugin_data = PluginData(app_id=url_to_plugin_id(MESSAGING_PLUGIN_URL),
                             name="WeaveServer",
                             description="Messaging",
                             enabled=True,
                             machine=instance_data)
    plugin_data.save(force_insert=True)
    instance_data.save(force_insert=True)
Beispiel #5
0
    def test_activate_disabled_plugin(self, *args):
        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()

        plugin_url = self.get_test_plugin_path('plugin1')
        plugin = pm.install(plugin_url)

        with pytest.raises(PluginLoadError, match=".*not enabled.*"):
            pm.activate(plugin_url)
Beispiel #6
0
    def test_load_plugin_not_enabled(self, *args):
        plugin_url = self.get_test_plugin_path('plugin1')
        db_plugin = PluginData(name="plugin1",
                               description="x",
                               app_url=plugin_url,
                               machine=self.instance)
        db_plugin.save(force_insert=True)

        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()

        assert pm.plugin_state(plugin_url) == {
            "name": "plugin1",
            "description": "description",
            "id": self.get_test_id('plugin1'),
            "enabled": False,
            "installed": False,
            "active": False,
            "remote_url": self.get_test_plugin_path('plugin1'),
        }
Beispiel #7
0
def handle_main():
    base_path = get_config_path()
    plugins_db = PluginsDatabase(os.path.join(base_path, "db"))
    plugin_manager = PluginManager(base_path)

    plugins_db.start()

    weave = LocalWeaveInstance(get_instance_data(), plugin_manager)
    try:
        weave.start()
    except WeaveException:
        weave.stop()

    signal.signal(signal.SIGTERM, lambda x, y: weave.stop())
    signal.signal(signal.SIGINT, lambda x, y: weave.stop())

    weave.wait()
Beispiel #8
0
def handle_main():
    machine_id = get_machine_id()
    base_path = get_config_path()
    plugins_db = PluginsDatabase(os.path.join(base_path, "db"))
    plugin_manager = PluginManager(base_path)

    plugins_db.start()

    try:
        instance_data = WeaveEnvInstanceData.get(
            WeaveEnvInstanceData.machine_id == machine_id)
    except DoesNotExist:
        sys.exit("Please re-install messaging plugin.")

    weave = LocalWeaveInstance(instance_data, plugin_manager)
    weave.start()

    signal.signal(signal.SIGTERM, lambda x, y: weave.stop())
    signal.signal(signal.SIGINT, lambda x, y: weave.stop())

    weave.wait()
Beispiel #9
0
    def test_plugin_double_install(self, *args):
        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()
        res1 = pm.install(self.get_test_plugin_path('plugin1'))

        expected = {
            "name": "plugin1",
            "description": "description",
            "id": self.get_test_id('plugin1'),
            "enabled": False,
            "installed": True,
            "active": False,
            "remote_url": self.get_test_plugin_path('plugin1'),
        }

        res2 = pm.install(self.get_test_plugin_path('plugin1'))
        assert res1 == res2 == expected
Beispiel #10
0
    def test_activate(self, *args):
        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()

        plugin_url = self.get_test_plugin_path('plugin1')
        pm.install(plugin_url)
        pm.enable(plugin_url)
        result = pm.activate(plugin_url)

        expected = {
            "name": "plugin1",
            "description": "description",
            "id": self.get_test_id('plugin1'),
            "enabled": True,
            "installed": True,
            "active": True,
            "remote_url": self.get_test_plugin_path('plugin1'),
        }
        assert result == expected

        result = pm.deactivate(plugin_url)
        expected = {
            "name": "plugin1",
            "description": "description",
            "id": self.get_test_id('plugin1'),
            "enabled": True,
            "installed": True,
            "active": False,
            "remote_url": self.get_test_plugin_path('plugin1'),
        }
        assert result == expected

        pm.stop()
Beispiel #11
0
    def test_uninstall_enabled_plugin(self, *args):
        pm = PluginManager(self.base_dir,
                           self.instance,
                           self.fake_service,
                           lister_fn=self.list_plugins)
        pm.start()
        plugin_url = self.get_test_plugin_path('plugin1')
        pm.install(plugin_url)
        pm.enable(plugin_url)

        with pytest.raises(PluginLoadError,
                           match="Must disable the plugin .*"):
            pm.uninstall(self.get_test_plugin_path('plugin1'))

        pm.stop()