~ubuntu-branches/ubuntu/raring/cinder/raring-updates

« back to all changes in this revision

Viewing changes to cinder/tests/api/v1/stubs.py

Tags: upstream-2013.1~g2
ImportĀ upstreamĀ versionĀ 2013.1~g2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
3
# Copyright 2010 OpenStack LLC.
 
4
# All Rights Reserved.
 
5
#
 
6
#    Licensed under the Apache License, Version 2.0 (the "License"); you may
 
7
#    not use this file except in compliance with the License. You may obtain
 
8
#    a copy of the License at
 
9
#
 
10
#         http://www.apache.org/licenses/LICENSE-2.0
 
11
#
 
12
#    Unless required by applicable law or agreed to in writing, software
 
13
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
14
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
15
#    License for the specific language governing permissions and limitations
 
16
#    under the License.
 
17
 
 
18
import datetime
 
19
 
 
20
from cinder import exception as exc
 
21
 
 
22
FAKE_UUID = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
 
23
FAKE_UUIDS = {}
 
24
 
 
25
 
 
26
def stub_volume(id, **kwargs):
 
27
    volume = {
 
28
        'id': id,
 
29
        'user_id': 'fakeuser',
 
30
        'project_id': 'fakeproject',
 
31
        'host': 'fakehost',
 
32
        'size': 1,
 
33
        'availability_zone': 'fakeaz',
 
34
        'instance_uuid': 'fakeuuid',
 
35
        'mountpoint': '/',
 
36
        'status': 'fakestatus',
 
37
        'attach_status': 'attached',
 
38
        'bootable': 'false',
 
39
        'name': 'vol name',
 
40
        'display_name': 'displayname',
 
41
        'display_description': 'displaydesc',
 
42
        'created_at': datetime.datetime(1, 1, 1, 1, 1, 1),
 
43
        'snapshot_id': None,
 
44
        'source_volid': None,
 
45
        'volume_type_id': '3e196c20-3c06-11e2-81c1-0800200c9a66',
 
46
        'volume_metadata': [],
 
47
        'volume_type': {'name': 'vol_type_name'}}
 
48
 
 
49
    volume.update(kwargs)
 
50
    return volume
 
51
 
 
52
 
 
53
def stub_volume_create(self, context, size, name, description, snapshot,
 
54
                       **param):
 
55
    vol = stub_volume('1')
 
56
    vol['size'] = size
 
57
    vol['display_name'] = name
 
58
    vol['display_description'] = description
 
59
    vol['source_volid'] = None
 
60
    try:
 
61
        vol['snapshot_id'] = snapshot['id']
 
62
    except (KeyError, TypeError):
 
63
        vol['snapshot_id'] = None
 
64
    vol['availability_zone'] = param.get('availability_zone', 'fakeaz')
 
65
    return vol
 
66
 
 
67
 
 
68
def stub_volume_create_from_image(self, context, size, name, description,
 
69
                                  snapshot, volume_type, metadata,
 
70
                                  availability_zone):
 
71
    vol = stub_volume('1')
 
72
    vol['status'] = 'creating'
 
73
    vol['size'] = size
 
74
    vol['display_name'] = name
 
75
    vol['display_description'] = description
 
76
    vol['availability_zone'] = 'cinder'
 
77
    return vol
 
78
 
 
79
 
 
80
def stub_volume_update(self, context, *args, **param):
 
81
    pass
 
82
 
 
83
 
 
84
def stub_volume_delete(self, context, *args, **param):
 
85
    pass
 
86
 
 
87
 
 
88
def stub_volume_get(self, context, volume_id):
 
89
    return stub_volume(volume_id)
 
90
 
 
91
 
 
92
def stub_volume_get_notfound(self, context, volume_id):
 
93
    raise exc.NotFound
 
94
 
 
95
 
 
96
def stub_volume_get_all(context, search_opts=None):
 
97
    return [stub_volume(100, project_id='fake'),
 
98
            stub_volume(101, project_id='superfake'),
 
99
            stub_volume(102, project_id='superduperfake')]
 
100
 
 
101
 
 
102
def stub_volume_get_all_by_project(self, context, search_opts=None):
 
103
    return [stub_volume_get(self, context, '1')]
 
104
 
 
105
 
 
106
def stub_snapshot(id, **kwargs):
 
107
    snapshot = {'id': id,
 
108
                'volume_id': 12,
 
109
                'status': 'available',
 
110
                'volume_size': 100,
 
111
                'created_at': None,
 
112
                'display_name': 'Default name',
 
113
                'display_description': 'Default description',
 
114
                'project_id': 'fake'}
 
115
 
 
116
    snapshot.update(kwargs)
 
117
    return snapshot
 
118
 
 
119
 
 
120
def stub_snapshot_get_all(self):
 
121
    return [stub_snapshot(100, project_id='fake'),
 
122
            stub_snapshot(101, project_id='superfake'),
 
123
            stub_snapshot(102, project_id='superduperfake')]
 
124
 
 
125
 
 
126
def stub_snapshot_get_all_by_project(self, context):
 
127
    return [stub_snapshot(1)]
 
128
 
 
129
 
 
130
def stub_snapshot_update(self, context, *args, **param):
 
131
    pass