Exemplo n.º 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)
Exemplo n.º 2
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 setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        self.disk = self.params.get('disk', default=None)
        vg_name = self.params.get('vg_name', default='avocado_vg')
        lv_name = self.params.get('lv_name', default='avocado_lv')
        self.lv_size = self.params.get('lv_size', default='1G')
        self.fs_name = self.params.get('fs_name', default='ext4')
        lv_snapshot_name = self.params.get(
            'lv_snapshot_name', default='avocado_sn')
        self.lv_snapshot_size = self.params.get(
            'lv_snapshot_size', default='1G')
        self.ramdisk_vg_size = self.params.get(
            'ramdisk_vg_size', default='10000')
        self.ramdisk_basedir = self.params.get(
            'ramdisk_basedir', default=self.workdir)
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if lv_utils.vg_check(vg_name):
            self.skip('Volume group %s already exists' % vg_name)
        self.vg_name = vg_name
        if lv_utils.lv_check(vg_name, lv_name):
            self.skip('Logical Volume %s already exists' % lv_name)
        self.lv_name = lv_name
        if lv_utils.lv_check(vg_name, lv_snapshot_name):
            self.skip('Snapshot %s already exists' % lv_snapshot_name)
        self.mount_loc = 'avocado_%s' % self.fs_name
        os.mkdir(self.mount_loc)
        self.lv_snapshot_name = lv_snapshot_name
Exemplo n.º 4
0
 def pre_cleanup(self):
     """
     cleanup the disk and directory before test starts on it
     """
     self.log.info("Pre_cleaning of disk and diretories...")
     disk_list = [
         '/dev/mapper/avocado_vg-avocado_lv', self.raid_name, self.disk
     ]
     for disk in disk_list:
         self.delete_fs(disk)
     self.log.info("checking ...lv/vg existance...")
     if lv_utils.lv_check(self.vgname, self.lvname):
         self.log.info("found lv existance... deleting it")
         self.delete_lv()
     elif lv_utils.vg_check(self.vgname):
         self.log.info("found vg existance ... deleting it")
         lv_utils.vg_remove(self.vgname)
     else:
         self.log.info("No VG/LV detected")
     self.log.info("checking for sraid existance...")
     if self.sraid.exists():
         self.log.info("found sraid existance... deleting it")
         self.delete_raid()
     else:
         self.log.info("No softwareraid detected ")
     self.log.info("\n End of pre_cleanup")
Exemplo n.º 5
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        self.disk = self.params.get('disk', default=None)
        vg_name = self.params.get('vg_name', default='avocado_vg')
        lv_name = self.params.get('lv_name', default='avocado_lv')
        self.lv_size = self.params.get('lv_size', default='1G')
        self.fs_name = self.params.get('fs_name', default='ext4')
        lv_snapshot_name = self.params.get('lv_snapshot_name',
                                           default='avocado_sn')
        self.lv_snapshot_size = self.params.get('lv_snapshot_size',
                                                default='1G')
        self.ramdisk_vg_size = self.params.get('ramdisk_vg_size',
                                               default='10000')
        self.ramdisk_basedir = self.params.get('ramdisk_basedir',
                                               default=self.workdir)
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if lv_utils.vg_check(vg_name):
            self.skip('Volume group %s already exists' % vg_name)
        self.vg_name = vg_name
        if lv_utils.lv_check(vg_name, lv_name):
            self.skip('Logical Volume %s already exists' % lv_name)
        self.lv_name = lv_name
        if lv_utils.lv_check(vg_name, lv_snapshot_name):
            self.skip('Snapshot %s already exists' % lv_snapshot_name)
        self.mount_loc = 'avocado_%s' % self.fs_name
        os.mkdir(self.mount_loc)
        self.lv_snapshot_name = lv_snapshot_name
Exemplo n.º 6
0
 def delete_lv(self):
     """
     Clear all PV,VG, LV and snapshots created by the test.
     """
     if lv_utils.lv_check(self.vg_name, self.lv_name):
         lv_utils.lv_remove(self.vg_name, self.lv_name)
     if lv_utils.vg_check(self.vg_name):
         lv_utils.vg_remove(self.vg_name)
Exemplo n.º 7
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        pkg = ""
        smm = SoftwareManager()
        self.disk = self.params.get('lv_disks', default=None)
        self.vg_name = self.params.get('vg_name', default='avocado_vg')
        self.lv_name = self.params.get('lv_name', default='avocado_lv')
        self.fs_name = self.params.get('fs', default='ext4').lower()
        if self.fs_name == 'xfs':
            pkg = 'xfsprogs'
        if self.fs_name == 'btrfs':
            ver = int(distro.detect().version)
            rel = int(distro.detect().release)
            if distro.detect().name == 'rhel':
                if (ver == 7 and rel >= 4) or ver > 7:
                    self.cancel("btrfs is not supported with RHEL 7.4 onwards")
            if distro.detect().name == 'SuSE':
                pkg = 'btrfsprogs'
            else:
                pkg = 'btrfs-progs'
        if pkg and not smm.check_installed(pkg) and not smm.install(pkg):
            self.cancel("Package %s could not be installed" % pkg)

        self.lv_snap_name = self.params.get(
            'lv_snapshot_name', default='avocado_sn')
        self.ramdisk_basedir = self.params.get(
            'ramdisk_basedir', default=os.path.join(self.workdir, 'ramdisk'))
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if 'delete' not in str(self.name.name):
            if lv_utils.vg_check(self.vg_name):
                self.cancel('Volume group %s already exists' % self.vg_name)
            if lv_utils.lv_check(self.vg_name, self.lv_name):
                self.cancel('Logical Volume %s already exists' % self.lv_name)
            if lv_utils.lv_check(self.vg_name, self.lv_snap_name):
                self.cancel('Snapshot %s already exists' % self.lv_snap_name)

        self.mount_loc = os.path.join(self.workdir, 'mountpoint')
        if not os.path.isdir(self.mount_loc):
            os.makedirs(self.mount_loc)

        if self.disk:
            # converting bytes to megabytes, and using only 45% of the size
            self.lv_size = int(lv_utils.get_diskspace(self.disk)) / 2330168
        else:
            self.lv_size = '1G'
        self.lv_size = self.params.get('lv_size', default=self.lv_size)
        self.lv_snapshot_size = self.params.get('lv_snapshot_size',
                                                default=self.lv_size)
        self.ramdisk_vg_size = self.params.get('ramdisk_vg_size',
                                               default=self.lv_size)
        self.ramdisks.append(lv_utils.vg_ramdisk(self.disk, self.vg_name,
                                                 self.ramdisk_vg_size,
                                                 self.ramdisk_basedir,
                                                 self.ramdisk_sparse_filename))
Exemplo n.º 8
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")
Exemplo n.º 9
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)
Exemplo n.º 10
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        pkg = ""
        smm = SoftwareManager()
        self.disk = self.params.get('disks', default=None)
        vg_name = self.params.get('vg_name', default='avocado_vg')
        lv_name = self.params.get('lv_name', default='avocado_lv')
        self.fs_name = self.params.get('fs', default='ext4').lower()
        if self.fs_name == 'xfs':
            pkg = 'xfsprogs'
        if self.fs_name == 'btrfs':
            if distro.detect().name == 'SuSE':
                pkg = 'btrfsprogs'
            else:
                pkg = 'btrfs-progs'
        if pkg and not smm.check_installed(pkg) and not smm.install(pkg):
            self.cancel("Package %s could not be installed" % pkg)
        lv_snapshot_name = self.params.get('lv_snapshot_name',
                                           default='avocado_sn')
        self.ramdisk_basedir = self.params.get('ramdisk_basedir',
                                               default=os.path.join(
                                                   self.workdir, 'ramdisk'))
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if lv_utils.vg_check(vg_name):
            self.cancel('Volume group %s already exists' % vg_name)
        self.vg_name = vg_name
        if lv_utils.lv_check(vg_name, lv_name):
            self.cancel('Logical Volume %s already exists' % lv_name)
        self.lv_name = lv_name
        if lv_utils.lv_check(vg_name, lv_snapshot_name):
            self.cancel('Snapshot %s already exists' % lv_snapshot_name)
        self.mount_loc = os.path.join(self.workdir, 'mountpoint')
        if not os.path.isdir(self.mount_loc):
            os.makedirs(self.mount_loc)
        self.lv_snapshot_name = lv_snapshot_name

        if self.disk:
            # converting bytes to megabytes, and using only 45% of the size
            self.lv_size = int(lv_utils.get_diskspace(self.disk)) / 2330168
        else:
            self.lv_size = '1G'
        self.lv_size = self.params.get('lv_size', default=self.lv_size)
        self.lv_snapshot_size = self.params.get('lv_snapshot_size',
                                                default=self.lv_size)
        self.ramdisk_vg_size = self.params.get('ramdisk_vg_size',
                                               default=self.lv_size)
Exemplo n.º 11
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        pkg = ""
        smm = SoftwareManager()
        self.disk = self.params.get('disks', default=None)
        vg_name = self.params.get('vg_name', default='avocado_vg')
        lv_name = self.params.get('lv_name', default='avocado_lv')
        self.lv_size = self.params.get('lv_size', default='1G')
        self.fs_name = self.params.get('fs', default='ext4').lower()
        if self.fs_name == 'xfs':
            pkg = 'xfsprogs'
        if self.fs_name == 'btrfs':
            if distro.detect().name == 'SuSE':
                pkg = 'btrfsprogs'
            else:
                pkg = 'btrfs-progs'
        if pkg and not smm.check_installed(pkg) and not smm.install(pkg):
            self.cancel("Package %s is missing and could not be installed" % pkg)
        lv_snapshot_name = self.params.get(
            'lv_snapshot_name', default='avocado_sn')
        self.lv_snapshot_size = self.params.get(
            'lv_snapshot_size', default='1G')
        self.ramdisk_vg_size = self.params.get(
            'ramdisk_vg_size', default='10000')
        self.ramdisk_basedir = self.params.get(
            'ramdisk_basedir', default=os.path.join(self.workdir, 'ramdisk'))
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if lv_utils.vg_check(vg_name):
            self.cancel('Volume group %s already exists' % vg_name)
        self.vg_name = vg_name
        if lv_utils.lv_check(vg_name, lv_name):
            self.cancel('Logical Volume %s already exists' % lv_name)
        self.lv_name = lv_name
        if lv_utils.lv_check(vg_name, lv_snapshot_name):
            self.cancel('Snapshot %s already exists' % lv_snapshot_name)
        self.mount_loc = os.path.join(self.workdir, 'mountpoint')
        if not os.path.isdir(self.mount_loc):
            os.makedirs(self.mount_loc)
        self.lv_snapshot_name = lv_snapshot_name
Exemplo n.º 12
0
    def unset_root(params, object=None):
        """
        Unset a root state to prevent object existence.

        All arguments match the base class and in addition:

        :raises: :py:class:`exceptions.TestWarn` if permanent vm was detected

        Remove the ramdisk, virtual group, thin pool and logical volume
        of each object (all off).
        """
        vm_name = params["vms"]
        mount_loc = LVMBackend._get_images_mount_loc(params)
        logging.info("Removing original logical volume for %s", vm_name)
        try:
            if mount_loc:
                if lv_utils.vg_check(params["vg_name"]):
                    # mount to avoid not-mounted errors
                    try:
                        lv_utils.lv_mount(params["vg_name"],
                                          params["lv_pointer_name"], mount_loc)
                    except lv_utils.LVException:
                        pass
                    lv_utils.lv_umount(params["vg_name"],
                                       params["lv_pointer_name"])
                if os.path.exists(mount_loc):
                    try:
                        os.rmdir(mount_loc)
                    except OSError as ex:
                        logging.warning(
                            "No permanent vm can be removed automatically. If "
                            "this is not a permanent test object, see the debug."
                        )
                        raise exceptions.TestWarn(
                            "Permanent vm %s was detected but cannot be "
                            "removed automatically" % vm_name)
            lv_utils.vg_ramdisk_cleanup(
                params["ramdisk_sparse_filename"],
                os.path.join(params["ramdisk_basedir"], params["vg_name"]),
                params["vg_name"], None, params["use_tmpfs"] == "yes")
        except exceptions.TestError as ex:
            logging.error(ex)
Exemplo n.º 13
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        pkg = ""
        smm = SoftwareManager()
        self.disk = self.params.get('disk', default=None)
        vg_name = self.params.get('vg_name', default='avocado_vg')
        lv_name = self.params.get('lv_name', default='avocado_lv')
        self.lv_size = self.params.get('lv_size', default='1G')
        self.fs_name = self.params.get('fs', default='ext4').lower()
        if self.fs_name == 'xfs':
            pkg = 'xfsprogs'
        if self.fs_name == 'btrfs':
            if distro.detect().name == 'SuSE':
                pkg = 'btrfsprogs'
            else:
                pkg = 'btrfs-progs'
        if pkg and not smm.check_installed(pkg) and not smm.install(pkg):
            self.cancel("Package %s is missing and could not be installed" %
                        pkg)
        lv_snapshot_name = self.params.get('lv_snapshot_name',
                                           default='avocado_sn')
        self.lv_snapshot_size = self.params.get('lv_snapshot_size',
                                                default='1G')
        self.ramdisk_vg_size = self.params.get('ramdisk_vg_size',
                                               default='10000')
        self.ramdisk_basedir = self.params.get('ramdisk_basedir',
                                               default=self.workdir)
        self.ramdisk_sparse_filename = self.params.get(
            'ramdisk_sparse_filename', default='virtual_hdd')

        if lv_utils.vg_check(vg_name):
            self.cancel('Volume group %s already exists' % vg_name)
        self.vg_name = vg_name
        if lv_utils.lv_check(vg_name, lv_name):
            self.cancel('Logical Volume %s already exists' % lv_name)
        self.lv_name = lv_name
        if lv_utils.lv_check(vg_name, lv_snapshot_name):
            self.cancel('Snapshot %s already exists' % lv_snapshot_name)
        self.mount_loc = self.srcdir
        self.lv_snapshot_name = lv_snapshot_name
Exemplo n.º 14
0
def unset_root(run_params):
    """
    Remove the ramdisk, virtual group, thin pool and logical volume
    of each vm (all offline).

    :param run_params: configuration parameters
    :type run_params: {str, str}
    """
    vms = run_params.objects("vms")
    logging.info("Removing vms %s with their images", run_params["vms"])
    for vm_name in vms:
        vm_params = run_params.object_params(vm_name)
        try:
            if vm_params.get("image_raw_device", "yes") == "no":
                mount_loc = os.path.dirname(vm_params["image_name"])
                if lv_utils.vg_check(vm_params["vg_name"]):
                    try:
                        lv_utils.lv_umount(vm_params["vg_name"],
                                           vm_params["lv_pointer_name"])
                    except lv_utils.LVException:
                        pass
                if os.path.exists(mount_loc):
                    try:
                        os.rmdir(mount_loc)
                    except OSError as ex:
                        logging.warning("No permanent vm can be removed automatically. If "
                                        "this is not a permanent test object, see the debug.")
                        logging.debug(ex)
                        return
            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")
        except exceptions.TestError as ex:
            logging.error(ex)
Exemplo n.º 15
0
    def setUp(self):
        """
        Check existence of input PV,VG, LV and snapshots prior to Test.
        """
        pkgs = [""]
        smm = SoftwareManager()
        self.disk = self.params.get('lv_disks', default=None)
        self.vg_name = self.params.get('vg_name', default='avocado_vg')
        self.lv_name = self.params.get('lv_name', default='avocado_lv')
        self.fs_name = self.params.get('fs', default='ext4').lower()
        self.lv_size = self.params.get('lv_size', default='0')
        if self.fs_name == 'xfs':
            pkgs = ['xfsprogs']
        if self.fs_name == 'btrfs':
            ver = int(distro.detect().version)
            rel = int(distro.detect().release)
            if distro.detect().name == 'rhel':
                if (ver == 7 and rel >= 4) or ver > 7:
                    self.cancel("btrfs is not supported with RHEL 7.4 onwards")
            if distro.detect().name == 'SuSE':
                pkgs = ['btrfsprogs']
            else:
                pkgs = ['btrfs-progs']
        if distro.detect().name in ['Ubuntu', 'debian']:
            pkgs.extend(['lvm2'])

        for pkg in pkgs:
            if pkg and not smm.check_installed(pkg) and not smm.install(pkg):
                self.cancel("Package %s could not be installed" % pkg)

        self.lv_snap_name = self.params.get('lv_snapshot_name',
                                            default='avocado_sn')

        if lv_utils.vg_check(self.vg_name):
            self.cancel('Volume group %s already exists' % self.vg_name)
        if lv_utils.lv_check(self.vg_name, self.lv_name):
            self.cancel('Logical Volume %s already exists' % self.lv_name)
        if lv_utils.lv_check(self.vg_name, self.lv_snap_name):
            self.cancel('Snapshot %s already exists' % self.lv_snap_name)

        self.mount_loc = os.path.join(self.workdir, 'mountpoint')
        if not os.path.isdir(self.mount_loc):
            os.makedirs(self.mount_loc)

        if self.lv_size:
            # converting to megabytes
            if self.lv_size.endswith('G'):
                self.lv_size = int(self.lv_size.strip('G')) * 1024
            elif self.lv_size.endswith('M'):
                self.lv_size = int(self.lv_size.strip('M'))
            else:
                self.lv_size = int(self.lv_size) / 1024 / 1024

        if self.disk:
            disk_size = lv_utils.get_devices_total_space(self.disk.split())
            # converting bytes to megabytes
            disk_size = disk_size / (1024 * 1024)

            if self.lv_size:
                if self.lv_size > disk_size:
                    self.cancel("lv size provided more than size of disks")
            else:
                self.lv_size = disk_size

            self.device = self.disk
        else:
            if not self.lv_size:
                self.lv_size = 1024 * 1024 * 1024

            try:
                self.device = disk.create_loop_device(self.lv_size)
            except DiskError:
                self.cancel("Could not create loop device")

            # converting bytes to megabytes
            self.lv_size = self.lv_size / (1024 * 1024)

        # Using only 45% of lv size, to accomodate lv snapshot also.
        self.lv_size = (self.lv_size * 45) / 100

        self.lv_snapshot_size = self.params.get('lv_snapshot_size',
                                                default=self.lv_size)