Example #1
0
 def test_basic_workflow(self):
     """
     Check the basic workflow works using ramdisk
     """
     ramdisk_filename = vg_ramdisk_dir = loop_device = None
     vg_name = "avocado_testing_vg_e5kj3erv11a"
     lv_name = "avocado_testing_lv_lk0ff33al5h"
     ramdisk_basedir = os.path.join(self.tmpdir, "foo", "bar")
     mount_loc = os.path.join(self.tmpdir, "lv_mount_location")
     os.mkdir(mount_loc)
     try:
         # Create ramdisk vg
         self.assertFalse(os.path.exists(ramdisk_basedir))
         self.assertFalse(lv_utils.vg_check(vg_name))
         spec = lv_utils.vg_ramdisk(False, vg_name, 10, ramdisk_basedir,
                                    "sparse_file")
         ramdisk_filename, vg_ramdisk_dir, vg_name, loop_device = spec
         # Check it was created properly
         self.assertTrue(ramdisk_filename)
         self.assertTrue(vg_ramdisk_dir)
         self.assertTrue(vg_name)
         self.assertTrue(loop_device)
         self.assertTrue(os.path.exists(ramdisk_basedir))
         self.assertTrue(glob.glob(os.path.join(ramdisk_basedir, "*")))
         self.assertTrue(lv_utils.vg_check(vg_name))
         vgs = lv_utils.vg_list()
         self.assertIn(vg_name, vgs)
         # Can't create existing vg
         self.assertRaises(lv_utils.LVException, lv_utils.vg_create,
                           vg_name, loop_device)
         # Create and check LV
         lv_utils.lv_create(vg_name, lv_name, 1)
         lv_utils.lv_check(vg_name, lv_name)
         self.assertIn(vg_name, process.run("lvs --all",
                                            sudo=True).stdout_text)
         self.assertIn(lv_name, lv_utils.lv_list())
         lv_utils.lv_mount(vg_name, lv_name, mount_loc, "ext2")
         lv_utils.lv_umount(vg_name, lv_name)
         lv_utils.lv_remove(vg_name, lv_name)
         self.assertNotIn(lv_name, lv_utils.lv_list())
         # Cleanup ramdisk vgs
         lv_utils.vg_ramdisk_cleanup(ramdisk_filename, vg_ramdisk_dir,
                                     vg_name, loop_device)
         self.assertTrue(os.path.exists(ramdisk_basedir))
         self.assertFalse(glob.glob(os.path.join(ramdisk_basedir, "*")))
     except BaseException as details:
         try:
             process.run("mountpoint %s && umount %s"
                         % (mount_loc, mount_loc), shell=True, sudo=True)
         except BaseException as details:
             print("Fail to unmount LV: %s" % details)
         try:
             lv_utils.lv_remove(vg_name, lv_name)
         except BaseException as details:
             print("Fail to cleanup LV: %s" % details)
         try:
             lv_utils.vg_ramdisk_cleanup(ramdisk_filename, vg_ramdisk_dir,
                                         vg_name, loop_device)
         except BaseException as details:
             print("Fail to cleanup vg_ramdisk: %s" % details)
    def test_snapshot(self):
        """
        General logical volume setup.

        A volume group with given name is created in the ramdisk. It then
        creates a logical volume. Takes a snapshot from the logical and
        merges snapshot with the logical volume.
        """
        self.ramdisks.append(lv_utils.vg_ramdisk(self.disk, self.vg_name,
                                                 self.ramdisk_vg_size,
                                                 self.ramdisk_basedir,
                                                 self.ramdisk_sparse_filename))
        lv_utils.lv_create(self.vg_name, self.lv_name, self.lv_size)
        lv_utils.lv_mount(self.vg_name, self.lv_name, self.mount_loc,
                          create_filesystem=self.fs_name)
        lv_utils.lv_umount(self.vg_name, self.lv_name)
        lv_utils.lv_take_snapshot(self.vg_name, self.lv_name,
                                  self.lv_snapshot_name,
                                  self.lv_snapshot_size)
        lv_utils.lv_revert(self.vg_name, self.lv_name, self.lv_snapshot_name)