Add: test for path sep in scripts in rq/default.yaml

Change-Id: I97977efc2ae21dff68752bba7836e2cc1e922db7
This commit is contained in:
Dmitry Sutyagin 2016-09-19 18:33:53 +03:00
parent 7b4cdaee78
commit 0942e2dcef

View File

@ -22,21 +22,33 @@ from timmy import conf, tools
class RQDefault(unittest.TestCase):
def test_filelists(self):
def iter_dict(d):
def test_filelists_and_scripts(self):
def check_sep(val, err_text, err_text2):
self.assertEqual(os.path.sep in val, False,
err_text % (err_text2, val, err_text2))
def iter_dict(d, err_text, err_text2):
for el in d.values():
if type(el) is dict:
iter_dict(el)
# for sub-matches
iter_dict(el, err_text, err_text2)
elif type(el) is str:
# single value, not a list
self.assertEqual(os.path.sep in el, False, sep_error % el)
else:
for sub in el:
self.assertEqual(os.path.sep in sub, False,
sep_error % el)
# list of values
if type(sub) is dict:
# for scripts with env. variables
for k in sub.keys():
check_sep(k, err_text, err_text2)
else:
# normal list of strings
check_sep(sub, err_text, err_text2)
sep_error = ('default filelist value %s has path separator(s) - this '
sep_error = ('default %s value %s has path separator(s) - this '
'will cause NodeManager to search the file by full path '
'instead of looking in the default rq/filelists path.')
'instead of looking in the default rq/%s path.')
config = conf.load_conf(None)
for rqfile in config['rqfile']:
f = rqfile['file']
@ -45,8 +57,8 @@ class RQDefault(unittest.TestCase):
else:
f = os.path.join(self.rqdir, f)
src = tools.load_yaml_file(f)
filelists = src['filelists']
iter_dict(filelists)
iter_dict(src['filelists'], sep_error, 'filelists')
iter_dict(src['scripts'], sep_error, 'scripts')
if __name__ == '__main__':