def test_inventory_host_invalid_host(self): try: invalid_hostfile = op.join(inventory_dir, "invalid") os.mkdir(invalid_hostfile) hosts = ("invalid", ) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="del", hosts=hosts) invHost.run() except e: os.rmdir(invalid_hostfile) raise e
def test_inventory_host_del_hosts(self): hosts = ( "web1", "shell1", ) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="del", hosts=hosts) invHost.run() invList = inventory.InventoryList(db_basedir=inventory_dir, hosts=hosts) expected_hosts = tuple(invList.host_entries()) self.assertTupleEqual(expected_hosts, ())
def test_inventory_host_add_hosts(self): hosts = ( "spam", "eggs", "foo", ) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="add", hosts=hosts) invHost.run() invList = inventory.InventoryList(db_basedir=inventory_dir) expected_hosts = tuple(x for x in invList.host_entries() if x in hosts) self.assertEqual(sorted(hosts), sorted(expected_hosts))
def test_inventory_host_del_hostfile(self): hosts = ( "loadbalancer3", "loadbalancer4", ) hostfile = op.join(fixtures, "hosts") with open(hostfile, "w") as f: for x in hosts: f.write("{}\n".format(x)) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="del", hostfile=hostfile) invHost.run() invList = inventory.InventoryList(db_basedir=inventory_dir, hosts=hosts) expected_hosts = tuple(invList.host_entries()) self.assertTupleEqual(expected_hosts, ()) os.remove(hostfile)
def test_inventory_host_add_hostfile(self): hosts = ( "spam-new", "eggs-new", "foo-new", ) hostfile = op.join(fixtures, "hosts") with open(hostfile, "w") as f: for x in hosts: f.write("{}\n".format(x)) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="add", hostfile=hostfile) invHost.run() invList = inventory.InventoryList(db_basedir=inventory_dir) expected_hosts = tuple(x for x in invList.host_entries() if x in hosts) self.assertEqual(sorted(hosts), sorted(expected_hosts)) os.remove(hostfile)
def test_inventory_tag_del_all_tags(self): hosts = ( "web3", "shell1", ) hostsf = ( "shell2", "loadbalancer1", ) hostfile = op.join(fixtures, "hosts") with open(hostfile, "w") as f: for x in hostsf: f.write("{}\n".format(x)) invHost = inventory.InventoryHost(db_basedir=inventory_dir, action="del", all=True, hosts=hosts, hostfile=hostfile) invHost.run() invList = inventory.InventoryList(db_basedir=inventory_dir, hosts=hosts + hostsf) for host, htags in invList.entries(): self.assertEqual(htags, ()) os.remove(hostfile)