mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Refactor salt key tests to be raet compatible
This commit is contained in:
parent
458744db02
commit
91943766d3
2 changed files with 114 additions and 47 deletions
|
@ -919,6 +919,14 @@ class AdaptedConfigurationTestCaseMixIn(object):
|
|||
def get_config_file_path(self, filename):
|
||||
return os.path.join(TMP_CONF_DIR, filename)
|
||||
|
||||
@property
|
||||
def master_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.master_config(
|
||||
self.get_config_file_path('master')
|
||||
)
|
||||
|
||||
class SaltClientTestCaseMixIn(AdaptedConfigurationTestCaseMixIn):
|
||||
|
||||
|
@ -1004,15 +1012,6 @@ class ModuleCase(TestCase, SaltClientTestCaseMixIn):
|
|||
self.get_config_file_path('sub_minion')
|
||||
)
|
||||
|
||||
@property
|
||||
def master_opts(self):
|
||||
'''
|
||||
Return the options used for the minion
|
||||
'''
|
||||
return salt.config.master_config(
|
||||
self.get_config_file_path('master')
|
||||
)
|
||||
|
||||
def _check_state_return(self, ret, func='state.single'):
|
||||
if isinstance(ret, dict):
|
||||
# This is the supposed return format for state calls
|
||||
|
|
|
@ -38,13 +38,24 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
test salt-key -L
|
||||
'''
|
||||
data = self.run_key('-L')
|
||||
expect = [
|
||||
'Accepted Keys:',
|
||||
'minion',
|
||||
'sub_minion',
|
||||
'Unaccepted Keys:',
|
||||
'Rejected Keys:'
|
||||
]
|
||||
expect = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
expect = [
|
||||
'Accepted Keys:',
|
||||
'minion',
|
||||
'sub_minion',
|
||||
'Unaccepted Keys:',
|
||||
'Rejected Keys:'
|
||||
]
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
expect = [
|
||||
'Accepted Keys:',
|
||||
'master',
|
||||
'minion',
|
||||
'sub_minion',
|
||||
'Unaccepted Keys:',
|
||||
'Rejected Keys:'
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_list_json_out(self):
|
||||
|
@ -52,17 +63,30 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
test salt-key -L --json-out
|
||||
'''
|
||||
data = self.run_key('-L --out json')
|
||||
|
||||
expect = [
|
||||
'{',
|
||||
' "minions_rejected": [], ',
|
||||
' "minions_pre": [], ',
|
||||
' "minions": [',
|
||||
' "minion", ',
|
||||
' "sub_minion"',
|
||||
' ]',
|
||||
'}',
|
||||
]
|
||||
expect = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
expect = [
|
||||
'{',
|
||||
' "minions_rejected": [], ',
|
||||
' "minions_pre": [], ',
|
||||
' "minions": [',
|
||||
' "minion", ',
|
||||
' "sub_minion"',
|
||||
' ]',
|
||||
'}',
|
||||
]
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
expect = [
|
||||
'{',
|
||||
' "accepted": [',
|
||||
' "master", ',
|
||||
' "minion", ',
|
||||
' "sub_minion"',
|
||||
' ], ',
|
||||
' "rejected": [], ',
|
||||
' "pending": []',
|
||||
'}'
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_list_yaml_out(self):
|
||||
|
@ -70,14 +94,24 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
test salt-key -L --yaml-out
|
||||
'''
|
||||
data = self.run_key('-L --out yaml')
|
||||
|
||||
expect = [
|
||||
'minions:',
|
||||
'- minion',
|
||||
'- sub_minion',
|
||||
'minions_pre: []',
|
||||
'minions_rejected: []',
|
||||
]
|
||||
expect = []
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
expect = [
|
||||
'minions:',
|
||||
'- minion',
|
||||
'- sub_minion',
|
||||
'minions_pre: []',
|
||||
'minions_rejected: []',
|
||||
]
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
expect = [
|
||||
'accepted:',
|
||||
'- master',
|
||||
'- minion',
|
||||
'- sub_minion',
|
||||
'pending: []',
|
||||
'rejected: []'
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_list_raw_out(self):
|
||||
|
@ -85,11 +119,19 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
test salt-key -L --raw-out
|
||||
'''
|
||||
data = self.run_key('-L --out raw')
|
||||
|
||||
expect = [
|
||||
"{'minions_rejected': [], 'minions_pre': [], "
|
||||
"'minions': ['minion', 'sub_minion']}"
|
||||
]
|
||||
expect = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
expect = [
|
||||
"{'minions_rejected': [], 'minions_pre': [], "
|
||||
"'minions': ['minion', 'sub_minion']}"
|
||||
]
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
expected_txt = (
|
||||
'{\'accepted\': '
|
||||
'[\'master\', \'minion\', \'sub_minion\'], '
|
||||
'\'rejected\': [], \'pending\': []}'
|
||||
)
|
||||
expect = [expected_txt]
|
||||
self.assertEqual(data, expect)
|
||||
|
||||
def test_list_acc(self):
|
||||
|
@ -97,19 +139,35 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
test salt-key -l
|
||||
'''
|
||||
data = self.run_key('-l acc')
|
||||
self.assertEqual(
|
||||
data,
|
||||
['Accepted Keys:', 'minion', 'sub_minion']
|
||||
)
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
self.assertEqual(
|
||||
data,
|
||||
['Accepted Keys:', 'minion', 'sub_minion']
|
||||
)
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
self.assertEqual(
|
||||
data,
|
||||
[
|
||||
'minions:',
|
||||
' - master',
|
||||
' - minion',
|
||||
' - sub_minion'
|
||||
]
|
||||
)
|
||||
|
||||
def test_list_un(self):
|
||||
'''
|
||||
test salt-key -l
|
||||
'''
|
||||
data = self.run_key('-l un')
|
||||
expect = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
expect = ['Unaccepted Keys:']
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
expect = ['minions_pre:']
|
||||
self.assertEqual(
|
||||
data,
|
||||
['Unaccepted Keys:']
|
||||
expect
|
||||
)
|
||||
|
||||
def test_keys_generation(self):
|
||||
|
@ -117,7 +175,12 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
arg_str = '--gen-keys minibar --gen-keys-dir {0}'.format(tempdir)
|
||||
self.run_key(arg_str)
|
||||
try:
|
||||
for fname in ('minibar.pub', 'minibar.pem'):
|
||||
key_names = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
key_names = ('minibar.pub', 'minibar.pem')
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
key_names = ('minibar.key',)
|
||||
for fname in key_names:
|
||||
self.assertTrue(os.path.isfile(os.path.join(tempdir, fname)))
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
@ -128,7 +191,12 @@ class KeyTest(integration.ShellCase, integration.ShellCaseCommonTestsMixIn):
|
|||
arg_str = '--gen-keys minibar --gen-keys-dir {0}'.format(tempdir)
|
||||
self.run_script('salt-key', arg_str)
|
||||
try:
|
||||
for fname in ('minibar.pub', 'minibar.pem'):
|
||||
key_names = None
|
||||
if self.master_opts['transport'] == 'zeromq':
|
||||
key_names = ('minibar.pub', 'minibar.pem')
|
||||
elif self.master_opts['transport'] == 'raet':
|
||||
key_names = ('minibar.key',)
|
||||
for fname in key_names:
|
||||
self.assertTrue(os.path.isfile(os.path.join(tempdir, fname)))
|
||||
finally:
|
||||
shutil.rmtree(tempdir)
|
||||
|
|
Loading…
Add table
Reference in a new issue