Skip to content
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

Listen interface deployment tests #3736

Merged
merged 3 commits into from
Oct 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions deployments/chef/kitchen.windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ suites:
splunk_api_url: https://fake-splunk-api.com
splunk_memory_total_mib: "256"
splunk_hec_token: fake-hec-token
splunk_listen_interface: "0.0.0.0"
collector_version: 0.48.0
collector_additional_env_vars:
MY_CUSTOM_VAR1: value1
Expand Down
1 change: 1 addition & 0 deletions deployments/chef/kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ suites:
splunk_api_url: https://fake-splunk-api.com
splunk_memory_total_mib: "256"
splunk_hec_token: fake-hec-token
splunk_listen_interface: "0.0.0.0"
user: custom-user
group: custom-group
collector_additional_env_vars:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
splunk_hec_url = "#{splunk_ingest_url}/v1/log"
splunk_hec_token = 'fake-hec-token'
splunk_memory_total = '256'
splunk_listen_interface = '0.0.0.0'

describe service('splunk-otel-collector') do
it { should be_enabled }
Expand All @@ -25,6 +26,7 @@
its('SPLUNK_HEC_TOKEN') { should eq splunk_hec_token }
its('SPLUNK_HEC_URL') { should eq splunk_hec_url }
its('SPLUNK_INGEST_URL') { should eq splunk_ingest_url }
its('SPLUNK_LISTEN_INTERFACE') { should eq splunk_listen_interface }
its('SPLUNK_MEMORY_TOTAL_MIB') { should eq splunk_memory_total }
its('SPLUNK_REALM') { should eq splunk_realm }
its('SPLUNK_TRACE_URL') { should eq splunk_trace_url }
Expand All @@ -48,6 +50,7 @@
its('content') { should match /^SPLUNK_HEC_TOKEN=#{splunk_hec_token}$/ }
its('content') { should match /^SPLUNK_HEC_URL=#{splunk_hec_url}$/ }
its('content') { should match /^SPLUNK_INGEST_URL=#{splunk_ingest_url}$/ }
its('content') { should match /^SPLUNK_LISTEN_INTERFACE=#{splunk_listen_interface}$/ }
its('content') { should match /^SPLUNK_MEMORY_TOTAL_MIB=#{splunk_memory_total}$/ }
its('content') { should match /^SPLUNK_REALM=test$/ }
its('content') { should match /^SPLUNK_TRACE_URL=#{splunk_trace_url}$/ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
its('SPLUNK_MEMORY_TOTAL_MIB') { should eq splunk_memory_total }
its('SPLUNK_REALM') { should eq splunk_realm }
its('SPLUNK_TRACE_URL') { should eq splunk_trace_url }
it { should_not have_property('SPLUNK_LISTEN_INTERFACE') }
end
describe service('fluentdwinsvc') do
it { should_not be_enabled }
Expand All @@ -49,6 +50,7 @@
its('content') { should match /^SPLUNK_MEMORY_TOTAL_MIB=#{splunk_memory_total}$/ }
its('content') { should match /^SPLUNK_REALM=test$/ }
its('content') { should match /^SPLUNK_TRACE_URL=#{splunk_trace_url}$/ }
its('content') { should_not match /^SPLUNK_LISTEN_INTERFACE=.*$/ }
end
describe file('/etc/systemd/system/splunk-otel-collector.service.d/service-owner.conf') do
its('content') { should match /^User=splunk-otel-collector$/ }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def verify_env_file(container):
run_container_cmd(container, f"grep '^SPLUNK_INGEST_URL={SPLUNK_INGEST_URL}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_REALM={SPLUNK_REALM}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_TRACE_URL={SPLUNK_INGEST_URL}/v2/trace$' {SPLUNK_ENV_PATH}")
assert container.exec_run(f"grep '^SPLUNK_LISTEN_INTERFACE=.*' {SPLUNK_ENV_PATH}").exit_code != 0


def skip_if_necessary(distro, puppet_release):
Expand Down Expand Up @@ -234,6 +235,7 @@ class {{ splunk_otel_collector:
splunk_api_url => '$api_url',
splunk_ingest_url => '$ingest_url',
splunk_hec_token => 'fake-hec-token',
splunk_listen_interface => '0.0.0.0',
collector_version => '$version',
with_fluentd => $fluentd,
collector_additional_env_vars => {{ 'MY_CUSTOM_VAR1' => 'value1', 'MY_CUSTOM_VAR2' => 'value2' }},
Expand Down Expand Up @@ -268,6 +270,7 @@ def test_puppet_with_custom_vars(distro, puppet_release):
run_container_cmd(container, f"grep '^SPLUNK_HEC_TOKEN=fake-hec-token$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_HEC_URL={ingest_url}/v1/log$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_INGEST_URL={ingest_url}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_LISTEN_INTERFACE=0.0.0.0$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_REALM={SPLUNK_REALM}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_TRACE_URL={ingest_url}/v2/trace$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^MY_CUSTOM_VAR1=value1$' {SPLUNK_ENV_PATH}")
Expand Down Expand Up @@ -327,6 +330,11 @@ def test_win_puppet_default():
assert get_registry_value("SPLUNK_HEC_URL") == f"{SPLUNK_INGEST_URL}/v1/log"
assert get_registry_value("SPLUNK_TRACE_URL") == f"{SPLUNK_INGEST_URL}/v2/trace"
assert get_registry_value("SPLUNK_HEC_TOKEN") == SPLUNK_ACCESS_TOKEN
try:
listen_interface = get_registry_value("SPLUNK_LISTEN_INTERFACE")
except FileNotFoundError:
listen_interface = None
assert listen_interface is None

assert psutil.win_service_get("splunk-otel-collector").status() == psutil.STATUS_RUNNING
for service in psutil.win_service_iter():
Expand All @@ -349,6 +357,7 @@ def test_win_puppet_custom_vars():
assert get_registry_value("SPLUNK_API_URL") == api_url
assert get_registry_value("SPLUNK_INGEST_URL") == ingest_url
assert get_registry_value("SPLUNK_HEC_URL") == f"{ingest_url}/v1/log"
assert get_registry_value("SPLUNK_LISTEN_INTERFACE") == "0.0.0.0"
assert get_registry_value("SPLUNK_TRACE_URL") == f"{ingest_url}/v2/trace"
assert get_registry_value("SPLUNK_HEC_TOKEN") == "fake-hec-token"
assert get_registry_value("MY_CUSTOM_VAR1") == "value1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ def run_salt_apply(container, config):
run_container_cmd(container, SALT_CMD)


def verify_env_file(container):
def verify_env_file(container, listen_interface=None):
run_container_cmd(container, f"grep '^SPLUNK_CONFIG={SPLUNK_CONFIG}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_ACCESS_TOKEN={SPLUNK_ACCESS_TOKEN}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_REALM={SPLUNK_REALM}$' {SPLUNK_ENV_PATH}")
Expand All @@ -88,6 +88,10 @@ def verify_env_file(container):
run_container_cmd(container, f"grep '^SPLUNK_MEMORY_TOTAL_MIB={SPLUNK_MEMORY_TOTAL_MIB}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_BUNDLE_DIR={SPLUNK_BUNDLE_DIR}$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^SPLUNK_COLLECTD_DIR={SPLUNK_COLLECTD_DIR}$' {SPLUNK_ENV_PATH}")
if listen_interface:
run_container_cmd(container, f"grep '^SPLUNK_LISTEN_INTERFACE={listen_interface}$' {SPLUNK_ENV_PATH}")
else:
assert container.exec_run(f"grep '^SPLUNK_LISTEN_INTERFACE=.*' {SPLUNK_ENV_PATH}").exit_code != 0


@pytest.mark.salt
Expand Down Expand Up @@ -268,6 +272,7 @@ def test_salt_service_owner(distro):
splunk-otel-collector:
splunk_access_token: '{SPLUNK_ACCESS_TOKEN}'
splunk_realm: '{SPLUNK_REALM}'
splunk_listen_interface: '0.0.0.0'
collector_additional_env_vars:
MY_CUSTOM_VAR1: value1
MY_CUSTOM_VAR2: value2
Expand All @@ -289,7 +294,7 @@ def test_salt_custom_env_vars(distro):
with run_distro_container(distro, dockerfile=dockerfile, path=REPO_DIR) as container:
try:
run_salt_apply(container, CUSTOM_ENV_VARS_CONFIG)
verify_env_file(container)
verify_env_file(container, listen_interface="0.0.0.0")
run_container_cmd(container, f"grep '^MY_CUSTOM_VAR1=value1$' {SPLUNK_ENV_PATH}")
run_container_cmd(container, f"grep '^MY_CUSTOM_VAR2=value2$' {SPLUNK_ENV_PATH}")
assert wait_for(lambda: service_is_running(container))
Expand Down