1
0

test_salt_cp.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. """
  2. :codeauthor: Pedro Algarvio (pedro@algarvio.me)
  3. tests.integration.shell.cp
  4. ~~~~~~~~~~~~~~~~~~~~~~~~~~
  5. """
  6. import logging
  7. import os
  8. import pathlib
  9. import pytest
  10. import salt.utils.files
  11. from tests.support.helpers import slowTest
  12. from tests.support.runtests import RUNTIME_VARS
  13. log = logging.getLogger(__name__)
  14. @pytest.fixture
  15. def source_testfile():
  16. src = pathlib.Path(RUNTIME_VARS.BASE_FILES) / "testfile"
  17. return str(src.resolve())
  18. @pytest.fixture
  19. def dest_testfile():
  20. dst = pathlib.Path(RUNTIME_VARS.TMP) / "test_cp_testfile_copy"
  21. try:
  22. yield str(dst)
  23. finally:
  24. if dst.exists():
  25. dst.unlink()
  26. @slowTest
  27. @pytest.mark.windows_whitelisted
  28. def test_cp_testfile(salt_minion, salt_cp_cli, source_testfile, dest_testfile):
  29. """
  30. test salt-cp
  31. """
  32. ret = salt_cp_cli.run(source_testfile, dest_testfile, minion_tgt=salt_minion.id)
  33. assert ret.exitcode == 0
  34. assert ret.json[dest_testfile] is True
  35. assert os.path.exists(dest_testfile)
  36. with salt.utils.files.fopen(source_testfile) as rfh:
  37. source_testfile_contents = rfh.read()
  38. with salt.utils.files.fopen(dest_testfile) as rfh:
  39. dest_test_file = rfh.read()
  40. assert source_testfile_contents == dest_test_file