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"
def test_installer_on_all_distros(base_image, init_system, agent_version): if agent_version.endswith("-post") and (base_image, init_system) in RPM_DISTROS: agent_version = agent_version.replace("-post", "~post") elif agent_version.endswith("~post") and (base_image, init_system) in DEB_DISTROS: agent_version = agent_version.replace("~post", "-post") args = "MYTOKEN" if agent_version == "latest" else f"--package-version {agent_version}-1 MYTOKEN" args = args if STAGE == "release" else f"--{STAGE} {args}" if agent_version == "latest" or tuple( agent_version.split(".")) >= ("5", "1", "0"): user = "******" else: user = None with _run_tests(base_image, init_system, args, user=user) as [backend, cont]: if agent_version != "latest": installed_version = get_agent_version(cont) agent_version = agent_version.replace("~", "-") assert ( installed_version == agent_version ), f"Installed agent version is {installed_version} but should be {agent_version}" try: assert wait_for( p(has_datapoint_with_dim, backend, "plugin", "host-metadata")), "Datapoints didn't come through" finally: print("\nDatapoints received:") for dp in backend.datapoints: print_dp_or_event(dp) print("\nEvents received:") for event in backend.events: print_dp_or_event(event) print(f"\nDimensions set: {backend.dims}")
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"
def run_puppet_agent(cont, backend, monitors, agent_version, stage): with tempfile.NamedTemporaryFile(mode="w+") as fd: fd.write(get_config(backend, monitors, agent_version, stage)) 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) 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), "Agent is not running as non-root user"
def run_chef_client(cont, chef_version, agent_version=None, stage="final"): attributes = json.loads(ATTRIBUTES_JSON % stage) attributes["signalfx_agent"]["agent_version"] = agent_version 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) assert is_agent_running_as_non_root( cont), "Agent is not running as non-root user" return get_agent_version(cont)
def run_salt(cont, backend, agent_version, monitors, stage): with tempfile.NamedTemporaryFile(mode="w+") as fd: config_yaml = get_config(backend, agent_version, monitors, stage) 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" 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), "Agent is not running as non-root user"