mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
PEP8 fixes for tests
This commit is contained in:
parent
5f98f6cc83
commit
a1433ef5ec
12 changed files with 259 additions and 121 deletions
|
@ -15,6 +15,7 @@ import tempfile
|
|||
# Import Salt libs
|
||||
import salt.utils.event
|
||||
|
||||
|
||||
def parse():
|
||||
'''
|
||||
Parse the script command line inputs
|
||||
|
@ -37,7 +38,7 @@ def parse():
|
|||
options, args = parser.parse_args()
|
||||
|
||||
opts = {}
|
||||
|
||||
|
||||
for k, v in options.__dict__.items():
|
||||
if v is not None:
|
||||
opts[k] = v
|
||||
|
@ -58,7 +59,7 @@ def listen(sock_dir, node):
|
|||
if ret is None:
|
||||
continue
|
||||
print('Event fired at {0}'.format(time.asctime()))
|
||||
print('*'*25)
|
||||
print('*' * 25)
|
||||
print('Tag: {0}'.format(ret['tag']))
|
||||
print('Data:')
|
||||
pprint.pprint(ret['data'])
|
||||
|
|
|
@ -23,7 +23,9 @@ import salt.runner
|
|||
from salt.utils.verify import verify_env
|
||||
from saltunittest import TestCase
|
||||
|
||||
INTEGRATION_TEST_DIR = os.path.dirname(os.path.normpath(os.path.abspath(__file__)))
|
||||
INTEGRATION_TEST_DIR = os.path.dirname(
|
||||
os.path.normpath(os.path.abspath(__file__))
|
||||
)
|
||||
CODE_DIR = os.path.dirname(os.path.dirname(INTEGRATION_TEST_DIR))
|
||||
SCRIPT_DIR = os.path.join(CODE_DIR, 'scripts')
|
||||
|
||||
|
@ -42,55 +44,68 @@ class TestDaemon(object):
|
|||
Start a master and minion
|
||||
'''
|
||||
self.master_opts = salt.config.master_config(
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'master'))
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'master')
|
||||
)
|
||||
self.minion_opts = salt.config.minion_config(
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'minion'))
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'minion')
|
||||
)
|
||||
self.sub_minion_opts = salt.config.minion_config(
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'sub_minion'))
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'sub_minion')
|
||||
)
|
||||
self.smaster_opts = salt.config.master_config(
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'syndic_master'))
|
||||
os.path.join(
|
||||
INTEGRATION_TEST_DIR, 'files', 'conf', 'syndic_master'
|
||||
)
|
||||
)
|
||||
self.syndic_opts = salt.config.minion_config(
|
||||
os.path.join(INTEGRATION_TEST_DIR, 'files', 'conf', 'syndic'))
|
||||
self.syndic_opts['_master_conf_file'] = os.path.join(
|
||||
INTEGRATION_TEST_DIR,
|
||||
'files/conf/master'
|
||||
)
|
||||
INTEGRATION_TEST_DIR,
|
||||
'files/conf/master'
|
||||
)
|
||||
# Set up config options that require internal data
|
||||
self.master_opts['pillar_roots'] = {
|
||||
'base': [os.path.join(FILES, 'pillar', 'base')]
|
||||
}
|
||||
'base': [os.path.join(FILES, 'pillar', 'base')]
|
||||
}
|
||||
self.master_opts['file_roots'] = {
|
||||
'base': [os.path.join(FILES, 'file', 'base')]
|
||||
}
|
||||
'base': [os.path.join(FILES, 'file', 'base')]
|
||||
}
|
||||
self.master_opts['ext_pillar'] = [
|
||||
{'cmd_yaml': 'cat {0}'.format(
|
||||
os.path.join(
|
||||
FILES,
|
||||
'ext.yaml'
|
||||
)
|
||||
)}
|
||||
]
|
||||
{'cmd_yaml': 'cat {0}'.format(
|
||||
os.path.join(
|
||||
FILES,
|
||||
'ext.yaml'
|
||||
)
|
||||
)}
|
||||
]
|
||||
# clean up the old files
|
||||
self._clean()
|
||||
self.master_opts['hosts.file'] = os.path.join(TMP, 'hosts')
|
||||
self.minion_opts['hosts.file'] = os.path.join(TMP, 'hosts')
|
||||
verify_env([
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions'),
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(self.master_opts['cachedir'], 'jobs'),
|
||||
os.path.join(self.smaster_opts['pki_dir'], 'minions'),
|
||||
os.path.join(self.smaster_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(self.smaster_opts['pki_dir'], 'minions_rejected'),
|
||||
os.path.join(self.smaster_opts['cachedir'], 'jobs'),
|
||||
os.path.dirname(self.master_opts['log_file']),
|
||||
self.minion_opts['extension_modules'],
|
||||
self.sub_minion_opts['extension_modules'],
|
||||
self.sub_minion_opts['pki_dir'],
|
||||
self.master_opts['sock_dir'],
|
||||
self.smaster_opts['sock_dir'],
|
||||
],
|
||||
pwd.getpwuid(os.getuid())[0])
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions'),
|
||||
os.path.join(self.master_opts['pki_dir'], 'minions_pre'),
|
||||
os.path.join(
|
||||
self.master_opts['pki_dir'], 'minions_rejected'
|
||||
),
|
||||
os.path.join(self.master_opts['cachedir'], 'jobs'),
|
||||
os.path.join(self.smaster_opts['pki_dir'], 'minions'),
|
||||
os.path.join(
|
||||
self.smaster_opts['pki_dir'], 'minions_pre'
|
||||
),
|
||||
os.path.join(
|
||||
self.smaster_opts['pki_dir'], 'minions_rejected'
|
||||
),
|
||||
os.path.join(self.smaster_opts['cachedir'], 'jobs'),
|
||||
os.path.dirname(self.master_opts['log_file']),
|
||||
self.minion_opts['extension_modules'],
|
||||
self.sub_minion_opts['extension_modules'],
|
||||
self.sub_minion_opts['pki_dir'],
|
||||
self.master_opts['sock_dir'],
|
||||
self.smaster_opts['sock_dir'],
|
||||
],
|
||||
pwd.getpwuid(os.getuid())[0]
|
||||
)
|
||||
|
||||
master = salt.master.Master(self.master_opts)
|
||||
self.master_process = multiprocessing.Process(target=master.start)
|
||||
|
@ -102,7 +117,8 @@ class TestDaemon(object):
|
|||
|
||||
sub_minion = salt.minion.Minion(self.sub_minion_opts)
|
||||
self.sub_minion_process = multiprocessing.Process(
|
||||
target=sub_minion.tune_in)
|
||||
target=sub_minion.tune_in
|
||||
)
|
||||
self.sub_minion_process.start()
|
||||
|
||||
smaster = salt.master.Master(self.smaster_opts)
|
||||
|
|
|
@ -19,14 +19,20 @@ class TestModulesGrains(integration.ModuleCase):
|
|||
grains.items
|
||||
'''
|
||||
opts = self.minion_opts()
|
||||
self.assertEqual(self.run_function('grains.items')['test_grain'], opts['grains']['test_grain'])
|
||||
self.assertEqual(
|
||||
self.run_function('grains.items')['test_grain'],
|
||||
opts['grains']['test_grain']
|
||||
)
|
||||
|
||||
def test_item(self):
|
||||
'''
|
||||
grains.item
|
||||
'''
|
||||
opts = self.minion_opts()
|
||||
self.assertEqual(self.run_function('grains.item', ['test_grain']), opts['grains']['test_grain'])
|
||||
self.assertEqual(
|
||||
self.run_function('grains.item', ['test_grain']),
|
||||
opts['grains']['test_grain']
|
||||
)
|
||||
|
||||
def test_ls(self):
|
||||
'''
|
||||
|
|
|
@ -62,7 +62,9 @@ class HostsModuleTest(integration.ModuleCase):
|
|||
hosts.get_ip
|
||||
'''
|
||||
self.__clean_hosts()
|
||||
self.assertEqual(self.run_function('hosts.get_ip', ['myname']), '127.0.0.1')
|
||||
self.assertEqual(
|
||||
self.run_function('hosts.get_ip', ['myname']), '127.0.0.1'
|
||||
)
|
||||
self.assertEqual(self.run_function('hosts.get_ip', ['othername']), '')
|
||||
self.__clear_hosts()
|
||||
self.assertEqual(self.run_function('hosts.get_ip', ['othername']), '')
|
||||
|
@ -72,18 +74,31 @@ class HostsModuleTest(integration.ModuleCase):
|
|||
hosts.get_alias
|
||||
'''
|
||||
self.__clean_hosts()
|
||||
self.assertEqual(self.run_function('hosts.get_alias', ['127.0.0.1']), ['localhost', 'myname'])
|
||||
self.assertEqual(self.run_function('hosts.get_alias', ['127.0.0.2']), [])
|
||||
self.assertEqual(
|
||||
self.run_function('hosts.get_alias', ['127.0.0.1']),
|
||||
['localhost', 'myname']
|
||||
)
|
||||
self.assertEqual(
|
||||
self.run_function('hosts.get_alias', ['127.0.0.2']),
|
||||
[]
|
||||
)
|
||||
self.__clear_hosts()
|
||||
self.assertEqual(self.run_function('hosts.get_alias', ['127.0.0.1']), [])
|
||||
self.assertEqual(
|
||||
self.run_function('hosts.get_alias', ['127.0.0.1']),
|
||||
[]
|
||||
)
|
||||
|
||||
def test_has_pair(self):
|
||||
'''
|
||||
hosts.has_pair
|
||||
'''
|
||||
self.__clean_hosts()
|
||||
self.assertTrue(self.run_function('hosts.has_pair', ['127.0.0.1', 'myname']))
|
||||
self.assertFalse(self.run_function('hosts.has_pair', ['127.0.0.1', 'othername']))
|
||||
self.assertTrue(
|
||||
self.run_function('hosts.has_pair', ['127.0.0.1', 'myname'])
|
||||
)
|
||||
self.assertFalse(
|
||||
self.run_function('hosts.has_pair', ['127.0.0.1', 'othername'])
|
||||
)
|
||||
|
||||
def test_set_host(self):
|
||||
'''
|
||||
|
@ -91,10 +106,15 @@ class HostsModuleTest(integration.ModuleCase):
|
|||
'''
|
||||
self.__clean_hosts()
|
||||
assert self.run_function('hosts.set_host', ['192.168.1.123', 'newip'])
|
||||
self.assertTrue(self.run_function('hosts.has_pair', ['192.168.1.123', 'newip']))
|
||||
self.assertTrue(
|
||||
self.run_function('hosts.has_pair', ['192.168.1.123', 'newip'])
|
||||
)
|
||||
self.assertEqual(len(self.run_function('hosts.list_hosts')), 7)
|
||||
assert self.run_function('hosts.set_host', ['127.0.0.1', 'localhost'])
|
||||
self.assertFalse(self.run_function('hosts.has_pair', ['127.0.0.1', 'myname']), 'should remove second entry')
|
||||
self.assertFalse(
|
||||
self.run_function('hosts.has_pair', ['127.0.0.1', 'myname']),
|
||||
'should remove second entry'
|
||||
)
|
||||
|
||||
def test_add_host(self):
|
||||
'''
|
||||
|
@ -102,9 +122,13 @@ class HostsModuleTest(integration.ModuleCase):
|
|||
'''
|
||||
self.__clean_hosts()
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.123', 'newip'])
|
||||
self.assertTrue(self.run_function('hosts.has_pair', ['192.168.1.123', 'newip']))
|
||||
self.assertTrue(
|
||||
self.run_function('hosts.has_pair', ['192.168.1.123', 'newip'])
|
||||
)
|
||||
self.assertEqual(len(self.run_function('hosts.list_hosts')), 7)
|
||||
assert self.run_function('hosts.add_host', ['127.0.0.1', 'othernameip'])
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['127.0.0.1', 'othernameip']
|
||||
)
|
||||
self.assertEqual(len(self.run_function('hosts.list_hosts')), 7)
|
||||
|
||||
def test_rm_host(self):
|
||||
|
@ -126,14 +150,24 @@ class HostsModuleTest(integration.ModuleCase):
|
|||
f = open(HFN, 'w')
|
||||
f.close()
|
||||
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.1', 'host1.fqdn.com'])
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['192.168.1.1', 'host1.fqdn.com']
|
||||
)
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.1', 'host1'])
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.2', 'host2.fqdn.com'])
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['192.168.1.2', 'host2.fqdn.com']
|
||||
)
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.2', 'host2'])
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.2', 'oldhost2'])
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.3', 'host3.fqdn.com'])
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.2', 'host2-reorder'])
|
||||
assert self.run_function('hosts.add_host', ['192.168.1.1', 'host1-reorder'])
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['192.168.1.3', 'host3.fqdn.com']
|
||||
)
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['192.168.1.2', 'host2-reorder']
|
||||
)
|
||||
assert self.run_function(
|
||||
'hosts.add_host', ['192.168.1.1', 'host1-reorder']
|
||||
)
|
||||
|
||||
# now read the lines and ensure they're formatted correctly
|
||||
lines = open(HFN, 'r').readlines()
|
||||
|
|
|
@ -13,7 +13,9 @@ class PipModuleTest(integration.ModuleCase):
|
|||
'''
|
||||
def setUp(self):
|
||||
super(PipModuleTest, self).setUp()
|
||||
ret = self.run_function('cmd.which_bin', [['pip2', 'pip', 'pip-python']])
|
||||
ret = self.run_function(
|
||||
'cmd.which_bin', [['pip2', 'pip', 'pip-python']]
|
||||
)
|
||||
if not ret:
|
||||
self.skipTest("pip not installed")
|
||||
|
||||
|
|
|
@ -62,7 +62,8 @@ class KeyTest(integration.ShellCase):
|
|||
'''
|
||||
data = self.run_key('-L --raw-out')
|
||||
expect = [
|
||||
"{'unaccepted': [], 'accepted': ['minion', 'sub_minion'], 'rejected': []}",
|
||||
"{'unaccepted': [], 'accepted': ['minion', "
|
||||
"'sub_minion'], 'rejected': []}",
|
||||
''
|
||||
]
|
||||
self.assertEqual(data, expect)
|
||||
|
|
|
@ -67,7 +67,9 @@ class MatchTest(integration.ShellCase):
|
|||
'''
|
||||
test salt grain matcher
|
||||
'''
|
||||
data = self.run_salt('-t 1 --grain-pcre "test_grain:^cheese$" test.ping')
|
||||
data = self.run_salt(
|
||||
'-t 1 --grain-pcre "test_grain:^cheese$" test.ping'
|
||||
)
|
||||
data = '\n'.join(data)
|
||||
self.assertIn('minion', data)
|
||||
self.assertNotIn('sub_minion', data)
|
||||
|
|
|
@ -21,7 +21,9 @@ class HostTest(integration.ModuleCase):
|
|||
'''
|
||||
host.present
|
||||
'''
|
||||
ret = self.run_state('host.present', name='spam.bacon', ip='10.10.10.10')
|
||||
ret = self.run_state(
|
||||
'host.present', name='spam.bacon', ip='10.10.10.10'
|
||||
)
|
||||
result = self.state_result(ret)
|
||||
self.assertTrue(result)
|
||||
with open(HFILE) as fp_:
|
||||
|
|
|
@ -25,7 +25,9 @@ class TestGemModule(TestCase):
|
|||
{'rvm.is_installed': MagicMock(return_value=True),
|
||||
'rvm.do': mock}):
|
||||
gem._gem("install rails", ruby="1.9.3")
|
||||
mock.assert_called_once_with("1.9.3", "gem install rails", runas=None)
|
||||
mock.assert_called_once_with(
|
||||
"1.9.3", "gem install rails", runas=None
|
||||
)
|
||||
|
||||
def test_list(self):
|
||||
output = '''
|
||||
|
|
|
@ -17,7 +17,9 @@ class TestRvmModule(TestCase):
|
|||
mock = MagicMock(return_value={'retcode': 0, 'stdout': ''})
|
||||
with patch.dict(rvm.__salt__, {'cmd.run_all': mock}):
|
||||
rvm._rvm("install", "1.9.3")
|
||||
mock.assert_called_once_with("/usr/local/rvm/bin/rvm install 1.9.3", runas=None)
|
||||
mock.assert_called_once_with(
|
||||
"/usr/local/rvm/bin/rvm install 1.9.3", runas=None
|
||||
)
|
||||
|
||||
def test__rvm_do(self):
|
||||
mock = MagicMock(return_value=None)
|
||||
|
|
|
@ -37,7 +37,8 @@ class TestSaltCacheLoader(TestCase):
|
|||
|
||||
def test_mockclient(self):
|
||||
'''
|
||||
A MockFileClient is used that records all file request normally send to the master.
|
||||
A MockFileClient is used that records all file requests normally sent
|
||||
to the master.
|
||||
'''
|
||||
loader = SaltCacheLoader({'cachedir': TEMPLATES_DIR}, 'test')
|
||||
fc = MockFileClient(loader)
|
||||
|
|
|
@ -116,7 +116,9 @@ class TestFind(TestCase):
|
|||
self.assertIs(option.match('', 'HELLO.TXT', '').group(), 'HELLO.TXT')
|
||||
|
||||
def test_regex_option_match(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.RegexOption, 'name', '(.*}')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.RegexOption, 'name', '(.*}'
|
||||
)
|
||||
|
||||
option = salt.utils.find.RegexOption('name', '.*\.txt')
|
||||
self.assertIs(option.match('', '', ''), None)
|
||||
|
@ -124,7 +126,9 @@ class TestFind(TestCase):
|
|||
self.assertIs(option.match('', 'HELLO.TXT', ''), None)
|
||||
|
||||
def test_iregex_option_match(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.IregexOption, 'name', '(.*}')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.IregexOption, 'name', '(.*}'
|
||||
)
|
||||
|
||||
option = salt.utils.find.IregexOption('name', '.*\.txt')
|
||||
self.assertIs(option.match('', '', ''), None)
|
||||
|
@ -179,7 +183,9 @@ class TestFind(TestCase):
|
|||
|
||||
@skipIf(sys.platform.startswith('win'), 'No /dev/null on Windows')
|
||||
def test_owner_option_requires(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.OwnerOption, 'owner', 'notexist')
|
||||
self.assertRaises(i
|
||||
ValueError, salt.utils.find.OwnerOption, 'owner', 'notexist'
|
||||
)
|
||||
|
||||
option = salt.utils.find.OwnerOption('owner', 'root')
|
||||
self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
|
||||
|
@ -194,7 +200,9 @@ class TestFind(TestCase):
|
|||
|
||||
@skipIf(sys.platform.startswith('win'), 'No /dev/null on Windows')
|
||||
def test_group_option_requires(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.GroupOption, 'group', 'notexist')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.GroupOption, 'group', 'notexist'
|
||||
)
|
||||
|
||||
option = salt.utils.find.GroupOption('group', 'root')
|
||||
self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
|
||||
|
@ -208,7 +216,9 @@ class TestFind(TestCase):
|
|||
self.assertEqual(option.match('', '', [500] * 6), True)
|
||||
|
||||
def test_size_option_requires(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.SizeOption, 'size', '1s1s')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.SizeOption, 'size', '1s1s'
|
||||
)
|
||||
|
||||
option = salt.utils.find.SizeOption('size', '+1G')
|
||||
self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
|
||||
|
@ -221,7 +231,9 @@ class TestFind(TestCase):
|
|||
self.assertEqual(option.match('', '', [10000] * 7), False)
|
||||
|
||||
def test_mtime_option_requires(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.MtimeOption, 'mtime', '4g')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.MtimeOption, 'mtime', '4g'
|
||||
)
|
||||
|
||||
option = salt.utils.find.MtimeOption('mtime', '1d')
|
||||
self.assertEqual(option.requires(), salt.utils.find._REQUIRES_STAT)
|
||||
|
@ -245,11 +257,15 @@ class TestGrepOption(TestCase):
|
|||
super(TestGrepOption, self).tearDown()
|
||||
|
||||
def test_grep_option_requires(self):
|
||||
self.assertRaises(ValueError, salt.utils.find.GrepOption, 'grep', '(foo)|(bar}')
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.GrepOption, 'grep', '(foo)|(bar}'
|
||||
)
|
||||
|
||||
option = salt.utils.find.GrepOption('grep', '(foo)|(bar)')
|
||||
self.assertEqual(option.requires(),
|
||||
(salt.utils.find._REQUIRES_CONTENTS | salt.utils.find._REQUIRES_STAT))
|
||||
find = salt.utils.find
|
||||
self.assertEqual(
|
||||
option.requires(), (find._REQUIRES_CONTENTS | find._REQUIRES_STAT)
|
||||
)
|
||||
|
||||
def test_grep_option_match_regular_file(self):
|
||||
hello_file = os.path.join(self.tmpdir, 'hello.txt')
|
||||
|
@ -257,15 +273,23 @@ class TestGrepOption(TestCase):
|
|||
fd.write("foo")
|
||||
fd.close()
|
||||
option = salt.utils.find.GrepOption('grep', 'foo')
|
||||
self.assertEqual(option.match(self.tmpdir, 'hello.txt', os.stat(hello_file)), hello_file)
|
||||
self.assertEqual(
|
||||
option.match(self.tmpdir, 'hello.txt', os.stat(hello_file)),
|
||||
hello_file
|
||||
)
|
||||
|
||||
option = salt.utils.find.GrepOption('grep', 'bar')
|
||||
self.assertEqual(option.match(self.tmpdir, 'hello.txt', os.stat(hello_file)), None)
|
||||
self.assertEqual(
|
||||
option.match(self.tmpdir, 'hello.txt', os.stat(hello_file)),
|
||||
None
|
||||
)
|
||||
|
||||
@skipIf(sys.platform.startswith('win'), 'No /dev/null on Windows')
|
||||
def test_grep_option_match_dev_null(self):
|
||||
option = salt.utils.find.GrepOption('grep', 'foo')
|
||||
self.assertEqual(option.match('dev', 'null', os.stat('/dev/null')), None)
|
||||
self.assertEqual(
|
||||
option.match('dev', 'null', os.stat('/dev/null')), None
|
||||
)
|
||||
|
||||
|
||||
class TestPrintOption(TestCase):
|
||||
|
@ -348,21 +372,27 @@ class TestPrintOption(TestCase):
|
|||
#self.assertEqual(option.execute('', [2 ** 31] * 10), 2 ** 31)
|
||||
|
||||
option = salt.utils.find.PrintOption('print', 'md5')
|
||||
self.assertEqual(option.execute(hello_file, os.stat(hello_file)),
|
||||
'acbd18db4cc2f85cedef654fccc4a4d8')
|
||||
self.assertEqual(
|
||||
option.execute(hello_file, os.stat(hello_file)),
|
||||
'acbd18db4cc2f85cedef654fccc4a4d8'
|
||||
)
|
||||
|
||||
@skipIf(sys.platform.startswith('Windows'), "no /dev/null on windows")
|
||||
def _test_print_md5():
|
||||
option = salt.utils.find.PrintOption('print', 'md5')
|
||||
self.assertEqual(option.execute('/dev/null', os.stat('/dev/null')), '')
|
||||
self.assertEqual(
|
||||
option.execute('/dev/null', os.stat('/dev/null')), ''
|
||||
)
|
||||
|
||||
option = salt.utils.find.PrintOption('print', 'path name')
|
||||
self.assertEqual(option.execute('test_name', [0] * 9),
|
||||
['test_name', 'test_name'])
|
||||
self.assertEqual(
|
||||
option.execute('test_name', [0] * 9), ['test_name', 'test_name']
|
||||
)
|
||||
|
||||
option = salt.utils.find.PrintOption('print', 'size name')
|
||||
self.assertEqual(option.execute('test_name', [0] * 9),
|
||||
[0, 'test_name'])
|
||||
self.assertEqual(
|
||||
option.execute('test_name', [0] * 9), [0, 'test_name']
|
||||
)
|
||||
|
||||
|
||||
class TestFinder(TestCase):
|
||||
|
@ -374,75 +404,111 @@ class TestFinder(TestCase):
|
|||
def tearDown(self):
|
||||
shutil.rmtree(self.tmpdir)
|
||||
super(TestFinder, self).tearDown()
|
||||
|
||||
@skipIf(sys.platform.startswith('win'), 'No /dev/null on Windows')
|
||||
def test_init(self):
|
||||
finder = salt.utils.find.Finder({})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(finder.criteria, [])
|
||||
|
||||
finder = salt.utils.find.Finder({'_': None})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(finder.criteria, [])
|
||||
|
||||
self.assertRaises(ValueError, salt.utils.find.Finder, {'': None})
|
||||
self.assertRaises(ValueError, salt.utils.find.Finder, {'name': None})
|
||||
self.assertRaises(ValueError, salt.utils.find.Finder, {'nonexist': 'somevalue'})
|
||||
self.assertRaises(
|
||||
ValueError, salt.utils.find.Finder, {'nonexist': 'somevalue'}
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'name': 'test_name'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-12:-2], 'NameOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-12:-2], 'NameOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'iname': 'test_name'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-13:-2], 'InameOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-13:-2], 'InameOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'regex': '.*\.txt'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-13:-2], 'RegexOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-13:-2], 'RegexOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'iregex': '.*\.txt'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-14:-2], 'IregexOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-14:-2], 'IregexOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'type': 'd'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-12:-2], 'TypeOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-12:-2], 'TypeOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'owner': 'root'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-13:-2], 'OwnerOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-13:-2], 'OwnerOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'group': 'root'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-13:-2], 'GroupOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-13:-2], 'GroupOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'size': '+1G'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-12:-2], 'SizeOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-12:-2], 'SizeOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'mtime': '1d'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-13:-2], 'MtimeOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-13:-2], 'MtimeOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'grep': 'foo'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(str(finder.criteria[0].__class__)[-12:-2], 'GrepOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(
|
||||
str(finder.criteria[0].__class__)[-12:-2], 'GrepOption'
|
||||
)
|
||||
|
||||
finder = salt.utils.find.Finder({'print': 'name'})
|
||||
self.assertEqual(str(finder.actions[0].__class__)[-13:-2],
|
||||
'PrintOption')
|
||||
self.assertEqual(
|
||||
str(finder.actions[0].__class__)[-13:-2], 'PrintOption'
|
||||
)
|
||||
self.assertEqual(finder.criteria, [])
|
||||
|
||||
def test_find(self):
|
||||
|
@ -464,9 +530,12 @@ class TestFinder(TestCase):
|
|||
finder = salt.utils.find.Finder({'size': '+1G', 'print': 'path'})
|
||||
self.assertEqual(list(finder.find(self.tmpdir)), [])
|
||||
|
||||
finder = salt.utils.find.Finder({
|
||||
'name': 'hello.txt', 'print': 'path name'})
|
||||
self.assertEqual(list(finder.find(self.tmpdir)), [[hello_file, 'hello.txt']])
|
||||
finder = salt.utils.find.Finder(
|
||||
{'name': 'hello.txt', 'print': 'path name'}
|
||||
)
|
||||
self.assertEqual(
|
||||
list(finder.find(self.tmpdir)), [[hello_file, 'hello.txt']]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
|
Loading…
Add table
Reference in a new issue