def test_run_correctly_log_all_exceptions(self, mock_parse, mock_run_statics, mock_reduce, mock_SMlog, mock_exit): """ Assert that any arbitrary exception raised and with a big message length is logged to SMlog. Only the first line of the message is asserted (traceback ommited). """ from random import choice from string import ascii_letters from DummySR import DRIVER_INFO MSG_LEN = 2048 # TestSRCommand data member to hold SMlog output. self.smlog_out = "" # Generate random exception message of MSG_LEN characters rand_huge_msg = ''.join(choice(ascii_letters) for _ in range(MSG_LEN)) # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException(rand_huge_msg)) # MockSMlog replaces util.SMlog. Instead of printing to # /var/log/SMlog, it writes the output to self.smlog_out. def MockSMlog(str_arg): self.smlog_out = self.smlog_out + str_arg.strip() mock_reduce.return_value = '' mock_SMlog.side_effect = MockSMlog SRCommand.run(mock_driver, DRIVER_INFO) self.assertTrue(rand_huge_msg in self.smlog_out)
def test_run_wrapped_if_not_SRException(self, mock_parse, mock_run_statics, mock_logException, mock_exit): """ If an exception other than SR.SRException is thrown, assert that it is wrapped and not thrown. """ from DummySR import DRIVER_INFO # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException) SRCommand.run(mock_driver, DRIVER_INFO)
def test_run_reraise_if_not_SRException(self, mock_parse, mock_run_statics, mock_logException): """ If an exception other than SR.SRException is thrown, assert that it is re-raised. """ from DummySR import DRIVER_INFO # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException) try: SRCommand.run(mock_driver, DRIVER_INFO) except Exception, e: self.assertTrue(isinstance(e, SomeException))
def test_run_wrapped_if_not_SRException( self, mock_parse, mock_run_statics, mock_logException, mock_exit): """ If an exception other than SR.SRException is thrown, assert that it is wrapped and not thrown. """ from DummySR import DRIVER_INFO # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException) SRCommand.run(mock_driver, DRIVER_INFO)
def test_run_reraise_if_not_SRException( self, mock_parse, mock_run_statics, mock_logException): """ If an exception other than SR.SRException is thrown, assert that it is re-raised. """ from DummySR import DRIVER_INFO # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException) try: SRCommand.run(mock_driver, DRIVER_INFO) except Exception, e: self.assertTrue(isinstance(e, SomeException))
def test_run_print_xml_error_if_SRException( self, mock_parse, mock_run_statics, mock_logException): """ If an SR.SRException is thrown, assert that print <SR.SRException instance>.toxml()" is called. """ import sys from StringIO import StringIO from SR import SRException from DummySR import DRIVER_INFO # Save original sys.stdout file object. saved_stdout = sys.stdout # Create a mock_stdout object and assign it to sys.stdout mock_stdout = StringIO() sys.stdout = mock_stdout # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SRException( "[UnitTest] SRException thrown")) try: SRCommand.run(mock_driver, DRIVER_INFO) except SystemExit: pass # Write SRCommand.run() output to variable. actual_out = mock_stdout.getvalue() # Restore the original sys.stdout object. sys.stdout = saved_stdout expected_out = ("<?xml version='1.0'?>\n<methodResponse>\n<fault>\n" "<value><struct>\n<member>\n<name>faultCode</name>\n" "<value><int>22</int></value>\n</member>\n<member>\n" "<name>faultString</name>\n<value><string>[UnitTest] " "SRException thrown</string></value>\n</member>\n" "</struct></value>\n</fault>\n</methodResponse>\n\n") self.assertEqual(actual_out, expected_out)
def test_run_correctly_log_all_exceptions( self, mock_parse, mock_run_statics, mock_reduce, mock_SMlog): """ Assert that any arbitrary exception raised and with a big message length is logged to SMlog. Only the first line of the message is asserted (traceback ommited). """ from random import choice from string import ascii_letters from DummySR import DRIVER_INFO MSG_LEN = 2048 # TestSRCommand data member to hold SMlog output. self.smlog_out = None # Generate random exception message of MSG_LEN characters rand_huge_msg = ''.join(choice(ascii_letters) for _ in range(MSG_LEN)) # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock(side_effect=SomeException(rand_huge_msg)) # MockSMlog replaces util.SMlog. Instead of printing to # /var/log/SMlog, it writes the output to self.smlog_out. def MockSMlog(str_arg): self.smlog_out = str_arg.strip() mock_reduce.return_value = '' mock_SMlog.side_effect = MockSMlog try: SRCommand.run(mock_driver, DRIVER_INFO) except SomeException: # SomeException needs to be suppressed for this # test, as it is re-raised after it is logged. pass self.assertTrue(rand_huge_msg in self.smlog_out)
def test_run_print_xml_error_if_SRException(self, mock_parse, mock_run_statics, mock_logException): """ If an SR.SRException is thrown, assert that print <SR.SRException instance>.toxml()" is called. """ import sys from StringIO import StringIO from SR import SRException from DummySR import DRIVER_INFO # Save original sys.stdout file object. saved_stdout = sys.stdout # Create a mock_stdout object and assign it to sys.stdout mock_stdout = StringIO() sys.stdout = mock_stdout # Create function to raise exception in SRCommand.run() mock_driver = mock.Mock( side_effect=SRException("[UnitTest] SRException thrown")) try: SRCommand.run(mock_driver, DRIVER_INFO) except SystemExit: pass # Write SRCommand.run() output to variable. actual_out = mock_stdout.getvalue() # Restore the original sys.stdout object. sys.stdout = saved_stdout expected_out = ("<?xml version='1.0'?>\n<methodResponse>\n<fault>\n" "<value><struct>\n<member>\n<name>faultCode</name>\n" "<value><int>22</int></value>\n</member>\n<member>\n" "<name>faultString</name>\n<value><string>[UnitTest] " "SRException thrown</string></value>\n</member>\n" "</struct></value>\n</fault>\n</methodResponse>\n\n") self.assertEqual(actual_out, expected_out)
self.sr.dconf['multipathhandle'] = self.sr.mpathhandle dict['device_config'] = self.sr.dconf dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("OCFSoHBAVDI.attach_from_config") self.sr.hbasr.attach(sr_uuid) if self.sr.mpath == "true": self.sr.mpathmodule.refresh(self.sr.SCSIid,0) try: return self.attach(sr_uuid, vdi_uuid) except: util.logException("OCFSoHBAVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') def match_scsidev(s): regex = re.compile("^/dev/disk/by-id|^/dev/mapper") return regex.search(s, 0) if __name__ == '__main__': SRCommand.run(OCFSoHBASR, DRIVER_INFO) else: SR.registerSR(OCFSoHBASR)
dict['device_config'] = self.sr.dconf dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['allocation'] = self.sr.sm_config['allocation'] dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("LVHDoHBAVDI.attach_from_config") self.sr.hbasr.attach(sr_uuid) if self.sr.mpath == "true": self.sr.mpathmodule.refresh(self.sr.SCSIid,0) try: return self.attach(sr_uuid, vdi_uuid) except: util.logException("LVHDoHBAVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') def match_scsidev(s): regex = re.compile("^/dev/disk/by-id|^/dev/mapper") return regex.search(s, 0) if __name__ == '__main__': SRCommand.run(LVHDoHBASR, DRIVER_INFO) else: SR.registerSR(LVHDoHBASR)
def vdiExists(self, vdi_path): """ Reads first 8 bytes of the path and checks for the cookie """ fd = open(vdi_path) cookie = fd.read(8) fd.close() if cookie == VHD_COOKIE: return True return False def _get_vdi_from_xapi(self, vdi_uuid): vdi = {} try: vdi_ref = self.sr.session.xenapi.VDI.get_by_uuid(vdi_uuid) vdi = self.sr.session.xenapi.VDI.get_record(vdi_ref) except: # Can raise exception when creating a new VDI so it is not yet in the DB pass return vdi if __name__ == '__main__': SRCommand.run(VDILUNSR, DRIVER_INFO) else: SR.registerSR(VDILUNSR)
element.appendChild(entry) subentry = dom.createElement("UUID") entry.appendChild(subentry) textnode = dom.createTextNode(val) subentry.appendChild(textnode) subentry = dom.createElement("Target") entry.appendChild(subentry) textnode = dom.createTextNode(record['target']) subentry.appendChild(textnode) subentry = dom.createElement("TargetIQN") entry.appendChild(subentry) textnode = dom.createTextNode(record['targetIQN']) subentry.appendChild(textnode) return dom.toprettyxml() def match_lun(self, s): regex = re.compile("_") if regex.search(s,0): return False regex = re.compile("LUN") return regex.search(s, 0) if __name__ == '__main__': SRCommand.run(ISCSISR, DRIVER_INFO) else: SR.registerSR(ISCSISR)
st = os.stat(self.path) self.size = long(st.st_size) self.utilisation = long(st.st_size) except OSError, inst: raise xs_errors.XenError('EIO', \ opterr='failed to star %s error is %d' % self.path % \ inst.sterror) def create(self, sr_uuid, vdi_uuid, size): # This is a no-op in this driver, VDI's will be introduced via # separate call vdi_introduce raise xs_errors.XenError('Unimplemented', \ opterr='VDI create unsupported') def delete(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI delete unsupported') def clone(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI clone unsupported') def snapshot(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI snapshot unsupported') if __name__ == '__main__': SRCommand.run(RAWSR, DRIVER_INFO) else: SR.registerSR(RAWSR)
result = [] try: # Get all configured iscsiadm interfaces cmd = ["iscsiadm", "-m", "iface"] (stdout, stderr) = iscsilib.exn_on_failure( cmd, "Failure occured querying iscsi daemon") # Get the interface (first column) from a line such as default # tcp,<empty>,<empty>,<empty>,<empty> for line in stdout.split("\n"): line_element = line.split(" ") interface_name = line_element[0] # ignore interfaces which aren't marked as starting with # c_. if len(line_element) == 2 and interface_name[:2] == "c_": result.append(interface_name) except: # Ignore exception from exn on failure, still return the default # interface pass # In case there are no configured interfaces, still add the default # interface if len(result) == 0: result.append("default") return result if __name__ == '__main__': SRCommand.run(ISCSISR, DRIVER_INFO) else: SR.registerSR(ISCSISR)
"field \"VDI\" = \"%s\"" % vdi_ref) return filter(lambda v: v['currently_attached'] == "true", vbds.values()) def check_vbd_list_is_stable(self, attached_vbds): newly_attached_vbds = self.get_attached_vbds() old_set = set(attached_vbds) new_set = set(newly_attached_vbds) diff_set = old_set.difference(new_set) | new_set.difference(old_set) if len(diff_set) != 0: msg = "LVHDRT: found a non-stable VBD: %s" % (diff_set.pop()) util.SMlog(msg) raise xs_errors.XenError('VBDListNotStable') def run_corner_cases_tests(self): def fn(): attached_vbds = self.get_attached_vbds() for i in range(0, 10): time.sleep(2) self.check_no_other_vdi_operation_in_progress() self.check_vbd_list_is_stable(attached_vbds) util.fistpoint.activate_custom_fn("LVHDRT_xapiSM_serialization_tests", fn) if __name__ == '__main__': SRCommand.run(DummySR, DRIVER_INFO) else: SR.registerSR(DummySR)
def get_attached_vbds(self): vdi_ref = self.session.xenapi.VDI.get_by_uuid(self.uuid) vbds = self.session.xenapi.VBD.get_all_records_where("field \"VDI\" = \"%s\"" % vdi_ref) return filter(lambda v: v['currently_attached'] == "true", vbds.values()) def check_vbd_list_is_stable(self, attached_vbds): newly_attached_vbds = self.get_attached_vbds() old_set = set(attached_vbds) new_set = set(newly_attached_vbds) diff_set = old_set.difference(new_set) | new_set.difference(old_set) if len(diff_set) != 0: msg = "LVHDRT: found a non-stable VBD: %s" % (diff_set.pop()) util.SMlog(msg) raise xs_errors.XenError('VBDListNotStable') def run_corner_cases_tests(self): def fn(): attached_vbds = self.get_attached_vbds() for i in range(0,10): time.sleep(2) self.check_no_other_vdi_operation_in_progress() self.check_vbd_list_is_stable(attached_vbds) util.fistpoint.activate_custom_fn("LVHDRT_xapiSM_serialization_tests", fn) if __name__ == '__main__': SRCommand.run(DummySR, DRIVER_INFO) else: SR.registerSR(DummySR)
self._db_introduce() return super(LocalISOVDI, self).get_params() except Exception, exn: util.SMlog("Exception when creating VDI: %s" % exn) raise xs_errors.XenError('VDICreate', \ opterr='could not create file: "%s"' % self.path) def delete(self, sr_uuid, vdi_uuid): util.SMlog("Deleting...") self.uuid = vdi_uuid self._db_forget() if not util.pathexists(self.path): return try: util.SMlog("Unlinking...") os.unlink(self.path) util.SMlog("Done...") except: raise xs_errors.XenError('VDIDelete') # Update, introduce unimplemented. super class will raise # exceptions if __name__ == '__main__': SRCommand.run(LocalISOSR, DRIVER_INFO) else: SR.registerSR(LocalISOSR)
class LVHDoRBDVDI(LVHDSR.LVHDVDI): def generate_config(self, sr_uuid, vdi_uuid): if not lvutil._checkLV(self.path): raise xs_errors.XenError('VDIUnavailable') data = { 'sr_uuid': sr_uuid, 'vdi_uuid': vdi_uuid, 'command': 'vdi_attach_from_config', 'device_config': self.sr.dconf } config = xmlrpclib.dumps(tuple([data]), 'vdi_attach_from_config') return xmlrpclib.dumps((config, ), '', True) def attach_from_config(self, sr_uuid, vdi_uuid): try: self.sr.attach(sr_uuid) if not self.sr._attach_LUN_bySCSIid(self.sr.SCSIid): raise xs_errors.XenError('InvalidDev') return LVHDSR.LVHDVDI.attach(self, sr_uuid, vdi_uuid) except: util.logException('LVHDoRBDVDI.attach_from_config') raise xs_errors.XenError('SRUnavailable', opterr='Failed to attach RBD') if __name__ == '__main__': SRCommand.run(LVHDoRBDSR, DRIVER_INFO) else: SR.registerSR(LVHDoRBDSR)
return False handles = staticmethod(handles) def load(self, sr_uuid): driver = SR.driver('iscsi') self.iscsi = driver(self.original_srcmd, sr_uuid) # User must specify a LUN ID(s) for adding to the VG if not self.dconf.has_key('LUNid') or not self.dconf['LUNid']: raise xs_errors.XenError('ConfigLUNIDMissing') self.dconf['device'] = os.path.join(self.iscsi.path,"LUN%s" % \ self.dconf['LUNid']) if not self.iscsi.attached: # Must attach SR here in order to load VG self.iscsi.attach(sr_uuid) super(EXToISCSISR, self).load(sr_uuid) def delete(self, sr_uuid): super(EXToISCSISR, self).delete(sr_uuid) self.iscsi.detach(sr_uuid) def detach(self, sr_uuid): super(EXToISCSISR, self).detach(sr_uuid) self.iscsi.detach(sr_uuid) if __name__ == '__main__': SRCommand.run(EXToISCSISR) else: SR.registerSR(EXToISCSISR)
opterr='LVM clone unsupported') def snapshot(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='LVM snapshot unsupported') def _isactive(self, path): try: f=open(path, 'r') f.close() return True except IOError: return False class BufferedLVSCAN(VDI.VDI): def load(self, line): fields = line.split() self.lvname = fields[0] self.uuid = fields[0].replace("LV-","") self.size = long(fields[3].replace("B","")) self.utilisation = self.size self.location = self.uuid if len(fields) > 4: self.parent = fields[4].replace("LV-","") if __name__ == '__main__': SRCommand.run(LVMSR, DRIVER_INFO) else: SR.registerSR(LVMSR)
def generate_config(self, sr_uuid, vdi_uuid): util.SMlog("SMBFileVDI.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) def attach_from_config(self, sr_uuid, vdi_uuid): try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("SMBFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', opterr='Unable to attach from config') if __name__ == '__main__': SRCommand.run(GlusterFSSR, DRIVER_INFO) else: SR.registerSR(GlusterFSSR)
stat = os.stat(self.path) self.utilisation = long(stat.st_size) self.size = long(stat.st_size) except: pass def __init__(self, mysr, uuid, filename): self.uuid = uuid VDI.VDI.__init__(self, mysr, None) self.path = os.path.join(mysr.dconf['location'], filename) self.label = filename self.location = filename self.vdi_type = 'file' self.read_only = True self.shareable = True self.sm_config = {} def detach(self, sr_uuid, vdi_uuid): pass def clone(self, sr_uuid, vdi_uuid): return self.get_params() def snapshot(self, sr_uuid, vdi_uuid): return self.get_params() if __name__ == '__main__': SRCommand.run(SHMSR, DRIVER_INFO) else: SR.registerSR(SHMSR)
pass elif self.mode == "nbd": self._disable_rbd_caching() cmdout = util.pread2([ "rbd-nbd", "--device", "/dev/nbd0", "--nbds_max", str(cephutils.NBDS_MAX), "-c", "/etc/ceph/ceph.conf.nocaching", "map", "%s/%s" % (self.sr.CEPH_POOL_NAME, _vdi_name), "--name", self.sr.CEPH_USER ]).rstrip('\n') util.pread2(["ln", "-s", cmdout, _dev_name]) util.pread2(["ln", "-s", cmdout, dev_name]) self.path = self.sr._get_path(vdi_uuid) if not util.pathexists(self.path): raise xs_errors.XenError('VDIUnavailable', opterr='Could not find: %s' % self.path) return VDI.VDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("RBDVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') if __name__ == '__main__': SRCommand.run(RBDSR, DRIVER_INFO) else: SR.registerSR(RBDSR)
self.size = long(st.st_size) self.utilisation = long(st.st_size) except OSError, inst: raise xs_errors.XenError('EIO', \ opterr='failed to star %s error is %d' % self.path % \ inst.sterror) def create(self, sr_uuid, vdi_uuid, size): # This is a no-op in this driver, VDI's will be introduced via # separate call vdi_introduce raise xs_errors.XenError('Unimplemented', \ opterr='VDI create unsupported') def delete(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI delete unsupported') def clone(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI clone unsupported') def snapshot(self, sr_uuid, vdi_uuid): raise xs_errors.XenError('Unimplemented', \ opterr='VDI snapshot unsupported') if __name__ == '__main__': SRCommand.run(RAWSR, DRIVER_INFO) else: SR.registerSR(RAWSR)
self.utilisation = long(stat.st_size) self.size = long(stat.st_size) except: pass def __init__(self, mysr, uuid, filename): self.uuid = uuid self.path = os.path.join(mysr.dconf['location'], filename) VDI.VDI.__init__(self, mysr, None) self.label = filename self.location = filename self.vdi_type = 'file' self.read_only = True self.shareable = True self.sm_config = {} def detach(self, sr_uuid, vdi_uuid): pass def clone(self, sr_uuid, vdi_uuid): return self.get_params() def snapshot(self, sr_uuid, vdi_uuid): return self.get_params() if __name__ == '__main__': SRCommand.run(SHMSR, DRIVER_INFO) else: SR.registerSR(SHMSR)
try: util.pread2(["mkfs.ext4", "-F", self.remotepath]) except util.CommandException as inst: raise xs_errors.XenError('LVMFilesystem', \ opterr='mkfs failed error %d' % inst.code) #Update serial number string scsiutil.add_serial_record(self.session, self.sr_ref, \ scsiutil.devlist_to_serialstring(self.root.split(','))) def vdi(self, uuid, loadLocked=False): if not loadLocked: return EXTFileVDI(self, uuid) return EXTFileVDI(self, uuid) class EXTFileVDI(FileSR.FileVDI): def attach(self, sr_uuid, vdi_uuid): if not hasattr(self, 'xenstore_data'): self.xenstore_data = {} self.xenstore_data["storage-type"] = "ext" return super(EXTFileVDI, self).attach(sr_uuid, vdi_uuid) if __name__ == '__main__': SRCommand.run(EXTSR, DRIVER_INFO) else: SR.registerSR(EXTSR)
return super(udevVDI, self).get_params() def update(self, sr_uuid, vdi_location): self.load(vdi_location) # _db_update requires self.uuid to be set self.uuid = self.sr.srcmd.params['vdi_uuid'] self._db_update() # also reset the name-label and description since we're a bit of # a special SR # this would lead to an infinite loop as VDI.set_name_label now # calls VDI.update # temporarily commenting this to pass quicktest #vdi = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid) #self.sr.session.xenapi.VDI.set_name_label(vdi, self.label) #self.sr.session.xenapi.VDI.set_name_description(vdi, self.description) def attach(self, sr_uuid, vdi_uuid): if self.deleted: raise xs_errors.XenError('VDIUnavailable') return super(udevVDI, self).attach(sr_uuid, vdi_uuid) def detach(self, sr_uuid, vdi_uuid): pass if __name__ == '__main__': SRCommand.run(udevSR, DRIVER_INFO) else: SR.registerSR(udevSR)
s = util.get_secret(self.session, dict['device_config']['chappassword_secret']) del dict['device_config']['chappassword_secret'] dict['device_config']['chappassword'] = s dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['allocation'] = self.sr.sm_config['allocation'] dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config, ), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("LVHDoISCSIVDI.attach_from_config") try: self.sr.iscsi.attach(sr_uuid) if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid): raise xs_errors.XenError('InvalidDev') return LVHDSR.LVHDVDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("LVHDoISCSIVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') if __name__ == '__main__': SRCommand.run(LVHDoISCSISR, DRIVER_INFO) else: SR.registerSR(LVHDoISCSISR)
handles = staticmethod(handles) def load(self, sr_uuid): driver = SR.driver('iscsi') self.iscsi = driver(self.original_srcmd, sr_uuid) # User must specify a LUN ID(s) for adding to the VG if not self.dconf.has_key('LUNid') or not self.dconf['LUNid']: raise xs_errors.XenError('ConfigLUNIDMissing') self.dconf['device'] = os.path.join(self.iscsi.path,"LUN%s" % \ self.dconf['LUNid']) if not self.iscsi.attached: # Must attach SR here in order to load VG self.iscsi.attach(sr_uuid) super(EXToISCSISR, self).load(sr_uuid) def delete(self, sr_uuid): super(EXToISCSISR, self).delete(sr_uuid) self.iscsi.detach(sr_uuid) def detach(self, sr_uuid): super(EXToISCSISR, self).detach(sr_uuid) self.iscsi.detach(sr_uuid) if __name__ == '__main__': SRCommand.run(EXToISCSISR) else: SR.registerSR(EXToISCSISR)
if 'type' not in self.original_srcmd.params['device_config'] or \ 'type' in self.original_srcmd.params['device_config'] and \ self.original_srcmd.dconf['type'] == "any": self.original_srcmd.dconf['type'] = "fcoe" self.hbasr = driver(self.original_srcmd, sr_uuid) pbd = None try: pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref) except: pass if not self.dconf.has_key('SCSIid') or not self.dconf['SCSIid']: print >>sys.stderr, self.hbasr.print_devs() raise xs_errors.XenError('ConfigSCSIid') self.SCSIid = self.dconf['SCSIid'] self._pathrefresh(LVHDoFCoESR) LVHDSR.LVHDSR.load(self, sr_uuid) def vdi(self, uuid): return LVHDoFCoEVDI(self, uuid) class LVHDoFCoEVDI(LVHDoHBASR.LVHDoHBAVDI): pass if __name__ == '__main__': SRCommand.run(LVHDoFCoESR, DRIVER_INFO) else: SR.registerSR(LVHDoFCoESR)
if dict['device_config'].has_key('chappassword_secret'): s = util.get_secret(self.session, dict['device_config']['chappassword_secret']) del dict['device_config']['chappassword_secret'] dict['device_config']['chappassword'] = s dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['allocation'] = self.sr.sm_config['allocation'] dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("LVHDoISCSIVDI.attach_from_config") try: self.sr.iscsi.attach(sr_uuid) if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid): raise xs_errors.XenError('InvalidDev') return LVHDSR.LVHDVDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("LVHDoISCSIVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') if __name__ == '__main__': SRCommand.run(LVHDoISCSISR, DRIVER_INFO) else: SR.registerSR(LVHDoISCSISR)
if dict['device_config'].has_key('chappassword_secret'): s = util.get_secret(self.session, dict['device_config']['chappassword_secret']) del dict['device_config']['chappassword_secret'] dict['device_config']['chappassword'] = s dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config, ), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("OCFSoISCSIVDI.attach_from_config") try: self.sr.iscsi.attach(sr_uuid) if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid): raise xs_errors.XenError('InvalidDev') return OCFSSR.OCFSFileVDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("OCFSoISCSIVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') if __name__ == '__main__': SRCommand.run(OCFSoISCSISR, DRIVER_INFO) else: SR.registerSR(OCFSoISCSISR)
self.sr.update(sr_uuid) return super(udevVDI, self).get_params() def update(self, sr_uuid, vdi_location): self.load(vdi_location) # _db_update requires self.uuid to be set self.uuid = self.sr.srcmd.params['vdi_uuid'] self._db_update() # also reset the name-label and description since we're a bit of # a special SR # this would lead to an infinite loop as VDI.set_name_label now # calls VDI.update # temporarily commenting this to pass quicktest #vdi = self.sr.session.xenapi.VDI.get_by_uuid(self.uuid) #self.sr.session.xenapi.VDI.set_name_label(vdi, self.label) #self.sr.session.xenapi.VDI.set_name_description(vdi, self.description) def attach(self, sr_uuid, vdi_uuid): if self.deleted: raise xs_errors.XenError('VDIUnavailable') return super(udevVDI, self).attach(sr_uuid, vdi_uuid) def detach(self, sr_uuid, vdi_uuid): pass if __name__ == '__main__': SRCommand.run(udevSR, DRIVER_INFO) else: SR.registerSR(udevSR)
diskinfo = {} cmd = [SR.TAPDISK_UTIL, "query", vhdutil.VDI_TYPE_VHD, "-vpf", path] txt = util.pread(cmd).split('\n') diskinfo['size'] = txt[0] lst = [txt[1].split('/')[-1].replace(vhdutil.FILE_EXTN_VHD, "")] for val in filter(util.exactmatch_uuid, lst): diskinfo['parent'] = val diskinfo['hidden'] = txt[2].split()[1] return diskinfo def _create(self, size, path): cmd = [SR.TAPDISK_UTIL, "create", vhdutil.VDI_TYPE_VHD, size, path] text = util.pread(cmd) def _mark_hidden(self, path): vhdutil.setHidden(path, True) self.hidden = 1 def extractUuid(path): fileName = os.path.basename(path) uuid = fileName.replace(vhdutil.FILE_EXTN_VHD, "") return uuid extractUuid = staticmethod(extractUuid) if __name__ == '__main__': SRCommand.run(FileSR, DRIVER_INFO) else: SR.registerSR(FileSR)
util.SMlog("NFSFileVDI.generate_config") if not util.pathexists(self.path): raise xs_errors.XenError('VDIUnavailable') resp = {} resp['device_config'] = self.sr.dconf resp['sr_uuid'] = sr_uuid resp['vdi_uuid'] = vdi_uuid resp['sr_sm_config'] = self.sr.sm_config resp['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) def attach_from_config(self, sr_uuid, vdi_uuid): """Used for HA State-file only. Will not just attach the VDI but also start a tapdisk on the file""" util.SMlog("NFSFileVDI.attach_from_config") try: self.sr.attach(sr_uuid) except: util.logException("NFSFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach from config') if __name__ == '__main__': SRCommand.run(NFSSR, DRIVER_INFO) else: SR.registerSR(NFSSR)
count += 1 return count def _getLUNbySMconfig(self, sm_config): raise xs_errors.XenError('VDIUnavailable') def vdi(self, uuid): return LUNperVDI.RAWVDI(self, uuid) def srlist_toxml(self, SRs): dom = xml.dom.minidom.Document() element = dom.createElement("SRlist") dom.appendChild(element) for val in SRs: record = SRs[val] entry = dom.createElement('SR') element.appendChild(entry) subentry = dom.createElement("UUID") entry.appendChild(subentry) textnode = dom.createTextNode(val) subentry.appendChild(textnode) return dom.toprettyxml() if __name__ == '__main__': SRCommand.run(HBASR, DRIVER_INFO) else: SR.registerSR(HBASR)
driver = SR.driver('hba') if 'type' not in self.original_srcmd.params['device_config'] or \ 'type' in self.original_srcmd.params['device_config'] and \ self.original_srcmd.dconf['type'] == "any": self.original_srcmd.dconf['type'] = "fcoe" self.hbasr = driver(self.original_srcmd, sr_uuid) pbd = None try: pbd = util.find_my_pbd(self.session, self.host_ref, self.sr_ref) except: pass if 'SCSIid' not in self.dconf or not self.dconf['SCSIid']: print(self.hbasr.print_devs(), file=sys.stderr) raise xs_errors.XenError('ConfigSCSIid') self.SCSIid = self.dconf['SCSIid'] LVHDSR.LVHDSR.load(self, sr_uuid) def vdi(self, uuid): return LVHDoFCoEVDI(self, uuid) class LVHDoFCoEVDI(LVHDoHBASR.LVHDoHBAVDI): pass if __name__ == '__main__': SRCommand.run(LVHDoFCoESR, DRIVER_INFO) else: SR.registerSR(LVHDoFCoESR)
resp['device_config'] = self.sr.dconf resp['sr_uuid'] = sr_uuid resp['vdi_uuid'] = vdi_uuid resp['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) def attach_from_config(self, sr_uuid, vdi_uuid): """ Attach and activate a VDI using config generated by vdi_generate_config above. This is used for cases such as the HA state-file and the redo-log. """ util.SMlog("FileVDI.attach_from_config") try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("FileVDI.attach_from_config") raise xs_errors.XenError( 'SRUnavailable', opterr='Unable to attach from config' ) if __name__ == '__main__': SRCommand.run(FileSR, DRIVER_INFO) else: SR.registerSR(FileSR)
dict['device_config'] = self.sr.dconf if dict['device_config'].has_key('chappassword_secret'): s = util.get_secret(self.session, dict['device_config']['chappassword_secret']) del dict['device_config']['chappassword_secret'] dict['device_config']['chappassword'] = s dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config,), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("OCFSoISCSIVDI.attach_from_config") try: self.sr.iscsi.attach(sr_uuid) if not self.sr.iscsi._attach_LUN_bySCSIid(self.sr.SCSIid): raise xs_errors.XenError('InvalidDev') return OCFSSR.OCFSFileVDI.attach(self, sr_uuid, vdi_uuid) except: util.logException("OCFSoISCSIVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') if __name__ == '__main__': SRCommand.run(OCFSoISCSISR, DRIVER_INFO) else: SR.registerSR(OCFSoISCSISR)
raise xs_errors.XenError("VDICreate") # XXX we ignore given vdi_uuid. is this ok? self.sr._get_lvols() try: vdi = self.sr._find_vdi_by_lvolid(lvolid) except: # XXX a bug or race with other clients raise vdi._db_introduce() return vdi.get_params() # called by SRCommand def delete(self, sr_uuid, vdi_uuid): log("VASVDI.delete %s" % vdi_uuid) assert vdi_uuid == self.uuid lvolid = int(self.location) try: vas_delete_lvol(lvolid) except xmlrpclib.Fault, inst: # ignore ENOENT as vdi.delete is an idempotent operation. if inst.faultCode != ENOENT: raise # update xapi's db # XXX i guess there's a smarter way... self.sr.scan(sr_uuid) if __name__ == '__main__': log("VASSR run %s" % sys.argv) SRCommand.run(VASSR, DRIVER_INFO)
raise xs_errors.XenError('VDIUnavailable') resp = {} resp['device_config'] = self.sr.dconf resp['sr_uuid'] = sr_uuid resp['vdi_uuid'] = vdi_uuid resp['sr_sm_config'] = self.sr.sm_config resp['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) def attach_from_config(self, sr_uuid, vdi_uuid): """Used for HA State-file only. Will not just attach the VDI but also start a tapdisk on the file""" util.SMlog("SMBFileVDI.attach_from_config") try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("SMBFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach from config') if __name__ == '__main__': SRCommand.run(SMBSR, DRIVER_INFO) else: SR.registerSR(SMBSR) #
raise xs_errors.XenError('VDIUnavailable') resp = {} resp['device_config'] = self.sr.dconf resp['sr_uuid'] = sr_uuid resp['vdi_uuid'] = vdi_uuid resp['sr_sm_config'] = self.sr.sm_config resp['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) def attach_from_config(self, sr_uuid, vdi_uuid): """Used for HA State-file only. Will not just attach the VDI but also start a tapdisk on the file""" util.SMlog("SMBFileVDI.attach_from_config") try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("SMBFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach from config') if __name__ == '__main__': SRCommand.run(SMBSR, DRIVER_INFO) else: SR.registerSR(SMBSR) #
self.physical_size += obj.size count += 1 return count def _getLUNbySMconfig(self, sm_config): raise xs_errors.XenError('VDIUnavailable') def vdi(self, uuid): return LUNperVDI.RAWVDI(self, uuid) def srlist_toxml(self, SRs): dom = xml.dom.minidom.Document() element = dom.createElement("SRlist") dom.appendChild(element) for val in SRs: record = SRs[val] entry = dom.createElement('SR') element.appendChild(entry) subentry = dom.createElement("UUID") entry.appendChild(subentry) textnode = dom.createTextNode(val) subentry.appendChild(textnode) return dom.toprettyxml() if __name__ == '__main__': SRCommand.run(HBASR, DRIVER_INFO) else: SR.registerSR(HBASR)
try: util.pread2(["mkfs.ext3", "-F", self.remotepath]) except util.CommandException, inst: raise xs_errors.XenError('LVMFilesystem', \ opterr='mkfs failed error %d' % inst.code) #Update serial number string scsiutil.add_serial_record(self.session, self.sr_ref, \ scsiutil.devlist_to_serialstring(self.root.split(','))) def vdi(self, uuid, loadLocked = False): if not loadLocked: return EXTFileVDI(self, uuid) return EXTFileVDI(self, uuid) class EXTFileVDI(FileSR.FileVDI): def attach(self, sr_uuid, vdi_uuid): if not hasattr(self,'xenstore_data'): self.xenstore_data = {} self.xenstore_data["storage-type"]="ext" return super(EXTFileVDI, self).attach(sr_uuid, vdi_uuid) if __name__ == '__main__': SRCommand.run(EXTSR, DRIVER_INFO) else: SR.registerSR(EXTSR)
# XXX we ignore given vdi_uuid. is this ok? self.sr._get_lvols() try: vdi = self.sr._find_vdi_by_lvolid(lvolid) except: # XXX a bug or race with other clients raise vdi._db_introduce() return vdi.get_params() # called by SRCommand def delete(self, sr_uuid, vdi_uuid): log("VASVDI.delete %s" % vdi_uuid) assert vdi_uuid == self.uuid lvolid = int(self.location) try: vas_delete_lvol(lvolid) except xmlrpclib.Fault, inst: # ignore ENOENT as vdi.delete is an idempotent operation. if inst.faultCode != ENOENT: raise # update xapi's db # XXX i guess there's a smarter way... self.sr.scan(sr_uuid) if __name__ == "__main__": log("VASSR run %s" % sys.argv) SRCommand.run(VASSR, DRIVER_INFO)
return super(ISOVDI, self).get_params() except Exception as exn: util.SMlog("Exception when creating VDI: %s" % exn) raise xs_errors.XenError('VDICreate', \ opterr='could not create file: "%s"' % self.path) def delete(self, sr_uuid, vdi_uuid): util.SMlog("Deleting...") self.uuid = vdi_uuid self._db_forget() if not util.pathexists(self.path): return try: util.SMlog("Unlinking...") os.unlink(self.path) util.SMlog("Done...") except: raise xs_errors.XenError('VDIDelete') # delete, update, introduce unimplemented. super class will raise # exceptions if __name__ == '__main__': SRCommand.run(ISOSR, DRIVER_INFO) else: SR.registerSR(ISOSR)
cephutils.VDI.update(self, sr_uuid, vdi_uuid) sm_config = self.session.xenapi.VDI.get_sm_config(self_vdi_ref) if sm_config.has_key('reverted'): if sm_config['reverted'] == 'true': del sm_config['reverted'] self.session.xenapi.VDI.set_sm_config(self_vdi_ref, sm_config) else: if has_snapshots == True: for snapshot_uuid in self.snaps.keys(): util.SMlog("RBDVDI.update start setting snapshots") snapshot_vdi_ref = self.session.xenapi.VDI.get_by_uuid(snapshot_uuid) self.session.xenapi.VDI.set_name_label(snapshot_vdi_ref, self.session.xenapi.VDI.get_name_label(self_vdi_ref)) self.session.xenapi.VDI.set_name_description(snapshot_vdi_ref, self.session.xenapi.VDI.get_name_description(self_vdi_ref)) util.SMlog("RBDVDI.update finish setting snapshots") else: self_vdi_sm_config = self.session.xenapi.VDI.get_sm_config(self_vdi_ref) base_vdi_uuid = self_vdi_sm_config["snapshot-of"] base_vdi_ref = self.session.xenapi.VDI.get_by_uuid(base_vdi_uuid) self.label=self.session.xenapi.VDI.get_name_label(base_vdi_ref) self.description=self.session.xenapi.VDI.get_name_description(base_vdi_ref) self.snaps = {} self.snaps[vdi_uuid]=self.session.xenapi.VDI.get_snapshot_time(self_vdi_ref) cephutils.VDI.update(self, sr_uuid, base_vdi_uuid) if __name__ == '__main__': SRCommand.run(RBDSR, DRIVER_INFO) else: SR.registerSR(RBDSR)
dict['sr_uuid'] = sr_uuid dict['vdi_uuid'] = vdi_uuid dict['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([dict]), "vdi_attach_from_config") return xmlrpclib.dumps((config, ), "", True) def attach_from_config(self, sr_uuid, vdi_uuid): util.SMlog("LVHDoHBAVDI.attach_from_config") self.sr.hbasr.attach(sr_uuid) if self.sr.mpath == "true": self.sr.mpathmodule.refresh(self.sr.SCSIid, 0) try: return self.attach(sr_uuid, vdi_uuid) except: util.logException("LVHDoHBAVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', \ opterr='Unable to attach the heartbeat disk') def match_scsidev(s): regex = re.compile("^/dev/disk/by-id|^/dev/mapper") return regex.search(s, 0) if __name__ == '__main__': SRCommand.run(LVHDoHBASR, DRIVER_INFO) else: SR.registerSR(LVHDoHBASR)
self.session.xenapi.VDI.remove_from_xenstore_data(vdi_ref, \ "storage-type") self.session.xenapi.VDI.add_to_xenstore_data(vdi_ref, \ "storage-type", "nfs") except: util.logException("NFSSR:attach") pass return super(NFSFileVDI, self).attach(sr_uuid, vdi_uuid) def clone(self, sr_uuid, vdi_uuid): timestamp_before = int(util.get_mtime(self.sr.path)) ret = super(NFSFileVDI, self).clone(sr_uuid, vdi_uuid) timestamp_after = int(util.get_mtime(self.sr.path)) if timestamp_after == timestamp_before: util.SMlog("SR dir timestamp didn't change, updating") timestamp_after += 1 os.utime(self.sr.path, (timestamp_after, timestamp_after)) return ret class NFSFileVDINolock(NFSFileVDI): def load(self, vdi_uuid): self.lock = self.sr.lock self._load(vdi_uuid) if __name__ == '__main__': SRCommand.run(NFSSR, DRIVER_INFO) else: SR.registerSR(NFSSR)
def generate_config(self, sr_uuid, vdi_uuid): util.SMlog("SMBFileVDI.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) def attach_from_config(self, sr_uuid, vdi_uuid): try: if not util.pathexists(self.sr.path): self.sr.attach(sr_uuid) except: util.logException("SMBFileVDI.attach_from_config") raise xs_errors.XenError('SRUnavailable', opterr='Unable to attach from config') if __name__ == '__main__': SRCommand.run(CephFSSR, DRIVER_INFO) else: SR.registerSR(CephFSSR)