@ -37,14 +37,14 @@ class TestGetCollectorNames(unittest.TestCase):
def test_empty_sets ( self ) :
def test_empty_sets ( self ) :
res = collector . get_collector_names ( valid_subsets = frozenset ( [ ] ) ,
res = collector . get_collector_names ( valid_subsets = frozenset ( [ ] ) ,
minimal_gather_subset = frozenset ( [ ] ) ,
minimal_gather_subset = frozenset ( [ ] ) ,
gather_subset = set ( [ ] ) )
gather_subset = [ ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ] ) )
self . assertEqual ( res , set ( [ ] ) )
def test_empty_valid_and_min_with_all_gather_subset ( self ) :
def test_empty_valid_and_min_with_all_gather_subset ( self ) :
res = collector . get_collector_names ( valid_subsets = frozenset ( [ ] ) ,
res = collector . get_collector_names ( valid_subsets = frozenset ( [ ] ) ,
minimal_gather_subset = frozenset ( [ ] ) ,
minimal_gather_subset = frozenset ( [ ] ) ,
gather_subset = set ( [ ' all ' ] ) )
gather_subset = [ ' all ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ] ) )
self . assertEqual ( res , set ( [ ] ) )
@ -52,10 +52,48 @@ class TestGetCollectorNames(unittest.TestCase):
valid_subsets = frozenset ( [ ' my_fact ' ] )
valid_subsets = frozenset ( [ ' my_fact ' ] )
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = frozenset ( [ ] ) ,
minimal_gather_subset = frozenset ( [ ] ) ,
gather_subset = set ( [ ' all ' ] ) )
gather_subset = [ ' all ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
def _compare_res ( self , gather_subset1 , gather_subset2 ,
valid_subsets = None , min_subset = None ) :
valid_subsets = valid_subsets or frozenset ( )
minimal_gather_subset = min_subset or frozenset ( )
res1 = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = gather_subset1 )
res2 = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = gather_subset2 )
return res1 , res2
def test_not_all_other_order ( self ) :
valid_subsets = frozenset ( [ ' min_fact ' , ' something_else ' , ' whatever ' ] )
minimal_gather_subset = frozenset ( [ ' min_fact ' ] )
res1 , res2 = self . _compare_res ( [ ' !all ' , ' whatever ' ] ,
[ ' whatever ' , ' !all ' ] ,
valid_subsets = valid_subsets ,
min_subset = minimal_gather_subset )
self . assertEqual ( res1 , res2 )
self . assertEqual ( res1 , set ( [ ' min_fact ' , ' whatever ' ] ) )
def test_not_all_other_order_min ( self ) :
valid_subsets = frozenset ( [ ' min_fact ' , ' something_else ' , ' whatever ' ] )
minimal_gather_subset = frozenset ( [ ' min_fact ' ] )
res1 , res2 = self . _compare_res ( [ ' !min_fact ' , ' whatever ' ] ,
[ ' whatever ' , ' !min_fact ' ] ,
valid_subsets = valid_subsets ,
min_subset = minimal_gather_subset )
self . assertEqual ( res1 , res2 )
self . assertEqual ( res1 , set ( [ ' whatever ' ] ) )
def test_one_minimal_with_all_gather_subset ( self ) :
def test_one_minimal_with_all_gather_subset ( self ) :
my_fact = ' my_fact '
my_fact = ' my_fact '
valid_subsets = frozenset ( [ my_fact ] )
valid_subsets = frozenset ( [ my_fact ] )
@ -63,7 +101,7 @@ class TestGetCollectorNames(unittest.TestCase):
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' all ' ] ) )
gather_subset = [ ' all ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
@ -74,7 +112,7 @@ class TestGetCollectorNames(unittest.TestCase):
# even with '!all', the minimal_gather_subset should be returned
# even with '!all', the minimal_gather_subset should be returned
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' all ' ] ) )
gather_subset = [ ' all ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] ) )
self . assertEqual ( res , set ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] ) )
@ -85,21 +123,23 @@ class TestGetCollectorNames(unittest.TestCase):
# even with '!all', the minimal_gather_subset should be returned
# even with '!all', the minimal_gather_subset should be returned
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' !all ' ] ) )
gather_subset = [ ' !all ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
def test_gather_subset_excludes ( self ) :
def test_gather_subset_excludes ( self ) :
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] )
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] )
minimal_gather_subset = frozenset ( [ ' m y_fact ' ] )
minimal_gather_subset = frozenset ( [ ' m in_fact' , ' min_another ' ] )
# even with '!all', the minimal_gather_subset should be returned
# even with '!all', the minimal_gather_subset should be returned
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' all ' , ' !my_fact ' , ' !whatever ' ] ) )
# gather_subset=set(['all', '!my_fact', '!whatever']))
# gather_subset=['all', '!my_fact', '!whatever'])
gather_subset = [ ' !min_fact ' , ' !whatever ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
# my_facts is in minimal_gather_subset, so always returned
# m in_another is in minimal_gather_subset, so always returned
self . assertEqual ( res , set ( [ ' m y_fact' , ' something_else ' ] ) )
self . assertEqual ( res , set ( [ ' m in_another ' ] ) )
def test_gather_subset_excludes_ordering ( self ) :
def test_gather_subset_excludes_ordering ( self ) :
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] )
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' , ' whatever ' ] )
@ -107,11 +147,35 @@ class TestGetCollectorNames(unittest.TestCase):
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' !all ' , ' whatever ' ] ) )
gather_subset = [ ' !all ' , ' whatever ' ] )
self . assertIsInstance ( res , set )
self . assertIsInstance ( res , set )
# excludes are higher precedence than includes, so !all excludes everything
# excludes are higher precedence than includes, so !all excludes everything
# and then minimal_gather_subset is added. so '!all', 'other' == '!all'
# and then minimal_gather_subset is added. so '!all', 'other' == '!all'
self . assertEqual ( res , set ( [ ' my_fact ' ] ) )
self . assertEqual ( res , set ( [ ' my_fact ' , ' whatever ' ] ) )
def test_gather_subset_excludes_min ( self ) :
valid_subsets = frozenset ( [ ' min_fact ' , ' something_else ' , ' whatever ' ] )
minimal_gather_subset = frozenset ( [ ' min_fact ' ] )
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = [ ' whatever ' , ' !min ' ] )
self . assertIsInstance ( res , set )
# excludes are higher precedence than includes, so !all excludes everything
# and then minimal_gather_subset is added. so '!all', 'other' == '!all'
self . assertEqual ( res , set ( [ ' whatever ' ] ) )
def test_gather_subset_excludes_min_and_all ( self ) :
valid_subsets = frozenset ( [ ' min_fact ' , ' something_else ' , ' whatever ' ] )
minimal_gather_subset = frozenset ( [ ' min_fact ' ] )
res = collector . get_collector_names ( valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = [ ' whatever ' , ' !all ' , ' !min ' ] )
self . assertIsInstance ( res , set )
# excludes are higher precedence than includes, so !all excludes everything
# and then minimal_gather_subset is added. so '!all', 'other' == '!all'
self . assertEqual ( res , set ( [ ' whatever ' ] ) )
def test_invaid_gather_subset ( self ) :
def test_invaid_gather_subset ( self ) :
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' ] )
valid_subsets = frozenset ( [ ' my_fact ' , ' something_else ' ] )
@ -122,7 +186,7 @@ class TestGetCollectorNames(unittest.TestCase):
collector . get_collector_names ,
collector . get_collector_names ,
valid_subsets = valid_subsets ,
valid_subsets = valid_subsets ,
minimal_gather_subset = minimal_gather_subset ,
minimal_gather_subset = minimal_gather_subset ,
gather_subset = set ( [ ' my_fact ' , ' not_a_valid_gather_subset ' ] ) )
gather_subset = [ ' my_fact ' , ' not_a_valid_gather_subset ' ] )
class TestCollectorClassesFromGatherSubset ( unittest . TestCase ) :
class TestCollectorClassesFromGatherSubset ( unittest . TestCase ) :
@ -145,13 +209,13 @@ class TestCollectorClassesFromGatherSubset(unittest.TestCase):
def test ( self ) :
def test ( self ) :
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
gather_subset = set ( [ ' !all ' ] ) )
gather_subset = [ ' !all ' ] )
self . assertIsInstance ( res , list )
self . assertIsInstance ( res , list )
self . assertEqual ( res , [ ] )
self . assertEqual ( res , [ ] )
def test_env ( self ) :
def test_env ( self ) :
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
gather_subset = set ( [ ' env ' ] ) )
gather_subset = [ ' env ' ] )
self . assertIsInstance ( res , list )
self . assertIsInstance ( res , list )
self . assertEqual ( res , [ default_collectors . EnvFactCollector ] )
self . assertEqual ( res , [ default_collectors . EnvFactCollector ] )
@ -181,7 +245,7 @@ class TestCollectorClassesFromGatherSubset(unittest.TestCase):
def test_collector_specified_multiple_times ( self ) :
def test_collector_specified_multiple_times ( self ) :
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
res = self . _classes ( all_collector_classes = default_collectors . collectors ,
gather_subset = set ( [ ' platform ' , ' all ' , ' machine ' ] ) )
gather_subset = [ ' platform ' , ' all ' , ' machine ' ] )
self . assertIsInstance ( res , list )
self . assertIsInstance ( res , list )
self . assertIn ( default_collectors . PlatformFactCollector ,
self . assertIn ( default_collectors . PlatformFactCollector ,
res )
res )
@ -193,4 +257,4 @@ class TestCollectorClassesFromGatherSubset(unittest.TestCase):
' Bad subset.*unknown_collector.*given to Ansible.*allowed \ :.*all,.*env.* ' ,
' Bad subset.*unknown_collector.*given to Ansible.*allowed \ :.*all,.*env.* ' ,
self . _classes ,
self . _classes ,
all_collector_classes = default_collectors . collectors ,
all_collector_classes = default_collectors . collectors ,
gather_subset = set ( [ ' env ' , ' unknown_collector ' ] ) )
gather_subset = [ ' env ' , ' unknown_collector ' ] )