def test_puppet_without_fluentd(distro, puppet_release): if "jessie" in distro and puppet_release != "6": pytest.skip( f"Puppet release version {puppet_release} not supported on debian jessie" ) if distro in DEB_DISTROS: dockerfile = IMAGES_DIR / "deb" / f"Dockerfile.{distro}" else: dockerfile = IMAGES_DIR / "rpm" / f"Dockerfile.{distro}" buildargs = {"PUPPET_RELEASE": puppet_release} with run_distro_container(distro, dockerfile=dockerfile, path=REPO_DIR, buildargs=buildargs) as container: try: config = CONFIG.substitute(collector_version="latest", with_fluentd="false") run_puppet_apply(container, config) verify_env_file(container) assert wait_for(lambda: service_is_running(container)) assert container.exec_run( "systemctl status td-agent").exit_code != 0 finally: run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_installer_without_fluentd(distro, version): install_cmd = f"sh -x /test/install.sh -- testing123 --realm us0 --memory {TOTAL_MEMORY} --without-fluentd" if version != "latest": install_cmd = f"{install_cmd} --collector-version {version.lstrip('v')}" if STAGE != "release": assert STAGE in ("test", "beta"), f"Unsupported stage '{STAGE}'!" install_cmd = f"{install_cmd} --{STAGE}" print(f"Testing installation on {distro} from {STAGE} stage ...") with run_distro_container(distro) as container: copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: # run installer script run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) config_path = AGENT_CONFIG_PATH if container.exec_run(f"test -f {OLD_CONFIG_PATH}").exit_code == 0: config_path = OLD_CONFIG_PATH splunk_env_path = SPLUNK_ENV_PATH if container.exec_run( f"test -f {OLD_SPLUNK_ENV_PATH}").exit_code == 0: splunk_env_path = OLD_SPLUNK_ENV_PATH # verify env file created with configured parameters run_container_cmd( container, f"grep '^SPLUNK_CONFIG={config_path}$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}") run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}" ) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=SERVICE_OWNER)) if distro in DEB_DISTROS: assert container.exec_run("dpkg -s td-agent").exit_code != 0 else: assert container.exec_run("rpm -q td-agent").exit_code != 0 run_container_cmd(container, "sh -x /test/install.sh --uninstall") finally: run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_collector_package_upgrade(distro): install_cmd = f"sh /test/install.sh -- testing123 --realm test --without-fluentd --collector-version 0.35.0" pkg_path = get_package(distro, PKG_NAME, PKG_DIR) assert pkg_path, f"{PKG_NAME} package not found in {PKG_DIR}" pkg_base = os.path.basename(pkg_path) with run_distro_container(distro) as container: copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: # install an older version of the collector package run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=SERVICE_OWNER)) # change the config run_container_cmd( container, f"sh -c 'echo \"# This line should be preserved\" >> {AGENT_CONFIG_PATH}'" ) copy_file_into_container(container, pkg_path, f"/test/{pkg_base}") # upgrade package if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -i --force-confold /test/{pkg_base}") else: run_container_cmd(container, f"rpm -U /test/{pkg_base}") time.sleep(5) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=SERVICE_OWNER)) # verify changed config was preserved after upgrade run_container_cmd( container, f"grep '# This line should be preserved' {AGENT_CONFIG_PATH}") finally: run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_installer(distro, version, memory_option): install_cmd = f"sh -x /test/install.sh -- testing123 --realm us0" if memory_option == "memory": install_cmd = f"{install_cmd} --{memory_option} {TOTAL_MEMORY}" elif memory_option == "ballast": install_cmd = f"{install_cmd} --{memory_option} {BALLAST}" if version != "latest": install_cmd = f"{install_cmd} --collector-version {version.lstrip('v')}" if STAGE != "release": assert STAGE in ("test", "beta"), f"Unsupported stage '{STAGE}'!" install_cmd = f"{install_cmd} --{STAGE}" print(f"Testing installation on {distro} from {STAGE} stage ...") with run_distro_container(distro) as container: # run installer script copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) # verify env file created with configured parameters splunk_env_path = SPLUNK_ENV_PATH if container.exec_run(f"test -f {OLD_SPLUNK_ENV_PATH}").exit_code == 0: splunk_env_path = OLD_SPLUNK_ENV_PATH run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}") run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}") if memory_option == "memory": run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}") elif memory_option == "ballast": run_container_cmd(container, f"grep '^SPLUNK_BALLAST_SIZE_MIB={BALLAST}$' {splunk_env_path}") # verify collector service status assert wait_for(lambda: service_is_running(container, service_owner=SERVICE_OWNER)) # the td-agent service should only be running when installing # collector packages that have our custom fluent config if container.exec_run("test -f /etc/otel/collector/fluentd/fluent.conf").exit_code == 0: assert container.exec_run("systemctl status td-agent").exit_code == 0 else: assert container.exec_run("systemctl status td-agent").exit_code != 0 run_container_cmd(container, "sh -x /test/install.sh --uninstall") finally: run_container_cmd(container, "journalctl -u td-agent --no-pager") if container.exec_run("test -f /var/log/td-agent/td-agent.log").exit_code == 0: run_container_cmd(container, "cat /var/log/td-agent/td-agent.log") run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_installer_mode(distro, version, mode): install_cmd = f"sh -x /test/install.sh -- testing123 --realm {REALM} --memory {TOTAL_MEMORY} --mode {mode}" if version != "latest": install_cmd = f"{install_cmd} --collector-version {version.lstrip('v')}" if STAGE != "release": assert STAGE in ("test", "beta"), f"Unsupported stage '{STAGE}'!" install_cmd = f"{install_cmd} --{STAGE}" print(f"Testing installation on {distro} from {STAGE} stage ...") with run_distro_container(distro) as container: # run installer script copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) # verify env file created with configured parameters verify_env_file(container, mode=mode) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=SERVICE_OWNER)) if "opensuse" not in distro: assert container.exec_run( "systemctl status td-agent").exit_code == 0 # test support bundle script verify_support_bundle(container) run_container_cmd(container, "sh -x /test/install.sh --uninstall") finally: if "opensuse" not in distro: run_container_cmd(container, "journalctl -u td-agent --no-pager") if container.exec_run("test -f /var/log/td-agent/td-agent.log" ).exit_code == 0: run_container_cmd(container, "cat /var/log/td-agent/td-agent.log") run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_salt_without_fluentd(distro): if distro in DEB_DISTROS: dockerfile = IMAGES_DIR / "deb" / f"Dockerfile.{distro}" else: dockerfile = IMAGES_DIR / "rpm" / f"Dockerfile.{distro}" with run_distro_container(distro, dockerfile=dockerfile, path=REPO_DIR) as container: try: config = CONFIG.substitute(collector_version="latest", install_fluentd=False) run_salt_apply(container, config) verify_env_file(container) assert wait_for(lambda: service_is_running(container)) assert container.exec_run( "systemctl status td-agent").exit_code != 0 finally: run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_installer_mode(distro, version, mode): install_cmd = f"sh -x /test/install.sh -- testing123 --realm us0 --memory {TOTAL_MEMORY} --mode {mode}" if version != "latest": install_cmd = f"{install_cmd} --collector-version {version.lstrip('v')}" if STAGE != "release": assert STAGE in ("test", "beta"), f"Unsupported stage '{STAGE}'!" install_cmd = f"{install_cmd} --{STAGE}" print(f"Testing installation on {distro} from {STAGE} stage ...") with run_distro_container(distro) as container: # run installer script copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) config_path = AGENT_CONFIG_PATH if mode == "agent" else GATEWAY_CONFIG_PATH if container.exec_run(f"test -f {OLD_CONFIG_PATH}").exit_code == 0: config_path = OLD_CONFIG_PATH elif mode == "gateway" and container.exec_run( f"test -f {GATEWAY_CONFIG_PATH}").exit_code != 0: config_path = AGENT_CONFIG_PATH # verify env file created with configured parameters splunk_env_path = SPLUNK_ENV_PATH if container.exec_run( f"test -f {OLD_SPLUNK_ENV_PATH}").exit_code == 0: splunk_env_path = OLD_SPLUNK_ENV_PATH run_container_cmd( container, f"grep '^SPLUNK_CONFIG={config_path}$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}") run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}" ) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=SERVICE_OWNER)) # the td-agent service should only be running when installing # collector packages that have our custom fluent config if container.exec_run( "test -f /etc/otel/collector/fluentd/fluent.conf" ).exit_code == 0: assert container.exec_run( "systemctl status td-agent").exit_code == 0 else: assert container.exec_run( "systemctl status td-agent").exit_code != 0 # test support bundle script # if container.exec_run("test -f /etc/otel/collector/splunk-support-bundle.sh").exit_code == 0: # run_container_cmd(container, "/etc/otel/collector/splunk-support-bundle.sh -t /tmp/splunk-support-bundle") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/config/agent_config.yaml") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/logs/splunk-otel-collector.log") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/logs/splunk-otel-collector.txt") # if container.exec_run("test -f /etc/otel/collector/fluentd/fluent.conf").exit_code == 0: # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/logs/td-agent.log") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/logs/td-agent.txt") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/metrics/collector-metrics.txt") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/metrics/df.txt") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/metrics/free.txt") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/metrics/top.txt") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle/zpages/tracez.html") # run_container_cmd(container, "test -f /tmp/splunk-support-bundle.tar.gz") run_container_cmd(container, "sh -x /test/install.sh --uninstall") finally: run_container_cmd(container, "journalctl -u td-agent --no-pager") if container.exec_run( "test -f /var/log/td-agent/td-agent.log").exit_code == 0: run_container_cmd(container, "cat /var/log/td-agent/td-agent.log") run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_installer_service_owner(distro, version): service_owner = "test-user" install_cmd = f"sh -x /test/install.sh -- testing123 --realm us0 --memory {TOTAL_MEMORY}" install_cmd = f"{install_cmd} --service-user {service_owner} --service-group {service_owner}" if version != "latest": install_cmd = f"{install_cmd} --collector-version {version.lstrip('v')}" if STAGE != "release": assert STAGE in ("test", "beta"), f"Unsupported stage '{STAGE}'!" install_cmd = f"{install_cmd} --{STAGE}" print(f"Testing installation on {distro} from {STAGE} stage ...") with run_distro_container(distro) as container: copy_file_into_container(container, INSTALLER_PATH, "/test/install.sh") try: # run installer script run_container_cmd(container, install_cmd, env={"VERIFY_ACCESS_TOKEN": "false"}) time.sleep(5) config_path = AGENT_CONFIG_PATH if container.exec_run(f"test -f {OLD_CONFIG_PATH}").exit_code == 0: config_path = OLD_CONFIG_PATH splunk_env_path = SPLUNK_ENV_PATH if container.exec_run( f"test -f {OLD_SPLUNK_ENV_PATH}").exit_code == 0: splunk_env_path = OLD_SPLUNK_ENV_PATH # verify env file created with configured parameters run_container_cmd( container, f"grep '^SPLUNK_CONFIG={config_path}$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_ACCESS_TOKEN=testing123$' {splunk_env_path}") run_container_cmd(container, f"grep '^SPLUNK_REALM=us0$' {splunk_env_path}") run_container_cmd( container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={TOTAL_MEMORY}$' {splunk_env_path}" ) # verify collector service status assert wait_for(lambda: service_is_running( container, service_owner=service_owner)) # the td-agent service should only be running when installing # collector packages that have our custom fluent config if container.exec_run( "test -f /etc/otel/collector/fluentd/fluent.conf" ).exit_code == 0: assert container.exec_run( "systemctl status td-agent").exit_code == 0 else: assert container.exec_run( "systemctl status td-agent").exit_code != 0 finally: run_container_cmd(container, "journalctl -u td-agent --no-pager") run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager")
def test_collector_package_install(distro): pkg_path = get_package(distro, PKG_NAME, PKG_DIR) assert pkg_path, f"{PKG_NAME} package not found in {PKG_DIR}" pkg_base = os.path.basename(pkg_path) with run_distro_container(distro) as container: # install setcap dependency if distro in RPM_DISTROS: run_container_cmd(container, get_libcap_command(container)) else: run_container_cmd(container, "apt-get update") run_container_cmd(container, "apt-get install -y libcap2-bin") copy_file_into_container(container, pkg_path, f"/test/{pkg_base}") try: # install package if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -i /test/{pkg_base}") else: run_container_cmd(container, f"rpm -i /test/{pkg_base}") run_container_cmd(container, f"test -d {BUNDLE_DIR}") run_container_cmd(container, f"test -d {BUNDLE_DIR}/run/collectd") run_container_cmd(container, f"test -f {AGENT_CONFIG_PATH}") run_container_cmd(container, f"test -f {GATEWAY_CONFIG_PATH}") # verify service is not running after install without config file time.sleep(5) assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC) # verify service starts with config file run_container_cmd(container, f"cp -f {ENV_PATH}.example {ENV_PATH}") run_container_cmd(container, f"systemctl start {SERVICE_NAME}") time.sleep(5) assert wait_for(lambda: service_is_running( container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC)) # verify service restart run_container_cmd(container, f"systemctl restart {SERVICE_NAME}") time.sleep(5) assert wait_for(lambda: service_is_running( container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC)) # verify service stop run_container_cmd(container, f"systemctl stop {SERVICE_NAME}") time.sleep(5) assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC) finally: run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager") # verify uninstall run_container_cmd(container, f"systemctl start {SERVICE_NAME}") time.sleep(5) if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -P {PKG_NAME}") else: run_container_cmd(container, f"rpm -e {PKG_NAME}") time.sleep(5) assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC) # verify config file is not removed run_container_cmd(container, f"test -f {ENV_PATH}")
def test_collector_package_install(distro): pkg_name = "splunk-otel-collector" pkg_dir = REPO_DIR / "dist" service_name = "splunk-otel-collector" service_owner = "splunk-otel-collector" service_proc = "otelcol" config_path = "/etc/otel/collector/splunk-otel-collector.conf" bundle_dir = "/usr/lib/splunk-otel-collector/agent-bundle" pkg_path = get_package(distro, pkg_name, pkg_dir) assert pkg_path, f"{pkg_name} package not found in {pkg_dir}" pkg_base = os.path.basename(pkg_path) with run_distro_container(distro) as container: copy_file_into_container(container, pkg_path, f"/test/{pkg_base}") try: # install package if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -i /test/{pkg_base}") else: run_container_cmd(container, f"rpm -i /test/{pkg_base}") run_container_cmd(container, f"test -d {bundle_dir}") run_container_cmd(container, f"test -d {bundle_dir}/run/collectd") # verify service is not running after install without config file time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) # verify service starts with config file run_container_cmd(container, f"cp -f {config_path}.example {config_path}") run_container_cmd(container, f"systemctl start {service_name}") time.sleep(5) assert wait_for(lambda: service_is_running( container, service_name, service_owner, service_proc)) # verify service restart run_container_cmd(container, f"systemctl restart {service_name}") time.sleep(5) assert wait_for(lambda: service_is_running( container, service_name, service_owner, service_proc)) # verify service stop run_container_cmd(container, f"systemctl stop {service_name}") time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) finally: run_container_cmd(container, f"journalctl -u {service_name} --no-pager") # verify uninstall run_container_cmd(container, f"systemctl start {service_name}") time.sleep(5) if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -P {pkg_name}") else: run_container_cmd(container, f"rpm -e {pkg_name}") time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) # verify config file is not removed run_container_cmd(container, f"test -f {config_path}")
def test_collector_package_install(distro): pkg_name = "splunk-otel-collector" pkg_dir = REPO_DIR / "dist" service_name = "splunk-otel-collector" service_owner = "splunk-otel-collector" service_proc = "otelcol" env_path = "/etc/otel/collector/splunk-otel-collector.conf" agent_config_path = "/etc/otel/collector/agent_config.yaml" gateway_config_path = "/etc/otel/collector/gateway_config.yaml" bundle_dir = "/usr/lib/splunk-otel-collector/agent-bundle" pkg_path = get_package(distro, pkg_name, pkg_dir) assert pkg_path, f"{pkg_name} package not found in {pkg_dir}" pkg_base = os.path.basename(pkg_path) with run_distro_container(distro) as container: # install setcap dependency if distro in RPM_DISTROS: if container.exec_run("command -v yum").exit_code == 0: run_container_cmd(container, "yum install -y libcap") else: run_container_cmd(container, "dnf install -y libcap") else: run_container_cmd(container, "apt-get update") run_container_cmd(container, "apt-get install -y libcap2-bin") copy_file_into_container(container, pkg_path, f"/test/{pkg_base}") try: # install package if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -i /test/{pkg_base}") else: run_container_cmd(container, f"rpm -i /test/{pkg_base}") run_container_cmd(container, f"test -d {bundle_dir}") run_container_cmd(container, f"test -d {bundle_dir}/run/collectd") run_container_cmd(container, f"test -f {agent_config_path}") run_container_cmd(container, f"test -f {gateway_config_path}") # verify service is not running after install without config file time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) # verify service starts with config file run_container_cmd(container, f"cp -f {env_path}.example {env_path}") run_container_cmd(container, f"systemctl start {service_name}") time.sleep(5) assert wait_for(lambda: service_is_running( container, service_name, service_owner, service_proc)) # verify service restart run_container_cmd(container, f"systemctl restart {service_name}") time.sleep(5) assert wait_for(lambda: service_is_running( container, service_name, service_owner, service_proc)) # verify service stop run_container_cmd(container, f"systemctl stop {service_name}") time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) finally: run_container_cmd(container, f"journalctl -u {service_name} --no-pager") # verify uninstall run_container_cmd(container, f"systemctl start {service_name}") time.sleep(5) if distro in DEB_DISTROS: run_container_cmd(container, f"dpkg -P {pkg_name}") else: run_container_cmd(container, f"rpm -e {pkg_name}") time.sleep(5) assert not service_is_running(container, service_name, service_owner, service_proc) # verify config file is not removed run_container_cmd(container, f"test -f {env_path}")