salt/tests/integration/shell/key.py

140 lines
3.7 KiB
Python
Raw Normal View History

# Import python libs
import sys
import shutil
import tempfile
2012-04-21 23:31:46 +00:00
# Import salt libs
from saltunittest import TestLoader, TextTestRunner
2012-04-21 23:31:46 +00:00
import integration
from integration import TestDaemon
2012-04-21 23:31:46 +00:00
class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
2012-04-21 23:31:46 +00:00
'''
Test salt-key script
'''
_call_binary_ = 'salt-key'
2012-04-21 23:31:46 +00:00
def test_list(self):
'''
test salt-key -L
'''
data = self.run_key('-L')
expect = [
'Unaccepted Keys:',
'Accepted Keys:',
'minion',
'sub_minion',
'Rejected:', '']
2012-04-21 23:31:46 +00:00
self.assertEqual(data, expect)
2012-04-21 23:47:04 +00:00
def test_list_json_out(self):
'''
test salt-key -L --json-out
'''
data = self.run_key('-L --json-out')
expect = [
'{"unaccepted": [], "accepted": ["minion", "sub_minion"], "rejected": []}',
''
]
self.assertEqual(data, expect)
def test_list_yaml_out(self):
'''
test salt-key -L --yaml-out
'''
data = self.run_key('-L --yaml-out')
expect = [
2012-05-29 16:40:20 +00:00
'accepted: [minion, sub_minion]',
'rejected: []',
'unaccepted: []',
'',
''
]
self.assertEqual(data, expect)
2012-05-29 16:40:20 +00:00
def test_list_raw_out(self):
'''
test salt-key -L --raw-out
'''
data = self.run_key('-L --raw-out')
expect = [
2012-06-30 20:10:34 +00:00
"{'unaccepted': [], 'accepted': ['minion', "
"'sub_minion'], 'rejected': []}",
''
2012-05-29 16:40:20 +00:00
]
self.assertEqual(data, expect)
2012-04-21 23:47:04 +00:00
def test_list_acc(self):
'''
test salt-key -l
'''
data = self.run_key('-l acc')
self.assertEqual(
data,
[
'minion',
'sub_minion',
''
]
2012-04-21 23:47:04 +00:00
)
def test_list_un(self):
'''
test salt-key -l
'''
data = self.run_key('-l un')
self.assertEqual(
data,
['']
)
def test_keys_generation(self):
tempdir = tempfile.mkdtemp()
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
data = self.run_key(arg_str)
try:
self.assertIn('Keys generation complete', data)
finally:
shutil.rmtree(tempdir)
def test_keys_generation_no_configdir(self):
tempdir = tempfile.mkdtemp()
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
data = self.run_script('salt-key', arg_str)
try:
self.assertIn('Keys generation complete', data)
finally:
shutil.rmtree(tempdir)
def test_keys_generation_keysize_minmax(self):
tempdir = tempfile.mkdtemp()
arg_str = '--gen-keys minion --gen-keys-dir {0}'.format(tempdir)
try:
data, error = self.run_key(
arg_str + ' --keysize=1024', catch_stderr=True
)
self.assertIn(
'salt-key: error: The minimum value for keysize is 2048', error
)
data, error = self.run_key(
arg_str + ' --keysize=32769', catch_stderr=True
)
self.assertIn(
'salt-key: error: The maximum value for keysize is 32768', error
)
finally:
shutil.rmtree(tempdir)
if __name__ == "__main__":
loader = TestLoader()
tests = loader.loadTestsFromTestCase(KeyTest)
print('Setting up Salt daemons to execute tests')
with TestDaemon():
runner = TextTestRunner(verbosity=1).run(tests)
sys.exit(runner.wasSuccessful())