~ubuntu-branches/ubuntu/precise/virtinst/precise-updates

« back to all changes in this revision

Viewing changes to tests/validation.py

  • Committer: Bazaar Package Importer
  • Author(s): Marc Deslauriers
  • Date: 2011-02-01 15:40:11 UTC
  • mfrom: (1.3.16 experimental)
  • Revision ID: james.westby@ubuntu.com-20110201154011-op0nusgc240xajvb
Tags: 0.500.5-1ubuntu1
* Merge from debian experimental. Remaining changes:
  - debian/patches/9001_Ubuntu.patch:
     + Updated to add maverick and natty to OS list and enable virtio
       for them.
  - debian/patches/9003-fix-path-to-hvmloader-in-testsuite.patch: adjust
    testsuite for 0001-fix-path-to-hvmloader.patch and
    0002-Fix-path-to-pygrub.patch. (refreshed)
  - debian/control: added acl package to depends.
  - Demote virt-viewer to Suggests, as it's in universe.
  - Recommends libvirt-bin
* Removed patches:
  - debian/patches/9002-libvirt_disk_format.patch: Upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
from virtinst import VirtualDisk
19
19
from virtinst import Interface
20
20
 
21
 
# Test helpers
22
 
import tests
 
21
import utils
23
22
 
24
23
import unittest
25
24
import logging
40
39
 
41
40
# We install several storage pools on the connection to ensure
42
41
# we aren't bumping up against errors in that department.
43
 
testconn = tests.open_testdriver()
 
42
testconn = utils.open_testdriver()
44
43
testcaps = virtinst.CapabilitiesParser.parse(testconn.getCapabilities())
45
44
 
46
45
virtimage = virtinst.ImageParser.parse_file("tests/image-xml/image.xml")
85
84
        'valid'   : [ 1, 32 ] },
86
85
    'graphics'  : {
87
86
        'invalid' : ['', True, 'unknown', {}, ('', '', '', 0),
88
 
                     ('','','', 'longerthan16chars'),
89
 
                     ('','','','invalid!!ch@r')],
 
87
                     ('', '', '', 'longerthan16chars'),
 
88
                     ('', '', '', 'invalid!!ch@r')],
90
89
        'valid'   : [False, 'sdl', 'vnc', (True, 'sdl', '', 'key_map-2'),
91
90
                     {'enabled' : True, 'type':'vnc', 'opts':5900} ]},
92
91
    'type'      : {
104
103
 
105
104
'fvguest'  : {
106
105
    'os_type'   : {
107
 
        'invalid' : ['notpresent',0,''],
 
106
        'invalid' : ['notpresent', 0, ''],
108
107
        'valid'   : ['other', 'windows', 'unix', 'linux']},
109
108
    'os_variant': {
110
109
        'invalid' : ['', 0, 'invalid'],
121
120
    { 'path' : 'valid', 'size' : None },
122
121
    { 'path' : "valid", 'size' : 'invalid' },
123
122
    { 'path' : 'valid', 'size' : -1},
124
 
    { 'path' : 'notblock', 'type' : VirtualDisk.TYPE_BLOCK},
125
 
    { 'path' :'/dev/null', 'type' : VirtualDisk.TYPE_BLOCK},
126
123
    { 'path' : None },
127
124
    { 'path' : "noexist1", 'size' : 900000, 'sparse' : False },
128
125
    { 'path' : "noexist2", 'type' : VirtualDisk.DEVICE_CDROM},
204
201
    '__init__' : {
205
202
        'invalid' : \
206
203
            [{'image' : virtimage, 'capabilities': testcaps, 'boot_index': 5},
207
 
             {'image' : virtimage, 'capabilities': "foo"},],
 
204
             {'image' : virtimage, 'capabilities': "foo"}],
208
205
        'valid'   : \
209
206
            [{'image' : virtimage, 'capabilities': testcaps, 'boot_index': 1},
210
207
            {'image' : virtimage },
211
 
            {'image' : virtimage, 'capabilities': testcaps, 'conn': None},],
 
208
            {'image' : virtimage, 'capabilities': testcaps, 'conn': None}],
212
209
    }
213
210
},
214
211
 
221
218
},
222
219
 
223
220
'clonedesign' : {
224
 
    'original_guest' :{
 
221
    'original_guest' : {
225
222
        'invalid' : ['idontexist'],
226
223
        'valid'   : ['test']},
227
224
    'clone_name': { 'invalid' : [0, 'test' # Already in use
364
361
class TestValidation(unittest.TestCase):
365
362
 
366
363
    def _getInitConns(self, label):
367
 
        if args[label].has_key("init_conns"):
 
364
        if "init_conns" in args[label]:
368
365
            return args[label]["init_conns"]
369
366
        return [testconn]
370
367
 
371
368
    def _runObjInit(self, testclass, valuedict, defaultsdict=None):
372
369
        if defaultsdict:
373
370
            for key in defaultsdict.keys():
374
 
                if not valuedict.has_key(key):
 
371
                if key not in valuedict:
375
372
                    valuedict[key] = defaultsdict.get(key)
376
373
        return testclass(*(), **valuedict)
377
374
 
385
382
            msg = ("Expected TypeError or ValueError: None Raised.\n"
386
383
                   "For '%s' object, paramname '%s', val '%s':" %
387
384
                   (name, paramname, paramvalue))
388
 
            raise AssertionError, msg
 
385
            raise AssertionError(msg)
389
386
 
390
387
        except AssertionError:
391
388
            raise
397
394
                   "Original traceback was: \n%s\n" % traceback.format_exc() +
398
395
                   "For '%s' object, paramname '%s', val '%s':" %
399
396
                   (name, paramname, paramvalue))
400
 
            raise AssertionError, msg
 
397
            raise AssertionError(msg)
401
398
 
402
399
    def _testValid(self, name, obj, testclass, paramname, paramvalue):
403
400
 
404
401
        try:
405
402
            if paramname is '__init__':
406
403
                conns = self._getInitConns(name)
407
 
                if paramvalue.has_key("conn"):
 
404
                if "conn" in paramvalue:
408
405
                    conns = [paramvalue["conn"]]
409
406
                for conn in conns:
410
407
                    paramvalue["conn"] = conn
417
414
                   "Original traceback was: \n%s\n" % traceback.format_exc() +
418
415
                   "For '%s' object, paramname '%s', val '%s':" %
419
416
                   (name, paramname, paramvalue))
420
 
            raise AssertionError, msg
 
417
            raise AssertionError(msg)
421
418
 
422
419
    def _testArgs(self, obj, testclass, name, exception_check=None,
423
420
                  manual_dict=None):
477
474
            network = virtinst.VirtualNetworkInterface()
478
475
            network.setup(testconn)
479
476
        except Exception, e:
480
 
            raise AssertionError, \
481
 
                "Network setup with no params failed, expected success." + \
482
 
                " Exception was: %s: %s" % (str(e), "".join(traceback.format_exc()))
 
477
            raise AssertionError(
 
478
            "Network setup with no params failed, expected success." +
 
479
            " Exception was: %s: %s" %
 
480
            (str(e), "".join(traceback.format_exc())))
483
481
 
484
482
    def testDistroInstaller(self):
485
483
        def exception_check(obj, paramname, paramvalue):