Skip to content

Commit 81ab54f

Browse files
PML-157: Fixing and readding percona-mongolink Version test
1 parent 5be4b34 commit 81ab54f

File tree

4 files changed

+27
-6
lines changed

4 files changed

+27
-6
lines changed

pml/install/playbooks/debian.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
update_cache: yes
5151
vars:
5252
packages:
53+
- git
5354
- python3-pip
5455
- wget
5556
- iputils-ping

pml/install/playbooks/redhat.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
update_cache: yes
4848
vars:
4949
packages:
50+
- git
5051
- python3-pip
5152
- wget
5253
- docker-ce

pml/install/playbooks/ubuntu.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
update_cache: yes
4949
vars:
5050
packages:
51+
- git
5152
- python3-pip
5253
- wget
5354
- iputils-ping

pml/tests/test_plm.py

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
import pytest
66
import json
77

8+
import requests
89
import testinfra.utils.ansible_runner
910
pml = testinfra.utils.ansible_runner.AnsibleRunner(
1011
os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
1112

13+
version = os.getenv("pml_version")
14+
1215
def pml_start(host, timeout=60, interval=2):
1316
"""Starts PML and waits until the endpoint is ready
1417
Also confirms the PML start command works and is ready to clone"""
@@ -94,7 +97,6 @@ def pml_status(host, timeout=45):
9497
except Exception as e:
9598
return {"success": False, "error": str(e)}
9699

97-
@pytest.fixture()
98100
def pml_version(host):
99101
"""Capture PLM Version command and returns output"""
100102
result = host.run("percona-mongolink version")
@@ -175,11 +177,27 @@ def start_plm_service(host):
175177
assert status.stdout.strip() == "active", f"PLM service is inactive: {status.stdout}"
176178
return start_plm
177179

178-
# def test_pml_version(pml_version):
179-
# """Test that percona-mongolink version output is correct"""
180-
# pattern = r"^v\d+\.\d+ [a-f0-9]{7} \d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$"
181-
#
182-
# assert re.match(pattern, pml_version.stderr)
180+
def get_git_commit():
181+
url = f"https://api.github.com/repos/percona/percona-mongolink/commits/release-{version}"
182+
git_commit = requests.get(url)
183+
184+
if git_commit.status_code == 200:
185+
return git_commit.json()["sha"][:7]
186+
else:
187+
print(f"Unable to obtain git commit, failed with status code: {git_commit.status_code}")
188+
return False
189+
190+
def test_pml_version(host):
191+
"""Test that percona-mongolink version output is correct"""
192+
result = pml_version(host)
193+
lines = result.stderr.split("\n")
194+
parsed_config = {line.split(":")[0]: line.split(":")[1].strip() for line in lines[0:-1]}
195+
assert parsed_config['Version'] == f"v{version}", parsed_config
196+
assert parsed_config['Platform'], parsed_config
197+
assert parsed_config['GitCommit'] == get_git_commit(), parsed_config
198+
assert parsed_config['GitBranch'] == f"release-{version}", parsed_config
199+
assert parsed_config['BuildTime'], parsed_config
200+
assert parsed_config['GoVersion'], parsed_config
183201

184202
def test_plm_binary(host):
185203
"""Check PLM binary exists with the correct permissions"""

0 commit comments

Comments
 (0)