Example #1
0
 def test_inventory_tag_add_for_all_hosts(self):
     tags = (
         "spam-spam-spam",
         "spam-spam-eggs",
     )
     tagsf = (
         "spam-spam-spam-eggs",
         "spam-spam-eggs-spam",
     )
     tagfile = op.join(fixtures, "tags")
     with open(tagfile, "w") as f:
         for x in tagsf:
             f.write("{}\n".format(x))
     invTag = inventory.InventoryTag(db_basedir=inventory_dir,
                                     action="add",
                                     tags=tags,
                                     tagfile=tagfile)
     invTag.run()
     invList = inventory.InventoryList(db_basedir=inventory_dir)
     failed = False
     for host, taglist in invList.entries():
         for x in tagsf + tags:
             if x not in taglist:
                 failed = True
                 break
         if failed:
             break
     os.remove(tagfile)
     if failed:
         self.fail()
Example #2
0
 def test_inventory_tag_stdin_hostfile(self):
     try:
         invTag = inventory.InventoryTag(db_basedir=inventory_dir,
                                         action="add",
                                         tagfile="-",
                                         hostfile="hosts")
     except e:
         self.fail()
Example #3
0
 def test_inventory_tag_stdin_multiple_hosts(self):
     try:
         invTag = inventory.InventoryTag(db_basedir=inventory_dir,
                                         action="add",
                                         tagfile="-",
                                         hosts=(
                                             "host1",
                                             "host2",
                                         ))
     except e:
         self.fail()
Example #4
0
 def test_inventory_tag_add(self):
     tags = (
         "spam-spam-spam",
         "spam-spam-eggs",
     )
     tagsf = (
         "spam-spam-spam-eggs",
         "spam-spam-eggs-spam",
     )
     hosts = (
         "loadbalancer1",
         "loadbalancer2",
         "shell2",
     )
     hostsf = (
         "web2",
         "web3",
     )
     tagfile = op.join(fixtures, "tags")
     with open(tagfile, "w") as f:
         for x in tagsf:
             f.write("{}\n".format(x))
     hostfile = op.join(fixtures, "hosts")
     with open(hostfile, "w") as f:
         for x in hostsf:
             f.write("{}\n".format(x))
     invTag = inventory.InventoryTag(db_basedir=inventory_dir,
                                     action="add",
                                     tags=tags,
                                     tagfile=tagfile,
                                     hosts=hosts,
                                     hostfile=hostfile)
     invTag.run()
     invList = inventory.InventoryList(db_basedir=inventory_dir,
                                       hosts=hosts + hostsf)
     failed = False
     for host, taglist in invList.entries():
         if host not in hosts + hostsf:
             failed = True
             break
         for x in tagsf + tags:
             if x not in taglist:
                 failed = True
                 break
         if failed:
             break
     os.remove(tagfile)
     os.remove(hostfile)
     if failed:
         self.fail()
Example #5
0
 def test_inventory_tag_stdin_both(self):
     invTag = inventory.InventoryTag(db_basedir=inventory_dir,
                                     action="add",
                                     tagfile="-",
                                     hostfile="-")
Example #6
0
 def test_inventory_tag_init(self):
     invTag = inventory.InventoryTag(db_basedir=inventory_dir, action="add")
     self.assertTrue(invTag.allhosts)
     self.assertEqual(invTag.tagfile, "-")
Example #7
0
 def test_inventory_tag_init(self):
     invTag = inventory.InventoryTag(db_basedir=inventory_dir, action="add")