Merge "Test inventory backup file creation"

This commit is contained in:
Jenkins 2016-05-12 16:33:43 +00:00 committed by Gerrit Code Review
commit 9694d3dbbc

View File

@ -36,15 +36,17 @@ def cleanup():
os.remove(f_file)
def get_inventory():
def get_inventory(clean=True):
"Return the inventory mapping in a dict."
try:
inventory_string = di.main({'config': TARGET_DIR})
inventory = json.loads(inventory_string)
return inventory
finally:
# Remove the file system artifacts since we want to force fresh runs
cleanup()
if clean:
# Remove the file system artifacts since we want to force
# fresh runs
cleanup()
class TestArgParser(unittest.TestCase):
@ -516,5 +518,33 @@ class TestConfigChecks(unittest.TestCase):
os.rename(USER_CONFIG_FILE + ".tmp", USER_CONFIG_FILE)
class TestMultipleRuns(unittest.TestCase):
def test_creating_backup_file(self):
# Generate the initial inventory files
get_inventory(clean=False)
# run again to force creation of the backup files
get_inventory(clean=False)
backup_path = path.join(TARGET_DIR, 'backup_openstack_inventory.tar')
self.assertTrue(os.path.exists(backup_path))
def test_recreating_files(self):
# Deleting the files after the first run should cause the files to be
# completely remade
get_inventory()
get_inventory()
backup_path = path.join(TARGET_DIR, 'backup_openstack_inventory.tar')
self.assertFalse(os.path.exists(backup_path))
def tearDown(self):
# Clean up here since get_inventory will not do it by design in
# this test.
cleanup()
if __name__ == '__main__':
unittest.main()