pass ssl to mongo top as well

This commit is contained in:
Wayne Werner 2022-02-15 15:23:28 -06:00 committed by Daniel Wozniak
parent 793b0bbe6a
commit 23db530c03
2 changed files with 30 additions and 1 deletions

View file

@ -95,6 +95,7 @@ def top(**kwargs):
"""
host = __opts__["mongo.host"]
port = __opts__["mongo.port"]
ssl = __opts__.get("mongo.ssl") or False
collection = __opts__["master_tops"]["mongo"].get("collection", "tops")
id_field = __opts__["master_tops"]["mongo"].get("id_field", "_id")
re_pattern = __opts__["master_tops"]["mongo"].get("re_pattern", "")
@ -105,7 +106,7 @@ def top(**kwargs):
)
log.info("connecting to %s:%s for mongo ext_tops", host, port)
conn = pymongo.MongoClient(host, port)
conn = pymongo.MongoClient(host=host, port=port, ssl=ssl)
log.debug("using database '%s'", __opts__["mongo.db"])
mdb = conn[__opts__["mongo.db"]]

View file

@ -0,0 +1,28 @@
import pytest
import salt.tops.mongo
from tests.support.mock import patch
@pytest.mark.parametrize(
"expected_ssl, use_ssl",
[
(True, True),
(False, False),
(False, None),
],
)
def test_tops_should_correctly_pass_ssl_arg_to_MongoClient(expected_ssl, use_ssl):
salt.tops.mongo.HAS_PYMONGO = True
with patch("salt.tops.mongo.pymongo", create=True) as fake_pymongo, patch.dict(
"salt.tops.mongo.__opts__",
{
"master_tops": {"mongo": {}},
"mongo.host": "fnord",
"mongo.port": "fnord",
"mongo.ssl": use_ssl,
},
):
salt.tops.mongo.top(opts={"id": "fnord"})
fake_pymongo.MongoClient.assert_called_with(
host="fnord", port="fnord", ssl=expected_ssl
)