Example #1
0
    def mount(self, pointName):
        # validate input against the manifest
        if pointName not in self.db:
            raise error.StacksException("Point does not exist: {0!s}".format(
                str(pointName)))

        pointObj = self.db[pointName]
        imageName = pointObj.currentImage

        pointDir = self.getMountPointDir(pointName)
        pointDir = os.path.abspath(pointDir)

        # TEMP TEMP TEMP: for the meantime, lets be verbose about mount/bind actions
        topMountDir = self.imageManager.mountInstance(imageName,
                                                      pointName,
                                                      writable=True,
                                                      verbose=True)

        # if there was a successful mount, then bind the point dir to the
        # top mount dir
        if topMountDir:
            topMountDir = os.path.abspath(topMountDir)

            subwrap.run(['mount', '--bind', '-o', 'rw', topMountDir, pointDir])

        return pointDir
Example #2
0
def test_pass_options(fake_popen):
    any = arg.any
    fake_process = (fake_popen.expects_call()
            .with_args(any(), cwd="test", stderr=any(), stdout=any())
            .returns_fake())
    fake_process.expects('communicate').returns(('', ''))
    fake_process.has_attr(returncode=0)
    subwrap.run(['somecmd'], cwd="test")
Example #3
0
def test_custom_exit_handle_with_fake(fake_popen):
    fake_process = fake_popen.expects_call().returns_fake()
    fake_process.expects('communicate').returns(('', ''))
    fake_process.has_attr(returncode=1000)

    def custom_handle(response):
        assert response.return_code == 1000

    subwrap.run(['somecmd'], exit_handle=custom_handle)
Example #4
0
    def umount(self, pointName):
        # validate input against the manifest
        if pointName not in self.db:
            raise error.StacksException("Point does not exist: {0!s}".format(str(pointName)))

        pointObj = self.db[pointName]
        imageName = pointObj.currentImage

        self.imageManager.umountInstance(imageName, pointName)

        # unbind the point dir
        pointDir = self.getMountPointDir(pointName)
        pointDir = os.path.abspath(pointDir)
        subwrap.run(['umount', pointDir ])
Example #5
0
    def umount(self, pointName):
        # validate input against the manifest
        if pointName not in self.db:
            raise error.StacksException("Point does not exist: {0!s}".format(
                str(pointName)))

        pointObj = self.db[pointName]
        imageName = pointObj.currentImage

        self.imageManager.umountInstance(imageName, pointName)

        # unbind the point dir
        pointDir = self.getMountPointDir(pointName)
        pointDir = os.path.abspath(pointDir)
        subwrap.run(['umount', pointDir])
Example #6
0
def test_simple_run_with_fake(fake_popen):
    fake_process = fake_popen.expects_call().returns_fake()
    fake_process.expects('communicate').returns(('hello', ''))
    fake_process.has_attr(returncode=0)

    output = subwrap.run(['somecmd'])
    assert output.std_out == 'hello'
Example #7
0
 def mount(cls, mount_point, lower_dir, upper_dir, mount_table=None):
     """Execute the mount. This requires root"""
     ensure_directories(mount_point, lower_dir, upper_dir)
     # Load the mount table if it isn't given
     if not mount_table:
         mount_table = MountTable.load()
     # Check if the mount_point is in use
     if mount_table.is_mounted(mount_point):
         # Throw an error if it is
         raise AlreadyMounted()
     # Build mount options
     options = "rw,lowerdir=%s,upperdir=%s" % (lower_dir, upper_dir)
     # Run the actual mount
     subwrap.run(['mount', '-t', 'overlayfs', '-o', options,
         'olyfs%s' % random_name(), mount_point])
     return cls(mount_point, lower_dir, upper_dir)
Example #8
0
 def mount(cls, mount_point, lower_dir, upper_dir, mount_table=None):
     """Execute the mount. This requires root"""
     ensure_directories(mount_point, lower_dir, upper_dir)
     # Load the mount table if it isn't given
     if not mount_table:
         mount_table = MountTable.load()
     # Check if the mount_point is in use
     if mount_table.is_mounted(mount_point):
         # Throw an error if it is
         raise AlreadyMounted()
     # Build mount options
     options = "rw,lowerdir=%s,upperdir=%s" % (lower_dir, upper_dir)
     # Run the actual mount
     subwrap.run([
         'mount', '-t', 'overlayfs', '-o', options,
         'olyfs%s' % random_name(), mount_point
     ])
     return cls(mount_point, lower_dir, upper_dir)
Example #9
0
    def mount(self, pointName):
        # validate input against the manifest
        if pointName not in self.db:
            raise error.StacksException("Point does not exist: {0!s}".format(str(pointName)))

        pointObj = self.db[pointName]
        imageName = pointObj.currentImage

        pointDir = self.getMountPointDir(pointName)
        pointDir = os.path.abspath(pointDir)

        # TEMP TEMP TEMP: for the meantime, lets be verbose about mount/bind actions
        topMountDir = self.imageManager.mountInstance(imageName, pointName, writable=True, verbose=True)

        # if there was a successful mount, then bind the point dir to the
        # top mount dir
        if topMountDir:
            topMountDir = os.path.abspath(topMountDir)

            subwrap.run(['mount', '--bind','-o','rw', topMountDir, pointDir ])

        return pointDir
Example #10
0
 def load(cls, entry_class=None):
     response = subwrap.run(['mount'])
     return cls.from_string(response.std_out)
Example #11
0
    def _mountInstance_legacy(self, name, instanceName, writable=False, verbose=False):
        """ [Image3] <--- not possible due to overlayfs limitations with this kernel version!
            [Image2]
                [.self]
                    [mount]     upper=contents, lower=Image1:mount
                    [content]
                [instance1]
                    [mount]     upper=contents, lower=Image2.self:mount
                    [content]
            [Image1]
                [.self]
                    [mount]      bind mount to Image1.self.contents ----|
                    [content]         <---------------------------------|
        """
        imageObj = self.db[name]

        # ensure the image is not already mounted, if so, assume the remaining
        # parents are already mounted (as we will be unable to mount them
        # anyway if they are not already mounted)
        instanceDir = self.getInstancesDir(imageObj, instanceName)
        mountDir = os.path.join( instanceDir, "mount")
        if overlayUtils.isMounted(mountDir):
            return

        # Before mounting this instance, ensure the image is mounted as read-only.
        # This is done by mounting the ".self" instance of the current image.
        # After that, you can mount this [writable] instance
        if instanceName != self.ownInstance:
            self.mountImage(imageObj.name, writable=False)

        upperDir = os.path.join( instanceDir, "content")
        workingDir = os.path.join( instanceDir, "working")
        lowerDir = None

        # mount the necessary parent images, then mount the parent instance to .self
        if imageObj.parent is not None:
            if instanceName == self.ownInstance:
                self.mountImage(imageObj.parent, writable=False)

                parentInstanceDir = self.getInstancesDir(imageObj.parent,
                                                         self.ownInstance)
                lowerDir = os.path.join( parentInstanceDir, "mount")
            # ... or mount the non-.self instance
            else:
                ownInstanceDir = self.getInstancesDir(imageObj, self.ownInstance)
                lowerDir = os.path.join( ownInstanceDir, "mount")

            if verbose:
                print("Mounting:\n\tmount: {0!s}\n\tupper: {1!s}\n\tlower: {2!s}\n".format(os.path.abspath(mountDir),
                        os.path.abspath(upperDir),
                        os.path.abspath(lowerDir)))

            overlayUtils.mount(directory=os.path.abspath(mountDir),
                               lower_dir=os.path.abspath(lowerDir),
                               upper_dir=os.path.abspath(upperDir),
                               working_dir=os.path.abspath(workingDir),
                               readonly=not writable)

        # ... or this is the root, no need to mount parents
        else:
            import subwrap
            if writable:
                options="rw"
            else:
                options="ro"

            # This could be in use by other layers
            #subwrap.run(['umount', mountDir ])

            if verbose:
                print("Binding:\n\tmount: {0!s}\n\source: {1!s}\n".format(os.path.abspath(mountDir),
                        os.path.abspath(upperDir)))

            # perform a bind mount to the contents dir
            subwrap.run(['mount', '--bind','-o',options, upperDir, mountDir ])


        return mountDir
Example #12
0
def test_simple_run():
    output1 = subwrap.run(['echo', 'hello'])
    assert output1.std_out.strip() == 'hello'
Example #13
0
def test_default_exit_handle_with_fake(fake_popen):
    fake_process = fake_popen.expects_call().returns_fake()
    fake_process.expects('communicate').returns(('', ''))
    fake_process.has_attr(returncode=1)

    subwrap.run(['somecmd'])
Example #14
0
 def load(cls, entry_class=None):
     response = subwrap.run(['mount'])
     return cls.from_string(response.std_out)
Example #15
0
 def unmount(self):
     subwrap.run(['umount', self.mount_point])
Example #16
0
 def unmount(self):
     subwrap.run(['umount', self.mount_point])