mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Add shell cp tests and fix them
This commit is contained in:
parent
85478cd2b3
commit
a3897290e8
2 changed files with 32 additions and 13 deletions
|
@ -14,13 +14,16 @@ import os
|
|||
import pipes
|
||||
import shutil
|
||||
import tempfile
|
||||
import logging
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.case import ShellCase
|
||||
from tests.support.paths import TMP
|
||||
from tests.support.mixins import ShellCaseCommonTestsMixin
|
||||
from tests.support.unit import skipIf
|
||||
|
||||
# Import salt libs
|
||||
import salt.utils.platform
|
||||
import salt.utils.files
|
||||
import salt.utils.yaml
|
||||
|
||||
|
@ -28,6 +31,9 @@ import salt.utils.yaml
|
|||
from salt.ext import six
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
|
||||
|
||||
_call_binary_ = 'salt-cp'
|
||||
|
@ -54,19 +60,24 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
|
|||
with salt.utils.files.fopen(testfile, 'r') as fh_:
|
||||
testfile_contents = fh_.read()
|
||||
|
||||
def quote(arg):
|
||||
if salt.utils.platform.is_windows():
|
||||
return arg
|
||||
return pipes.quote(arg)
|
||||
|
||||
for idx, minion in enumerate(minions):
|
||||
if 'localhost' in minion:
|
||||
continue
|
||||
ret = self.run_salt(
|
||||
'--out yaml {0} file.directory_exists {1}'.format(
|
||||
pipes.quote(minion), TMP
|
||||
quote(minion), TMP
|
||||
)
|
||||
)
|
||||
data = salt.utils.yaml.safe_load('\n'.join(ret))
|
||||
if data[minion] is False:
|
||||
ret = self.run_salt(
|
||||
'--out yaml {0} file.makedirs {1}'.format(
|
||||
pipes.quote(minion),
|
||||
quote(minion),
|
||||
TMP
|
||||
)
|
||||
)
|
||||
|
@ -79,19 +90,25 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
|
|||
)
|
||||
|
||||
ret = self.run_cp('--out pprint {0} {1} {2}'.format(
|
||||
pipes.quote(minion),
|
||||
pipes.quote(testfile),
|
||||
pipes.quote(minion_testfile)
|
||||
quote(minion),
|
||||
quote(testfile),
|
||||
quote(minion_testfile),
|
||||
'-l debug',
|
||||
))
|
||||
log.error("RET = %s", ret)
|
||||
|
||||
data = salt.utils.yaml.safe_load('\n'.join(ret))
|
||||
for part in six.itervalues(data):
|
||||
self.assertTrue(part[minion_testfile])
|
||||
if salt.utils.platform.is_windows():
|
||||
key = minion_testfile.replace('\\', '\\\\')
|
||||
else:
|
||||
key = minion_testfile
|
||||
self.assertTrue(part[key])
|
||||
|
||||
ret = self.run_salt(
|
||||
'--out yaml {0} file.file_exists {1}'.format(
|
||||
pipes.quote(minion),
|
||||
pipes.quote(minion_testfile)
|
||||
quote(minion),
|
||||
quote(minion_testfile)
|
||||
)
|
||||
)
|
||||
data = salt.utils.yaml.safe_load('\n'.join(ret))
|
||||
|
@ -99,22 +116,23 @@ class CopyTest(ShellCase, ShellCaseCommonTestsMixin):
|
|||
|
||||
ret = self.run_salt(
|
||||
'--out yaml {0} file.contains {1} {2}'.format(
|
||||
pipes.quote(minion),
|
||||
pipes.quote(minion_testfile),
|
||||
pipes.quote(testfile_contents)
|
||||
quote(minion),
|
||||
quote(minion_testfile),
|
||||
quote(testfile_contents)
|
||||
)
|
||||
)
|
||||
data = salt.utils.yaml.safe_load('\n'.join(ret))
|
||||
self.assertTrue(data[minion])
|
||||
ret = self.run_salt(
|
||||
'--out yaml {0} file.remove {1}'.format(
|
||||
pipes.quote(minion),
|
||||
pipes.quote(minion_testfile)
|
||||
quote(minion),
|
||||
quote(minion_testfile)
|
||||
)
|
||||
)
|
||||
data = salt.utils.yaml.safe_load('\n'.join(ret))
|
||||
self.assertTrue(data[minion])
|
||||
|
||||
@skipIf(salt.utils.platform.is_windows(), 'Skip on Windows OS')
|
||||
def test_issue_7754(self):
|
||||
config_dir = os.path.join(TMP, 'issue-7754')
|
||||
|
||||
|
|
|
@ -77,6 +77,7 @@ integration.shell.test_arguments
|
|||
integration.shell.test_auth
|
||||
integration.shell.test_call
|
||||
integration.shell.test_cloud
|
||||
integration.shell.test_cp
|
||||
integration.states.test_host
|
||||
integration.states.test_pip_state
|
||||
integration.states.test_pkg
|
||||
|
|
Loading…
Add table
Reference in a new issue