test_cp.py 1.3 KB

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