mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
change to run git.latest from minion module rather than directly
This commit is contained in:
parent
5c9321c0d5
commit
570857f269
5 changed files with 71 additions and 49 deletions
|
@ -115,7 +115,7 @@ def genrepo(opts=None, fire_event=True):
|
|||
return ret
|
||||
|
||||
|
||||
def update_git_repos(opts=None, clean=False, masterless=False, saltenv="base"):
|
||||
def update_git_repos(opts=None, clean=False, masterless=False):
|
||||
"""
|
||||
Checkout git repos containing Windows Software Package Definitions
|
||||
|
||||
|
@ -134,12 +134,6 @@ def update_git_repos(opts=None, clean=False, masterless=False, saltenv="base"):
|
|||
|
||||
.. versionadded:: 2015.8.0
|
||||
|
||||
saltenv
|
||||
Specify the saltenv to use for the underlying git.latest call if no
|
||||
git dependencies are installed
|
||||
|
||||
.. versionadded:: 3005
|
||||
|
||||
CLI Examples:
|
||||
|
||||
.. code-block:: bash
|
||||
|
@ -201,15 +195,27 @@ def update_git_repos(opts=None, clean=False, masterless=False, saltenv="base"):
|
|||
result = result[key]
|
||||
else:
|
||||
mminion = salt.minion.MasterMinion(opts)
|
||||
result = mminion.states["git.latest"](
|
||||
remote_url,
|
||||
result = mminion.functions["state.single"](
|
||||
"git.latest",
|
||||
name=remote_url,
|
||||
rev=rev,
|
||||
branch="winrepo",
|
||||
target=gittarget,
|
||||
force_checkout=True,
|
||||
force_reset=True,
|
||||
saltenv=saltenv,
|
||||
)
|
||||
if isinstance(result, list):
|
||||
# Errors were detected
|
||||
raise CommandExecutionError(
|
||||
"Failed up update winrepo remotes: {}".format(
|
||||
"\n".join(result)
|
||||
)
|
||||
)
|
||||
if "name" not in result:
|
||||
# Highstate output dict, the results are actually nested
|
||||
# one level down.
|
||||
key = next(iter(result))
|
||||
result = result[key]
|
||||
winrepo_result[result["name"]] = result["result"]
|
||||
ret.update(winrepo_result)
|
||||
else:
|
||||
|
|
|
@ -609,11 +609,7 @@ def latest(
|
|||
- ssh_known_hosts: gitlab.example.com
|
||||
"""
|
||||
ret = {"name": name, "result": True, "comment": "", "changes": {}}
|
||||
|
||||
# If we call from a runner, __env__ will not be populated, so we need to do so.
|
||||
if "saltenv" in kwargs:
|
||||
__env__ = kwargs.pop("saltenv")
|
||||
|
||||
|
||||
kwargs = salt.utils.args.clean_kwargs(**kwargs)
|
||||
if kwargs:
|
||||
return _fail(ret, salt.utils.args.invalid_kwargs(kwargs, raise_exc=False))
|
||||
|
|
0
tests/pytests/functional/runners/__init__.py
Normal file
0
tests/pytests/functional/runners/__init__.py
Normal file
54
tests/pytests/functional/runners/test_winrepo.py
Normal file
54
tests/pytests/functional/runners/test_winrepo.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
from tests.support.mock import Mock, patch
|
||||
import pytest
|
||||
from salt.runners import winrepo
|
||||
import salt.utils.gitfs
|
||||
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.windows_whitelisted
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def configure_loader_modules(minion_opts):
|
||||
return {
|
||||
winrepo: {
|
||||
"__opts__": minion_opts,
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def winrepo_remotes(minion_opts):
|
||||
winrepo_remotes = minion_opts.get("winrepo_remotes", [])
|
||||
winrepo_remotes_ng = minion_opts.get("winrepo_remotes_ng", [])
|
||||
winrepo_remotes.extend(winrepo_remotes_ng)
|
||||
return winrepo_remotes
|
||||
|
||||
|
||||
def test_update_git_repos(winrepo_remotes):
|
||||
"""
|
||||
Ensure update git repos works as intended.
|
||||
"""
|
||||
res = winrepo.update_git_repos()
|
||||
|
||||
assert res
|
||||
|
||||
for remote in winrepo_remotes:
|
||||
assert remote in res
|
||||
assert res[remote]
|
||||
|
||||
|
||||
def test_legacy_update_git_repos(winrepo_remotes):
|
||||
"""
|
||||
Ensure update git repos works as intended with legacy (non-gitfs) code.
|
||||
"""
|
||||
with patch.object(salt.utils.gitfs, "GITPYTHON_VERSION", False):
|
||||
with patch.object(salt.utils.gitfs, "PYGIT2_VERSION", False):
|
||||
res = winrepo.update_git_repos()
|
||||
|
||||
assert res
|
||||
|
||||
for remote in winrepo_remotes:
|
||||
assert remote in res
|
||||
assert res[remote]
|
|
@ -1,34 +0,0 @@
|
|||
"""
|
||||
Tests the winrepo runner
|
||||
"""
|
||||
|
||||
import logging
|
||||
|
||||
import pytest
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.slow_test,
|
||||
pytest.mark.windows_whitelisted,
|
||||
]
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_update_winrepo(salt_master, salt_run_cli):
|
||||
"""
|
||||
Simple test to make sure that update_git_repos works.
|
||||
"""
|
||||
winrepo_remotes = salt_master.config["winrepo_remotes"]
|
||||
winrepo_remotes_ng = salt_master.config["winrepo_remotes_ng"]
|
||||
|
||||
res = salt_run_cli.run("winrepo.update_git_repos").json
|
||||
|
||||
assert res
|
||||
|
||||
for remote in winrepo_remotes:
|
||||
assert remote in res
|
||||
assert res[remote]
|
||||
|
||||
for remote in winrepo_remotes_ng:
|
||||
assert remote in res
|
||||
assert res[remote]
|
Loading…
Add table
Reference in a new issue