Coverage for drivers/MooseFSSR : 33%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
#!/usr/bin/env python # # Original work copyright (C) Citrix systems # Modified work copyright (C) Tappest sp. z o.o., Vates SAS and XCP-ng community # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU Lesser General Public License as published # by the Free Software Foundation; version 2.1 only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Lesser General Public License for more details. # # You should have received a copy of the GNU Lesser General Public License # along with this program; if not, write to the Free Software Foundation, Inc., # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA # # MooseFSSR: Based on CEPHFSSR and FileSR, mounts MooseFS share
# careful with the import order here # FileSR has a circular dependency: # FileSR -> blktap2 -> lvutil -> EXTSR -> FileSR # importing in this order seems to avoid triggering the issue. # end of careful
"VDI_CREATE", "VDI_DELETE", "VDI_ATTACH", "VDI_DETACH", "VDI_UPDATE", "VDI_CLONE", "VDI_SNAPSHOT", "VDI_RESIZE", "VDI_MIRROR", "VDI_GENERATE_CONFIG", "VDI_RESET_ON_BOOT/2", "ATOMIC_PAUSE"]
['masterhost', 'MooseFS Master Server hostname or IP address (required, e.g.: "mfsmaster.local.lan" or "10.10.10.1")'], ['masterport', 'MooseFS Master Server port, default: 9421'], ['rootpath', 'MooseFS path (required, e.g.: "/")'], ['options', 'MooseFS Client additional options (e.g.: "mfspassword=PASSWORD,mfstimeout=300")'] ]
'name': 'MooseFS VHD', 'description': 'SR plugin which stores disks as VHD files on a MooseFS storage', 'vendor': 'Tappest sp. z o.o.', 'copyright': '(C) 2021 Tappest sp. z o.o.', 'driver_version': '1.0', 'required_api_version': '1.0', 'capabilities': CAPABILITIES, 'configuration': CONFIGURATION }
# The mountpoint for the directory when performing an sr_probe. All probes # are guaranteed to be serialised by xapi, so this single mountpoint is fine.
"""MooseFS file-based storage"""
# fudge, because the parent class (FileSR) checks for smb to alter its behavior return sr_type == MooseFSSR.DRIVER_TYPE or sr_type == 'smb'
raise xs_errors.XenError( 'SRUnavailable', opterr='MooseFS Client is not installed!' )
raise xs_errors.XenError('ConfigServerMissing') # if masterport is not specified, use default: 9421 else: self.remoteport = self.dconf['masterport'] self.sm_config = self.session.xenapi.SR.get_sm_config(self.sr_ref) else:
self.sm_config.get('subdir') or '0' ) self.remotepath = os.path.join(self.remotepath, sr_uuid)
return util.ioretry(lambda: ((util.pathexists(self.mountpoint) and util.ismount(self.mountpoint))))
"""Mount MooseFS share at 'mountpoint'""" elif not util.is_string(mountpoint) or mountpoint == "": raise MooseFSException("Mountpoint is not a string object")
try: options = [] if self.dconf.has_key('options'): options.append(self.dconf['options']) if options: options = ['-o', ','.join(options)] remote = '{}:{}:{}'.format( self.remoteserver, self.remoteport, self.remotepath ) command = ["mount", '-t', 'moosefs', remote, mountpoint] + options util.ioretry(lambda: util.pread(command), errlist=[errno.EPIPE, errno.EIO], maxretry=2, nofail=True) except util.CommandException, inst: syslog(_syslog.LOG_ERR, 'MooseFS mount failed ' + inst.__str__()) raise MooseFSException("Mount failed with return code %d" % inst.code)
# Sanity check to ensure that the user has at least RO access to the # mounted share. Windows sharing and security settings can be tricky. try: util.listdir(mountpoint) except util.CommandException: try: self.unmount(mountpoint, True) except MooseFSException: util.logException('MooseFSSR.unmount()') raise MooseFSException("Permission denied. Please check user privileges.")
try: util.pread(["umount", mountpoint]) except util.CommandException, inst: raise MooseFSException("Command umount failed with return code %d" % inst.code) if rmmountpoint: try: os.rmdir(mountpoint) except OSError, inst: raise MooseFSException("Command rmdir failed with error '%s'" % inst.strerror)
try: self.mount() except MooseFSException, exc: raise SR.SROSError(12, exc.errstr)
try: self.mount(PROBE_MOUNTPOINT) sr_list = filter(util.match_uuid, util.listdir(PROBE_MOUNTPOINT)) self.unmount(PROBE_MOUNTPOINT, True) except (util.CommandException, xs_errors.XenError): raise # Create a dictionary from the SR uuids to feed SRtoXML() sr_dict = {sr_uuid: {} for sr_uuid in sr_list} return util.SRtoXML(sr_dict)
util.SMlog("Aborting GC/coalesce") cleanup.abort(sr_uuid) # Change directory to avoid unmount conflicts os.chdir(SR.MOUNT_BASE) self.unmount(self.mountpoint, True) self.attached = False
if self.checkmount(): raise SR.SROSError(113, 'MooseFS mount point already attached')
assert self.remotepath == self.rootpath try: self.mount() except MooseFSException, exc: # noinspection PyBroadException try: os.rmdir(self.mountpoint) except: # we have no recovery strategy pass raise SR.SROSError(111, "MooseFS mount error [opterr=%s]" % exc.errstr)
try: self.subdir = self.sm_config.get('subdir') if self.subdir is None: self.subdir = True else: self.subdir = distutils.util.strtobool(self.subdir)
self.sm_config['subdir'] = str(self.subdir) self.session.xenapi.SR.set_sm_config(self.sr_ref, self.sm_config)
if not self.subdir: return
subdir = os.path.join(self.mountpoint, sr_uuid) if util.ioretry(lambda: util.pathexists(subdir)): if util.ioretry(lambda: util.isdir(subdir)): raise xs_errors.XenError('SRExists') else: try: util.ioretry(lambda: util.makedirs(subdir)) except util.CommandException as e: if e.code != errno.EEXIST: raise MooseFSException( 'Failed to create SR subdir: {}'.format(e) ) finally: self.detach(sr_uuid)
# try to remove/delete non VDI contents first super(MooseFSSR, self).delete(sr_uuid) try: if self.checkmount(): self.detach(sr_uuid)
if self.subdir: # Mount using rootpath (<root>) instead of <root>/<sr_uuid>. self.remotepath = self.rootpath self.attach(sr_uuid) subdir = os.path.join(self.mountpoint, sr_uuid) if util.ioretry(lambda: util.pathexists(subdir)): util.ioretry(lambda: os.rmdir(subdir)) self.detach(sr_uuid) except util.CommandException, inst: self.detach(sr_uuid) if inst.code != errno.ENOENT: raise SR.SROSError(114, "Failed to remove MooseFS mount point")
return MooseFSFileVDI(self, uuid)
def _is_moosefs_available(): import distutils.spawn return distutils.spawn.find_executable('mfsmount')
if not hasattr(self, 'xenstore_data'): self.xenstore_data = {}
self.xenstore_data['storage-type'] = MooseFSSR.DRIVER_TYPE
return super(MooseFSFileVDI, self).attach(sr_uuid, vdi_uuid)
util.SMlog("MooseFSFileVDI.generate_config") if not util.pathexists(self.path): raise xs_errors.XenError('VDIUnavailable') resp = {'device_config': self.sr.dconf, 'sr_uuid': sr_uuid, 'vdi_uuid': vdi_uuid, 'sr_sm_config': self.sr.sm_config, 'command': 'vdi_attach_from_config'} # Return the 'config' encoded within a normal XMLRPC response so that # we can use the regular response/error parsing code. config = xmlrpclib.dumps(tuple([resp]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True)
try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("MooseFSFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', opterr='Unable to attach from config')
SRCommand.run(MooseFSSR, DRIVER_INFO) else: |