|
5 | 5 | import pytest
|
6 | 6 | import json
|
7 | 7 |
|
| 8 | +import requests |
8 | 9 | import testinfra.utils.ansible_runner
|
9 | 10 | pml = testinfra.utils.ansible_runner.AnsibleRunner(
|
10 | 11 | os.environ['MOLECULE_INVENTORY_FILE']).get_hosts('all')
|
11 | 12 |
|
| 13 | +version = os.getenv("pml_version") |
| 14 | + |
12 | 15 | def pml_start(host, timeout=60, interval=2):
|
13 | 16 | """Starts PML and waits until the endpoint is ready
|
14 | 17 | Also confirms the PML start command works and is ready to clone"""
|
@@ -94,7 +97,6 @@ def pml_status(host, timeout=45):
|
94 | 97 | except Exception as e:
|
95 | 98 | return {"success": False, "error": str(e)}
|
96 | 99 |
|
97 |
| -@pytest.fixture() |
98 | 100 | def pml_version(host):
|
99 | 101 | """Capture PLM Version command and returns output"""
|
100 | 102 | result = host.run("percona-mongolink version")
|
@@ -175,11 +177,27 @@ def start_plm_service(host):
|
175 | 177 | assert status.stdout.strip() == "active", f"PLM service is inactive: {status.stdout}"
|
176 | 178 | return start_plm
|
177 | 179 |
|
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 |
183 | 201 |
|
184 | 202 | def test_plm_binary(host):
|
185 | 203 | """Check PLM binary exists with the correct permissions"""
|
|
0 commit comments