当前位置: 首页>>代码示例>>Python>>正文


Python SRCommand.run方法代码示例

本文整理汇总了Python中SRCommand.run方法的典型用法代码示例。如果您正苦于以下问题:Python SRCommand.run方法的具体用法?Python SRCommand.run怎么用?Python SRCommand.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SRCommand的用法示例。


在下文中一共展示了SRCommand.run方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_run_wrapped_if_not_SRException

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
    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)
开发者ID:chandrikas,项目名称:sm,代码行数:18,代码来源:test_SRCommand.py

示例2: test_run_reraise_if_not_SRException

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
    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))
开发者ID:BobBall,项目名称:sm,代码行数:20,代码来源:test_SRCommand.py

示例3: test_run_print_xml_error_if_SRException

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
    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)
开发者ID:chandrikas,项目名称:sm,代码行数:46,代码来源:test_SRCommand.py

示例4: test_run_correctly_log_all_exceptions

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
    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)
开发者ID:BobBall,项目名称:sm,代码行数:43,代码来源:test_SRCommand.py

示例5: long

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
            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)
开发者ID:rdobson,项目名称:sm,代码行数:32,代码来源:SHMSR.py

示例6: attach_from_config

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:letsboogey,项目名称:sm,代码行数:32,代码来源:LVHDoHBASR.py

示例7: attach_from_config

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:Sisimon,项目名称:sm,代码行数:32,代码来源:OCFSoHBASR.py

示例8: attach_from_config

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:falaa,项目名称:sm,代码行数:32,代码来源:FileSR.py

示例9: _getLUNbySMconfig

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
            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)
开发者ID:redivy,项目名称:xe-storage-plugins,代码行数:32,代码来源:HBASR.py

示例10: super

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:ESDS,项目名称:sm,代码行数:32,代码来源:udevSR.py

示例11: vdi

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:chandrikas,项目名称:sm,代码行数:32,代码来源:EXTSR.py

示例12: attach_from_config

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
                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)
#
开发者ID:malcolmcrossley,项目名称:sm,代码行数:32,代码来源:SMBSR.py

示例13: staticmethod

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
        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)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:32,代码来源:EXToISCSISR.py

示例14: snapshot

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
              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)
开发者ID:JohnGarbutt,项目名称:xcp-storage-managers,代码行数:32,代码来源:LVMSR.py

示例15: get_attached_vbds

# 需要导入模块: import SRCommand [as 别名]
# 或者: from SRCommand import run [as 别名]
    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)
开发者ID:chandrikas,项目名称:sm,代码行数:32,代码来源:DummySR.py


注:本文中的SRCommand.run方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。