mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #47603 from terminalmage/more-test-renaming
Move/merge more test modules
This commit is contained in:
commit
99f53c0a9f
12 changed files with 202 additions and 263 deletions
|
@ -1,8 +1,6 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: `Anthony Shaw <anthonyshaw@apache.org>`
|
||||
|
||||
tests.unit.cloud.clouds.dimensiondata_test
|
||||
tests.unit.cloud.test_libcloudfuncs
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
|
@ -1,79 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
tests.unit.file_test
|
||||
~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
# Import pytohn libs
|
||||
from __future__ import absolute_import
|
||||
import os
|
||||
import copy
|
||||
import shutil
|
||||
import tempfile
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import TestCase
|
||||
|
||||
# Import Salt libs
|
||||
from salt.ext import six
|
||||
import salt.utils.files
|
||||
|
||||
|
||||
class FilesTestCase(TestCase):
|
||||
|
||||
STRUCTURE = {
|
||||
'foo': {
|
||||
'foofile.txt': 'fooSTRUCTURE'
|
||||
},
|
||||
'bar': {
|
||||
'barfile.txt': 'barSTRUCTURE'
|
||||
}
|
||||
}
|
||||
|
||||
def _create_temp_structure(self, temp_directory, structure):
|
||||
for folder, files in six.iteritems(structure):
|
||||
current_directory = os.path.join(temp_directory, folder)
|
||||
os.makedirs(current_directory)
|
||||
for name, content in six.iteritems(files):
|
||||
path = os.path.join(temp_directory, folder, name)
|
||||
with salt.utils.files.fopen(path, 'w+') as fh:
|
||||
fh.write(content)
|
||||
|
||||
def _validate_folder_structure_and_contents(self, target_directory,
|
||||
desired_structure):
|
||||
for folder, files in six.iteritems(desired_structure):
|
||||
for name, content in six.iteritems(files):
|
||||
path = os.path.join(target_directory, folder, name)
|
||||
with salt.utils.files.fopen(path) as fh:
|
||||
assert fh.read().strip() == content
|
||||
|
||||
def setUp(self):
|
||||
super(FilesTestCase, self).setUp()
|
||||
self.temp_dir = tempfile.mkdtemp()
|
||||
self._create_temp_structure(self.temp_dir,
|
||||
self.STRUCTURE)
|
||||
|
||||
def tearDown(self):
|
||||
super(FilesTestCase, self).tearDown()
|
||||
shutil.rmtree(self.temp_dir)
|
||||
|
||||
def test_recursive_copy(self):
|
||||
test_target_directory = tempfile.mkdtemp()
|
||||
TARGET_STRUCTURE = {
|
||||
'foo': {
|
||||
'foo.txt': 'fooTARGET_STRUCTURE'
|
||||
},
|
||||
'baz': {
|
||||
'baz.txt': 'bazTARGET_STRUCTURE'
|
||||
}
|
||||
}
|
||||
self._create_temp_structure(test_target_directory, TARGET_STRUCTURE)
|
||||
try:
|
||||
salt.utils.files.recursive_copy(self.temp_dir, test_target_directory)
|
||||
DESIRED_STRUCTURE = copy.copy(TARGET_STRUCTURE)
|
||||
DESIRED_STRUCTURE.update(self.STRUCTURE)
|
||||
self._validate_folder_structure_and_contents(
|
||||
test_target_directory,
|
||||
DESIRED_STRUCTURE
|
||||
)
|
||||
finally:
|
||||
shutil.rmtree(test_target_directory)
|
|
@ -1,175 +0,0 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
:codeauthor: :email: `Mike Place <mp@saltstack.com>`
|
||||
|
||||
tests.unit.target_test
|
||||
~~~~~~~~~~~~~~~~~~~~~~
|
||||
'''
|
||||
|
||||
# Import Python libs
|
||||
from __future__ import absolute_import
|
||||
import sys
|
||||
|
||||
# Import Salt libs
|
||||
import salt.utils.minions
|
||||
import salt.config
|
||||
|
||||
# Import Salt Testing libs
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
|
||||
import logging
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CkMinionTestCase(TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.ck_ = salt.utils.minions.CkMinions(salt.config.DEFAULT_MASTER_OPTS)
|
||||
|
||||
def tearDown(self):
|
||||
self.ck_ = None
|
||||
|
||||
#TODO This is just a stub for upcoming tests
|
||||
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'Python 2.7 needed for dictionary equality assertions')
|
||||
class TargetParseTestCase(TestCase):
|
||||
|
||||
def test_parse_grains_target(self):
|
||||
'''
|
||||
Ensure proper parsing for grains
|
||||
'''
|
||||
g_tgt = 'G@a:b'
|
||||
ret = salt.utils.minions.parse_target(g_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'G', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_grains_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for grains PCRE matching
|
||||
'''
|
||||
p_tgt = 'P@a:b'
|
||||
ret = salt.utils.minions.parse_target(p_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'P', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_pillar_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for pillar PCRE matching
|
||||
'''
|
||||
j_tgt = 'J@a:b'
|
||||
ret = salt.utils.minions.parse_target(j_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'J', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_list_target(self):
|
||||
'''
|
||||
Ensure proper parsing for list matching
|
||||
'''
|
||||
l_tgt = 'L@a:b'
|
||||
ret = salt.utils.minions.parse_target(l_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'L', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_nodegroup_target(self):
|
||||
'''
|
||||
Ensure proper parsing for pillar matching
|
||||
'''
|
||||
n_tgt = 'N@a:b'
|
||||
ret = salt.utils.minions.parse_target(n_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'N', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_subnet_target(self):
|
||||
'''
|
||||
Ensure proper parsing for subnet matching
|
||||
'''
|
||||
s_tgt = 'S@a:b'
|
||||
ret = salt.utils.minions.parse_target(s_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'S', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_minion_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for minion PCRE matching
|
||||
'''
|
||||
e_tgt = 'E@a:b'
|
||||
ret = salt.utils.minions.parse_target(e_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'E', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_range_target(self):
|
||||
'''
|
||||
Ensure proper parsing for range matching
|
||||
'''
|
||||
r_tgt = 'R@a:b'
|
||||
ret = salt.utils.minions.parse_target(r_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'R', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_multiword_target(self):
|
||||
'''
|
||||
Ensure proper parsing for multi-word targets
|
||||
|
||||
Refs https://github.com/saltstack/salt/issues/37231
|
||||
'''
|
||||
mw_tgt = 'G@a:b c'
|
||||
ret = salt.utils.minions.parse_target(mw_tgt)
|
||||
self.assertEqual(ret['pattern'], 'a:b c')
|
||||
|
||||
|
||||
class NodegroupCompTest(TestCase):
|
||||
'''
|
||||
Test nodegroup comparisons found in
|
||||
salt.utils.minions.nodgroup_comp()
|
||||
'''
|
||||
|
||||
def test_simple_nodegroup(self):
|
||||
'''
|
||||
Smoke test a very simple nodegroup. No recursion.
|
||||
'''
|
||||
simple_nodegroup = {'group1': 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', simple_nodegroup)
|
||||
expected_ret = ['L@foo.domain.com,bar.domain.com,baz.domain.com', 'or', 'bl*.domain.com']
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_simple_expression_nodegroup(self):
|
||||
'''
|
||||
Smoke test a nodegroup with a simple expression. No recursion.
|
||||
'''
|
||||
simple_nodegroup = {'group1': '[foo,bar,baz].domain.com'}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', simple_nodegroup)
|
||||
expected_ret = ['E@[foo,bar,baz].domain.com']
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_simple_recurse(self):
|
||||
'''
|
||||
Test a case where one nodegroup contains a second nodegroup
|
||||
'''
|
||||
referenced_nodegroups = {
|
||||
'group1': 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com',
|
||||
'group2': 'G@os:Debian and N@group1'
|
||||
}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group2', referenced_nodegroups)
|
||||
expected_ret = [
|
||||
'(',
|
||||
'G@os:Debian',
|
||||
'and',
|
||||
'(',
|
||||
'L@foo.domain.com,bar.domain.com,baz.domain.com',
|
||||
'or',
|
||||
'bl*.domain.com',
|
||||
')',
|
||||
')'
|
||||
]
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_circular_nodegroup_reference(self):
|
||||
'''
|
||||
Test to see what happens if A refers to B
|
||||
and B in turn refers back to A
|
||||
'''
|
||||
referenced_nodegroups = {
|
||||
'group1': 'N@group2',
|
||||
'group2': 'N@group1'
|
||||
}
|
||||
|
||||
# If this works, it should also print an error to the console
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', referenced_nodegroups)
|
||||
self.assertEqual(ret, [])
|
|
@ -1,10 +1,11 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
Unit Tests for functions located in salt.utils.files.py.
|
||||
Unit Tests for functions located in salt/utils/files.py
|
||||
'''
|
||||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals, print_function
|
||||
import copy
|
||||
import os
|
||||
|
||||
# Import Salt libs
|
||||
|
@ -21,7 +22,7 @@ from tests.support.mock import (
|
|||
)
|
||||
|
||||
|
||||
class FilesUtilTestCase(TestCase):
|
||||
class FilesTestCase(TestCase):
|
||||
'''
|
||||
Test case for files util.
|
||||
'''
|
||||
|
@ -94,3 +95,54 @@ class FilesUtilTestCase(TestCase):
|
|||
'fopen() should have been prevented from opening a file '
|
||||
'using {0} as the filename'.format(invalid_fn)
|
||||
)
|
||||
|
||||
def _create_temp_structure(self, temp_directory, structure):
|
||||
for folder, files in six.iteritems(structure):
|
||||
current_directory = os.path.join(temp_directory, folder)
|
||||
os.makedirs(current_directory)
|
||||
for name, content in six.iteritems(files):
|
||||
path = os.path.join(temp_directory, folder, name)
|
||||
with salt.utils.files.fopen(path, 'w+') as fh:
|
||||
fh.write(content)
|
||||
|
||||
def _validate_folder_structure_and_contents(self, target_directory,
|
||||
desired_structure):
|
||||
for folder, files in six.iteritems(desired_structure):
|
||||
for name, content in six.iteritems(files):
|
||||
path = os.path.join(target_directory, folder, name)
|
||||
with salt.utils.files.fopen(path) as fh:
|
||||
assert fh.read().strip() == content
|
||||
|
||||
@with_tempdir()
|
||||
@with_tempdir()
|
||||
def test_recursive_copy(self, src, dest):
|
||||
src_structure = {
|
||||
'foo': {
|
||||
'foofile.txt': 'fooSTRUCTURE'
|
||||
},
|
||||
'bar': {
|
||||
'barfile.txt': 'barSTRUCTURE'
|
||||
}
|
||||
}
|
||||
dest_structure = {
|
||||
'foo': {
|
||||
'foo.txt': 'fooTARGET_STRUCTURE'
|
||||
},
|
||||
'baz': {
|
||||
'baz.txt': 'bazTARGET_STRUCTURE'
|
||||
}
|
||||
}
|
||||
|
||||
# Create the file structures in both src and dest dirs
|
||||
self._create_temp_structure(src, src_structure)
|
||||
self._create_temp_structure(dest, dest_structure)
|
||||
|
||||
# Perform the recursive copy
|
||||
salt.utils.files.recursive_copy(src, dest)
|
||||
|
||||
# Confirm results match expected results
|
||||
desired_structure = copy.copy(dest_structure)
|
||||
desired_structure.update(src_structure)
|
||||
self._validate_folder_structure_and_contents(
|
||||
dest,
|
||||
desired_structure)
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
|
||||
# Import python libs
|
||||
from __future__ import absolute_import, unicode_literals
|
||||
import sys
|
||||
|
||||
# Import Salt Libs
|
||||
import salt.utils.minions as minions
|
||||
import salt.utils.minions
|
||||
|
||||
# Import Salt Testing Libs
|
||||
from tests.support.unit import TestCase
|
||||
from tests.support.unit import TestCase, skipIf
|
||||
from tests.support.mock import (
|
||||
patch,
|
||||
MagicMock,
|
||||
|
@ -38,7 +39,7 @@ class MinionsTestCase(TestCase):
|
|||
'''
|
||||
for nodegroup in NODEGROUPS:
|
||||
expected = EXPECTED[nodegroup]
|
||||
ret = minions.nodegroup_comp(nodegroup, NODEGROUPS)
|
||||
ret = salt.utils.minions.nodegroup_comp(nodegroup, NODEGROUPS)
|
||||
self.assertEqual(ret, expected)
|
||||
|
||||
|
||||
|
@ -47,7 +48,7 @@ class CkMinionsTestCase(TestCase):
|
|||
TestCase for salt.utils.minions.CkMinions class
|
||||
'''
|
||||
def setUp(self):
|
||||
self.ckminions = minions.CkMinions({})
|
||||
self.ckminions = salt.utils.minions.CkMinions({})
|
||||
|
||||
def test_spec_check(self):
|
||||
# Test spec-only rule
|
||||
|
@ -366,3 +367,145 @@ class CkMinionsTestCase(TestCase):
|
|||
args = ['1', '2']
|
||||
ret = self.ckminions.auth_check(auth_list, 'test.arg', args, 'runner')
|
||||
self.assertTrue(ret)
|
||||
|
||||
|
||||
@skipIf(sys.version_info < (2, 7), 'Python 2.7 needed for dictionary equality assertions')
|
||||
class TargetParseTestCase(TestCase):
|
||||
|
||||
def test_parse_grains_target(self):
|
||||
'''
|
||||
Ensure proper parsing for grains
|
||||
'''
|
||||
g_tgt = 'G@a:b'
|
||||
ret = salt.utils.minions.parse_target(g_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'G', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_grains_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for grains PCRE matching
|
||||
'''
|
||||
p_tgt = 'P@a:b'
|
||||
ret = salt.utils.minions.parse_target(p_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'P', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_pillar_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for pillar PCRE matching
|
||||
'''
|
||||
j_tgt = 'J@a:b'
|
||||
ret = salt.utils.minions.parse_target(j_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'J', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_list_target(self):
|
||||
'''
|
||||
Ensure proper parsing for list matching
|
||||
'''
|
||||
l_tgt = 'L@a:b'
|
||||
ret = salt.utils.minions.parse_target(l_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'L', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_nodegroup_target(self):
|
||||
'''
|
||||
Ensure proper parsing for pillar matching
|
||||
'''
|
||||
n_tgt = 'N@a:b'
|
||||
ret = salt.utils.minions.parse_target(n_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'N', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_subnet_target(self):
|
||||
'''
|
||||
Ensure proper parsing for subnet matching
|
||||
'''
|
||||
s_tgt = 'S@a:b'
|
||||
ret = salt.utils.minions.parse_target(s_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'S', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_minion_pcre_target(self):
|
||||
'''
|
||||
Ensure proper parsing for minion PCRE matching
|
||||
'''
|
||||
e_tgt = 'E@a:b'
|
||||
ret = salt.utils.minions.parse_target(e_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'E', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_range_target(self):
|
||||
'''
|
||||
Ensure proper parsing for range matching
|
||||
'''
|
||||
r_tgt = 'R@a:b'
|
||||
ret = salt.utils.minions.parse_target(r_tgt)
|
||||
self.assertDictEqual(ret, {'engine': 'R', 'pattern': 'a:b', 'delimiter': None})
|
||||
|
||||
def test_parse_multiword_target(self):
|
||||
'''
|
||||
Ensure proper parsing for multi-word targets
|
||||
|
||||
Refs https://github.com/saltstack/salt/issues/37231
|
||||
'''
|
||||
mw_tgt = 'G@a:b c'
|
||||
ret = salt.utils.minions.parse_target(mw_tgt)
|
||||
self.assertEqual(ret['pattern'], 'a:b c')
|
||||
|
||||
|
||||
class NodegroupCompTest(TestCase):
|
||||
'''
|
||||
Test nodegroup comparisons found in
|
||||
salt.utils.minions.nodgroup_comp()
|
||||
'''
|
||||
|
||||
def test_simple_nodegroup(self):
|
||||
'''
|
||||
Smoke test a very simple nodegroup. No recursion.
|
||||
'''
|
||||
simple_nodegroup = {'group1': 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com'}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', simple_nodegroup)
|
||||
expected_ret = ['L@foo.domain.com,bar.domain.com,baz.domain.com', 'or', 'bl*.domain.com']
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_simple_expression_nodegroup(self):
|
||||
'''
|
||||
Smoke test a nodegroup with a simple expression. No recursion.
|
||||
'''
|
||||
simple_nodegroup = {'group1': '[foo,bar,baz].domain.com'}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', simple_nodegroup)
|
||||
expected_ret = ['E@[foo,bar,baz].domain.com']
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_simple_recurse(self):
|
||||
'''
|
||||
Test a case where one nodegroup contains a second nodegroup
|
||||
'''
|
||||
referenced_nodegroups = {
|
||||
'group1': 'L@foo.domain.com,bar.domain.com,baz.domain.com or bl*.domain.com',
|
||||
'group2': 'G@os:Debian and N@group1'
|
||||
}
|
||||
|
||||
ret = salt.utils.minions.nodegroup_comp('group2', referenced_nodegroups)
|
||||
expected_ret = [
|
||||
'(',
|
||||
'G@os:Debian',
|
||||
'and',
|
||||
'(',
|
||||
'L@foo.domain.com,bar.domain.com,baz.domain.com',
|
||||
'or',
|
||||
'bl*.domain.com',
|
||||
')',
|
||||
')'
|
||||
]
|
||||
self.assertListEqual(ret, expected_ret)
|
||||
|
||||
def test_circular_nodegroup_reference(self):
|
||||
'''
|
||||
Test to see what happens if A refers to B
|
||||
and B in turn refers back to A
|
||||
'''
|
||||
referenced_nodegroups = {
|
||||
'group1': 'N@group2',
|
||||
'group2': 'N@group1'
|
||||
}
|
||||
|
||||
# If this works, it should also print an error to the console
|
||||
ret = salt.utils.minions.nodegroup_comp('group1', referenced_nodegroups)
|
||||
self.assertEqual(ret, [])
|
||||
|
|
Loading…
Add table
Reference in a new issue