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

« back to all changes in this revision

Viewing changes to nova/tests/api/openstack/contrib/test_volumes.py

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-10-21 14:37:26 UTC
  • mto: This revision was merged to the branch mainline in revision 47.
  • Revision ID: james.westby@ubuntu.com-20111021143726-dk1m1a0vwov3kyls
Tags: upstream-2012.1~e1~20111020.11229
ImportĀ upstreamĀ versionĀ 2012.1~e1~20111020.11229

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright 2011 Josh Durgin
 
1
# Copyright 2013 Josh Durgin
2
2
# All Rights Reserved.
3
3
#
4
4
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
18
18
import webob
19
19
 
20
20
import nova
21
 
from nova import context
 
21
from nova import flags
22
22
from nova import test
23
 
from nova.api.openstack.contrib.volumes import BootFromVolumeController
24
23
from nova.compute import instance_types
25
24
from nova.tests.api.openstack import fakes
26
25
from nova.tests.api.openstack.test_servers import fake_gen_uuid
27
26
 
28
27
 
 
28
FLAGS = flags.FLAGS
 
29
 
 
30
 
29
31
def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
 
32
    global _block_device_mapping_seen
 
33
    _block_device_mapping_seen = kwargs.get('block_device_mapping')
 
34
 
30
35
    inst_type = instance_types.get_instance_type_by_flavor_id(2)
31
 
    return [{'id': 1,
 
36
    resv_id = None
 
37
    return ([{'id': 1,
32
38
             'display_name': 'test_server',
33
39
             'uuid': fake_gen_uuid(),
34
40
             'instance_type': dict(inst_type),
39
45
             'project_id': 'fake',
40
46
             'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
41
47
             'updated_at': datetime.datetime(2010, 11, 11, 11, 0, 0),
42
 
             }]
 
48
             'progress': 0
 
49
             }], resv_id)
43
50
 
44
51
 
45
52
class BootFromVolumeTest(test.TestCase):
47
54
    def setUp(self):
48
55
        super(BootFromVolumeTest, self).setUp()
49
56
        self.stubs.Set(nova.compute.API, 'create', fake_compute_api_create)
 
57
        fakes.stub_out_nw_api(self.stubs)
50
58
 
51
59
    def test_create_root_volume(self):
52
60
        body = dict(server=dict(
59
67
                        delete_on_termination=False,
60
68
                        )]
61
69
                ))
 
70
        global _block_device_mapping_seen
 
71
        _block_device_mapping_seen = None
62
72
        req = webob.Request.blank('/v1.1/fake/os-volumes_boot')
63
73
        req.method = 'POST'
64
74
        req.body = json.dumps(body)
70
80
        self.assertEqual(2, int(server['flavor']['id']))
71
81
        self.assertEqual(u'test_server', server['name'])
72
82
        self.assertEqual(3, int(server['image']['id']))
73
 
        self.assertEqual(16, len(server['adminPass']))
 
83
        self.assertEqual(FLAGS.password_length, len(server['adminPass']))
 
84
        self.assertEqual(len(_block_device_mapping_seen), 1)
 
85
        self.assertEqual(_block_device_mapping_seen[0]['volume_id'], 1)
 
86
        self.assertEqual(_block_device_mapping_seen[0]['device_name'],
 
87
                '/dev/vda')