Skip to content

Commit

Permalink
PSMDB-1531 test telemetry agent on package tests (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
olexandr-havryliak authored Sep 5, 2024
1 parent 726b57f commit 87b3d70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
7 changes: 4 additions & 3 deletions psmdb/psmdb/molecule/docker/molecule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ provisioner:
log: true
playbooks:
converge: ../../playbooks/playbook.yml
prepare: ../../../../playbooks/prepare.yml
verifier:
name: testinfra
directory: ../../../tests/
additional_files_or_dirs:
- ../psmdb/tests/
directory: ../../tests/
# additional_files_or_dirs:
# - ../psmdb/tests/
options:
verbose: true
s: true
Expand Down
37 changes: 36 additions & 1 deletion psmdb/psmdb/tests/test_psmdb_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import json
import yaml
import testinfra.utils.ansible_runner
from packaging import version

testinfra_hosts = testinfra.utils.ansible_runner.AnsibleRunner(
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
Expand Down Expand Up @@ -135,6 +136,13 @@ def test_version_pt(host):
assert PSMDB_VER in version

def test_telemetry(host):
if version.parse(PSMDB_VER) <= version.parse("5.0.27"):
pytest.skip("This version doesn't support telemetry")
if version.parse(PSMDB_VER) >= version.parse("6.0.0") and version.parse(PSMDB_VER) <= version.parse("6.0.15"):
pytest.skip("This version doesn't support telemetry")
if version.parse(PSMDB_VER) >= version.parse("7.0.0") and version.parse(PSMDB_VER) <= version.parse("7.0.11"):
pytest.skip("This version doesn't support telemetry")

file_path = "/usr/local/percona/telemetry_uuid"
expected_fields = ["instanceId", "PRODUCT_FAMILY_PSMDB"]
expected_group = "percona-telemetry"
Expand All @@ -149,6 +157,34 @@ def test_telemetry(host):
file_group = host.file(file_path).group
assert file_group == expected_group, f"File '{file_path}' group is '{file_group}', expected group is '{expected_group}'."

#reconfigure telemetry agent
with host.sudo():
assert host.service('percona-telemetry-agent').is_running
assert host.service('percona-telemetry-agent').is_enabled
if host.system_info.distribution == "debian" or host.system_info.distribution == "ubuntu":
host.check_output("sed -E 's|PERCONA_TELEMETRY_URL=(.+)|PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport|' -i /etc/default/percona-telemetry-agent")
host.check_output("sed -E 's|PERCONA_TELEMETRY_CHECK_INTERVAL=(.+)|PERCONA_TELEMETRY_CHECK_INTERVAL=10|' -i /etc/default/percona-telemetry-agent")
else:
host.check_output("sed -E 's|PERCONA_TELEMETRY_URL=(.+)|PERCONA_TELEMETRY_URL=https://check-dev.percona.com/v1/telemetry/GenericReport|' -i /etc/sysconfig/percona-telemetry-agent")
host.check_output("sed -E 's|PERCONA_TELEMETRY_CHECK_INTERVAL=(.+)|PERCONA_TELEMETRY_CHECK_INTERVAL=10|' -i /etc/sysconfig/percona-telemetry-agent")
host.check_output('systemctl restart percona-telemetry-agent')
assert host.service('percona-telemetry-agent').is_running

#test mongod telemetry
restore_defaults(host)
conf = get_default_conf(host)
conf['setParameter'] = {}
conf['setParameter']['perconaTelemetryGracePeriod'] = 2
apply_conf(host,conf,True)
time.sleep(3)
with host.sudo():
assert "1"==host.check_output("ls -1 /usr/local/percona/telemetry/psmdb/ | wc -l")
time.sleep(15)
logs=host.check_output('cat /var/log/percona/telemetry-agent.log')
assert "Sending request to host=check-dev.percona.com." in logs
assert "0"==host.check_output("ls -1 /usr/local/percona/telemetry/psmdb/ | wc -l")
assert "1"==host.check_output("ls -1 /usr/local/percona/telemetry/history/ | wc -l")

def test_profiling(host):
restore_defaults(host)

Expand Down Expand Up @@ -280,4 +316,3 @@ def test_encryption(host,encryption,cipher):
assert "Rotated master encryption key" in logs, logs
assert '"Shutting down","attr":{"exitCode":0}}' in logs, logs
apply_conf(host,conf)

0 comments on commit 87b3d70

Please sign in to comment.