~ubuntu-branches/ubuntu/precise/nova/precise

« back to all changes in this revision

Viewing changes to nova/tests/test_api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, Chuck Short, Adam Gandleman
  • Date: 2012-03-09 13:07:19 UTC
  • mfrom: (1.1.48)
  • Revision ID: package-import@ubuntu.com-20120309130719-ytcnrxb0mj3epour
Tags: 2012.1~rc1~20120309.13261-0ubuntu1
[ Chuck Short ]
* New upstream release.
* Refreshed libvirt-console-patch again.

[ Adam Gandleman ]
* debian/patches/{ec2-fixes.patch, libvirt-console-pipe.patch}: Fix and
  refresh. Add dep3 headers from original git commits.
* debian/patches/ec2-fixes.patch: Dropped.  Merge upstream at 121537c3
* debain/{rules, nova-docs.doc}: Docs now built in doc/build/.
* debian/patches/libvirt-use-console-pipe.patch: Update use of
  instance['name'] instead of instance_name

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 
19
19
"""Unit tests for the API endpoint"""
20
20
 
21
 
import boto
22
 
from boto.ec2 import regioninfo
23
 
from boto.exception import EC2ResponseError
24
21
import datetime
25
22
import httplib
26
23
import random
27
24
import StringIO
 
25
 
 
26
import boto
 
27
from boto.ec2 import regioninfo
 
28
from boto import exception as boto_exc
28
29
import webob
29
30
 
30
31
from nova import block_device
271
272
        """Attempt to terminate an invalid instance"""
272
273
        self.expect_http()
273
274
        self.mox.ReplayAll()
274
 
        self.assertRaises(EC2ResponseError, self.ec2.terminate_instances,
275
 
                            "i-00000005")
 
275
        self.assertRaises(boto_exc.EC2ResponseError,
 
276
                self.ec2.terminate_instances, "i-00000005")
276
277
 
277
278
    def test_get_all_key_pairs(self):
278
279
        """Test that, after creating a user and project and generating
300
301
 
301
302
        try:
302
303
            self.ec2.create_key_pair('test')
303
 
        except EC2ResponseError, e:
 
304
        except boto_exc.EC2ResponseError, e:
304
305
            if e.code == 'KeyPairExists':
305
306
                pass
306
307
            else:
352
353
        # dashes, and underscores.
353
354
        security_group_name = "aa #^% -=99"
354
355
 
355
 
        self.assertRaises(EC2ResponseError, self.ec2.create_security_group,
356
 
                          security_group_name, 'test group')
 
356
        self.assertRaises(boto_exc.EC2ResponseError,
 
357
                self.ec2.create_security_group,
 
358
                security_group_name,
 
359
                'test group')
357
360
 
358
361
    def test_group_name_valid_length_security_group(self):
359
362
        """Test that we sanely handle invalid security group names.
365
368
        security_group_name = "".join(random.choice("poiuytrewqasdfghjklmnbvc")
366
369
                                      for x in range(random.randint(256, 266)))
367
370
 
368
 
        self.assertRaises(EC2ResponseError, self.ec2.create_security_group,
369
 
                          security_group_name, 'test group')
 
371
        self.assertRaises(boto_exc.EC2ResponseError,
 
372
                self.ec2.create_security_group,
 
373
                security_group_name,
 
374
                'test group')
370
375
 
371
376
    def test_authorize_revoke_security_group_cidr(self):
372
377
        """
389
394
        group.authorize('tcp', 80, 81, '0.0.0.0/0')
390
395
        group.authorize('icmp', -1, -1, '0.0.0.0/0')
391
396
        group.authorize('udp', 80, 81, '0.0.0.0/0')
 
397
 
 
398
        def _assert(message, *args):
 
399
            try:
 
400
                group.authorize(*args)
 
401
            except boto_exc.EC2ResponseError as e:
 
402
                self.assertEqual(e.status, 400, 'Expected status to be 400')
 
403
                self.assertIn(message, e.error_message, e.error_message)
 
404
            else:
 
405
                raise self.failureException, 'EC2ResponseError not raised'
 
406
 
392
407
        # Invalid CIDR address
393
 
        self.assertRaises(Exception,
394
 
                          group.authorize, 'tcp', 80, 81, '0.0.0.0/0444')
 
408
        _assert('Invalid CIDR', 'tcp', 80, 81, '0.0.0.0/0444')
395
409
        # Missing ports
396
 
        self.assertRaises(Exception,
397
 
                          group.authorize, 'tcp', '0.0.0.0/0')
 
410
        _assert('Not enough parameters', 'tcp', '0.0.0.0/0')
398
411
        # from port cannot be greater than to port
399
 
        self.assertRaises(Exception,
400
 
                          group.authorize, 'tcp', 100, 1, '0.0.0.0/0')
 
412
        _assert('Invalid port range', 'tcp', 100, 1, '0.0.0.0/0')
401
413
        # For tcp, negative values are not allowed
402
 
        self.assertRaises(Exception,
403
 
                          group.authorize, 'tcp', -1, 1, '0.0.0.0/0')
 
414
        _assert('Invalid port range', 'tcp', -1, 1, '0.0.0.0/0')
404
415
        # For tcp, valid port range 1-65535
405
 
        self.assertRaises(Exception,
406
 
                          group.authorize, 'tcp', 1, 65599, '0.0.0.0/0')
 
416
        _assert('Invalid port range', 'tcp', 1, 65599, '0.0.0.0/0')
407
417
        # For icmp, only -1:-1 is allowed for type:code
408
 
        self.assertRaises(Exception,
409
 
                          group.authorize, 'icmp', -1, 0, '0.0.0.0/0')
 
418
        _assert('An unknown error has occurred', 'icmp', -1, 0, '0.0.0.0/0')
410
419
        # Non valid type:code
411
 
        self.assertRaises(Exception,
412
 
                          group.authorize, 'icmp', 0, 3, '0.0.0.0/0')
 
420
        _assert('An unknown error has occurred', 'icmp', 0, 3, '0.0.0.0/0')
413
421
        # Invalid Cidr for ICMP type
414
 
        self.assertRaises(Exception,
415
 
                          group.authorize, 'icmp', -1, -1, '0.0.444.0/4')
 
422
        _assert('Invalid CIDR', 'icmp', -1, -1, '0.0.444.0/4')
416
423
        # Invalid protocol
417
 
        self.assertRaises(Exception,
418
 
                          group.authorize, 'xyz', 1, 14, '0.0.0.0/0')
 
424
        _assert('An unknown error has occurred', 'xyz', 1, 14, '0.0.0.0/0')
419
425
        # Invalid port
420
 
        self.assertRaises(Exception,
421
 
                          group.authorize, 'tcp', " ", "81", '0.0.0.0/0')
 
426
        _assert('An unknown error has occurred', 'tcp', " ", "81", '0.0.0.0/0')
422
427
        # Invalid icmp port
423
 
        self.assertRaises(Exception,
424
 
                          group.authorize, 'icmp', " ", "81", '0.0.0.0/0')
425
 
        # Invalid CIDR Address
426
 
        self.assertRaises(Exception,
427
 
                          group.authorize, 'icmp', -1, -1, '0.0.0.0')
428
 
        # Invalid CIDR Address
429
 
        self.assertRaises(Exception,
430
 
                          group.authorize, 'icmp', -1, -1, '0.0.0.0/')
 
428
        _assert('An unknown error has occurred', 'icmp', " ", "81",
 
429
                '0.0.0.0/0')
 
430
        # Invalid CIDR Address
 
431
        _assert('Invalid CIDR', 'icmp', -1, -1, '0.0.0.0')
 
432
        # Invalid CIDR Address
 
433
        _assert('Invalid CIDR', 'icmp', -1, -1, '0.0.0.0/')
431
434
        # Invalid Cidr ports
432
 
        self.assertRaises(Exception,
433
 
                          group.authorize, 'icmp', 1, 256, '0.0.0.0/0')
 
435
        _assert('Invalid port range', 'icmp', 1, 256, '0.0.0.0/0')
434
436
 
435
437
        self.expect_http()
436
438
        self.mox.ReplayAll()
572
574
 
573
575
        # Can not delete the group while it is still used by
574
576
        # another group.
575
 
        self.assertRaises(EC2ResponseError,
 
577
        self.assertRaises(boto_exc.EC2ResponseError,
576
578
                          self.ec2.delete_security_group,
577
579
                          other_security_group_name)
578
580