Skip to content

Commit

Permalink
Migrate grains tests to pytest
Browse files Browse the repository at this point in the history
  • Loading branch information
dwoz committed Aug 8, 2024
1 parent b40833e commit c0ce3f9
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 83 deletions.
83 changes: 0 additions & 83 deletions tests/integration/loader/test_ext_grains.py

This file was deleted.

Empty file.
48 changes: 48 additions & 0 deletions tests/pytests/integration/loader/test_ext_grains.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import pytest


def test_grains_overwrite(salt_cli, salt_master, salt_minion):
assert not salt_minion.config.get("grains_deep_merge", False)
# Force a grains sync
salt_cli.run("saltutil.sync_grains", minion_tgt=salt_minion.id)

# XXX: This should no longer be neede because of using salt_cli.run.
# To avoid a race condition on Windows, we need to make sure the
# `test_custom_grain2.py` file is present in the _grains directory
# before trying to get the grains. This test may execute before the
# minion has finished syncing down the files it needs.
# module = os.path.join(
# salt_minion.config["cachedir"],
# "files",
# "base",
# "_grains",
# "custom_grain2.py",
# )
# assert os.path.exists(module)

# Check that custom grains are overwritten
ret = salt_cli.run("grains.items", minion_tgt=salt_minion.id)
assert ret.data["a_custom"] == {"k2": "v2"}


def test_grains_merge(salt_cli, salt_master):
minion = salt_master.salt_minion_daemon(
"test_grains_merge",
overrides={
"grains_deep_merge": True,
# Grains in the minon config won't get merged.
# "grains": {"a_custom": {"k1": "v1"}},
},
)
minion.after_terminate(
pytest.helpers.remove_stale_minion_key, salt_master, minion.id
)
content = """
def grain():
return {"a_custom": {"k1": "v1"}}
"""
with salt_master.state_tree.base.temp_file("_grains/tempcustom.py", content):
with minion.started():
salt_cli.run("saltutil.sync_grains", minion_tgt=minion.id)
ret = salt_cli.run("grains.item", "a_custom", minion_tgt=minion.id)
assert ret.data["a_custom"] == {"k1": "v1", "k2": "v2"}

0 comments on commit c0ce3f9

Please sign in to comment.