diff options
author | Michael DeHaan <michael.dehaan@gmail.com> | 2012-05-06 18:01:11 -0400 |
---|---|---|
committer | Michael DeHaan <michael.dehaan@gmail.com> | 2012-05-06 18:01:11 -0400 |
commit | 157d21b1c33064ec5987d437120755859b30cded (patch) | |
tree | aa39597b4643d6460ac46e4d0ac57788bfa8f8d4 /test | |
parent | 1a00e2635e67ee82411714c52f24f89fdfe0d353 (diff) | |
download | ansible-157d21b1c33064ec5987d437120755859b30cded.tar.gz |
Add tests for new advanced inventory features (groups of groups, group variables) in the default INI format file.
Diffstat (limited to 'test')
-rw-r--r-- | test/TestInventory.py | 42 | ||||
-rw-r--r-- | test/complex_hosts | 58 |
2 files changed, 92 insertions, 8 deletions
diff --git a/test/TestInventory.py b/test/TestInventory.py index 58650cecd1..2a8930277c 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -11,9 +11,10 @@ class TestInventory(unittest.TestCase): self.cwd = os.getcwd() self.test_dir = os.path.join(self.cwd, 'test') - self.inventory_file = os.path.join(self.test_dir, 'simple_hosts') - self.inventory_script = os.path.join(self.test_dir, 'inventory_api.py') - self.inventory_yaml = os.path.join(self.test_dir, 'yaml_hosts') + self.inventory_file = os.path.join(self.test_dir, 'simple_hosts') + self.complex_inventory_file = os.path.join(self.test_dir, 'complex_hosts') + self.inventory_script = os.path.join(self.test_dir, 'inventory_api.py') + self.inventory_yaml = os.path.join(self.test_dir, 'yaml_hosts') os.chmod(self.inventory_script, 0755) @@ -28,16 +29,20 @@ class TestInventory(unittest.TestCase): assert left == right - ### Simple inventory format tests - def simple_inventory(self): - return Inventory( self.inventory_file ) + return Inventory(self.inventory_file) def script_inventory(self): - return Inventory( self.inventory_script ) + return Inventory(self.inventory_script) def yaml_inventory(self): - return Inventory( self.inventory_yaml ) + return Inventory(self.inventory_yaml) + + def complex_inventory(self): + return Inventory(self.complex_inventory_file) + + ##################################### + ### Simple inventory format tests def test_simple(self): inventory = self.simple_inventory() @@ -113,6 +118,27 @@ class TestInventory(unittest.TestCase): print expected assert vars == expected + ################################################### + ### INI file advanced tests + + def test_complex_vars(self): + inventory = self.complex_inventory() + + vars = inventory.get_variables('rtp_a') + print vars + + expected = dict( + a='1', b='2', c='3', d='100002', + inventory_hostname='rtp_a', + group_names=[ 'eastcoast', 'nc', 'rtp', 'us' ] + ) + print vars + print expected + assert vars == expected + + + + ################################################### ### Inventory API tests def test_script(self): diff --git a/test/complex_hosts b/test/complex_hosts new file mode 100644 index 0000000000..24bdbf1b96 --- /dev/null +++ b/test/complex_hosts @@ -0,0 +1,58 @@ +# order of groups, children, and vars is not signficant +# so this example mixes them up for maximum testing + +[nc:children] +rtp +triangle + +[eastcoast:children] +nc +florida + +[us:children] +eastcoast + +[nc:vars] +b=10000 +c=10001 +d=10002 + +[rtp] +rtp_a +rtp_b +rtb_c + +[rtp:vars] +a=1 +b=2 +c=3 + +[triangle] +tri_a +tri_b +tri_c + +[triangle:vars] +a=11 +b=12 +c=13 + +[florida] +orlando +miami + +[florida:vars] +a=100 +b=101 +c=102 + + +[eastcoast:vars] +b=100000 +c=100001 +d=100002 + +[us:vars] +c=1000000 + + |