Example #1
0
 def test_mkIsoFs(self, label):
     """
     Tests mkimage.mkIsoFs creating an image and checking its content
     """
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     iso_img = mkimage.mkIsoFs("vmId_iso", self.files, label)
     self.assertTrue(os.path.exists(iso_img))
     m = storage.mount.Mount(iso_img, self.workdir)
     m.mount(mntOpts='loop')
     try:
         self._check_content()
         self._check_label(iso_img, label)
         self._check_permissions(iso_img,
                                 ((stat.S_IRUSR, True),
                                  (stat.S_IWUSR, True),
                                  (stat.S_IXUSR, False)))
         self._check_permissions(iso_img,
                                 ((stat.S_IRGRP, True),
                                  (stat.S_IWGRP, False),
                                  (stat.S_IXGRP, False)))
         self._check_permissions(iso_img,
                                 ((stat.S_IROTH, False),
                                  (stat.S_IWOTH, False),
                                  (stat.S_IXOTH, False)))
     finally:
         m.umount(force=True, freeloop=True)
         # TODO: Use libudev to wait for specific event
         with stopwatch("Wait for udev events"):
             udevadm.settle(5)
Example #2
0
def _wait_for_udev_events():
    # FIXME: This is an ugly hack that is meant to prevent VDSM to report VFs
    # that are not yet named by udev or not report all of. This is a blocking
    # call that should wait for all udev events to be handled. a proper fix
    # should be registering and listening to the proper netlink and udev
    # events. The sleep prior to observing udev is meant to decrease the
    # chances that we wait for udev before it knows from the kernel about the
    # new devices.
    time.sleep(0.5)
    udevadm.settle(timeout=10)
Example #3
0
def _wait_for_udev_events():
    # FIXME: This is an ugly hack that is meant to prevent VDSM to report VFs
    # that are not yet named by udev or not report all of. This is a blocking
    # call that should wait for all udev events to be handled. a proper fix
    # should be registering and listening to the proper netlink and udev
    # events. The sleep prior to observing udev is meant to decrease the
    # chances that we wait for udev before it knows from the kernel about the
    # new devices.
    time.sleep(0.5)
    udevadm.settle(timeout=10)
Example #4
0
    def _wait_for_events(self):
        """
        This is an ugly hack to wait until the udev events generated when
        adding or removing a mount are processed.

        Note that we may wait for unrelated events, or wait too little if the
        system is overloaded.

        TODO: find a way to wait for the specific event.
        """
        with utils.stopwatch("Waiting for udev mount events", log=self.log):
            timeout = config.getint('irs', 'udev_settle_timeout')
            udevadm.settle(timeout)
Example #5
0
    def _wait_for_events(self):
        """
        This is an ugly hack to wait until the udev events generated when
        adding or removing a mount are processed.

        Note that we may wait for unrelated events, or wait too little if the
        system is overloaded.

        TODO: find a way to wait for the specific event.
        """
        with utils.stopwatch("Waiting for udev mount events", log=self.log):
            timeout = config.getint('irs', 'udev_settle_timeout')
            udevadm.settle(timeout)
Example #6
0
 def testLoopMount(self):
     with namedTemporaryDir() as mpath:
         # two nested with blocks to be python 2.6 friendly
         with createFloppyImage(FLOPPY_SIZE) as path:
             m = mount.Mount(path, mpath)
             m.mount(mntOpts="loop")
             try:
                 self.assertTrue(m.isMounted())
             finally:
                 m.umount(force=True, freeloop=True)
                 # TODO: Use libudev to wait for specific event
                 with stopwatch("Wait for udev events"):
                     udevadm.settle(5)
Example #7
0
 def testLoopMount(self):
     with namedTemporaryDir() as mpath:
         # two nested with blocks to be python 2.6 friendly
         with createFloppyImage(FLOPPY_SIZE) as path:
             m = mount.Mount(path, mpath)
             m.mount(mntOpts="loop")
             try:
                 self.assertTrue(m.isMounted())
             finally:
                 m.umount(force=True, freeloop=True)
                 # TODO: Use libudev to wait for specific event
                 with stopwatch("Wait for udev events"):
                     udevadm.settle(5)
Example #8
0
def rescan():
    """
    Forces multipath daemon to rescan the list of available devices and
    refresh the mapping table. New devices can be found under /dev/mapper

    Should only be called from hsm._rescanDevices()
    """

    # First rescan iSCSI and FCP connections
    iscsi.rescan()
    hba.rescan()

    # Scanning SCSI interconnects starts a storm of udev events. Wait until all
    # events are processed, ensuring detection of new devices and creation or
    # update of multipath devices.
    timeout = config.getint('irs', 'udev_settle_timeout')
    udevadm.settle(timeout)
Example #9
0
 def test_mkFloppyFs(self, label):
     """
     Tests mkimage.mkFloppyFs creating an image and checking its content.
     Requires root permissions for writing into the floppy image.
     """
     floppy = mkimage.mkFloppyFs("vmId_floppy", self.files, label)
     self.assertTrue(os.path.exists(floppy))
     m = mount.Mount(floppy, self.workdir)
     m.mount(mntOpts="loop")
     try:
         self._check_content(checkPerms=False)
         self._check_label(floppy, label)
     finally:
         m.umount(force=True, freeloop=True)
         # TODO: Use libudev to wait for specific event
         with stopwatch("Wait for udev events"):
             udevadm.settle(5)
Example #10
0
 def test_mkFloppyFs(self, label):
     """
     Tests mkimage.mkFloppyFs creating an image and checking its content.
     Requires root permissions for writing into the floppy image.
     """
     floppy = mkimage.mkFloppyFs("vmId_floppy", self.files, label)
     self.assertTrue(os.path.exists(floppy))
     m = mount.Mount(floppy, self.workdir)
     m.mount(mntOpts='loop')
     try:
         self._check_content(checkPerms=False)
         self._check_label(floppy, label)
     finally:
         m.umount(force=True, freeloop=True)
         # TODO: Use libudev to wait for specific event
         with stopwatch("Wait for udev events"):
             udevadm.settle(5)
Example #11
0
def rescan():
    """
    Forces multipath daemon to rescan the list of available devices and
    refresh the mapping table. New devices can be found under /dev/mapper

    Should only be called from hsm._rescanDevices()
    """

    # First rescan iSCSI and FCP connections
    iscsi.rescan()
    hba.rescan()

    # Scanning SCSI interconnects starts a storm of udev events. Wait until all
    # events are processed, ensuring detection of new devices and creation or
    # update of multipath devices.
    timeout = config.getint('irs', 'udev_settle_timeout')
    udevadm.settle(timeout)
Example #12
0
 def test_mkIsoFs(self, label):
     """
     Tests mkimage.mkIsoFs creating an image and checking its content
     """
     iso_img = mkimage.mkIsoFs("vmId_iso", self.files, label)
     self.assertTrue(os.path.exists(iso_img))
     m = mount.Mount(iso_img, self.workdir)
     try:
         m.mount(mntOpts="loop")
     except mount.MountError as e:
         raise SkipTest("Error mounting iso image: %s" % e)
     try:
         self._check_content()
         self._check_label(iso_img, label)
     finally:
         m.umount(force=True, freeloop=True)
         # TODO: Use libudev to wait for specific event
         with stopwatch("Wait for udev events"):
             udevadm.settle(5)
Example #13
0
 def test_mkIsoFs(self, label):
     """
     Tests mkimage.mkIsoFs creating an image and checking its content
     """
     iso_img = mkimage.mkIsoFs("vmId_iso", self.files, label)
     self.assertTrue(os.path.exists(iso_img))
     m = mount.Mount(iso_img, self.workdir)
     try:
         m.mount(mntOpts='loop')
     except mount.MountError as e:
         raise SkipTest("Error mounting iso image: %s" % e)
     try:
         self._check_content()
         self._check_label(iso_img, label)
     finally:
         m.umount(force=True, freeloop=True)
         # TODO: Use libudev to wait for specific event
         with stopwatch("Wait for udev events"):
             udevadm.settle(5)
Example #14
0
 def testSymlinkMount(self):
     with namedTemporaryDir() as root_dir:
         backing_image = os.path.join(root_dir, 'backing.img')
         link_to_image = os.path.join(root_dir, 'link_to_image')
         mountpoint = os.path.join(root_dir, 'mountpoint')
         with open(backing_image, 'w') as f:
             os.ftruncate(f.fileno(), 1024 ** 3)
         rc, out, err = execCmd(['/sbin/mkfs.ext2', "-F", backing_image],
                                raw=True)
         if rc != 0:
             raise RuntimeError("Error creating filesystem: %s" % err)
         os.symlink(backing_image, link_to_image)
         os.mkdir(mountpoint)
         m = mount.Mount(link_to_image, mountpoint)
         m.mount(mntOpts="loop")
         try:
             self.assertTrue(m.isMounted())
         finally:
             m.umount(force=True, freeloop=True)
             # TODO: Use libudev to wait for specific event
             with stopwatch("Wait for udev events"):
                 udevadm.settle(5)
Example #15
0
 def detach(self):
     if self._path is None:
         raise AssertionError("Device is detached: %s" % self)
     cmd = ["losetup", "--detach", self._path]
     rc, out, err = commands.execCmd(cmd, raw=True)
     if rc != 0:
         raise cmdutils.Error(cmd, rc, out, err)
     self._path = None
     # After deactivating lvs backed by loop device, we get tons of udev
     # events. We must wait for the events or we may get stale lvs that
     # would fail the next tests.
     #
     # $ udevadm monitor -u
     # ...
     # UDEV  [314195.642497] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.643032] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.653214] remove   /devices/virtual/bdi/253:4 (bdi)
     # UDEV  [314195.664478] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.664863] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.674426] remove   /devices/virtual/bdi/253:5 (bdi)
     # UDEV  [314195.807277] change   /devices/virtual/block/loop0 (block)
     udevadm.settle(5)
Example #16
0
 def testSymlinkMount(self):
     with namedTemporaryDir() as root_dir:
         backing_image = os.path.join(root_dir, 'backing.img')
         link_to_image = os.path.join(root_dir, 'link_to_image')
         mountpoint = os.path.join(root_dir, 'mountpoint')
         with open(backing_image, 'w') as f:
             os.ftruncate(f.fileno(), 1024 ** 3)
         rc, out, err = execCmd(['/sbin/mkfs.ext2', "-F", backing_image],
                                raw=True)
         if rc != 0:
             raise RuntimeError("Error creating filesystem: %s" % err)
         os.symlink(backing_image, link_to_image)
         os.mkdir(mountpoint)
         m = mount.Mount(link_to_image, mountpoint)
         m.mount(mntOpts="loop")
         try:
             self.assertTrue(m.isMounted())
         finally:
             m.umount(force=True, freeloop=True)
             # TODO: Use libudev to wait for specific event
             with stopwatch("Wait for udev events"):
                 udevadm.settle(5)
Example #17
0
 def detach(self):
     if self._path is None:
         raise AssertionError("Device is detached: %s" % self)
     cmd = ["losetup", "--detach", self._path]
     rc, out, err = commands.execCmd(cmd, raw=True)
     if rc != 0:
         raise cmdutils.Error(cmd, rc, out, err)
     self._path = None
     # After deactivating lvs backed by loop device, we get tons of udev
     # events. We must wait for the events or we may get stale lvs that
     # would fail the next tests.
     #
     # $ udevadm monitor -u
     # ...
     # UDEV  [314195.642497] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.643032] remove   /devices/virtual/block/dm-4 (block)
     # UDEV  [314195.653214] remove   /devices/virtual/bdi/253:4 (bdi)
     # UDEV  [314195.664478] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.664863] remove   /devices/virtual/block/dm-5 (block)
     # UDEV  [314195.674426] remove   /devices/virtual/bdi/253:5 (bdi)
     # UDEV  [314195.807277] change   /devices/virtual/block/loop0 (block)
     udevadm.settle(5)
Example #18
0
 def connect(self):
     iscsi.addIscsiNode(self._iface, self._target, self._cred)
     timeout = config.getint("irs", "udev_settle_timeout")
     udevadm.settle(timeout)