2012-08-04 21:28:51 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-08-04 21:28:51 +00:00
|
|
|
tests.integration.shell.cp
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
2012-12-11 10:23:37 +00:00
|
|
|
:codeauthor: :email:`Pedro Algarvio (pedro@algarvio.me)`
|
|
|
|
:copyright: © 2012 by the SaltStack Team, see AUTHORS for more details.
|
2012-08-04 21:28:51 +00:00
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-08-04 21:28:51 +00:00
|
|
|
|
|
|
|
# Import python libs
|
|
|
|
import os
|
|
|
|
import sys
|
2012-09-03 22:24:08 +00:00
|
|
|
import yaml
|
2012-10-14 21:31:58 +00:00
|
|
|
import pipes
|
2012-08-04 21:28:51 +00:00
|
|
|
|
|
|
|
# Import salt libs
|
2013-06-24 22:53:59 +00:00
|
|
|
try:
|
|
|
|
import integration
|
|
|
|
except ImportError:
|
|
|
|
if __name__ == '__main__':
|
|
|
|
sys.path.insert(
|
|
|
|
0, os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(__file__), '../../'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
import integration
|
2012-11-18 18:57:10 +00:00
|
|
|
import salt.utils
|
2012-08-04 21:28:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CopyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|
|
|
|
|
|
|
_call_binary_ = 'salt-cp'
|
|
|
|
|
|
|
|
def test_cp_testfile(self):
|
|
|
|
'''
|
|
|
|
test salt-cp
|
|
|
|
'''
|
2012-09-03 22:24:08 +00:00
|
|
|
minions = []
|
2012-11-16 17:15:39 +00:00
|
|
|
for line in self.run_salt('--out yaml "*" test.ping'):
|
2012-09-03 22:24:08 +00:00
|
|
|
if not line:
|
|
|
|
continue
|
|
|
|
data = yaml.load(line)
|
|
|
|
minions.extend(data.keys())
|
|
|
|
|
|
|
|
self.assertNotEqual(minions, [])
|
|
|
|
|
|
|
|
testfile = os.path.abspath(
|
|
|
|
os.path.join(
|
|
|
|
os.path.dirname(os.path.dirname(__file__)),
|
|
|
|
'files', 'file', 'base', 'testfile'
|
|
|
|
)
|
|
|
|
)
|
2012-11-18 18:57:10 +00:00
|
|
|
testfile_contents = salt.utils.fopen(testfile, 'r').read()
|
2012-09-03 22:24:08 +00:00
|
|
|
|
2012-10-14 21:31:58 +00:00
|
|
|
for idx, minion in enumerate(minions):
|
|
|
|
ret = self.run_salt(
|
2012-11-16 17:15:39 +00:00
|
|
|
'--out yaml {0} file.directory_exists {1}'.format(
|
2012-10-14 21:31:58 +00:00
|
|
|
pipes.quote(minion), integration.TMP
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
if data[minion] is False:
|
|
|
|
ret = self.run_salt(
|
2012-11-16 17:15:39 +00:00
|
|
|
'--out yaml {0} file.makedirs {1}'.format(
|
2012-10-14 21:31:58 +00:00
|
|
|
pipes.quote(minion),
|
|
|
|
integration.TMP
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
self.assertTrue(data[minion])
|
|
|
|
|
2012-08-04 21:28:51 +00:00
|
|
|
minion_testfile = os.path.join(
|
2012-10-14 21:31:58 +00:00
|
|
|
integration.TMP, 'cp_{0}_testfile'.format(idx)
|
|
|
|
)
|
|
|
|
|
|
|
|
ret = self.run_cp('{0} {1} {2}'.format(
|
|
|
|
pipes.quote(minion),
|
|
|
|
pipes.quote(testfile),
|
|
|
|
pipes.quote(minion_testfile)
|
|
|
|
))
|
|
|
|
|
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
for part in data.values():
|
|
|
|
self.assertTrue(part[minion_testfile])
|
|
|
|
|
|
|
|
ret = self.run_salt(
|
2012-11-16 17:15:39 +00:00
|
|
|
'--out yaml {0} file.file_exists {1}'.format(
|
2012-10-14 21:31:58 +00:00
|
|
|
pipes.quote(minion),
|
|
|
|
pipes.quote(minion_testfile)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
self.assertTrue(data[minion])
|
|
|
|
|
|
|
|
ret = self.run_salt(
|
2012-11-16 17:15:39 +00:00
|
|
|
'--out yaml {0} file.contains {1} {2}'.format(
|
2012-10-14 21:31:58 +00:00
|
|
|
pipes.quote(minion),
|
|
|
|
pipes.quote(minion_testfile),
|
|
|
|
pipes.quote(testfile_contents)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
self.assertTrue(data[minion])
|
|
|
|
ret = self.run_salt(
|
2012-11-16 17:15:39 +00:00
|
|
|
'--out yaml {0} file.remove {1}'.format(
|
2012-10-14 21:31:58 +00:00
|
|
|
pipes.quote(minion),
|
|
|
|
pipes.quote(minion_testfile)
|
|
|
|
)
|
2012-08-04 21:28:51 +00:00
|
|
|
)
|
2012-10-14 21:31:58 +00:00
|
|
|
data = yaml.load('\n'.join(ret))
|
|
|
|
self.assertTrue(data[minion])
|
2012-08-04 21:28:51 +00:00
|
|
|
|
2013-06-24 22:53:59 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
from integration import run_tests
|
|
|
|
run_tests(CopyTest)
|