Content-Length: 664662 | pFad | http://github.com/saltstack/salt/pull/68068/commits/306b50b33e78bdfeafc209fa2beb554fe3959bb7

AE new: salt.sqlalchemy base implementation (+ returner & cache) by mattp- · Pull Request #68068 · saltstack/salt · GitHub
Skip to content

new: salt.sqlalchemy base implementation (+ returner & cache) #68068

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
refactor functional database fixture
the mysql fixture was useful as a base, but making it database agnostic
required some changes. now it supports postgres, and easily others in
the future if desired. reworked the way versions work as well so it can
be consumed from different tests more easily.
  • Loading branch information
mattp- committed Jul 8, 2025
commit 306b50b33e78bdfeafc209fa2beb554fe3959bb7
15 changes: 11 additions & 4 deletions tests/pytests/functional/cache/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,13 @@ def run_common_cache_tests(subtests, cache):
assert actual_thing is new_thing
else:
assert actual_thing is not new_thing
assert actual_thing == new_thing

try:
assert actual_thing == new_thing
except AssertionError:
# json storage disallows int object keys, which some storages use
new_thing["42"] = new_thing.pop(42)
assert actual_thing == new_thing

with subtests.test("contains returns true if key in bank"):
assert cache.contains(bank=bank, key=good_key)
Expand Down Expand Up @@ -125,13 +131,14 @@ def run_common_cache_tests(subtests, cache):
assert timestamp is None

with subtests.test("Updated for key should return a reasonable time"):
before_storage = int(time.time())
before_storage = time.time()
cache.store(bank="fnord", key="updated test part 2", data="fnord")
after_storage = int(time.time())
after_storage = time.time()

timestamp = cache.updated(bank="fnord", key="updated test part 2")

assert before_storage <= timestamp <= after_storage
# the -1/+1 because mysql timestamps are janky
assert before_storage - 1 <= timestamp <= after_storage + 1

with subtests.test(
"If the module raises SaltCacheError then it should make it out of updated"
Expand Down
34 changes: 22 additions & 12 deletions tests/pytests/functional/cache/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import salt.loader
from salt.utils.versions import Version
from tests.pytests.functional.cache.helpers import run_common_cache_tests
from tests.support.pytest.mysql import * # pylint: disable=wildcard-import,unused-wildcard-import

docker = pytest.importorskip("docker")

Expand All @@ -19,24 +18,35 @@
Version(docker.__version__) < Version("4.0.0"),
reason="Test does not work in this version of docker-py",
),
pytest.mark.parametrize(
"database_backend",
[
("mysql-server", "5.5"),
("mysql-server", "5.6"),
("mysql-server", "5.7"),
("mysql-server", "8.0"),
("mariadb", "10.3"),
("mariadb", "10.4"),
("mariadb", "10.5"),
("percona", "5.6"),
("percona", "5.7"),
("percona", "8.0"),
],
ids=lambda val: f"{val[0]}-{val[1] or 'default'}",
indirect=True,
),
]


@pytest.fixture(scope="module")
def mysql_combo(create_mysql_combo): # pylint: disable=function-redefined
create_mysql_combo.mysql_database = "salt_cache"
return create_mysql_combo


@pytest.fixture
def cache(minion_opts, mysql_container):
def cache(minion_opts, database_backend):
opts = minion_opts.copy()
opts["cache"] = "mysql"
opts["mysql.host"] = "127.0.0.1"
opts["mysql.port"] = mysql_container.mysql_port
opts["mysql.user"] = mysql_container.mysql_user
opts["mysql.password"] = mysql_container.mysql_passwd
opts["mysql.database"] = mysql_container.mysql_database
opts["mysql.port"] = database_backend.port
opts["mysql.user"] = database_backend.user
opts["mysql.password"] = database_backend.passwd
opts["mysql.database"] = database_backend.database
opts["mysql.table_name"] = "cache"
cache = salt.cache.factory(opts)
return cache
Expand Down
2 changes: 2 additions & 0 deletions tests/pytests/functional/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import pytest
from saltfactories.utils.functional import Loaders

from tests.support.pytest.database import * # pylint: disable=wildcard-import,unused-wildcard-import

log = logging.getLogger(__name__)


Expand Down
112 changes: 65 additions & 47 deletions tests/pytests/functional/modules/test_mysql.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import salt.modules.mysql as mysqlmod
from salt.utils.versions import version_cmp
from tests.support.pytest.mysql import * # pylint: disable=wildcard-import,unused-wildcard-import
from tests.support.pytest.database import available_databases

log = logging.getLogger(__name__)

Expand All @@ -20,6 +20,24 @@
pytest.mark.skipif(
mysqlmod.MySQLdb is None, reason="No python mysql client installed."
),
pytest.mark.parametrize(
"database_backend",
available_databases(
[
("mysql-server", "5.5", "MySQLdb"),
("mysql-server", "5.6", "MySQLdb"),
("mysql-server", "5.7", "MySQLdb"),
("mysql-server", "8.0", "MySQLdb"),
("mariadb", "10.3", "MySQLdb"),
("mariadb", "10.4", "MySQLdb"),
("mariadb", "10.5", "MySQLdb"),
("percona", "5.6", "MySQLdb"),
("percona", "5.7", "MySQLdb"),
("percona", "8.0", "MySQLdb"),
]
),
indirect=True,
),
pytest.mark.skip_on_fips_enabled_platform,
]

Expand Down Expand Up @@ -61,13 +79,13 @@ def __call__(self, *args, **kwargs):


@pytest.fixture(scope="module")
def mysql(modules, mysql_container, loaders):
def mysql(modules, database_backend, loaders):
for name in list(modules):
if not name.startswith("mysql."):
continue
modules._dict[name] = CallWrapper(
modules._dict[name],
mysql_container,
database_backend,
loaders.context,
)
return modules.mysql
Expand All @@ -79,10 +97,10 @@ def test_query(mysql):
assert ret["results"] == (("1",),)


def test_version(mysql, mysql_container):
def test_version(mysql, database_backend):
ret = mysql.version()
assert ret
assert mysql_container.mysql_version in ret
assert database_backend.version in ret


def test_status(mysql):
Expand Down Expand Up @@ -111,20 +129,20 @@ def test_db_create_alter_remove(mysql):
assert ret


def test_user_list(mysql, mysql_combo):
def test_user_list(mysql, database_backend):
ret = mysql.user_list()
assert ret
assert {
"User": mysql_combo.mysql_root_user,
"Host": mysql_combo.mysql_host,
"User": database_backend.root_user,
"Host": database_backend.host,
} in ret


def test_user_exists(mysql, mysql_combo):
def test_user_exists(mysql, database_backend):
ret = mysql.user_exists(
mysql_combo.mysql_root_user,
host=mysql_combo.mysql_host,
password=mysql_combo.mysql_passwd,
database_backend.root_user,
host=database_backend.host,
password=database_backend.passwd,
)
assert ret

Expand All @@ -136,15 +154,15 @@ def test_user_exists(mysql, mysql_combo):
assert not ret


def test_user_info(mysql, mysql_combo):
ret = mysql.user_info(mysql_combo.mysql_root_user, host=mysql_combo.mysql_host)
def test_user_info(mysql, database_backend):
ret = mysql.user_info(database_backend.root_user, host=database_backend.host)
assert ret

# Check that a subset of the information
# is available in the returned user information.
expected = {
"Host": mysql_combo.mysql_host,
"User": mysql_combo.mysql_root_user,
"Host": database_backend.host,
"User": database_backend.root_user,
"Select_priv": "Y",
"Insert_priv": "Y",
"Update_priv": "Y",
Expand Down Expand Up @@ -201,8 +219,8 @@ def test_user_create_chpass_delete(mysql):
assert ret


def test_user_grants(mysql, mysql_combo):
ret = mysql.user_grants(mysql_combo.mysql_root_user, host=mysql_combo.mysql_host)
def test_user_grants(mysql, database_backend):
ret = mysql.user_grants(database_backend.root_user, host=database_backend.host)
assert ret


Expand Down Expand Up @@ -300,22 +318,22 @@ def test_grant_add_revoke(mysql):
assert ret


def test_grant_replication_replica_add_revoke(mysql, mysql_container):
def test_grant_replication_replica_add_revoke(mysql, database_backend):
# The REPLICATION REPLICA grant is only available for mariadb
if "mariadb" not in mysql_container.mysql_name:
if "mariadb" not in database_backend.name:
pytest.skip(
"The REPLICATION REPLICA grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

# The REPLICATION REPLICA grant was added in mariadb 10.5.1
if version_cmp(mysql_container.mysql_version, "10.5.1") < 0:
if version_cmp(database_backend.version, "10.5.1") < 0:
pytest.skip(
"The REPLICATION REPLICA grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

Expand Down Expand Up @@ -376,7 +394,7 @@ def test_grant_replication_replica_add_revoke(mysql, mysql_container):
assert ret


def test_grant_replication_slave_add_revoke(mysql, mysql_container):
def test_grant_replication_slave_add_revoke(mysql, database_backend):
# Create the database
ret = mysql.db_create("salt")
assert ret
Expand Down Expand Up @@ -434,7 +452,7 @@ def test_grant_replication_slave_add_revoke(mysql, mysql_container):
assert ret


def test_grant_replication_client_add_revoke(mysql, mysql_container):
def test_grant_replication_client_add_revoke(mysql, database_backend):
# Create the database
ret = mysql.db_create("salt")
assert ret
Expand Down Expand Up @@ -492,22 +510,22 @@ def test_grant_replication_client_add_revoke(mysql, mysql_container):
assert ret


def test_grant_binlog_monitor_add_revoke(mysql, mysql_container):
def test_grant_binlog_monitor_add_revoke(mysql, database_backend):
# The BINLOG MONITOR grant is only available for mariadb
if "mariadb" not in mysql_container.mysql_name:
if "mariadb" not in database_backend.name:
pytest.skip(
"The BINLOG MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

# The BINLOG MONITOR grant was added in mariadb 10.5.2
if version_cmp(mysql_container.mysql_version, "10.5.2") < 0:
if version_cmp(database_backend.version, "10.5.2") < 0:
pytest.skip(
"The BINLOG_MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

Expand Down Expand Up @@ -568,22 +586,22 @@ def test_grant_binlog_monitor_add_revoke(mysql, mysql_container):
assert ret


def test_grant_replica_monitor_add_revoke(mysql, mysql_container):
def test_grant_replica_monitor_add_revoke(mysql, database_backend):
# The REPLICA MONITOR grant is only available for mariadb
if "mariadb" not in mysql_container.mysql_name:
if "mariadb" not in database_backend.name:
pytest.skip(
"The REPLICA MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

# The REPLICA MONITOR grant was added in mariadb 10.5.9
if version_cmp(mysql_container.mysql_version, "10.5.9") < 0:
if version_cmp(database_backend.version, "10.5.9") < 0:
pytest.skip(
"The REPLICA MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

Expand Down Expand Up @@ -644,22 +662,22 @@ def test_grant_replica_monitor_add_revoke(mysql, mysql_container):
assert ret


def test_grant_slave_monitor_add_revoke(mysql, mysql_container):
def test_grant_slave_monitor_add_revoke(mysql, database_backend):
# The SLAVE MONITOR grant is only available for mariadb
if "mariadb" not in mysql_container.mysql_name:
if "mariadb" not in database_backend.name:
pytest.skip(
"The SLAVE MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

# The SLAVE MONITOR grant was added in mariadb 10.5.9
if version_cmp(mysql_container.mysql_version, "10.5.9") < 0:
if version_cmp(database_backend.version, "10.5.9") < 0:
pytest.skip(
"The SLAVE MONITOR grant is unavailable "
"for the {}:{} docker image.".format(
mysql_container.mysql_name, mysql_container.mysql_version
database_backend.name, database_backend.version
)
)

Expand Down Expand Up @@ -720,32 +738,32 @@ def test_grant_slave_monitor_add_revoke(mysql, mysql_container):
assert ret


def test_plugin_add_status_remove(mysql, mysql_combo):
def test_plugin_add_status_remove(mysql, database_backend):

if "mariadb" in mysql_combo.mysql_name:
if "mariadb" in database_backend.name:
plugin = "simple_password_check"
else:
plugin = "auth_socket"

ret = mysql.plugin_status(plugin, host=mysql_combo.mysql_host)
ret = mysql.plugin_status(plugin, host=database_backend.host)
assert not ret

ret = mysql.plugin_add(plugin)
assert ret

ret = mysql.plugin_status(plugin, host=mysql_combo.mysql_host)
ret = mysql.plugin_status(plugin, host=database_backend.host)
assert ret
assert ret == "ACTIVE"

ret = mysql.plugin_remove(plugin)
assert ret

ret = mysql.plugin_status(plugin, host=mysql_combo.mysql_host)
ret = mysql.plugin_status(plugin, host=database_backend.host)
assert not ret


def test_plugin_list(mysql, mysql_container):
if "mariadb" in mysql_container.mysql_name:
def test_plugin_list(mysql, database_backend):
if "mariadb" in database_backend.name:
plugin = "simple_password_check"
else:
plugin = "auth_socket"
Expand Down
Loading








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/saltstack/salt/pull/68068/commits/306b50b33e78bdfeafc209fa2beb554fe3959bb7

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy