Exemplo n.º 1
0
 def _getAllDomains(self, arch, channelName=None):
     for conf, rawXml in self._CONFS[arch]:
         if channelName is not None:
             conf = conf.copy()
             conf['agentChannelName'] = channelName
         domXml = rawXml % conf
         yield fake.Domain(domXml, vmId=conf['vmId']), domXml
Exemplo n.º 2
0
    def _verifyDeviceUpdate(self, device, allDevices, domXml, devXml):
        with fake.VM(devices=allDevices) as testvm:
            testvm._dom = fake.Domain(domXml)

            self._updateGraphicsDevice(testvm, device['device'])

            self.assertEquals(testvm._dom.devXml, devXml)
Exemplo n.º 3
0
 def listAllDomains(self):
     for conf, rawXml in self.CONFS[self.arch]:
         if self.channel_name is not None:
             conf = conf.copy()
             conf['agentChannelName'] = self.channel_name
         domXml = rawXml % conf
         yield fake.Domain(domXml, vmId=conf['vmId'])
Exemplo n.º 4
0
 def test_interface_update(self):
     devices = [{'nicModel': 'virtio', 'network': 'ovirtmgmt',
                 'macAddr': '52:54:00:59:F5:3F',
                 'device': 'bridge', 'type': 'interface',
                 'alias': 'net1', 'name': 'net1',
                 'linkActive': 'true',
                 'specParams': {'inbound': {'average': 1000, 'peak': 5000,
                                            'burst': 1024},
                                'outbound': {'average': 128, 'burst': 256}},
                 }]
     params = {'linkActive': 'true', 'alias': 'net1',
               'deviceType': 'interface', 'network': 'ovirtmgmt2',
               'specParams': {'inbound': {}, 'outbound': {}}}
     updated_xml = '''
         <interface type="bridge">
           <mac address="52:54:00:59:F5:3F"/>
           <model type="virtio"/>
           <source bridge="ovirtmgmt2"/>
           <virtualport type="openvswitch"/>
           <link state="up"/>
           <alias name="net1"/>
           <bandwidth/>
         </interface>
     '''
     with fake.VM(devices=devices, create_device_objects=True) as testvm:
         testvm._dom = fake.Domain()
         res = testvm.updateDevice(params)
         self.assertIn('vmList', res)
         self.assertXMLEqual(testvm._dom.devXml, updated_xml)
Exemplo n.º 5
0
    def testSetSaslPasswordInFips(self):
        graphics_params = dict(_GRAPHICS_DEVICE_PARAMS)
        del graphics_params['existingConnAction']
        device = self.GRAPHIC_DEVICES[1]  # VNC
        graphics_xml = ('<graphics type="%s" port="5900"/>' %
                        (device['device'], ))
        device_xml = '<devices>%s</devices>' '' % (graphics_xml, )

        with fake.VM(xmldevices=graphics_xml) as testvm:

            def _fake_set_vnc_pwd(username, pwd):
                testvm.pwd = pwd
                testvm.username = username

            testvm._dom = fake.Domain(device_xml)
            testvm.pwd = "invalid"
            params = {'graphicsType': device['device']}
            params.update(graphics_params)
            params['params']['fips'] = 'true'
            params['params']['vncUsername'] = '******'

            with MonkeyPatchScope([(saslpasswd2, 'set_vnc_password',
                                    _fake_set_vnc_pwd)]):
                testvm.updateDevice(params)

            self.assertEqual(password.unprotect(params['password']),
                             testvm.pwd)
            self.assertEqual(params['params']['vncUsername'], testvm.username)
Exemplo n.º 6
0
 def testReadPauseCodeDomainPausedCrash(self):
     with fake.VM() as testvm:
         # if paused for different reason we must not extend the disk
         # so anything else is ok
         dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED,
                           domReason=libvirt.VIR_DOMAIN_PAUSED_CRASHED)
         testvm._dom = dom
         self.assertNotEqual(testvm._readPauseCode(), 'ENOSPC')
Exemplo n.º 7
0
 def testReadPauseCodeDomainPausedEIO(self):
     with fake.VM() as testvm:
         dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED,
                           domReason=libvirt.VIR_DOMAIN_PAUSED_IOERROR)
         dom.setDiskErrors({'vda': libvirt.VIR_DOMAIN_DISK_ERROR_NONE,
                            'hdc': libvirt.VIR_DOMAIN_DISK_ERROR_UNSPEC})
         testvm._dom = dom
         self.assertEqual(testvm._readPauseCode(), 'EOTHER')
Exemplo n.º 8
0
 def _buildAllDomains(self, arch, channelName=None):
     for conf, _ in self._CONFS[arch]:
         if channelName is not None:
             conf = conf.copy()
             conf['agentChannelName'] = channelName
         with fake.VM(conf, arch=arch) as v:
             domXml = v._buildDomainXML()
             yield fake.Domain(domXml, vmId=v.id), domXml
Exemplo n.º 9
0
    def _verifyDeviceUpdate(self, device, allDevices, domXml, devXml,
                            graphics_params):
        with fake.VM(xmldevices=allDevices) as testvm:
            testvm._dom = fake.Domain(domXml)

            self._updateGraphicsDevice(testvm, device['device'],
                                       graphics_params)

            self.assertXMLEqual(testvm._dom.devXml, devXml)
Exemplo n.º 10
0
    def testIgnoreKnownErrors(self, code, text):
        def _fail(*args):
            raise_libvirt_error(code, text)

        with fake.VM() as testvm:
            dom = fake.Domain()
            dom.controlInfo = _fail
            testvm._dom = dom
            self.assertFalse(testvm.isDomainReadyForCommands())
Exemplo n.º 11
0
    def testDomainDisappearedNotReadyForCommands(self):
        def _fail(*args):
            raise_libvirt_error(libvirt.VIR_ERR_NO_DOMAIN,
                                "Disappeared domain")

        with fake.VM() as testvm:
            dom = fake.Domain()
            dom.controlInfo = _fail
            testvm._dom = dom
            self.assertFalse(testvm.isDomainReadyForCommands())
Exemplo n.º 12
0
 def setUp(self):
     devices = [{'nicModel': 'virtio', 'network': 'ovirtmgmt',
                 'macAddr': "11:22:33:44:55:66",
                 'device': 'bridge', 'type': 'interface',
                 'alias': 'net1', 'name': 'net1',
                 'linkActive': 'true',
                 }]
     with fake.VM(devices=devices, create_device_objects=True) as vm:
         vm._dom = fake.Domain(vm=vm)
         self.vm = vm
     self.supervdsm = fake.SuperVdsm()
Exemplo n.º 13
0
def _make_domains_collection(vm_uuids):
    return {
        vm_uuid: fake.Domain(
            vmId=vm_uuid,
            xml=_make_domain_xml(
                vm_uuid,
                external=external
            ),
        )
        for vm_uuid, external in vm_uuids
    }
Exemplo n.º 14
0
    def testReadPauseCodeDomainPausedCrash(self):
        # REQUIRED_FOR: el6
        if not hasattr(libvirt, 'VIR_DOMAIN_PAUSED_CRASHED'):
            raise SkipTest('libvirt.VIR_DOMAIN_PAUSED_CRASHED undefined')

        with fake.VM() as testvm:
            # if paused for different reason we must not extend the disk
            # so anything else is ok
            dom = fake.Domain(domState=libvirt.VIR_DOMAIN_PAUSED,
                              domReason=libvirt.VIR_DOMAIN_PAUSED_CRASHED)
            testvm._dom = dom
            self.assertNotEqual(testvm._readPauseCode(), 'ENOSPC')
Exemplo n.º 15
0
    def testReadyForCommandsRaisesLibvirtError(self):
        def _fail(*args):
            # anything != NO_DOMAIN is good
            raise_libvirt_error(libvirt.VIR_ERR_INTERNAL_ERROR,
                                "Fake internal error")

        with fake.VM() as testvm:
            dom = fake.Domain()
            dom.controlInfo = _fail
            testvm._dom = dom
            self.assertRaises(libvirt.libvirtError,
                              testvm.isDomainReadyForCommands)
Exemplo n.º 16
0
def _update_downtime_repeatedly(downtime, steps):
    dom = fake.Domain()

    with fake.VM({'memSize': 1024}) as testvm:
        testvm._dom = dom

        cfg = make_config([('vars', 'migration_downtime_delay', '0')])
        with MonkeyPatchScope([(migration, 'config', cfg)]):
            dt = migration.DowntimeThread(testvm, downtime, steps)
            dt.start()
            dt.join()

            return dom.getDowntimes()
Exemplo n.º 17
0
    def test_get_mapping_vcpu_to_pcpu(self):
        # stolen from real libvirt
        vcpu_output = ([(0, 1, 20050000000, 0),
                        (1, 1, 11300000000, 1)], [(True, True, True, True),
                                                  (True, True, True, True)])
        mapping = {0: 0, 1: 1}

        with fake.VM() as testvm:
            testvm._dom = fake.Domain()
            testvm._dom.vcpus = lambda: vcpu_output

            self.assertEqual(
                numa._get_mapping_vcpu_to_pcpu(
                    numa._get_vcpu_positioning(testvm)), mapping)
Exemplo n.º 18
0
    def testSetNumberOfVcpusFailed(self, virt_error, vdsm_error,
                                   error_message):
        def _fail(*args):
            raise_libvirt_error(virt_error, error_message)

        with MonkeyPatchScope([(hooks, 'before_set_num_of_cpus', lambda: None)
                               ]):
            with fake.VM() as testvm:
                dom = fake.Domain()
                dom.setVcpusFlags = _fail
                testvm._dom = dom

                res = testvm.setNumberOfCpus(4)  # random value

                self.assertEqual(res, response.error(vdsm_error))
Exemplo n.º 19
0
 def setUp(self):
     devices = '''
         <interface type="bridge">
           <mac address="11:22:33:44:55:66"/>
           <model type="virtio"/>
           <source bridge="ovirtmgmt"/>
           <virtualport type="openvswitch"/>
           <link state="down"/>
           <alias name="net1"/>
           <target dev="net1"/>
         </interface>
     '''
     with fake.VM(xmldevices=devices, create_device_objects=True) as vm:
         vm._dom = fake.Domain(vm=vm)
         self.vm = vm
     self.supervdsm = fake.SuperVdsm()
Exemplo n.º 20
0
 def test_interface_update(self):
     devices = '''
         <interface type="bridge">
           <mac address="52:54:00:59:F5:3F"/>
           <model type="virtio"/>
           <source bridge="ovirtmgmt"/>
           <virtualport type="openvswitch"/>
           <link state="up"/>
           <alias name="ua-net1"/>
           <target dev="net1"/>
           <bandwidth>
              <inbound average="1000" peak="5000" burst="1024"/>
              <inbound average="128" burst="256"/>
           </bandwidth>
         </interface>
     '''
     params = {
         'linkActive': 'true',
         'alias': 'ua-net1',
         'name': 'net1',
         'deviceType': 'interface',
         'network': 'ovirtmgmt2',
         'specParams': {
             'inbound': {},
             'outbound': {}
         }
     }
     updated_xml = '''
         <interface type="bridge">
           <mac address="52:54:00:59:F5:3F"/>
           <model type="virtio"/>
           <source bridge="ovirtmgmt2"/>
           <virtualport type="openvswitch"/>
           <link state="up"/>
           <alias name="ua-net1"/>
           <bandwidth/>
         </interface>
     '''
     with fake.VM(xmldevices=devices, create_device_objects=True) as testvm:
         testvm._dom = fake.Domain()
         res = testvm.updateDevice(params)
         self.assertIn('vmList', res)
         self.assertXMLEqual(testvm._dom.devXml, updated_xml)
Exemplo n.º 21
0
    def testUpdateDeviceGraphicsFailed(self):
        with fake.VM(devices=self.GRAPHIC_DEVICES) as testvm:
            message = 'fake timeout while setting ticket'
            device = 'spice'
            domXml = '''
                <devices>
                    <graphics type="%s" port="5900" />
                </devices>''' % device

            def _fail(*args):
                raise virdomain.TimeoutError(defmsg=message)

            domain = fake.Domain(domXml)
            domain.updateDeviceFlags = _fail
            testvm._dom = domain

            res = self._updateGraphicsDevice(testvm, device)

            self.assertEqual(res, response.error('ticketErr', message))
Exemplo n.º 22
0
    def testUpdateDeviceGraphicsFailed(self):
        with fake.VM(devices=self.GRAPHIC_DEVICES) as testvm:
            message = 'fake timeout while setting ticket'
            device = 'spice'
            domXml = '''
                <devices>
                    <graphics type="%s" port="5900" />
                </devices>''' % device

            def _fail(*args):
                raise virdomain.TimeoutError(defmsg=message)

            domain = fake.Domain(domXml)
            domain.updateDeviceFlags = _fail
            testvm._dom = domain

            self.assertRaises(exception.SpiceTicketError,
                              self._updateGraphicsDevice, testvm, device,
                              _GRAPHICS_DEVICE_PARAMS)
Exemplo n.º 23
0
    def test_memory_info_committed(self):
        vm_uuid = str(uuid.uuid4())
        memory_mb = 128
        minimal_xml = u"""<?xml version="1.0" encoding="utf-8"?>
<domain type="kvm" xmlns:ovirt="http://ovirt.org/vm/tune/1.0">
  <name>testVm</name>
  <uuid>{vm_uuid}</uuid>
  <memory unit='KiB'>{vm_memory}</memory>
  <maxMemory unit='KiB'>{vm_memory}</maxMemory>
</domain>""".format(vm_uuid=vm_uuid, vm_memory=memory_mb * define.Kbytes)
        vm_params = {
            'vmId': vm_uuid,
            'memSize': memory_mb,
            'xml': minimal_xml,
        }

        with fake.VM(params=vm_params) as testvm:
            testvm._dom = fake.Domain(xml=minimal_xml, vmId=vm_uuid)

            mem_info = testvm.memory_info()
            self.assertEqual(_mem_committed(memory_mb),
                             mem_info['commit'] * define.Kbytes)
Exemplo n.º 24
0
    def testClearSaslPasswordNoFips(self):
        graphics_params = dict(_GRAPHICS_DEVICE_PARAMS)
        del graphics_params['existingConnAction']
        device = self.GRAPHIC_DEVICES[1]  # VNC
        domXml = '''
            <devices>
                <graphics type="%s" port="5900" />
            </devices>''' % device['device']

        with fake.VM(devices=domXml) as testvm:
            def _fake_remove_pwd(username):
                testvm.username = username

            testvm._dom = fake.Domain(domXml)
            params = {'graphicsType': device['device']}
            params.update(graphics_params)
            params['params']['vncUsername'] = '******'

            with MonkeyPatchScope([(saslpasswd2, 'remove_vnc_password',
                                    _fake_remove_pwd)]):
                testvm.updateDevice(params)

            self.assertEqual(params['params']['vncUsername'], testvm.username)
Exemplo n.º 25
0
 def _build_domain_xml(self, arch):
     for conf, rawXml in self._CONFS[arch]:
         domXml = rawXml % conf
         yield fake.Domain(domXml, vmId=conf['vmId']), domXml
Exemplo n.º 26
0
 def _getAllDomains(self, arch):
     for conf, rawXml in self._CONFS[arch]:
         domXml = rawXml % conf
         yield fake.Domain(domXml, vmId=conf['vmId']), domXml
Exemplo n.º 27
0
 def testAcpiRebootConnected(self):
     with fake.VM() as testvm:
         testvm._dom = fake.Domain(vmId='testvm')
         self.assertFalse(response.is_error(testvm.acpiReboot()))
Exemplo n.º 28
0
 def testReadPauseCodeDomainRunning(self):
     with fake.VM() as testvm:
         testvm._dom = fake.Domain(domState=libvirt.VIR_DOMAIN_RUNNING)
         self.assertEqual(testvm._readPauseCode(), 'NOERR')
Exemplo n.º 29
0
 def _buildAllDomains(self, arch):
     for conf, _ in self._CONFS[arch]:
         with fake.VM(conf, arch=arch) as v:
             domXml = v._buildDomainXML()
             yield fake.Domain(domXml, vmId=v.id), domXml
Exemplo n.º 30
0
 def testDomainIsReadyForCommands(self):
     with fake.VM() as testvm:
         testvm._dom = fake.Domain()
         self.assertTrue(testvm.isDomainReadyForCommands())