~ubuntu-branches/ubuntu/quantal/nova/quantal-proposed

« back to all changes in this revision

Viewing changes to nova/tests/fakelibvirt.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-08-16 14:04:11 UTC
  • mto: This revision was merged to the branch mainline in revision 84.
  • Revision ID: package-import@ubuntu.com-20120816140411-0mr4n241wmk30t9l
Tags: upstream-2012.2~f3
ImportĀ upstreamĀ versionĀ 2012.2~f3

Show diffs side-by-side

added added

removed removed

Lines of Context:
78
78
VIR_CRED_AUTHNAME = 2
79
79
VIR_CRED_NOECHOPROMPT = 7
80
80
 
 
81
VIR_MIGRATE_PEER2PEER = 2
 
82
VIR_MIGRATE_UNDEFINE_SOURCE = 16
 
83
 
81
84
# libvirtError enums
82
85
# (Intentionally different from what's in libvirt. We do this to check,
83
86
#  that consumers of the library are using the symbolic names rather than
85
88
VIR_FROM_QEMU = 100
86
89
VIR_FROM_DOMAIN = 200
87
90
VIR_FROM_NWFILTER = 330
 
91
VIR_FROM_REMOTE = 340
 
92
VIR_FROM_RPC = 345
88
93
VIR_ERR_XML_DETAIL = 350
89
94
VIR_ERR_NO_DOMAIN = 420
90
95
VIR_ERR_NO_NWFILTER = 620
 
96
VIR_ERR_SYSTEM_ERROR = 900
 
97
VIR_ERR_INTERNAL_ERROR = 950
91
98
 
92
99
 
93
100
def _parse_disk_info(element):
118
125
 
119
126
 
120
127
class libvirtError(Exception):
121
 
    def __init__(self, error_code, error_domain, msg):
 
128
    def __init__(self, msg,
 
129
                 error_code=VIR_ERR_INTERNAL_ERROR,
 
130
                 error_domain=VIR_FROM_QEMU):
122
131
        self.error_code = error_code
123
132
        self.error_domain = error_domain
124
133
        Exception(self, msg)
162
171
        try:
163
172
            tree = etree.fromstring(xml)
164
173
        except etree.ParseError:
165
 
            raise libvirtError(VIR_ERR_XML_DETAIL, VIR_FROM_DOMAIN,
166
 
                               "Invalid XML.")
 
174
            raise libvirtError("Invalid XML.",
 
175
                               VIR_ERR_XML_DETAIL, VIR_FROM_DOMAIN)
167
176
 
168
177
        definition = {}
169
178
 
302
311
                self._def['vcpu'],
303
312
                123456789L]
304
313
 
 
314
    def migrateToURI(self, desturi, flags, dname, bandwidth):
 
315
        raise libvirtError("Migration always fails for fake libvirt!")
 
316
 
305
317
    def attachDevice(self, xml):
306
318
        disk_info = _parse_disk_info(etree.fromstring(xml))
307
319
        disk_info['_attached'] = True
412
424
        self._snapshots[name] = snapshot
413
425
        return snapshot
414
426
 
 
427
    def vcpus(self):
 
428
        vcpus = ([], [])
 
429
        for i in range(0, self._def['vcpu']):
 
430
            vcpus[0].append((i, 1, 120405L, i))
 
431
            vcpus[1].append((True, True, True, True))
 
432
        return vcpus
 
433
 
 
434
    def memoryStats(self):
 
435
        return {}
 
436
 
 
437
    def maxMemory(self):
 
438
        return self._def['memory']
 
439
 
415
440
 
416
441
class DomainSnapshot(object):
417
442
    def __init__(self, name, domain):
424
449
 
425
450
class Connection(object):
426
451
    def __init__(self, uri, readonly):
427
 
        if not uri:
 
452
        if not uri or uri == '':
428
453
            if allow_default_uri_connection:
429
454
                uri = 'qemu:///session'
430
455
            else:
434
459
        uri_whitelist = ['qemu:///system',
435
460
                         'qemu:///session',
436
461
                         'xen:///system',
437
 
                         'uml:///system']
 
462
                         'uml:///system',
 
463
                         'test:///default']
438
464
 
439
465
        if uri not in uri_whitelist:
440
 
            raise libvirtError(5, 0,
441
 
                               "libvir: error : no connection driver "
442
 
                               "available for No connection for URI %s" % uri)
 
466
            raise libvirtError("libvir: error : no connection driver "
 
467
                               "available for No connection for URI %s" % uri,
 
468
                               5, 0)
443
469
 
444
470
        self.readonly = readonly
445
471
        self._uri = uri
489
515
    def lookupByID(self, id):
490
516
        if id in self._running_vms:
491
517
            return self._running_vms[id]
492
 
        raise libvirtError(VIR_ERR_NO_DOMAIN, VIR_FROM_QEMU,
493
 
                           'Domain not found: no domain with matching '
494
 
                           'id %d' % id)
 
518
        raise libvirtError('Domain not found: no domain with matching '
 
519
                           'id %d' % id,
 
520
                           VIR_ERR_NO_DOMAIN, VIR_FROM_QEMU)
495
521
 
496
522
    def lookupByName(self, name):
497
523
        if name in self._vms:
498
524
            return self._vms[name]
499
 
        raise libvirtError(VIR_ERR_NO_DOMAIN, VIR_FROM_QEMU,
500
 
                           'Domain not found: no domain with matching '
501
 
                           'name "%s"' % name)
 
525
        raise libvirtError('Domain not found: no domain with matching '
 
526
                           'name "%s"' % name,
 
527
                           VIR_ERR_NO_DOMAIN, VIR_FROM_QEMU)
502
528
 
503
529
    def defineXML(self, xml):
504
530
        dom = Domain(connection=self, running=False, transient=False, xml=xml)
778
804
        try:
779
805
            return self._nwfilters[name]
780
806
        except KeyError:
781
 
            raise libvirtError(VIR_ERR_NO_NWFILTER, VIR_FROM_NWFILTER,
782
 
                               "no nwfilter with matching name %s" % name)
 
807
            raise libvirtError("no nwfilter with matching name %s" % name,
 
808
                               VIR_ERR_NO_NWFILTER, VIR_FROM_NWFILTER)
783
809
 
784
810
    def nwfilterDefineXML(self, xml):
785
811
        nwfilter = NWFilter(self, xml)