示例#1
0
def common_test_only_python_mapped_to_python3(install_package_fn,
                                              install_next_version_fn):
    """
    Test package installation on the machine with python3 but there is only 'python' command which is mapped on to it.
    :param install_package_fn: callable that installs package with appropriate type to the current machine OS.
    """

    # map 'python' command on to python3
    _link_to_default_python("python3")
    _remove_python("python2")
    _remove_python("python3")

    stdout, _ = install_package_fn()

    # make sure that installer has found 'python' mapped on to python3
    # this is signaled by the install script not trying to switch the interpreter
    assert "Switching the Python interpreter used by the Scalyr Agent" not in stdout

    # 'scalyr-agent-2-config' command must be a symlink to config_main.py
    assert _get_current_config_script_name() == "config_main.py"

    runner = AgentRunner(PACKAGE_INSTALL)
    runner.start()
    time.sleep(1)

    assert _get_python_major_version(runner) == 3
    runner.stop()

    # install next version of the package
    install_next_version_fn()

    # the source file should be "config_main.py"
    assert _get_current_config_script_name() == "config_main.py"
示例#2
0
def _test_standalone_smoke(agent_installation_type, python_version=None):
    """
    Agent standalone test to run within the same machine.
    """
    if agent_installation_type == DEV_INSTALL:
        os.chdir(get_package_root())

    print("Agent host name: {0}".format(
        compat.os_environ_unicode["AGENT_HOST_NAME"]))

    runner = AgentRunner(agent_installation_type, enable_debug_log=True)

    if python_version:
        runner.switch_version(python_version)

    agent_log_verifier = AgentLogVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    data_json_verifier = DataJsonVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    system_metrics_verifier = SystemMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    process_metrics_verifier = ProcessMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])

    # NOTE: It's important that the file exists before starting the agent otherwise it won't be
    # consumed by the agent and the tests will fail.
    agent_logs_dir_path = six.text_type(runner.agent_logs_dir_path)
    data_log_path = six.text_type(data_json_verifier._data_json_log_path)

    if os.path.exists(data_log_path):
        os.utime(data_log_path, None)
    else:
        try:
            os.makedirs(agent_logs_dir_path)
        except OSError:
            pass

        with open(data_log_path, "a") as _:
            pass

    runner.start()

    time.sleep(1)

    print("Verify 'agent.log'")
    assert agent_log_verifier.verify(
    ), "Verification of the file: 'agent.log' failed"
    print("Verify 'linux_system_metrics.log'")
    assert (system_metrics_verifier.verify()
            ), "Verification of the file: 'linux_system_metrics.log' failed"
    print("Verify 'linux_process_metrics.log'")
    assert (process_metrics_verifier.verify()
            ), "Verification of the file: 'linux_process_metrics.log' failed"

    assert data_json_verifier.verify(
    ), "Verification of the file: 'data.json' failed"

    runner.stop()
示例#3
0
def common_test_switch_default_to_python2(install_package_fn,
                                          install_next_version_fn):
    """
    Test package installation on machine with python and python2.
    Package installer should pick 'python' by default and then we switch it to python2 and get back to default.
    :param install_package_fn: callable that installs package with appropriate type to the current machine OS.
    """

    # let python2 be default.
    _link_to_default_python("python2")
    _remove_python("python3")

    stdout, _ = install_package_fn()

    # make sure that installer has found 'python' mapped on to python2.
    # this is signaled by the install script not trying to switch the interpreter
    assert "Switching the Python interpreter used by the Scalyr Agent" not in stdout

    assert _get_current_config_script_name() == "config_main.py"

    runner = AgentRunner(PACKAGE_INSTALL)
    runner.start()
    time.sleep(1)

    assert _get_python_major_version(runner) == 2

    # switching to python2
    runner.stop()
    runner.switch_version("python2")
    assert _get_current_config_script_name() == "config_main_py2.py"
    runner.start()
    time.sleep(1)
    assert _get_python_major_version(runner) == 2
    runner.stop()

    # install next version of the package and check that links are the same.
    stdout, _ = install_next_version_fn()
    # Installer must not switch to default python.
    assert "Switching the Python interpreter used by the Scalyr Agent" not in stdout
    # the source file should be "config_main_py3.py"
    assert _get_current_config_script_name() == "config_main_py2.py"

    # switching back to default python
    runner.switch_version("default")
    assert _get_current_config_script_name() == "config_main.py"
    runner.start()
    time.sleep(1)
    assert _get_python_major_version(runner) == 2
示例#4
0
def _test_standalone_smoke(agent_installation_type, python_version=None):
    """
    Agent standalone test to run within the same machine.
    """
    if agent_installation_type == DEV_INSTALL:
        os.chdir(get_package_root())

    print("Agent host name: {0}".format(
        compat.os_environ_unicode["AGENT_HOST_NAME"]))

    runner = AgentRunner(agent_installation_type, enable_debug_log=True)

    if python_version:
        runner.switch_version(python_version)

    agent_log_verifier = AgentLogVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    data_json_verifier = DataJsonVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    system_metrics_verifier = SystemMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])
    process_metrics_verifier = ProcessMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"])

    _create_data_json_file(runner=runner,
                           data_json_verifier=data_json_verifier)

    runner.start()

    time.sleep(1)

    print("Verify 'agent.log'")
    assert agent_log_verifier.verify(
    ), "Verification of the file: 'agent.log' failed"
    print("Verify 'linux_system_metrics.log'")
    assert (system_metrics_verifier.verify()
            ), "Verification of the file: 'linux_system_metrics.log' failed"
    print("Verify 'linux_process_metrics.log'")
    assert (process_metrics_verifier.verify()
            ), "Verification of the file: 'linux_process_metrics.log' failed"

    assert data_json_verifier.verify(
    ), "Verification of the file: 'data.json' failed"

    runner.stop()
示例#5
0
def test_default_compression_algorithm(request):
    runner = AgentRunner(PACKAGE_INSTALL, send_to_server=False)

    # deflate is the default
    install_rpm()

    runner.start()
    time.sleep(1)

    agent_status = runner.status_json(True)
    compression_algorithm = agent_status["compression_type"]
    compression_level = agent_status["compression_level"]

    assert compression_algorithm == "deflate", "expected deflate, got %s" % (
        compression_algorithm)
    assert compression_level == 6

    runner.stop()
示例#6
0
def common_test_switch_python2_to_python3(install_package_fn,
                                          install_next_version_fn):
    """
    Test package installation on machine with both python2 and python3 but without default 'python'.
    Package installer should pick python2 by default and then we switch to the python3.
    :param install_package_fn: callable that installs package with appropriate type to the current machine OS.
    """
    _remove_python("python")

    install_package_fn()
    assert _get_current_config_script_name() == "config_main_py2.py"

    runner = AgentRunner(PACKAGE_INSTALL)
    runner.start()
    time.sleep(1)

    assert _get_python_major_version(runner) == 2

    # switching to python3
    runner.stop()
    runner.switch_version("python3")
    assert _get_current_config_script_name() == "config_main_py3.py"
    runner.start()
    time.sleep(1)
    assert _get_python_major_version(runner) == 3
    runner.stop()

    # install next version of the package and check that links are the same.
    stdout, _ = install_next_version_fn()
    # Installer must not switch to default python.
    assert "Switching the Python interpreter used by the Scalyr Agent" not in stdout
    # the source file should be "config_main_py3.py"
    assert _get_current_config_script_name() == "config_main_py3.py"

    # switching bach to python2
    runner.switch_version("python2")
    assert _get_current_config_script_name() == "config_main_py2.py"
    runner.start()
    time.sleep(1)
    assert _get_python_major_version(runner) == 2
示例#7
0
def common_test_python2(install_package_fn, install_next_version_fn):
    """
    Test package installation on machine with python2.

    The function also verifies correct rc*.d symlinks are created.

    :param install_package_fn: callable that installs package with appropriate type to the current machine OS.
    """

    _remove_python("python")
    _remove_python("python3")

    # rc.d symlinks shouldn't exist before install
    files = _get_agent_rc_d_symlinks()
    assert len(files) == 0

    stdout, _ = install_package_fn()

    # But they should have been created during the postinst step
    _assert_rc_d_symlinks_exist()

    # make sure that installer has found 'python2'.
    assert "The default 'python' command not found, will use python2 binary" in stdout

    # 'scalyr-agent-2-config' command must be a symlink to config_main_py2.py
    assert _get_current_config_script_name() == "config_main_py2.py"

    runner = AgentRunner(PACKAGE_INSTALL)
    runner.start()

    time.sleep(1)

    assert _get_python_major_version(runner) == 2
    runner.stop()

    # install next version of the package
    stdout, _ = install_next_version_fn()
    # the source file should be "config_main_py2.py"
    assert _get_current_config_script_name() == "config_main_py2.py"
示例#8
0
def _test_standalone_smoke(
    agent_installation_type,
    python_version=None,
    rate_limited=False,
    workers_type="thread",
    workers_sessions_count=1,
):
    """
    Agent standalone test to run within the same machine.
    """
    if agent_installation_type == DEV_INSTALL:
        os.chdir(get_package_root())

    print("Agent host name: {0}".format(compat.os_environ_unicode["AGENT_HOST_NAME"]))

    runner = AgentRunner(
        agent_installation_type,
        enable_debug_log=True,
        workers_type=workers_type,
        workers_session_count=workers_sessions_count,
    )

    if python_version:
        runner.switch_version(python_version)

    agent_log_verifier = AgentLogVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"]
    )
    worker_sessions_verifier = None

    if workers_type == "process":
        worker_sessions_verifier = AgentWorkerSessionLogVerifier(
            runner, compat.os_environ_unicode["SCALYR_SERVER"]
        )

    if rate_limited:
        data_json_verifier = DataJsonVerifierRateLimited(
            runner, compat.os_environ_unicode["SCALYR_SERVER"]
        )
    else:
        data_json_verifier = DataJsonVerifier(
            runner, compat.os_environ_unicode["SCALYR_SERVER"]
        )
    system_metrics_verifier = SystemMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"]
    )
    process_metrics_verifier = ProcessMetricsVerifier(
        runner, compat.os_environ_unicode["SCALYR_SERVER"]
    )

    _create_data_json_file(runner=runner, data_json_verifier=data_json_verifier)

    runner.start()

    time.sleep(1)

    print("Verify 'agent.log'")
    assert agent_log_verifier.verify(), "Verification of the file: 'agent.log' failed"

    if workers_type == "process":
        # if workers are multiprocess, then we check if worker session logs are ingested.
        print("Verify worker sessions log files.")
        assert (
            worker_sessions_verifier.verify()
        ), "Verification of the worker session log files is failed"

    print("Verify 'linux_system_metrics.log'")
    assert (
        system_metrics_verifier.verify()
    ), "Verification of the file: 'linux_system_metrics.log' failed"
    print("Verify 'linux_process_metrics.log'")
    assert (
        process_metrics_verifier.verify()
    ), "Verification of the file: 'linux_process_metrics.log' failed"

    assert data_json_verifier.verify(), "Verification of the file: 'data.json' failed"

    if workers_type == "process":
        # increase worker sessions count, restart and also check if all worker logs are ingested.
        config = runner.config
        sessions_count = config["default_sessions_per_worker"]
        sessions_count += 1

        worker_sessions_verifier = AgentWorkerSessionLogVerifier(
            runner, compat.os_environ_unicode["SCALYR_SERVER"]
        )

        config["default_sessions_per_worker"] = sessions_count
        runner.write_config(config)
        runner.restart()

        agent_status = json.loads(runner.status_json())
        assert (
            len(agent_status["copying_manager_status"]["workers"][-1]["sessions"])
            == sessions_count
        )

        print("Verify worker sessions log files.")

        assert (
            worker_sessions_verifier.verify()
        ), "Verification of the worker session log files is failed"

    runner.stop()