~hudson-openstack/nova/trunk

« back to all changes in this revision

Viewing changes to nova/tests/test_vsa.py

  • Committer: vladimir.p
  • Date: 2011-08-26 01:38:35 UTC
  • mto: This revision was merged to the branch mainline in revision 1502.
  • Revision ID: vladimir@zadarastorage.com-20110826013835-sk22ic51cwbt0xa5
VSA code redesign. Drive types completely replaced by Volume types

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
#    License for the specific language governing permissions and limitations
14
14
#    under the License.
15
15
 
 
16
import base64
16
17
import stubout
17
 
import base64
18
18
 
19
19
from xml.etree import ElementTree
20
20
from xml.etree.ElementTree import Element, SubElement
21
21
 
 
22
from nova import context
 
23
from nova import db
22
24
from nova import exception
23
25
from nova import flags
 
26
from nova import log as logging
 
27
from nova import test
24
28
from nova import vsa
25
29
from nova import volume
26
 
from nova import db
27
 
from nova import context
28
 
from nova import test
29
 
from nova import log as logging
 
30
from nova.volume import volume_types
 
31
from nova.vsa import utils as vsa_utils
 
32
 
30
33
import nova.image.fake
31
34
 
32
35
FLAGS = flags.FLAGS
33
36
LOG = logging.getLogger('nova.tests.vsa')
34
37
 
35
38
 
36
 
def fake_drive_type_get_by_name(context, name):
37
 
    drive_type = {
38
 
            'id': 1,
39
 
            'name': name,
40
 
            'type': name.split('_')[0],
41
 
            'size_gb': int(name.split('_')[1]),
42
 
            'rpm': name.split('_')[2],
43
 
            'capabilities': '',
44
 
            'visible': True}
45
 
    return drive_type
46
 
 
47
 
 
48
39
class VsaTestCase(test.TestCase):
49
40
 
50
41
    def setUp(self):
53
44
        self.vsa_api = vsa.API()
54
45
        self.volume_api = volume.API()
55
46
 
 
47
        FLAGS.quota_volumes = 100
 
48
        FLAGS.quota_gigabytes = 10000
 
49
 
56
50
        self.context_non_admin = context.RequestContext(None, None)
57
51
        self.context = context.get_admin_context()
58
52
 
 
53
        volume_types.create(self.context,
 
54
                            'SATA_500_7200',
 
55
                            extra_specs={'type': 'vsa_drive',
 
56
                                         'drive_name': 'SATA_500_7200',
 
57
                                         'drive_type': 'SATA',
 
58
                                         'drive_size': '500',
 
59
                                         'drive_rpm': '7200'})
 
60
 
59
61
        def fake_show_by_name(meh, context, name):
60
62
            if name == 'wrong_image_name':
61
63
                LOG.debug(_("Test: Emulate wrong VSA name. Raise"))
124
126
 
125
127
        FLAGS.vsa_multi_vol_creation = multi_vol_creation
126
128
 
127
 
        self.stubs.Set(nova.vsa.drive_types, 'get_by_name',
128
 
                    fake_drive_type_get_by_name)
129
 
 
130
129
        param = {'storage': [{'drive_name': 'SATA_500_7200',
131
130
                              'num_drives': 3}]}
132
131
        vsa_ref = self.vsa_api.create(self.context, **param)
157
156
        self.vsa_api.delete(self.context, vsa_ref['id'])
158
157
 
159
158
    def test_vsa_generate_user_data(self):
160
 
        self.stubs.Set(nova.vsa.drive_types, 'get_by_name',
161
 
                    fake_drive_type_get_by_name)
162
159
 
163
160
        FLAGS.vsa_multi_vol_creation = False
164
161
        param = {'display_name': 'VSA name test',
167
164
                 'storage': [{'drive_name': 'SATA_500_7200',
168
165
                              'num_drives': 3}]}
169
166
        vsa_ref = self.vsa_api.create(self.context, **param)
170
 
        volumes = db.volume_get_all_assigned_to_vsa(self.context,
171
 
                                                    vsa_ref['id'])
 
167
        volumes = self.vsa_api.get_all_vsa_drives(self.context,
 
168
                                                  vsa_ref['id'])
172
169
 
173
 
        user_data = self.vsa_api.generate_user_data(self.context,
174
 
                                                    vsa_ref,
175
 
                                                    volumes)
 
170
        user_data = vsa_utils.generate_user_data(vsa_ref, volumes)
176
171
        user_data = base64.b64decode(user_data)
177
172
 
178
173
        LOG.debug(_("Test: user_data = %s"), user_data)