示例#1
0
def FakeVirshFactory(preserve=None):
    """
    Return Virsh() instance with methods to raise bogusVirshFailureException.

    Users of this class should override methods under test on instance.
    :param preserve: List of symbol names NOT to modify, None for all
    """
    import virsh

    def raise_bogusVirshFailureException(*args, **dargs):
        raise bogusVirshFailureException()

    if preserve is None:
        preserve = []
    fake_virsh = virsh.Virsh(virsh_exec='/bin/false',
                             uri='qemu:///system',
                             debug=True,
                             ignore_status=True)
    # Make all virsh commands throw an exception by calling it
    for symbol in dir(virsh):
        # Get names of just closure functions by Virsh class
        if symbol in virsh.NOCLOSE + preserve:
            continue
        if isinstance(getattr(fake_virsh, symbol), virsh.VirshClosure):
            xcpt = lambda *args, **dargs: raise_bogusVirshFailureException()
            # fake_virsh is a propcan, can't use setattr.
            fake_virsh.__super_set__(symbol, xcpt)
    return fake_virsh
 def setUp(self):
     # To avoid not installed libvirt packages
     virsh_instance = virsh.Virsh(virsh_exec=virsh.VIRSH_EXEC,
                                  uri='qemu:///system',
                                  debug=True,
                                  ignore_status=True)
     self.sp = libvirt_storage.StoragePool(virsh_instance)
示例#3
0
 def __setstate__(self, state):
     """Actualize instance from state"""
     # virsh is it's own dict of init params
     self.virsh = virsh.Virsh(**state['virsh'])
     # already used it's own get/sets state methods when unpickling state
     self.command = state['command']
     # Recreate SpecificServiceManager from the init args
     self._run = state['run']
     self.service = SpecificServiceManager(self.service_name, run=self._run)
     self._bind_service_commands()
示例#4
0
文件: infra.py 项目: farhany/klapi
def provider(sets):
    infr = sets.get('infra', None)
    if infr is None:
        return None

    if infr == 'libvirt' or infr == 'virsh':
        conn = sets.get('infra_connection', None)
        storage_name = sets.get('volume_storage_name', None)
        storage_loc = sets.get('volume_storage', None)
        return virsh.Virsh(conn)

    return None
示例#5
0
文件: lvsbs.py 项目: LeiCui/virt-test
 def __init__(self, params, service_name, uri='lxc:///'):
     """Initialize connection to sandbox service with name and parameters"""
     # Intended workflow is:
     #   Use virt-sandbox-service for create/destroy
     #   Use service/systemd for runtime management
     #   Use virsh for list/edit/modify manipulation
     self.virsh = virsh.Virsh(uri=uri, ignore_status=True)
     self.command = lvsb_base.SandboxCommandBase(params, service_name)
     self.command.BINARY_PATH_PARAM = 'virt_sandbox_service_binary'
     self.command.add_optarg('--connect', uri)
     # SpecificServiceManager is not pickleable, save init args
     self._run = utils.run
     self.service = SpecificServiceManager(self.service_name, run=self._run)
     # make self.start() --> self.service.start()
     self._bind_service_commands()
 def setUp(self):
     # Make all virsh commands fail the test unconditionally
     for symbol in dir(virsh):
         if symbol not in virsh.NOCLOSE:
             # Exceptions are callable
             setattr(virsh, symbol, self.bogusVirshFailureException)
     # To avoid not installed libvirt packages
     self.bogus_virsh = virsh.Virsh(virsh_exec='/bin/false',
                                    uri='qemu:///system',
                                    debug=True,
                                    ignore_status=True)
     # Use defined virsh methods above
     self.bogus_virsh.__super_set__('pool_list', self._pool_list)
     self.bogus_virsh.__super_set__('pool_info', self._pool_info)
     self.bogus_virsh.__super_set__('pool_define_as', self._pool_define_as)
     self.bogus_virsh.__super_set__('pool_build', self._pool_build)
     self.bogus_virsh.__super_set__('pool_start', self._pool_start)
     self.bogus_virsh.__super_set__('pool_destroy', self._pool_destroy)
     self.bogus_virsh.__super_set__('pool_undefine', self._pool_undefine)
     self.bogus_virsh.__super_set__('pool_autostart', self._pool_autostart)
     self.sp = libvirt_storage.StoragePool(virsh_instance=self.bogus_virsh)
示例#7
0
 def setUp(self):
     # Make all virsh commands fail the test unconditionally
     for symbol in dir(virsh):
         # Preserve original net_state_dict command.
         preserved_cmds = ['net_state_dict']
         if symbol not in virsh.NOCLOSE + preserved_cmds:
             # Exceptions are callable
             setattr(virsh, symbol, self.bogusVirshFailureException)
     # Redirect net_list called from net_state_dict to fake _net_list
     setattr(virsh, 'net_list', self._net_list)
     # Use defined virsh methods above
     self.bogus_virsh = virsh.Virsh(virsh_exec='/bin/false',
                                    uri='qemu:///system',
                                    debug=True,
                                    ignore_status=True)
     self.bogus_virsh.__super_set__('net_list', self._net_list)
     self.bogus_virsh.__super_set__('net_define', self._net_define)
     self.bogus_virsh.__super_set__('net_undefine', self._net_undefine)
     self.bogus_virsh.__super_set__('net_start', self._net_start)
     self.bogus_virsh.__super_set__('net_destroy', self._net_destroy)
     self.bogus_virsh.__super_set__('net_autostart', self._net_autostart)
示例#8
0
 def setUp(self):
     # cause all virsh commands to do nothing and return nothing
     # necessary so virsh module doesn't complain about missing virsh command
     self.dummy_virsh = virsh.Virsh(virsh_exec='/bin/true')