~ubuntu-branches/ubuntu/saucy/nova/saucy-proposed

« back to all changes in this revision

Viewing changes to nova/tests/test_api.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short
  • Date: 2012-05-24 13:12:53 UTC
  • mfrom: (1.1.55)
  • Revision ID: package-import@ubuntu.com-20120524131253-ommql08fg1en06ut
Tags: 2012.2~f1-0ubuntu1
* New upstream release.
* Prepare for quantal:
  - Dropped debian/patches/upstream/0006-Use-project_id-in-ec2.cloud._format_image.patch
  - Dropped debian/patches/upstream/0005-Populate-image-properties-with-project_id-again.patch
  - Dropped debian/patches/upstream/0004-Fixed-bug-962840-added-a-test-case.patch
  - Dropped debian/patches/upstream/0003-Allow-unprivileged-RADOS-users-to-access-rbd-volumes.patch
  - Dropped debian/patches/upstream/0002-Stop-libvirt-test-from-deleting-instances-dir.patch
  - Dropped debian/patches/upstream/0001-fix-bug-where-nova-ignores-glance-host-in-imageref.patch 
  - Dropped debian/patches/0001-fix-useexisting-deprecation-warnings.patch
* debian/control: Add python-keystone as a dependency. (LP: #907197)
* debian/patches/kombu_tests_timeout.patch: Refreshed.
* debian/nova.conf, debian/nova-common.postinst: Convert to new ini
  file configuration
* debian/patches/nova-manage_flagfile_location.patch: Refreshed

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
from boto import exception as boto_exc
29
29
import webob
30
30
 
 
31
from nova.api import auth
 
32
from nova.api import ec2
 
33
from nova.api.ec2 import apirequest
 
34
from nova.api.ec2 import ec2utils
31
35
from nova import block_device
 
36
from nova.compute import api as compute_api
32
37
from nova import context
33
38
from nova import exception
34
39
from nova import test
35
 
from nova.api import auth
36
 
from nova.api import ec2
37
 
from nova.api.ec2 import apirequest
38
 
from nova.api.ec2 import cloud
39
 
from nova.api.ec2 import ec2utils
40
40
 
41
41
 
42
42
class FakeHttplibSocket(object):
96
96
        conv = ec2utils._try_convert
97
97
        self.assertEqual(conv('None'), None)
98
98
        self.assertEqual(conv('True'), True)
 
99
        self.assertEqual(conv('TRUE'), True)
99
100
        self.assertEqual(conv('true'), True)
100
101
        self.assertEqual(conv('False'), False)
 
102
        self.assertEqual(conv('FALSE'), False)
101
103
        self.assertEqual(conv('false'), False)
102
104
        self.assertEqual(conv('0'), 0)
103
105
        self.assertEqual(conv('42'), 42)
107
109
        self.assertEqual(conv('-0x57'), -0x57)
108
110
        self.assertEqual(conv('-'), '-')
109
111
        self.assertEqual(conv('-0'), 0)
 
112
        self.assertEqual(conv('0.0'), 0.0)
 
113
        self.assertEqual(conv('1e-8'), 0.0)
 
114
        self.assertEqual(conv('-1e-8'), 0.0)
 
115
        self.assertEqual(conv('0xDD8G'), '0xDD8G')
 
116
        self.assertEqual(conv('0XDD8G'), '0XDD8G')
 
117
        self.assertEqual(conv('-stringy'), '-stringy')
 
118
        self.assertEqual(conv('stringy'), 'stringy')
 
119
        self.assertEqual(conv('add'), 'add')
 
120
        self.assertEqual(conv('remove'), 'remove')
 
121
        self.assertEqual(conv(''), '')
110
122
 
111
123
 
112
124
class Ec2utilsTestCase(test.TestCase):
278
290
    def test_get_all_key_pairs(self):
279
291
        """Test that, after creating a user and project and generating
280
292
         a key pair, that the API call to list key pairs works properly"""
 
293
        keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd")
 
294
                          for x in range(random.randint(4, 8)))
281
295
        self.expect_http()
282
296
        self.mox.ReplayAll()
283
 
        keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd")
284
 
                          for x in range(random.randint(4, 8)))
285
 
        # NOTE(vish): create depends on pool, so call helper directly
286
 
        cloud._gen_key(context.get_admin_context(), 'fake', keyname)
287
 
 
 
297
        self.ec2.create_key_pair(keyname)
288
298
        rv = self.ec2.get_all_key_pairs()
289
299
        results = [k for k in rv if k.name == keyname]
290
300
        self.assertEquals(len(results), 1)
294
304
        requesting a second keypair with the same name fails sanely"""
295
305
        self.expect_http()
296
306
        self.mox.ReplayAll()
297
 
        keyname = "".join(random.choice("sdiuisudfsdcnpaqwertasd")
298
 
                          for x in range(random.randint(4, 8)))
299
 
        # NOTE(vish): create depends on pool, so call helper directly
300
307
        self.ec2.create_key_pair('test')
301
308
 
302
309
        try:
475
482
        self.assertEqual(len(rv), 1)
476
483
        self.assertEqual(rv[0].name, 'default')
477
484
 
478
 
        return
479
 
 
480
485
    def test_authorize_revoke_security_group_cidr_v6(self):
481
486
        """
482
487
        Test that we can add and remove CIDR based rules
529
534
        self.assertEqual(len(rv), 1)
530
535
        self.assertEqual(rv[0].name, 'default')
531
536
 
532
 
        return
533
 
 
534
537
    def test_authorize_revoke_security_group_foreign_group(self):
535
538
        """
536
539
        Test that we can grant and revoke another security group access