示例#1
0
def VM(params=None,
       devices=None,
       runCpu=False,
       arch=caps.Architecture.X86_64,
       status=None,
       cif=None,
       create_device_objects=False):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir + '/'),
                               (libvirtconnection, 'get', Connection),
                               (vm.Vm, 'send_status_event',
                                lambda _, **kwargs: None)]):
            vmParams = {'vmId': 'TESTING'}
            vmParams.update({} if params is None else params)
            cif = ClientIF() if cif is None else cif
            fake = vm.Vm(cif, vmParams)
            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 = fake.devMapFromDevSpecMap(
                    fake.devSpecMapFromConf())
            fake._guestCpuRunning = runCpu
            if status is not None:
                fake._lastStatus = status
            sampling.stats_cache.add(fake.id)
            yield fake
示例#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):
    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
示例#3
0
文件: vmTests.py 项目: fzkbass/vdsm
def FakeVM(params=None, devices=None, runCpu=False):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir + '/'),
                               (libvirtconnection, 'get', ConnectionMock)]):
            vmParams = {'vmId': 'TESTING'}
            vmParams.update({} if params is None else params)
            fake = vm.Vm(None, vmParams)
            fake.guestAgent = FakeGuestAgent()
            fake.conf['devices'] = [] if devices is None else devices
            fake._guestCpuRunning = runCpu
            yield fake
示例#4
0
def VM(params=None, devices=None, runCpu=False,
       arch=caps.Architecture.X86_64, status=None):
    with namedTemporaryDir() as tmpDir:
        with MonkeyPatchScope([(constants, 'P_VDSM_RUN', tmpDir + '/'),
                               (libvirtconnection, 'get', Connection)]):
            vmParams = {'vmId': 'TESTING'}
            vmParams.update({} if params is None else params)
            cif = ClientIF()
            fake = vm.Vm(cif, vmParams)
            cif.vmContainer[fake.id] = fake
            fake.arch = arch
            fake.guestAgent = GuestAgent()
            fake.conf['devices'] = [] if devices is None else devices
            fake._guestCpuRunning = runCpu
            if status is not None:
                fake._lastStatus = status
            yield fake
示例#5
0
文件: vmTests.py 项目: fzkbass/vdsm
    def assertBuildCmdLine(self, confToDom):
        oldVdsmRun = constants.P_VDSM_RUN
        constants.P_VDSM_RUN = tempfile.mkdtemp()
        try:
            for conf, expectedXML in confToDom:

                expectedXML = expectedXML % conf

                testVm = vm.Vm(self, conf)

                output = testVm._buildCmdLine()

                self.assertEqual(re.sub('\n\s*', ' ', output.strip(' ')),
                                 re.sub('\n\s*', ' ', expectedXML.strip(' ')))
        finally:
            shutil.rmtree(constants.P_VDSM_RUN)
            constants.P_VDSM_RUN = oldVdsmRun