예제 #1
0
    def add(self):
        """
        Add this file system by creating a dedicated path (i.e., self.fs.mount_point)
        and exporting it over NFS. Set the owner of the repo as ``ubuntu`` user.
        """
        try:
            log.debug("Adding transient file system at {0}".format(
                self.fs.mount_point))
            if not os.path.exists(self.fs.mount_point):
                os.mkdir(self.fs.mount_point)
            os.chown(self.fs.mount_point, pwd.getpwnam(
                "ubuntu")[2], grp.getgrnam("ubuntu")[2])
            self.device = commands.getoutput("df -h %s | grep -v Filesystem | awk '{print $1}'"
                                             % self.fs.mount_point)

            # If based on bucket, extract bucket contents onto new volume
            try:
                if self.from_archive:
                    log.info("Extracting archive url: {0} to mount point: {1}. This could take a while...".format(self.from_archive['url'], self.fs.mount_point))
                    misc.extract_archive_content_to_path(self.from_archive['url'], self.fs.mount_point, self.from_archive['md5_sum'])
                    self.fs.persistent = True
            except Exception, e:
                log.error("Error while extracting archive: {0}".format(e))
                return False

            if self.fs.add_nfs_share(self.fs.mount_point):
                self.status()
                return True
            else:
                log.warning('Trouble sharing {0} over NFS?'.format(
                    self.fs.mount_point))
예제 #2
0
    def mount(self, mount_point):
        """
        Mount this volume as a locally accessible file system and make it
        available over NFS
        """
        for counter in range(30):
            if self.status == volume_status.ATTACHED:
                if os.path.exists(mount_point):
                    # Check if the mount location is empty
                    if len(os.listdir(mount_point)) != 0:
                        log.warning("A file system at {0} already exists and is not empty; cannot "
                                    "mount volume {1}".format(mount_point, self.volume_id))
                        return False
                else:
                    os.mkdir(mount_point)
                # Potentially wait for the device to actually become available in the system
                # TODO: Do something if the device is not available in the
                # given time period
                for i in range(10):
                    if os.path.exists(self.device):
                        log.debug("Device path {0} checked and it exists.".format(
                            self.device))
                        break
                    else:
                        log.debug("Device path {0} does not yet exist; waiting...".format(
                            self.device))
                        time.sleep(4)
                # Until the underlying issue is fixed (see FIXME below), mask this
                # even more by custom-handling the run command and thus not
                # printing the err
                cmd = '/bin/mount %s %s' % (self.device, mount_point)
                process = subprocess.Popen(
                    cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
                _, _ = process.communicate()
                if process.returncode != 0:
                    # FIXME: Assume if a file system cannot be mounted that it's because
                    # there is not a file system on the device so try creating
                    # one
                    if run('/sbin/mkfs.xfs %s' % self.device,
                           "Failed to create a files ystem on device %s" % self.device,
                           "Created a file system on device %s" % self.device):
                        if not run(
                            '/bin/mount %s %s' % (self.device, mount_point),
                            "Error mounting file system %s from %s" % (
                                mount_point, self.device),
                                "Successfully mounted file system %s from %s" %
                                (mount_point, self.device)):
                            log.error("Failed to mount device '%s' to mount point '%s'"
                                      % (self.device, mount_point))
                            return False
                # Resize the volume if it was created from a snapshot
                else:
                    if self.snapshot and self.volume.size > self.snapshot.volume_size:
                        run('/usr/sbin/xfs_growfs %s' % mount_point)
                        log.info("Successfully grew file system {0}".format(self.fs.get_full_name()))
                log.info("Successfully mounted file system {0} from {1}".format(mount_point,
                    self.device))

                try:
                    # Default owner of all mounted file systems to `galaxy`
                    # user
                    os.chown(mount_point, pwd.getpwnam(
                        "galaxy")[2], grp.getgrnam("galaxy")[2])
                    # Add Galaxy- and CloudBioLinux-required files under the
                    # 'data' dir
                    if ServiceRole.GALAXY_DATA in self.fs.svc_roles:
                        for sd in ['files', 'tmp', 'upload_store', 'export']:
                            path = os.path.join(
                                self.app.path_resolver.galaxy_data, sd)
                            if not os.path.exists(path):
                                os.mkdir(path)
                            # Make 'export' dir that's shared over NFS be
                            # owned by `ubuntu` user so it's accesible
                            # for use to the rest of the cluster
                            if sd == 'export':
                                os.chown(path, pwd.getpwnam(
                                    "ubuntu")[2], grp.getgrnam("ubuntu")[2])
                            else:
                                os.chown(path, pwd.getpwnam(
                                    "galaxy")[2], grp.getgrnam("galaxy")[2])
                except OSError, e:
                    log.debug(
                        "Tried making 'galaxyData' sub-dirs but failed: %s" % e)

                # If based on bucket, extract bucket contents onto new volume
                try:
                    if self.from_archive:
                        log.info("Extracting archive url: {0} to mount point: {1}. This could take a while...".format(self.from_archive['url'], mount_point))
                        misc.extract_archive_content_to_path(self.from_archive['url'], mount_point, self.from_archive['md5_sum'])
                except Exception, e:
                    log.error("Error while extracting archive: {0}".format(e))
                    return False

                # Lastly, share the newly mounted file system over NFS
                if self.fs.add_nfs_share(mount_point):
                    return True