2014-09-21 18:16:41 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
'''
|
|
|
|
Tests for the fileserver runner
|
|
|
|
'''
|
2014-11-21 19:05:13 +00:00
|
|
|
# Import Python libs
|
|
|
|
from __future__ import absolute_import
|
2016-09-12 06:16:09 +00:00
|
|
|
import contextlib
|
2014-09-21 18:16:41 +00:00
|
|
|
|
|
|
|
# Import Salt Testing libs
|
2017-02-27 15:59:04 +00:00
|
|
|
import tests.integration as integration
|
2017-02-27 22:05:17 +00:00
|
|
|
from salttesting import skipIf
|
|
|
|
from salttesting.helpers import ensure_in_syspath
|
|
|
|
|
|
|
|
# Import salt libs
|
|
|
|
import salt.utils
|
2014-09-21 18:16:41 +00:00
|
|
|
|
|
|
|
|
2016-09-12 06:16:09 +00:00
|
|
|
class FileserverTest(integration.ShellCase):
|
2014-09-21 18:16:41 +00:00
|
|
|
'''
|
|
|
|
Test the fileserver runner
|
|
|
|
'''
|
|
|
|
def test_dir_list(self):
|
|
|
|
'''
|
|
|
|
fileserver.dir_list
|
|
|
|
'''
|
2014-09-21 19:19:03 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.dir_list')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('_modules' in ret['return'])
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2015-03-10 16:25:28 +00:00
|
|
|
# Backend submitted as a string
|
2016-09-12 21:14:36 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.dir_list', backend='roots')
|
2016-09-01 16:40:13 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('_modules' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-12 21:14:36 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.dir_list', backend=['roots'])
|
2016-09-01 16:40:13 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('_modules' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
def test_empty_dir_list(self):
|
|
|
|
'''
|
|
|
|
fileserver.empty_dir_list
|
|
|
|
'''
|
|
|
|
ret = self.run_run_plus(fun='fileserver.empty_dir_list')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertEqual(ret['return'], [])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a string
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(
|
|
|
|
fun='fileserver.empty_dir_list',
|
|
|
|
backend='roots')
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertEqual(ret['return'], [])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(
|
|
|
|
fun='fileserver.empty_dir_list',
|
|
|
|
backend=['roots'])
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertEqual(ret['return'], [])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
2014-09-21 18:16:41 +00:00
|
|
|
def test_envs(self):
|
|
|
|
'''
|
|
|
|
fileserver.envs
|
|
|
|
'''
|
2014-09-21 19:19:03 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.envs')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2015-03-10 16:25:28 +00:00
|
|
|
# Backend submitted as a string
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.envs', backend='roots')
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.envs', backend=['roots'])
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2016-09-12 06:16:09 +00:00
|
|
|
def test_clear_file_list_cache(self):
|
|
|
|
'''
|
|
|
|
fileserver.clear_file_list_cache
|
|
|
|
|
|
|
|
If this test fails, then something may have changed in the test suite
|
|
|
|
and we may have more than just "roots" configured in the fileserver
|
|
|
|
backends. This assert will need to be updated accordingly.
|
|
|
|
'''
|
2016-09-13 20:55:51 +00:00
|
|
|
saltenvs = sorted(self.run_run_plus(fun='fileserver.envs')['return'])
|
|
|
|
|
2016-09-12 06:16:09 +00:00
|
|
|
@contextlib.contextmanager
|
|
|
|
def gen_cache():
|
|
|
|
'''
|
|
|
|
Create file_list cache so we have something to clear
|
|
|
|
'''
|
2016-09-13 20:55:51 +00:00
|
|
|
for saltenv in saltenvs:
|
|
|
|
self.run_run_plus(fun='fileserver.file_list', saltenv=saltenv)
|
2016-09-12 06:16:09 +00:00
|
|
|
yield
|
|
|
|
|
|
|
|
# Test with no arguments
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache')
|
2016-09-13 20:55:51 +00:00
|
|
|
ret['return']['roots'].sort()
|
|
|
|
self.assertEqual(ret['return'], {'roots': saltenvs})
|
2016-09-12 06:16:09 +00:00
|
|
|
|
|
|
|
# Test with backend passed as string
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
backend='roots')
|
2016-09-13 20:55:51 +00:00
|
|
|
ret['return']['roots'].sort()
|
|
|
|
self.assertEqual(ret['return'], {'roots': saltenvs})
|
2016-09-12 06:16:09 +00:00
|
|
|
|
|
|
|
# Test with backend passed as list
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
backend=['roots'])
|
2016-09-13 20:55:51 +00:00
|
|
|
ret['return']['roots'].sort()
|
|
|
|
self.assertEqual(ret['return'], {'roots': saltenvs})
|
2016-09-12 06:16:09 +00:00
|
|
|
|
|
|
|
# Test with backend passed as string, but with a nonsense backend
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
backend='notarealbackend')
|
|
|
|
self.assertEqual(ret['return'], {})
|
|
|
|
|
|
|
|
# Test with saltenv passed as string
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
saltenv='base')
|
|
|
|
self.assertEqual(ret['return'], {'roots': ['base']})
|
|
|
|
|
|
|
|
# Test with saltenv passed as list
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
saltenv=['base'])
|
|
|
|
self.assertEqual(ret['return'], {'roots': ['base']})
|
|
|
|
|
|
|
|
# Test with saltenv passed as string, but with a nonsense saltenv
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
saltenv='notarealsaltenv')
|
|
|
|
self.assertEqual(ret['return'], {})
|
|
|
|
|
|
|
|
# Test with both backend and saltenv passed
|
|
|
|
with gen_cache():
|
|
|
|
ret = self.run_run_plus(fun='fileserver.clear_file_list_cache',
|
|
|
|
backend='roots',
|
|
|
|
saltenv='base')
|
|
|
|
self.assertEqual(ret['return'], {'roots': ['base']})
|
|
|
|
|
2014-09-21 18:16:41 +00:00
|
|
|
def test_file_list(self):
|
|
|
|
'''
|
|
|
|
fileserver.file_list
|
|
|
|
'''
|
2014-09-21 19:19:03 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.file_list')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('grail/scene33' in ret['return'])
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2015-03-10 16:25:28 +00:00
|
|
|
# Backend submitted as a string
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.file_list', backend='roots')
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('grail/scene33' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.file_list', backend=['roots'])
|
|
|
|
self.assertIsInstance(ret['return'], list)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('grail/scene33' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
2017-02-27 22:05:17 +00:00
|
|
|
# Git doesn't handle symlinks in Windows. See the thread below:
|
|
|
|
# http://stackoverflow.com/questions/5917249/git-symlinks-in-windows
|
|
|
|
@skipIf(salt.utils.is_windows(),
|
2017-03-01 03:55:48 +00:00
|
|
|
'Git for Windows does not preserve symbolic links when cloning')
|
2014-09-21 18:16:41 +00:00
|
|
|
def test_symlink_list(self):
|
|
|
|
'''
|
|
|
|
fileserver.symlink_list
|
|
|
|
'''
|
2014-09-21 19:19:03 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.symlink_list')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertIsInstance(ret['return'], dict)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('dest_sym' in ret['return'])
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2015-03-10 16:25:28 +00:00
|
|
|
# Backend submitted as a string
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.symlink_list', backend='roots')
|
|
|
|
self.assertIsInstance(ret['return'], dict)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('dest_sym' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.symlink_list', backend=['roots'])
|
|
|
|
self.assertIsInstance(ret['return'], dict)
|
2016-09-12 21:14:36 +00:00
|
|
|
self.assertTrue('dest_sym' in ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
2014-09-21 18:16:41 +00:00
|
|
|
def test_update(self):
|
|
|
|
'''
|
|
|
|
fileserver.update
|
|
|
|
'''
|
2014-09-21 19:19:03 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.update')
|
2016-09-01 16:53:14 +00:00
|
|
|
self.assertTrue(ret['return'])
|
2014-09-21 18:16:41 +00:00
|
|
|
|
2015-03-10 16:25:28 +00:00
|
|
|
# Backend submitted as a string
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.update', backend='roots')
|
|
|
|
self.assertTrue(ret['return'])
|
2015-03-10 16:25:28 +00:00
|
|
|
|
|
|
|
# Backend submitted as a list
|
2016-09-01 16:40:13 +00:00
|
|
|
ret = self.run_run_plus(fun='fileserver.update', backend=['roots'])
|
|
|
|
self.assertTrue(ret['return'])
|