Exemplo n.º 1
0
 def testSudo(self, cmd):
     checkSudo(['echo'])
     rc, out, _ = commands.execCmd(cmd(('grep',
                                   'Uid', '/proc/self/status')),
                                   sudo=True)
     self.assertEquals(rc, 0)
     self.assertEquals(int(out[0].split()[2]), 0)
Exemplo n.º 2
0
 def testSudo(self, cmd):
     checkSudo(['echo'])
     rc, out, _ = commands.execCmd(cmd(
         ('grep', 'Uid', '/proc/self/status')),
                                   sudo=True)
     self.assertEquals(rc, 0)
     self.assertEquals(int(out[0].split()[2]), 0)
Exemplo n.º 3
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)
         os.unlink(iso_img)
Exemplo n.º 4
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)
Exemplo n.º 5
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)
         os.unlink(iso_img)
Exemplo n.º 6
0
 def testSudo(self):
     """
     Tests that when running with sudo the user really is root (or other
     desired user).
     """
     cmd = [EXT_WHOAMI]
     checkSudo(cmd)
     ret, stdout, stderr = commands.execCmd(cmd, sudo=True)
     self.assertEqual(stdout[0].decode("ascii"), SUDO_USER)
Exemplo n.º 7
0
 def testSudo(self):
     """
     Tests that when running with sudo the user really is root (or other
     desired user).
     """
     cmd = [EXT_WHOAMI]
     checkSudo(cmd)
     ret, stdout, stderr = commands.execCmd(cmd, sudo=True)
     self.assertEqual(stdout[0], SUDO_USER)
Exemplo n.º 8
0
 def testLoopMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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()
Exemplo n.º 9
0
 def testLoopMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     mpath = mkdtemp()
     with createFloppyImage(FLOPPY_SIZE) as path:
         m = mount.Mount(path, mpath)
         m.mount(mntOpts="loop")
         try:
             self.assertTrue(m.isMounted())
         finally:
             m.umount()
             shutil.rmtree(mpath)
Exemplo n.º 10
0
 def testLoopMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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()
Exemplo n.º 11
0
 def test_removeFs(self):
     """
     Tests mkimage.removeFs creating an image and removing it.
     Check also that removeFs doesn't remove anything
     outside mkimage._P_PAYLOAD_IMAGES
     """
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     iso_img = mkimage.mkIsoFs("vmId_iso", self.files)
     self.assertTrue(os.path.exists(iso_img))
     mkimage.removeFs(iso_img)
     self.assertFalse(os.path.exists(iso_img))
     self.assertRaises(Exception, mkimage.removeFs, self.workdir)
Exemplo n.º 12
0
 def test_removeFs(self):
     """
     Tests mkimage.removeFs creating an image and removing it.
     Check also that removeFs doesn't remove anything
     outside mkimage._P_PAYLOAD_IMAGES
     """
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     iso_img = mkimage.mkIsoFs("vmId_iso", self.files)
     self.assertTrue(os.path.exists(iso_img))
     mkimage.removeFs(iso_img)
     self.assertFalse(os.path.exists(iso_img))
     self.assertRaises(Exception, mkimage.removeFs, self.workdir)
Exemplo n.º 13
0
 def testLoopMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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)
Exemplo n.º 14
0
 def testLoopMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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)
Exemplo n.º 15
0
 def test_mkIsoFs(self):
     """
     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)
     self.assertTrue(os.path.exists(iso_img))
     m = storage.mount.Mount(iso_img, self.workdir)
     m.mount(mntOpts='loop')
     try:
         self._check_content()
     finally:
         m.umount(force=True)
         os.unlink(iso_img)
Exemplo n.º 16
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)
     try:
         m.mount(mntOpts='loop')
     except storage.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)
Exemplo n.º 17
0
 def testSymlinkMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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()
Exemplo n.º 18
0
 def testSymlinkMount(self):
     checkSudo(["mount", "-o", "loop", "somefile", "target"])
     checkSudo(["umount", "target"])
     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()