def test_03_group_missing(self): """Check error raised when a group does not exist """ inventory = AnsibleInventory(INV_FILENAME, True) with self.assertRaises(InventoryGroupMissing): inventory.group_remove('dodgy')
def test_05_group_remove(self): """Check remove a group that exists """ inventory = AnsibleInventory(INV_FILENAME, excl=True) inventory.group_add('newgroup') self.assertIn('newgroup', inventory.groups) # two write operations not supported.. # Needed another AnsibleInventary Object inventory = AnsibleInventory(INV_FILENAME, excl=True) inventory.group_remove('newgroup') self.assertNotIn('newgroup', inventory.groups)
def remove_group(group_name): r = APIResponse() inventory = AnsibleInventory(excl=True) if inventory.loaded: try: inventory.group_remove(group_name) except InventoryGroupMissing: r.status, r.msg = 'INVALID', "Group doesn't exist" else: r.status, r.msg = 'OK', 'Group {} removed'.format(group_name) return r else: r.status, r.msg = 'LOCKED', 'Unable to lock the inventory file' return r
def test_11_remove_nonempty(self): """remove a group with hosts """ inventory = AnsibleInventory(INV_FILENAME, excl=True) inventory.group_add('mygroup') self.assertIn('mygroup', inventory.groups) # two write operations not supported.. # Needed another AnsibleInventary Object inventory = AnsibleInventory(INV_FILENAME, excl=True) inventory.host_add('mygroup', 'myhost') self.assertIn('myhost', inventory.group_show('mygroup')) # two write operations not supported.. # Needed another AnsibleInventary Object inventory = AnsibleInventory(INV_FILENAME, excl=True) inventory.group_remove('mygroup') self.assertNotIn('mygroup', inventory.groups)