Go back to salt_call_cli.run

This commit is contained in:
Twangboy 2023-02-08 13:51:16 -07:00 committed by Pedro Algarvio
parent ef773ece29
commit 1e45b3d145
5 changed files with 29 additions and 48 deletions

View file

@ -1,6 +1,3 @@
import os.path
def test_help(install_salt):
"""
Test --help works for all salt cmds
@ -12,7 +9,6 @@ def test_help(install_salt):
ret = install_salt.proc.run(*cmd, "--version")
assert "Python" in ret.stdout
else:
test_bin = os.path.join(*cmd)
ret = install_salt.proc.run(test_bin, "--help")
ret = install_salt.proc.run(*cmd, "--help")
assert "Usage" in ret.stdout
assert ret.returncode == 0

View file

@ -31,7 +31,7 @@ def wipe_pydeps(pypath, install_salt):
)
def test_pip_install(install_salt):
def test_pip_install(salt_call_cli):
"""
Test pip.install and ensure module can use installed library
"""
@ -39,20 +39,15 @@ def test_pip_install(install_salt):
repo = "https://github.com/saltstack/salt.git"
try:
test_bin = os.path.join(*install_salt.binary_paths["call"])
install = install_salt.proc.run(test_bin, "--local", "pip.install", dep)
install = salt_call_cli.run("--local", "pip.install", dep)
assert install.returncode == 0
use_lib = install_salt.proc.run(
test_bin, "--local", "github.get_repo_info", repo
)
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
assert "Authentication information could" in use_lib.stderr
finally:
ret = install_salt.proc.run(test_bin, "--local", "pip.uninstall", dep)
ret = salt_call_cli.run("--local", "pip.uninstall", dep)
assert ret.returncode == 0
use_lib = install_salt.proc.run(
test_bin, "--local", "github.get_repo_info", repo
)
use_lib = salt_call_cli.run("--local", "github.get_repo_info", repo)
assert "The github execution module cannot be loaded" in use_lib.stderr

View file

@ -1,24 +1,22 @@
import os
import sys
import pytest
@pytest.fixture(scope="module")
def grains(install_salt):
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(test_bin, "--local", "grains.items")
assert ret.returncode == 0
assert "saltversioninfo" in ret.stdout
def grains(salt_call_cli):
ret = salt_call_cli.run("--local", "grains.items")
assert ret.data, ret
return ret.data
@pytest.fixture(scope="module")
def pkg_name(install_salt, grains):
def pkg_name(salt_call_cli, grains):
if sys.platform.startswith("win"):
test_bin = os.path.join(*install_salt.binary_paths["call"])
install_salt.proc.run(test_bin, "--local", "winrepo.update_git_repos")
install_salt.proc.run(test_bin, "--local", "pkg.refresh_db")
ret = salt_call_cli.run("--local", "winrepo.update_git_repos")
assert ret.returncode == 0
ret = salt_call_cli.run("--local", "pkg.refresh_db")
assert ret.returncode == 0
return "putty"
elif grains["os_family"] == "RedHat":
if grains["os"] == "VMware Photon OS":
@ -29,9 +27,6 @@ def pkg_name(install_salt, grains):
return "figlet"
def test_pkg_install(install_salt, pkg_name):
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(
test_bin, "--local", "state.single", "pkg.installed", pkg_name
)
def test_pkg_install(salt_call_cli, pkg_name):
ret = salt_call_cli.run("--local", "state.single", "pkg.installed", pkg_name)
assert ret.returncode == 0

View file

@ -1,15 +1,12 @@
import os.path
import pytest
def test_salt_call_local(install_salt):
def test_salt_call_local(salt_call_cli):
"""
Test salt-call --local test.ping
"""
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(test_bin, "--local", "test.ping")
assert "True" in ret.stdout
ret = salt_call_cli.run("--local", "test.ping")
assert ret.data is True
assert ret.returncode == 0
@ -33,33 +30,30 @@ def test_sls(salt_call_cli):
assert ret.returncode == 0
def test_salt_call_local_sys_doc_none(install_salt):
def test_salt_call_local_sys_doc_none(salt_call_cli):
"""
Test salt-call --local sys.doc none
"""
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(test_bin, "--local", "sys.doc", "none")
assert "local:\n ----------\n" == ret.stdout
ret = salt_call_cli.run("--local", "sys.doc", "none")
assert not ret.data
assert ret.returncode == 0
def test_salt_call_local_sys_doc_aliases(install_salt):
def test_salt_call_local_sys_doc_aliases(salt_call_cli):
"""
Test salt-call --local sys.doc aliases
"""
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(test_bin, "--local", "sys.doc", "aliases.list_aliases")
assert "aliases.list_aliases" in ret.stdout
ret = salt_call_cli.run("--local", "sys.doc", "aliases.list_aliases")
assert "aliases.list_aliases" in ret.data
assert ret.returncode == 0
@pytest.mark.skip_on_windows()
def test_salt_call_cmd_run_id_runas(install_salt, test_account, caplog):
def test_salt_call_cmd_run_id_runas(salt_call_cli, test_account, caplog):
"""
Test salt-call --local cmd_run id with runas
"""
test_bin = os.path.join(*install_salt.binary_paths["call"])
ret = install_salt.proc.run(test_bin, "--local", "id", runas=test_account.username)
ret = salt_call_cli.run("--local", "cmd.run", "id", runas=test_account.username)
assert "Environment could not be retrieved for user" not in caplog.text
assert str(test_account.uid) in ret.stdout
assert str(test_account.gid) in ret.stdout

View file

@ -111,7 +111,8 @@ class SaltPkgInstall:
@distro_name.default
def _default_distro_name(self):
return distro.name().split()[0].lower()
if distro.name():
return distro.name().split()[0].lower()
@distro_version.default
def _default_distro_version(self):