Esempio n. 1
0
def run_ansible(cont,
                init_system,
                backend,
                monitors,
                agent_version,
                stage,
                user="******"):
    with tempfile.NamedTemporaryFile(mode="w+") as fd:
        config_yaml = get_config(backend, monitors, agent_version, stage, user)
        print(config_yaml)
        fd.write(config_yaml)
        fd.flush()
        copy_file_into_container(fd.name, cont, CONFIG_DEST_PATH)
    code, output = cont.exec_run(ANSIBLE_CMD)
    assert code == 0, output.decode("utf-8")
    print_lines(output)
    verify_override_files(cont, init_system, user)
    installed_version = get_agent_version(cont).replace("~", "-")
    agent_version = re.sub(r"-\d+$", "", agent_version).replace("~", "-")
    assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % (
        installed_version,
        agent_version,
    )
    assert is_agent_running_as_non_root(
        cont, user=user), f"Agent is not running as {user} user"
def run_puppet_agent(cont,
                     init_system,
                     backend,
                     monitors,
                     agent_version,
                     stage,
                     user="******"):
    with tempfile.NamedTemporaryFile(mode="w+") as fd:
        hiera_yaml = get_hiera(HIERA_SRC_PATH, backend, monitors)
        print(hiera_yaml)
        fd.write(hiera_yaml)
        fd.flush()
        copy_file_into_container(fd.name, cont, HIERA_DEST_PATH)
    with tempfile.NamedTemporaryFile(mode="w+") as fd:
        config = get_config(agent_version, stage, user=user)
        print(config)
        fd.write(config)
        fd.flush()
        copy_file_into_container(fd.name, cont, "/root/agent.pp")
    code, output = cont.exec_run("puppet apply /root/agent.pp")
    assert code in (0, 2), output.decode("utf-8")
    print_lines(output)
    verify_override_files(cont, init_system, user)
    installed_version = get_agent_version(cont)
    assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % (
        installed_version,
        agent_version,
    )
    assert is_agent_running_as_non_root(
        cont, user=user), f"Agent is not running as {user} user"
Esempio n. 3
0
def run_chef_client(cont,
                    init_system,
                    chef_version,
                    agent_version,
                    stage,
                    monitors,
                    user="******"):
    attributes = json.loads(ATTRIBUTES_JSON)
    attributes["signalfx_agent"]["agent_version"] = agent_version
    attributes["signalfx_agent"]["package_stage"] = stage
    attributes["signalfx_agent"]["user"] = user
    attributes["signalfx_agent"]["group"] = user
    attributes["signalfx_agent"]["conf"]["monitors"] = monitors
    print(attributes)
    with tempfile.NamedTemporaryFile(mode="w", dir="/tmp/scratch") as fd:
        fd.write(json.dumps(attributes))
        fd.flush()
        cmd = CHEF_CMD.format(fd.name)
        if chef_version == "latest" or int(chef_version.split(".")[0]) >= 15:
            cmd += " --chef-license accept-silent"
        print('running "%s" ...' % cmd)
        code, output = cont.exec_run(cmd)
        output = output.decode("utf-8").strip()
        assert code == 0, "failed to install agent:\n%s" % output
        print(output)
    verify_override_files(cont, init_system, user)
    installed_version = get_agent_version(cont)
    assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % (
        installed_version,
        agent_version,
    )
    assert is_agent_running_as_non_root(
        cont, user=user), f"Agent is not running as {user} user"
Esempio n. 4
0
def _run_tests(base_image,
               init_system,
               installer_args,
               user=None,
               **extra_run_kwargs):
    if user:
        installer_args = f"--service-user {user} --service-group {user} {installer_args}"
    else:
        user = "******"
    with run_init_system_image(base_image,
                               **extra_run_kwargs) as [cont, backend]:
        copy_file_into_container(INSTALLER_PATH, cont, "/opt/install.sh")

        # Unfortunately, wget and curl both don't like self-signed certs, even
        # if they are in the system bundle, so we need to use the --insecure
        # flag.
        code, output = cont.exec_run(
            f"sh /opt/install.sh --insecure {installer_args}")
        print("Output of install script:")
        print_lines(output)
        assert code == 0, "Agent could not be installed!"

        try:
            verify_override_files(cont, init_system, user)
            assert is_agent_running_as_non_root(
                cont, user), f"Agent is not running as {user} user"
            yield backend, cont
        finally:
            print("Agent log:")
            print_lines(get_agent_logs(cont, init_system))
Esempio n. 5
0
def run_salt(cont, init_system, backend, agent_version, monitors, stage, user="******"):
    with tempfile.NamedTemporaryFile(mode="w+") as fd:
        config_yaml = get_config(backend, agent_version, monitors, stage, user)
        print(config_yaml)
        fd.write(config_yaml)
        fd.flush()
        copy_file_into_container(fd.name, cont, PILLAR_PATH)

    code, output = cont.exec_run(SALT_CMD)
    print_lines(output)
    assert code == 0, f"'{SALT_CMD}' failed"

    verify_override_files(cont, init_system, user)

    installed_version = get_agent_version(cont)
    assert installed_version == agent_version, "installed agent version is '%s', expected '%s'" % (
        installed_version,
        agent_version,
    )

    assert is_agent_running_as_non_root(cont, user), f"Agent is not running as {user} user"