Example #1
0
 def create_lv(self, l_disk):
     vgname = 'avocado_vg'
     lvname = 'avocado_lv'
     lv_size = lv_utils.get_device_total_space(l_disk) / 2330168
     lv_utils.vg_create(vgname, l_disk)
     lv_utils.lv_create(vgname, lvname, lv_size)
     return '/dev/%s/%s' % (vgname, lvname)
Example #2
0
    def set_root(params, object=None):
        """
        Set a root state to provide object existence.

        All arguments match the base class.

        Create a ramdisk, virtual group, thin pool and logical volume
        for each object (all off).
        """
        vm_name = params["vms"]
        mount_loc = LVMBackend._get_images_mount_loc(params)
        logging.info("Creating original logical volume for %s", vm_name)
        lv_utils.vg_ramdisk(None, params["vg_name"], params["ramdisk_vg_size"],
                            params["ramdisk_basedir"],
                            params["ramdisk_sparse_filename"],
                            params["use_tmpfs"] == "yes")
        lv_utils.lv_create(
            params["vg_name"],
            params["lv_name"],
            params["lv_size"],
            # NOTE: call by key to keep good argument order which wasn't
            # accepted upstream for backward API compatibility
            pool_name=params["pool_name"],
            pool_size=params["pool_size"])
        lv_utils.lv_take_snapshot(params["vg_name"], params["lv_name"],
                                  params["lv_pointer_name"])
        if mount_loc:
            if not os.path.exists(mount_loc):
                os.mkdir(mount_loc)
            lv_utils.lv_mount(params["vg_name"],
                              params["lv_pointer_name"],
                              mount_loc,
                              create_filesystem="ext4")
            super(LVMBackend, LVMBackend).set_root(params, object)
Example #3
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)
Example #4
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)
Example #5
0
    def create_lv(self):
        """
        General logical volume setup.

        A volume group with given name is created in the ramdisk. It then
        creates a logical volume.
        """
        lv_utils.lv_create(self.vg_name, self.lv_name, self.lv_size)
Example #6
0
def set_root(run_params):
    """
    Create a ramdisk, virtual group, thin pool and logical volume
    for each vm (all offline).

    :param run_params: configuration parameters
    :type run_params: {str, str}
    :raises: :py:class:`exceptions.TestError` if the root state already exists
    """
    vms = run_params.objects("vms")
    for vm_name in vms:
        vm_params = run_params.object_params(vm_name)

        if lv_utils.vg_check(vm_params["vg_name"]):
            if vm_params.get("force_create", "no") == "yes":
                logging.info("Removing the previously created %s", vm_name)
                if vm_params.get("image_raw_device", "yes") == "no":
                    mount_loc = os.path.dirname(vm_params["image_name"])
                    try:
                        lv_utils.lv_umount(vm_params["vg_name"],
                                           vm_params["lv_pointer_name"])
                    except lv_utils.LVException:
                        pass
                logging.debug("Removing previous volume group of %s", vm_name)
                lv_utils.vg_ramdisk_cleanup(vm_params["ramdisk_sparse_filename"],
                                            os.path.join(vm_params["ramdisk_basedir"],
                                                         vm_params["vg_name"]),
                                            vm_params["vg_name"],
                                            None,
                                            vm_params["use_tmpfs"] == "yes")
            else:
                raise exceptions.TestError("The root state of %s already exists" % vm_name)

        logging.info("Preparing original logical volume for %s", vm_name)
        lv_utils.vg_ramdisk(None,
                            vm_params["vg_name"],
                            vm_params["ramdisk_vg_size"],
                            vm_params["ramdisk_basedir"],
                            vm_params["ramdisk_sparse_filename"],
                            vm_params["use_tmpfs"] == "yes")
        lv_utils.lv_create(vm_params["vg_name"],
                           vm_params["lv_name"],
                           vm_params["lv_size"],
                           # NOTE: call by key to keep good argument order which wasn't
                           # accepted upstream for backward API compatibility
                           pool_name=vm_params["pool_name"],
                           pool_size=vm_params["pool_size"])
        lv_utils.lv_take_snapshot(vm_params["vg_name"],
                                  vm_params["lv_name"],
                                  vm_params["lv_pointer_name"])
        if vm_params.get("image_raw_device", "yes") == "no":
            mount_loc = os.path.dirname(vm_params["image_name"])
            if not os.path.exists(mount_loc):
                os.mkdir(mount_loc)
            lv_utils.lv_mount(vm_params["vg_name"], vm_params["lv_pointer_name"],
                              mount_loc, create_filesystem="ext4")
Example #7
0
    def create_lv(self, l_disk):
        """
        creates a volume group then logical volume on it and returns lv.

        :param l_disk: disk name on which a lv will be created
        :returns: Returns the lv name
        :rtype: str
        """
        lv_size = lv_utils.get_device_total_space(l_disk) / 2330168
        lv_utils.vg_create(self.vgname, l_disk)
        lv_utils.lv_create(self.vgname, self.lvname, lv_size)
        return '/dev/%s/%s' % (self.vgname, self.lvname)
Example #8
0
    def create_lv(self):
        """
        General logical volume setup.

        A volume group with given name is created in the ramdisk. It then
        creates a logical volume.
        """
        lv_utils.vg_create(self.vg_name, self.device)
        if not lv_utils.vg_check(self.vg_name):
            self.fail('Volume group %s not created' % self.vg_name)
        lv_utils.lv_create(self.vg_name, self.lv_name, self.lv_size)
        if not lv_utils.lv_check(self.vg_name, self.lv_name):
            self.fail('Logical Volume %s not created' % self.lv_name)
Example #9
0
    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_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)
Example #10
0
    def create_lv(self):
        """
        General logical volume setup.

        A volume group with given name is created in the ramdisk. It then
        creates a 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)
Example #11
0
    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)
Example #12
0
    def set_root(cls, params, object=None):
        """
        Set a root state to provide object existence.

        All arguments match the base class.

        Create a disk, virtual group, thin pool and logical volume
        for each object.
        """
        vm_name = params["vms"]
        mount_loc = cls._get_image_mount_loc(params)
        logging.info("Creating original logical volume for %s", vm_name)
        vg_setup(params["vg_name"], params["disk_vg_size"],
                 params["disk_basedir"], params["disk_sparse_filename"],
                 params["use_tmpfs"] == "yes")
        lv_utils.lv_create(
            params["vg_name"],
            params["lv_name"],
            params["lv_size"],
            # NOTE: call by key to keep good argument order which wasn't
            # accepted upstream for backward API compatibility
            pool_name=params["lv_pool_name"],
            pool_size=params["lv_pool_size"])
        lv_utils.lv_take_snapshot(params["vg_name"], params["lv_name"],
                                  params["lv_pointer_name"])
        if mount_loc:
            if not os.path.exists(mount_loc):
                os.mkdir(mount_loc)
            lv_utils.lv_mount(params["vg_name"],
                              params["lv_pointer_name"],
                              mount_loc,
                              create_filesystem="ext4")
            # TODO: it is not correct for the LVM backend to expect QCOW2 images
            # but at the moment we have no better way to provide on states with
            # base image to take snapshots of
            super(LVMBackend, LVMBackend).set_root(params, object)