Add tests for new advanced inventory features (groups of groups, group variables) in the default INI format file.

pull/603/head
Michael DeHaan 13 years ago
parent 1a00e2635e
commit 157d21b1c3

@ -57,6 +57,6 @@ class Host(object):
results.update(self.vars)
results['inventory_hostname'] = self.name
groups = self.get_groups()
results['group_names'] = [ g.name for g in groups if g.name != 'all']
results['group_names'] = sorted([ g.name for g in groups if g.name != 'all'])
return results

@ -119,7 +119,7 @@ class Inventory(object):
results = utils.parse_json(out)
results['inventory_hostname'] = hostname
groups = [ g.name for g in host.get_groups() if g.name != 'all' ]
results['group_names'] = groups
results['group_names'] = sorted(groups)
return results
host = self.get_host(hostname)

@ -12,6 +12,7 @@ class TestInventory(unittest.TestCase):
self.test_dir = os.path.join(self.cwd, 'test')
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')
@ -28,8 +29,6 @@ class TestInventory(unittest.TestCase):
assert left == right
### Simple inventory format tests
def simple_inventory(self):
return Inventory(self.inventory_file)
@ -39,6 +38,12 @@ class TestInventory(unittest.TestCase):
def yaml_inventory(self):
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()
hosts = inventory.list_hosts()
@ -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):

@ -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
Loading…
Cancel
Save