mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Migrate tests/integration/ssh/test_deploy.py
to pytest
Signed-off-by: Pedro Algarvio <palgarvio@vmware.com>
This commit is contained in:
parent
3d4dc9f274
commit
4ebb9c41d4
3 changed files with 88 additions and 64 deletions
|
@ -194,7 +194,7 @@ salt/cli/daemons.py:
|
|||
|
||||
salt/(client/ssh/.+|cli/ssh\.py):
|
||||
- integration.cli.test_custom_module
|
||||
- integration.ssh.test_deploy
|
||||
- pytests.integration.ssh.test_deploy
|
||||
- pytests.integration.ssh.test_grains
|
||||
- integration.ssh.test_jinja_filters
|
||||
- pytests.integration.ssh.test_mine
|
||||
|
|
|
@ -1,63 +0,0 @@
|
|||
"""
|
||||
salt-ssh testing
|
||||
"""
|
||||
|
||||
import os
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
from tests.support.case import SSHCase
|
||||
from tests.support.runtests import RUNTIME_VARS
|
||||
|
||||
|
||||
class SSHTest(SSHCase):
|
||||
"""
|
||||
Test general salt-ssh functionality
|
||||
"""
|
||||
|
||||
def setUp(self):
|
||||
thin_dir = self.run_function("config.get", ["thin_dir"], wipe=False)
|
||||
self.addCleanup(shutil.rmtree, thin_dir, ignore_errors=True)
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_ping(self):
|
||||
"""
|
||||
Test a simple ping
|
||||
"""
|
||||
ret = self.run_function("test.ping")
|
||||
self.assertTrue(ret, "Ping did not return true")
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_thin_dir(self):
|
||||
"""
|
||||
test to make sure thin_dir is created
|
||||
and salt-call file is included
|
||||
"""
|
||||
thin_dir = self.run_function("config.get", ["thin_dir"], wipe=False)
|
||||
os.path.isdir(thin_dir)
|
||||
os.path.exists(os.path.join(thin_dir, "salt-call"))
|
||||
os.path.exists(os.path.join(thin_dir, "running_data"))
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_set_path(self):
|
||||
"""
|
||||
test setting the path env variable
|
||||
"""
|
||||
path = "/pathdoesnotexist/"
|
||||
roster = os.path.join(RUNTIME_VARS.TMP, "roster-set-path")
|
||||
self.custom_roster(
|
||||
roster, data={"set_path": "$PATH:/usr/local/bin/:{}".format(path)}
|
||||
)
|
||||
ret = self.run_function("environ.get", ["PATH"], roster_file=roster)
|
||||
assert path in ret
|
||||
|
||||
@pytest.mark.slow_test
|
||||
def test_tty(self):
|
||||
"""
|
||||
test using tty
|
||||
"""
|
||||
roster = os.path.join(RUNTIME_VARS.TMP, "roster-tty")
|
||||
self.custom_roster(roster, data={"tty": True})
|
||||
ret = self.run_function("test.ping", roster_file=roster)
|
||||
assert ret is True
|
87
tests/pytests/integration/ssh/test_deploy.py
Normal file
87
tests/pytests/integration/ssh/test_deploy.py
Normal file
|
@ -0,0 +1,87 @@
|
|||
"""
|
||||
salt-ssh testing
|
||||
"""
|
||||
|
||||
import pathlib
|
||||
import shutil
|
||||
|
||||
import pytest
|
||||
|
||||
import salt.utils.files
|
||||
import salt.utils.yaml
|
||||
|
||||
pytestmark = [
|
||||
pytest.mark.slow_test,
|
||||
pytest.mark.skip_on_windows(reason="salt-ssh not available on Windows"),
|
||||
]
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def thin_dir(salt_ssh_cli):
|
||||
try:
|
||||
yield
|
||||
finally:
|
||||
ret = salt_ssh_cli.run("config.get", "thin_dir")
|
||||
assert ret.returncode == 0
|
||||
thin_dir_path = ret.data
|
||||
shutil.rmtree(thin_dir_path, ignore_errors=True)
|
||||
|
||||
|
||||
def test_ping(salt_ssh_cli):
|
||||
"""
|
||||
Test a simple ping
|
||||
"""
|
||||
ret = salt_ssh_cli.run("test.ping")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
||||
|
||||
|
||||
def test_thin_dir(salt_ssh_cli):
|
||||
"""
|
||||
test to make sure thin_dir is created
|
||||
and salt-call file is included
|
||||
"""
|
||||
ret = salt_ssh_cli.run("config.get", "thin_dir")
|
||||
assert ret.returncode == 0
|
||||
thin_dir = pathlib.Path(ret.data)
|
||||
assert thin_dir.is_dir()
|
||||
assert thin_dir.joinpath("salt-call").exists()
|
||||
assert thin_dir.joinpath("running_data").exists()
|
||||
|
||||
|
||||
def test_set_path(salt_ssh_cli, tmp_path, salt_ssh_roster_file):
|
||||
"""
|
||||
test setting the path env variable
|
||||
"""
|
||||
path = "/pathdoesnotexist/"
|
||||
roster_file = tmp_path / "roster-set-path"
|
||||
with salt.utils.files.fopen(salt_ssh_roster_file) as rfh:
|
||||
roster_data = salt.utils.yaml.safe_load(rfh)
|
||||
roster_data["localhost"].update(
|
||||
{
|
||||
"set_path": "$PATH:/usr/local/bin/:{}".format(path),
|
||||
}
|
||||
)
|
||||
with salt.utils.files.fopen(roster_file, "w") as wfh:
|
||||
salt.utils.yaml.safe_dump(roster_data, wfh)
|
||||
|
||||
ret = salt_ssh_cli.run(
|
||||
"--roster-file={}".format(roster_file), "environ.get", "PATH"
|
||||
)
|
||||
assert ret.returncode == 0
|
||||
assert path in ret.data
|
||||
|
||||
|
||||
def test_tty(salt_ssh_cli, tmp_path, salt_ssh_roster_file):
|
||||
"""
|
||||
test using tty
|
||||
"""
|
||||
roster_file = tmp_path / "roster-tty"
|
||||
with salt.utils.files.fopen(salt_ssh_roster_file) as rfh:
|
||||
roster_data = salt.utils.yaml.safe_load(rfh)
|
||||
roster_data["localhost"].update({"tty": True})
|
||||
with salt.utils.files.fopen(roster_file, "w") as wfh:
|
||||
salt.utils.yaml.safe_dump(roster_data, wfh)
|
||||
ret = salt_ssh_cli.run("--roster-file={}".format(roster_file), "test.ping")
|
||||
assert ret.returncode == 0
|
||||
assert ret.data is True
|
Loading…
Add table
Reference in a new issue