2012-08-04 22:07:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-08-04 22:07:39 +00:00
|
|
|
tests.integration.shell.call
|
|
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
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 22:07:39 +00:00
|
|
|
:license: Apache 2.0, see LICENSE for more details.
|
2012-12-11 10:23:37 +00:00
|
|
|
'''
|
2012-08-04 22:07:39 +00:00
|
|
|
|
2012-12-01 23:00:27 +00:00
|
|
|
# Import python libs
|
|
|
|
import os
|
2012-08-04 22:07:39 +00:00
|
|
|
import sys
|
2012-12-01 23:00:27 +00:00
|
|
|
import yaml
|
|
|
|
from datetime import datetime
|
2012-08-04 22:07:39 +00:00
|
|
|
|
|
|
|
# Import salt libs
|
2012-11-16 00:07:08 +00:00
|
|
|
from salt import version
|
2012-12-01 23:00:27 +00:00
|
|
|
|
|
|
|
# Import salt test libs
|
2012-08-04 22:07:39 +00:00
|
|
|
import integration
|
2012-12-01 23:00:27 +00:00
|
|
|
from saltunittest import (
|
|
|
|
TestLoader,
|
|
|
|
TextTestRunner,
|
|
|
|
skipIf,
|
|
|
|
)
|
2012-08-04 22:07:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
class CallTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|
|
|
|
|
|
|
_call_binary_ = 'salt-call'
|
|
|
|
|
2012-08-13 06:10:42 +00:00
|
|
|
def test_default_output(self):
|
2012-12-04 19:14:35 +00:00
|
|
|
out = self.run_call('-l quiet test.fib 3')
|
|
|
|
|
2013-01-13 07:01:30 +00:00
|
|
|
expect = ['local:',
|
|
|
|
' - 0',
|
|
|
|
' - 1',
|
2013-01-29 17:23:22 +00:00
|
|
|
' - 1',
|
|
|
|
' - 2']
|
2012-11-04 10:29:07 +00:00
|
|
|
self.assertEqual(expect, out[:-1])
|
2012-08-13 06:10:42 +00:00
|
|
|
|
|
|
|
def test_text_output(self):
|
2013-01-15 06:40:20 +00:00
|
|
|
out = self.run_call('-l quiet --out txt test.fib 3')
|
2012-11-16 00:07:08 +00:00
|
|
|
|
2013-01-15 07:10:19 +00:00
|
|
|
expect = [
|
2012-11-16 00:07:08 +00:00
|
|
|
'local: ([0, 1, 1, 2]'
|
|
|
|
]
|
|
|
|
|
|
|
|
self.assertEqual(''.join(expect), ''.join(out).rsplit(",", 1)[0])
|
2012-08-13 06:10:42 +00:00
|
|
|
|
2012-09-30 09:59:07 +00:00
|
|
|
@skipIf(sys.platform.startswith('win'), 'This test does not apply on Win')
|
|
|
|
def test_user_delete_kw_output(self):
|
2012-12-04 19:14:35 +00:00
|
|
|
ret = self.run_call('-l quiet -d user.delete')
|
2012-09-30 09:59:07 +00:00
|
|
|
self.assertIn(
|
|
|
|
'salt \'*\' user.delete name remove=True force=True',
|
|
|
|
''.join(ret)
|
|
|
|
)
|
|
|
|
|
2012-12-01 23:00:27 +00:00
|
|
|
@skipIf(sys.platform.startswith('win'), 'This test does not apply on Win')
|
|
|
|
def test_issue_2731_masterless(self):
|
|
|
|
config_dir = '/tmp/salttest'
|
|
|
|
minion_config_file = os.path.join(config_dir, 'minion')
|
2012-12-05 21:24:19 +00:00
|
|
|
this_minion_key = os.path.join(
|
|
|
|
config_dir, 'pki', 'minions', 'minion_test_issue_2731'
|
|
|
|
)
|
2012-12-01 23:00:27 +00:00
|
|
|
|
|
|
|
minion_config = {
|
|
|
|
'id': 'minion_test_issue_2731',
|
|
|
|
'master': 'localhost',
|
|
|
|
'master_port': 64506,
|
|
|
|
'root_dir': '/tmp/salttest',
|
|
|
|
'pki_dir': 'pki',
|
|
|
|
'cachedir': 'cachedir',
|
|
|
|
'sock_dir': 'minion_sock',
|
|
|
|
'open_mode': True,
|
|
|
|
'log_file': '/tmp/salttest/minion_test_issue_2731',
|
|
|
|
'log_level': 'quiet',
|
|
|
|
'log_level_logfile': 'info'
|
|
|
|
}
|
|
|
|
|
|
|
|
# Remove existing logfile
|
|
|
|
if os.path.isfile('/tmp/salttest/minion_test_issue_2731'):
|
|
|
|
os.unlink('/tmp/salttest/minion_test_issue_2731')
|
|
|
|
|
|
|
|
start = datetime.now()
|
|
|
|
# Let's first test with a master running
|
|
|
|
open(minion_config_file, 'w').write(
|
|
|
|
yaml.dump(minion_config, default_flow_style=False)
|
|
|
|
)
|
|
|
|
ret = self.run_script(
|
|
|
|
'salt-call',
|
|
|
|
'--config-dir {0} cmd.run "echo foo"'.format(
|
|
|
|
config_dir
|
|
|
|
)
|
|
|
|
)
|
2012-12-05 21:24:19 +00:00
|
|
|
try:
|
2013-01-13 07:01:30 +00:00
|
|
|
self.assertIn('local:', ret)
|
2012-12-05 21:24:19 +00:00
|
|
|
except AssertionError:
|
|
|
|
if os.path.isfile(minion_config_file):
|
|
|
|
os.unlink(minion_config_file)
|
|
|
|
# Let's remove our key from the master
|
|
|
|
if os.path.isfile(this_minion_key):
|
|
|
|
os.unlink(this_minion_key)
|
|
|
|
|
|
|
|
raise
|
2012-12-01 23:00:27 +00:00
|
|
|
|
|
|
|
# Calculate the required timeout, since next will fail.
|
|
|
|
# I needed this because after many attempts, I was unable to catch:
|
|
|
|
# WARNING: Master hostname: salt not found. Retrying in 30 seconds
|
2012-12-05 21:24:19 +00:00
|
|
|
ellapsed = datetime.now() - start
|
2012-12-01 23:00:27 +00:00
|
|
|
timeout = ellapsed.seconds + 3
|
|
|
|
|
|
|
|
# Now let's remove the master configuration
|
|
|
|
minion_config.pop('master')
|
|
|
|
minion_config.pop('master_port')
|
|
|
|
open(minion_config_file, 'w').write(
|
|
|
|
yaml.dump(minion_config, default_flow_style=False)
|
|
|
|
)
|
|
|
|
|
|
|
|
out = self.run_script(
|
|
|
|
'salt-call',
|
|
|
|
'--config-dir {0} cmd.run "echo foo"'.format(
|
2012-12-03 23:32:58 +00:00
|
|
|
config_dir
|
2012-12-01 23:00:27 +00:00
|
|
|
),
|
|
|
|
timeout=timeout,
|
|
|
|
)
|
|
|
|
|
2012-12-05 21:24:19 +00:00
|
|
|
try:
|
|
|
|
self.assertIn(
|
|
|
|
'Process took more than {0} seconds to complete. '
|
|
|
|
'Process Killed!'.format(timeout),
|
|
|
|
out
|
|
|
|
)
|
|
|
|
except AssertionError:
|
|
|
|
if os.path.isfile(minion_config_file):
|
|
|
|
os.unlink(minion_config_file)
|
|
|
|
# Let's remove our key from the master
|
|
|
|
if os.path.isfile(this_minion_key):
|
|
|
|
os.unlink(this_minion_key)
|
|
|
|
|
|
|
|
raise
|
2012-12-01 23:00:27 +00:00
|
|
|
|
|
|
|
# Should work with --local
|
|
|
|
ret = self.run_script(
|
|
|
|
'salt-call',
|
|
|
|
'--config-dir {0} --local cmd.run "echo foo"'.format(
|
|
|
|
config_dir
|
|
|
|
),
|
|
|
|
timeout=15
|
|
|
|
)
|
2012-12-05 21:24:19 +00:00
|
|
|
try:
|
2013-01-13 07:01:30 +00:00
|
|
|
self.assertIn('local:', ret)
|
2012-12-05 21:24:19 +00:00
|
|
|
except AssertionError:
|
|
|
|
if os.path.isfile(minion_config_file):
|
|
|
|
os.unlink(minion_config_file)
|
|
|
|
# Let's remove our key from the master
|
|
|
|
if os.path.isfile(this_minion_key):
|
|
|
|
os.unlink(this_minion_key)
|
|
|
|
raise
|
2012-12-01 23:00:27 +00:00
|
|
|
|
|
|
|
# Should work with local file client
|
|
|
|
minion_config['file_client'] = 'local'
|
|
|
|
open(minion_config_file, 'w').write(
|
|
|
|
yaml.dump(minion_config, default_flow_style=False)
|
|
|
|
)
|
|
|
|
ret = self.run_script(
|
|
|
|
'salt-call',
|
|
|
|
'--config-dir {0} cmd.run "echo foo"'.format(
|
|
|
|
config_dir
|
|
|
|
),
|
|
|
|
timeout=15
|
|
|
|
)
|
2012-12-05 21:24:19 +00:00
|
|
|
try:
|
2013-01-13 07:01:30 +00:00
|
|
|
self.assertIn('local:', ret)
|
2012-12-05 21:24:19 +00:00
|
|
|
finally:
|
|
|
|
if os.path.isfile(minion_config_file):
|
|
|
|
os.unlink(minion_config_file)
|
|
|
|
# Let's remove our key from the master
|
|
|
|
if os.path.isfile(this_minion_key):
|
|
|
|
os.unlink(this_minion_key)
|
2012-12-01 23:00:27 +00:00
|
|
|
|
2012-09-30 09:59:07 +00:00
|
|
|
|
2012-08-04 22:07:39 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
loader = TestLoader()
|
|
|
|
tests = loader.loadTestsFromTestCase(CallTest)
|
|
|
|
print('Setting up Salt daemons to execute tests')
|
2012-12-01 23:00:27 +00:00
|
|
|
with integration.TestDaemon():
|
2012-08-04 22:07:39 +00:00
|
|
|
runner = TextTestRunner(verbosity=1).run(tests)
|
2012-09-30 09:59:07 +00:00
|
|
|
sys.exit(runner.wasSuccessful())
|