Пример #1
0
def test_old_entry_points_returning_a_list(tmp_path, salt_extension,
                                           salt_minion_factory):
    with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as venv:
        # Install our extension into the virtualenv
        venv.install(str(salt_extension.srcdir))
        installed_packages = venv.get_installed_packages()
        assert salt_extension.name in installed_packages
        code = """
        import sys
        import json

        # If the test fails, for debugging purposes, comment out the following 2 lines
        #import salt.log.setup
        #salt.log.setup.setup_console_logger(log_level="debug")

        import salt.loader

        minion_config = json.loads(sys.stdin.read())
        loader = salt.loader.runner(minion_config)
        print(json.dumps(list(loader)))
        """
        ret = venv.run_code(code,
                            input=json.dumps(
                                salt_minion_factory.config.copy()))
        loader_functions = json.loads(ret.stdout)

        # A non existing module should not appear in the loader
        assert "monty.python" not in loader_functions

        # But our extension's modules should appear on the loader
        assert "foobar.echo1" in loader_functions
        assert "foobar.echo2" in loader_functions
Пример #2
0
def test_salt_extensions_absent_in_versions_report(tmp_path, salt_extension):
    """
    Ensure that the 'Salt Extensions' header does not show up when no extension is installed
    """
    with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as venv:
        installed_packages = venv.get_installed_packages()
        assert salt_extension.name not in installed_packages
        ret = venv.run_code("""
            import json
            import salt.version

            print(json.dumps(salt.version.versions_information()))
            """)
    versions_information = json.loads(ret.stdout)
    assert "Salt Extensions" not in versions_information
Пример #3
0
def test_salt_extensions_in_versions_report(tmp_path, salt_extension):
    with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as venv:
        # Install our extension into the virtualenv
        venv.install(str(salt_extension.srcdir))
        installed_packages = venv.get_installed_packages()
        assert salt_extension.name in installed_packages
        ret = venv.run_code("""
            import json
            import salt.version

            print(json.dumps(salt.version.versions_information()))
            """)
    versions_information = json.loads(ret.stdout)
    assert "Salt Extensions" in versions_information
    assert salt_extension.name in versions_information["Salt Extensions"]
Пример #4
0
def venv(tmp_path):
    with SaltVirtualEnv(venv_dir=tmp_path / ".venv") as _venv:
        yield _venv