• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import logging, os
2from autotest_lib.client.common_lib import error
3
4
5@error.context_aware
6def mount_lv(lv_path, session):
7    error.context("mounting ext3 filesystem made on logical volume %s" %
8                  os.path.basename(lv_path))
9    session.cmd("mkdir -p /mnt/kvm_test_lvm")
10    session.cmd("mount %s /mnt/kvm_test_lvm" % lv_path)
11
12
13@error.context_aware
14def umount_lv(lv_path, session):
15    error.context("umounting ext3 filesystem made on logical volume %s" %
16                  os.path.basename(lv_path))
17    session.cmd("umount %s" % lv_path)
18    session.cmd("rm -rf /mnt/kvm_test_lvm")
19
20
21@error.context_aware
22def run_lvm(test, params, env):
23    """
24    KVM reboot test:
25    1) Log into a guest
26    2) Create a volume group and add both disks as pv to the Group
27    3) Create a logical volume on the VG
28    5) `fsck' to check the partition that LV locates
29
30    @param test: kvm test object
31    @param params: Dictionary with the test parameters
32    @param env: Dictionary with test environment.
33    """
34    vm = env.get_vm(params["main_vm"])
35    vm.verify_alive()
36    timeout = int(params.get("login_timeout", 360))
37    session = vm.wait_for_login(timeout=timeout)
38
39    vg_name = "vg_kvm_test"
40    lv_name = "lv_kvm_test"
41    lv_path = "/dev/%s/%s" % (vg_name, lv_name)
42    disks = params.get("disks", "/dev/hdb /dev/hdc")
43    clean = params.get("clean", "yes")
44    timeout = params.get("lvm_timeout", "600")
45
46    try:
47        error.context("adding physical volumes %s" % disks)
48        session.cmd("pvcreate %s" % disks)
49
50        error.context("creating a volume group out of %s" % disks)
51        session.cmd("vgcreate %s %s" % (vg_name, disks))
52
53        error.context("activating volume group %s" % vg_name)
54        session.cmd("vgchange -ay %s" % vg_name)
55
56        error.context("creating logical volume on volume group %s" % vg_name)
57        session.cmd("lvcreate -L2000 -n %s %s" % (lv_name, vg_name))
58
59        error.context("creating ext3 filesystem on logical volume %s" % lv_name)
60        session.cmd("yes | mkfs.ext3 %s" % lv_path, timeout=int(timeout))
61
62        mount_lv(lv_path, session)
63
64        umount_lv(lv_path, session)
65
66        error.context("checking ext3 filesystem made on logical volume %s" %
67                      lv_name)
68        session.cmd("fsck %s" % lv_path, timeout=int(timeout))
69
70        if clean == "no":
71            mount_lv(lv_path, session)
72
73    finally:
74        if clean == "yes":
75            umount_lv(lv_path, session)
76
77            error.context("removing logical volume %s" % lv_name)
78            session.cmd("lvremove %s" % lv_name)
79
80            error.context("disabling volume group %s" % vg_name)
81            session.cmd("vgchange -a n %s" % vg_name)
82
83            error.context("removing volume group %s" % vg_name)
84            session.cmd("vgremove -f %s" % vg_name)
85