-
Notifications
You must be signed in to change notification settings - Fork 169
Start service after deb/rpm install or upgrade if env file exists #805
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,17 @@ | |
TESTS_DIR, | ||
) | ||
|
||
INSTALLER_PATH = REPO_DIR / "internal" / "buildscripts" / "packaging" / "installer" / "install.sh" | ||
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" | ||
|
||
|
||
def get_package(distro, name, path): | ||
if distro in DEB_DISTROS: | ||
|
@@ -58,19 +69,8 @@ def get_libcap_command(container): | |
+ [pytest.param(distro, marks=pytest.mark.rpm) for distro in RPM_DISTROS], | ||
) | ||
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_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: | ||
|
@@ -90,46 +90,93 @@ def test_collector_package_install(distro): | |
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 -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}") | ||
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) | ||
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}") | ||
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)) | ||
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}") | ||
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)) | ||
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}") | ||
run_container_cmd(container, f"systemctl stop {SERVICE_NAME}") | ||
time.sleep(5) | ||
assert not service_is_running(container, service_name, service_owner, service_proc) | ||
assert not service_is_running(container, SERVICE_NAME, SERVICE_OWNER, SERVICE_PROC) | ||
finally: | ||
run_container_cmd(container, f"journalctl -u {service_name} --no-pager") | ||
run_container_cmd(container, f"journalctl -u {SERVICE_NAME} --no-pager") | ||
|
||
# verify uninstall | ||
run_container_cmd(container, f"systemctl start {service_name}") | ||
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}") | ||
run_container_cmd(container, f"dpkg -P {PKG_NAME}") | ||
else: | ||
run_container_cmd(container, f"rpm -e {pkg_name}") | ||
run_container_cmd(container, f"rpm -e {PKG_NAME}") | ||
|
||
time.sleep(5) | ||
assert not service_is_running(container, service_name, service_owner, service_proc) | ||
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}") | ||
run_container_cmd(container, f"test -f {ENV_PATH}") | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"distro", | ||
[pytest.param(distro, marks=pytest.mark.deb) for distro in DEB_DISTROS] | ||
+ [pytest.param(distro, marks=pytest.mark.rpm) for distro in RPM_DISTROS], | ||
) | ||
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") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just curious if this for debugging purposes or a final check for service activity. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just for debugging. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.