From 264ebaa77c4243f2e9117e8d1168dc2f2eed7ee2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dag=20Wie=C3=ABrs?= Date: Thu, 12 Jul 2012 19:31:51 +0200 Subject: [PATCH] Combine both yaml unit tests into one example file --- test/TestInventory.py | 109 ------------------------------------------ test/yaml2_hosts | 40 ---------------- test/yaml_hosts | 8 +--- 3 files changed, 2 insertions(+), 155 deletions(-) delete mode 100644 test/yaml2_hosts diff --git a/test/TestInventory.py b/test/TestInventory.py index 043519f26a0..9537d3be919 100644 --- a/test/TestInventory.py +++ b/test/TestInventory.py @@ -15,7 +15,6 @@ class TestInventory(unittest.TestCase): 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') - self.inventory_yaml2 = os.path.join(self.test_dir, 'yaml2_hosts') os.chmod(self.inventory_script, 0755) @@ -326,111 +325,3 @@ class TestInventory(unittest.TestCase): assert 'group_names' in vars assert sorted(vars['group_names']) == [ 'norse', 'ruler' ] - - ### Tests for yaml2 inventory file - - def test_yaml2(self): - inventory = self.yaml2_inventory() - hosts = inventory.list_hosts() - print hosts - expected_hosts=['jupiter', 'saturn', 'mars', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki'] - self.compare(hosts, expected_hosts) - - def test_yaml2_all(self): - inventory = self.yaml2_inventory() - hosts = inventory.list_hosts('all') - - expected_hosts=['jupiter', 'saturn', 'mars', 'zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki'] - self.compare(hosts, expected_hosts) - - def test_yaml2_norse(self): - inventory = self.yaml2_inventory() - hosts = inventory.list_hosts("norse") - - expected_hosts=['thor', 'odin', 'loki'] - self.compare(hosts, expected_hosts) - - def test_yaml2_ungrouped(self): - inventory = self.yaml2_inventory() - hosts = inventory.list_hosts("ungrouped") - - expected_hosts=['jupiter', 'mars'] - self.compare(hosts, expected_hosts) - - def test_yaml2_combined(self): - inventory = self.yaml2_inventory() - hosts = inventory.list_hosts("norse:greek") - - expected_hosts=['zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki'] - self.compare(hosts, expected_hosts) - - def test_yaml2_restrict(self): - inventory = self.yaml2_inventory() - - restricted_hosts = ['hera', 'poseidon', 'thor'] - expected_hosts=['zeus', 'hera', 'poseidon', 'thor', 'odin', 'loki'] - - inventory.restrict_to(restricted_hosts) - hosts = inventory.list_hosts("norse:greek") - - self.compare(hosts, restricted_hosts) - - inventory.lift_restriction() - hosts = inventory.list_hosts("norse:greek") - - self.compare(hosts, expected_hosts) - - def test_yaml2_vars(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('thor') - assert vars == {'group_names': ['norse'], - 'hammer':True, - 'inventory_hostname': 'thor'} - - def test_yaml2_list_vars(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('zeus') - assert vars == {'ansible_ssh_port': 3001, - 'group_names': ['greek', 'ruler'], - 'inventory_hostname': 'zeus', - 'ntp_server': 'olympus.example.com'} - - def test_yaml2_change_vars(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('thor') - - vars["hammer"] = False - - vars = inventory.get_variables('thor') - print vars - assert vars == {'hammer':True, - 'inventory_hostname': 'thor', - 'group_names': ['norse']} - - def test_yaml2_host_vars(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('saturn') - - print vars - assert vars == {'inventory_hostname': 'saturn', - 'moon': 'titan', - 'moon2': 'enceladus', - 'group_names': ['multiple']} - - def test_yaml2_port(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('hera') - - print vars - assert vars == {'ansible_ssh_port': 3000, - 'inventory_hostname': 'hera', - 'ntp_server': 'olympus.example.com', - 'group_names': ['greek']} - - def test_yaml2_multiple_groups(self): - inventory = self.yaml2_inventory() - vars = inventory.get_variables('odin') - - assert 'group_names' in vars - assert sorted(vars['group_names']) == [ 'norse', 'ruler' ] - diff --git a/test/yaml2_hosts b/test/yaml2_hosts deleted file mode 100644 index 62cecdbddf9..00000000000 --- a/test/yaml2_hosts +++ /dev/null @@ -1,40 +0,0 @@ ---- - -- jupiter - -- host: saturn - groups: [ multiple ] - vars: - moon: titan - moon2: enceladus - -- host: hera - groups: [ greek ] - -- host: poseidon - groups: greek - -- host: mars - -- host: zeus - groups: [ greek, ruler ] - vars: - - ansible_ssh_port: 3001 - -- host: odin - groups: - - norse - - ruler - -- host: loki - groups: [ norse ] - -- host: thor - groups: [ norse ] - vars: - - hammer: True - -- group: greek - vars: - - ansible_ssh_port: 3000 - - ntp_server: olympus.example.com diff --git a/test/yaml_hosts b/test/yaml_hosts index cf73e8d4537..ea8b5681de6 100644 --- a/test/yaml_hosts +++ b/test/yaml_hosts @@ -2,6 +2,7 @@ - jupiter - host: saturn + groups: [ multiple ] vars: moon: titan moon2: enceladus @@ -9,12 +10,12 @@ - host: mars - host: zeus + groups: [ greek, ruler ] vars: - ansible_ssh_port: 3001 - group: greek hosts: - - zeus - hera - poseidon vars: @@ -31,9 +32,4 @@ - group: ruler hosts: - - zeus - odin - -- group: multiple - hosts: - - saturn