Skip to content

Commit

Permalink
Merge pull request #71 from Percona-Lab/PSMDB_fix
Browse files Browse the repository at this point in the history
PSMDB. Fix script exit code and change the way to get PMM metrics
  • Loading branch information
sandraromanchenko authored Jul 17, 2024
2 parents 7f5456d + 5eb6d74 commit 56e429c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pmm_psmdb_diffauth_setup/init/setup_psmdb.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var db = connect("mongodb://dba:secret@localhost:27017/admin");
var db = connect("mongodb://root:root@localhost:27017/admin");
db.getSiblingDB("admin").createRole({
"role": "pbmAnyAction",
"privileges": [{
Expand Down
7 changes: 6 additions & 1 deletion pmm_psmdb_diffauth_setup/test-auth.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ done
tests=${TESTS:-yes}
if [ $tests = "yes" ]; then
echo "running tests"
docker-compose -f docker-compose-pmm-psmdb.yml run test pytest -s -x --verbose test.py
output=$(docker-compose -f docker-compose-pmm-psmdb.yml run test pytest -s -x --verbose test.py)
else
echo "skipping tests"
fi
Expand All @@ -83,3 +83,8 @@ if [ $cleanup = "yes" ]; then
else
echo "skipping cleanup"
fi

echo "$output"
if echo "$output" | grep -q "\bFAILED\b"; then
exit 1
fi
17 changes: 9 additions & 8 deletions pmm_psmdb_diffauth_setup/test/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,16 @@ def run_test(add_db_command):
agent_port = agent['port']
break

url = f'http://psmdb-server:{agent_port}/metrics'
agent_id_parts = agent_id.split('/')
agent_pass = f"%2F{agent_id_parts[1]}%2F{agent_id_parts[2]}"

try:
response = requests.get(url, auth=('pmm', agent_id), timeout=5)
assert response.status_code == 200, f"Request for metrics failed with status code {response.status_code}"
pattern = r'mongodb_up (\d+)'
result = re.search(pattern, response.text)
assert result is not None, "MongoDB related data isn't exported"
except requests.exceptions.ConnectionError:
pytest.fail(f"Connection to {url} failed")
command = f"curl http://pmm:{agent_pass}@127.0.0.1:{agent_port}/metrics"
metrics = docker_pmm_client.run(command, timeout=30)
except Exception as e:
pytest.fail(f"Fail to get metrics from exporter")
if "mongodb_up" not in metrics.stdout:
pytest.fail("MongoDB related data isn't exported")

def test_simple_auth_wo_tls():
run_test('pmm-admin add mongodb psmdb-server --username=pmm_mongodb --password="5M](Q%q/U+YQ<^m" '\
Expand Down

0 comments on commit 56e429c

Please sign in to comment.