Ejemplo n.º 1
0
def VM(params=None,
       devices=None,
       runCpu=False,
       arch=cpuarch.X86_64,
       status=None,
       cif=None,
       create_device_objects=False,
       post_copy=None,
       recover=False):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([
            (constants, 'P_VDSM_RUN', tmpDir),
            (libvirtconnection, 'get', Connection),
            (containersconnection, 'get', Connection),
            (vm.Vm, '_updateDomainDescriptor', _updateDomainDescriptor),
            (vm.Vm, 'send_status_event', lambda _, **kwargs: None)
        ]):
            vmParams = {'vmId': 'TESTING', 'vmName': 'nTESTING'}
            vmParams.update({} if params is None else params)
            cif = ClientIF() if cif is None else cif
            fake = vm.Vm(cif, vmParams, recover=recover)
            cif.vmContainer[fake.id] = fake
            fake.arch = arch
            fake.guestAgent = GuestAgent()
            fake.conf['devices'] = [] if devices is None else devices
            if create_device_objects:
                fake._devices = common.dev_map_from_dev_spec_map(
                    fake._devSpecMapFromConf(), fake.log)
            fake._guestCpuRunning = runCpu
            if status is not None:
                fake._lastStatus = status
            if post_copy is not None:
                fake._post_copy = post_copy
            sampling.stats_cache.add(fake.id)
            yield fake
Ejemplo n.º 2
0
def VM(params=None,
       devices=None,
       runCpu=False,
       arch=cpuarch.X86_64,
       status=None,
       cif=None,
       create_device_objects=False,
       post_copy=None,
       recover=False,
       vmid=None,
       resume_behavior=None,
       pause_code=None,
       pause_time_offset=None,
       features='',
       xmldevices='',
       metadata=''):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([
            (constants, 'P_VDSM_RUN', tmpDir),
            (libvirtconnection, 'get', Connection),
            (domain_descriptor.DomainDescriptor, '__init__',
             fake_domain_descriptor_init),
        ]):
            if params is None:
                params = {}
            if vmid is None:
                vmid = params.get('vmId', 'TESTING')
            if 'xml' not in params:
                params = params.copy()
                params['xml'] = default_domain_xml(vm_id=vmid,
                                                   features=features,
                                                   devices=xmldevices,
                                                   metadata=metadata)
            cif = ClientIF() if cif is None else cif
            fake = vm.Vm(cif, params, recover=recover)
            cif.vmContainer[fake.id] = fake
            fake._update_metadata = lambda: None
            fake.send_status_event = lambda **kwargs: None
            fake.arch = arch
            fake.guestAgent = GuestAgent()
            fake.conf['devices'] = [] if devices is None else devices
            if create_device_objects:
                fake._devices = fake._make_devices()
                fake._getUnderlyingVmDevicesInfo()
            fake._guestCpuRunning = runCpu
            if status is not None:
                fake._lastStatus = status
            if post_copy is not None:
                fake._post_copy = post_copy
            if resume_behavior is not None:
                fake._resume_behavior = resume_behavior
            fake._pause_code = pause_code
            if pause_time_offset is not None:
                fake._pause_time = (vdsm.common.time.monotonic_time() -
                                    pause_time_offset)
            sampling.stats_cache.add(fake.id)
            yield fake
Ejemplo n.º 3
0
def VM(params=None,
       devices=None,
       runCpu=False,
       arch=cpuarch.X86_64,
       status=None,
       cif=None,
       create_device_objects=False,
       post_copy=None,
       recover=False,
       vmid=None,
       resume_behavior=None,
       pause_time_offset=None):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([
            (constants, 'P_VDSM_RUN', tmpDir),
            (libvirtconnection, 'get', Connection),
            (containersconnection, 'get', Connection),
        ]):
            if params and 'xml' in params:
                vmParams = {}
            else:
                if vmid is None:
                    vmid = 'TESTING'
                vmParams = {'vmId': vmid, 'vmName': 'n%s' % vmid}
            vmParams.update({} if params is None else params)
            cif = ClientIF() if cif is None else cif
            fake = vm.Vm(cif, vmParams, recover=recover)
            cif.vmContainer[fake.id] = fake
            fake._update_metadata = lambda: None
            fake._sync_metadata = lambda: None
            fake.send_status_event = lambda **kwargs: None
            fake._waitForDeviceRemoval = lambda device: None
            fake.arch = arch
            fake.guestAgent = GuestAgent()
            fake.conf['devices'] = [] if devices is None else devices
            if create_device_objects:
                fake._devices = common.dev_map_from_dev_spec_map(
                    fake._devSpecMapFromConf(), fake.log)
            fake._guestCpuRunning = runCpu
            if status is not None:
                fake._lastStatus = status
            if post_copy is not None:
                fake._post_copy = post_copy
            if resume_behavior is not None:
                fake._resume_behavior = resume_behavior
            if pause_time_offset is not None:
                fake._pause_time = (vdsm.common.time.monotonic_time() -
                                    pause_time_offset)
            sampling.stats_cache.add(fake.id)

            def _updateDomainDescriptor():
                fake._domain = DomainDescriptor(fake._buildDomainXML())

            fake._updateDomainDescriptor = _updateDomainDescriptor

            yield fake
Ejemplo n.º 4
0
    def test_compat41(self):
        expected_conf = json.loads(read_data('vm_compat41.json'))[0]

        vm_params = recovery._recovery_params(expected_conf['vmId'],
                                              read_data('vm_compat41.xml'),
                                              False)

        vm_obj = vm.Vm(fake.ClientIF(), vm_params, recover=True)
        # TODO: ugly hack, but we don't have APIs to do that
        vm_obj._devices = vm_obj._make_devices()

        recovered_conf = vm_obj.status(fullStatus=True)

        self.assert_conf_equal(recovered_conf, expected_conf,
                               filter_vm_conf_keys)

        self.assert_devices_conf_equal(recovered_conf['devices'],
                                       expected_conf['devices'],
                                       IGNORED_DEVICE_TYPES)