mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Adapt tests
This commit is contained in:
parent
dbc8b4cf66
commit
c74c37372b
4 changed files with 16 additions and 23 deletions
|
@ -132,11 +132,6 @@ def ext_pillar(
|
|||
host = __opts__["mongo.host"]
|
||||
port = __opts__["mongo.port"]
|
||||
ssl = __opts__.get("mongo.ssl") or False
|
||||
log.info("connecting to %s:%s for mongo ext_pillar", host, port)
|
||||
conn = pymongo.MongoClient(host=host, port=port, ssl=ssl)
|
||||
|
||||
log.debug("using database '%s'", __opts__["mongo.db"])
|
||||
mdb = conn[__opts__["mongo.db"]]
|
||||
|
||||
uri = __opts__.get("mongo.uri")
|
||||
host = __opts__.get("mongo.host")
|
||||
|
@ -144,10 +139,6 @@ def ext_pillar(
|
|||
user = __opts__.get("mongo.user")
|
||||
password = __opts__.get("mongo.password")
|
||||
|
||||
if user and password:
|
||||
log.debug("authenticating as '%s'", user)
|
||||
mdb.authenticate(user, password)
|
||||
|
||||
db = __opts__.get("mongo.db")
|
||||
|
||||
if uri:
|
||||
|
@ -164,7 +155,7 @@ def ext_pillar(
|
|||
else:
|
||||
log.info("connecting to %s:%s for mongo ext_pillar", host, port)
|
||||
conn = pymongo.MongoClient(
|
||||
host=host, port=port, username=user, password=password
|
||||
host=host, port=port, username=user, password=password, ssl=ssl
|
||||
)
|
||||
|
||||
log.debug("using database '%s'", db)
|
||||
|
|
|
@ -7,14 +7,7 @@ from tests.support.mock import patch
|
|||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules():
|
||||
|
||||
return {
|
||||
mongo: {
|
||||
"__opts__": {
|
||||
"mongo.uri": "mongodb://root:pass@localhost27017/salt?authSource=admin"
|
||||
}
|
||||
}
|
||||
}
|
||||
return {mongo: {"__opts__": {}}}
|
||||
|
||||
|
||||
def test_config_exception():
|
||||
|
@ -23,6 +16,7 @@ def test_config_exception():
|
|||
"mongo.port": 27017,
|
||||
"mongo.user": "root",
|
||||
"mongo.password": "pass",
|
||||
"mongo.db": "admin",
|
||||
"mongo.uri": "mongodb://root:pass@localhost27017/salt?authSource=admin",
|
||||
}
|
||||
with patch.dict(mongo.__opts__, opts):
|
||||
|
@ -46,5 +40,9 @@ def test_mongo_pillar_should_use_ssl_when_set_in_opts(expected_ssl, use_ssl):
|
|||
), patch("salt.pillar.mongo.pymongo", create=True) as fake_mongo:
|
||||
mongo.ext_pillar(minion_id="blarp", pillar=None)
|
||||
fake_mongo.MongoClient.assert_called_with(
|
||||
host="fnord", port="fnordport", ssl=expected_ssl
|
||||
host="fnord",
|
||||
port="fnordport",
|
||||
username=None,
|
||||
password=None,
|
||||
ssl=expected_ssl,
|
||||
)
|
||||
|
|
|
@ -62,7 +62,11 @@ def test_mongo_future_returner_should_correctly_pass_ssl_to_MongoClient_when_ret
|
|||
):
|
||||
mongo_future_return._get_conn(ret={"ret_config": "fnord"})
|
||||
fake_mongo.MongoClient.assert_called_with(
|
||||
host="fnordfnord", port="fnordfnordport", ssl=expected_ssl
|
||||
"fnordfnord",
|
||||
"fnordfnordport",
|
||||
username=None,
|
||||
password=None,
|
||||
ssl=expected_ssl,
|
||||
)
|
||||
|
||||
|
||||
|
@ -95,5 +99,5 @@ def test_mongo_future_returner_should_correctly_pass_ssl_to_MongoClient(
|
|||
):
|
||||
mongo_future_return._get_conn(ret=None)
|
||||
fake_mongo.MongoClient.assert_called_with(
|
||||
host="fnord", port="fnordport", ssl=expected_ssl
|
||||
"fnord", "fnordport", username=None, password=None, ssl=expected_ssl
|
||||
)
|
||||
|
|
|
@ -78,7 +78,7 @@ def test_when_mongodb_database_remove_is_called_it_should_correctly_pass_ssl_arg
|
|||
expected_ssl, expected_allow_invalid, absent_kwargs
|
||||
):
|
||||
# database from params needs to be in this return_value
|
||||
salt.modules.mongodb.pymongo.MongoClient.return_value.database_names.return_value = [
|
||||
salt.modules.mongodb.pymongo.MongoClient.return_value.list_database_names.return_value = [
|
||||
"foo",
|
||||
"bar",
|
||||
"some_database",
|
||||
|
@ -98,7 +98,7 @@ def test_when_mongodb_database_remove_is_called_it_should_correctly_pass_ssl_arg
|
|||
# from the mock call list, but it didn't. There's probably some
|
||||
# other way to ensure that database_names/drop_database is out of
|
||||
# the MongoClient mock call list, but it was taking too long.
|
||||
call().database_names(),
|
||||
call().list_database_names(),
|
||||
call(
|
||||
host="mongodb.example.net",
|
||||
port=1982,
|
||||
|
|
Loading…
Add table
Reference in a new issue