1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
3
# Copyright (c) 2011 Zadara Storage Inc.
4
# Copyright (c) 2011 OpenStack LLC.
5
# Copyright 2011 University of Southern California
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
10
# http://www.apache.org/licenses/LICENSE-2.0
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
18
Unit Tests for volume types extra specs code
21
from nova import context
24
from nova.db.sqlalchemy.session import get_session
25
from nova.db.sqlalchemy import models
28
class VolumeTypeExtraSpecsTestCase(test.TestCase):
31
super(VolumeTypeExtraSpecsTestCase, self).setUp()
32
self.context = context.get_admin_context()
33
self.vol_type1 = dict(name="TEST: Regular volume test")
34
self.vol_type1_specs = dict(vol_extra1="value1",
37
self.vol_type1['extra_specs'] = self.vol_type1_specs
38
ref = db.api.volume_type_create(self.context, self.vol_type1)
39
self.volume_type1_id = ref.id
40
for k, v in self.vol_type1_specs.iteritems():
41
self.vol_type1_specs[k] = str(v)
43
self.vol_type2_noextra = dict(name="TEST: Volume type without extra")
44
ref = db.api.volume_type_create(self.context, self.vol_type2_noextra)
45
self.vol_type2_id = ref.id
48
# Remove the instance type from the database
49
db.api.volume_type_purge(context.get_admin_context(),
50
self.vol_type1['name'])
51
db.api.volume_type_purge(context.get_admin_context(),
52
self.vol_type2_noextra['name'])
53
super(VolumeTypeExtraSpecsTestCase, self).tearDown()
55
def test_volume_type_specs_get(self):
56
expected_specs = self.vol_type1_specs.copy()
57
actual_specs = db.api.volume_type_extra_specs_get(
58
context.get_admin_context(),
60
self.assertEquals(expected_specs, actual_specs)
62
def test_volume_type_extra_specs_delete(self):
63
expected_specs = self.vol_type1_specs.copy()
64
del expected_specs['vol_extra2']
65
db.api.volume_type_extra_specs_delete(context.get_admin_context(),
68
actual_specs = db.api.volume_type_extra_specs_get(
69
context.get_admin_context(),
71
self.assertEquals(expected_specs, actual_specs)
73
def test_volume_type_extra_specs_update(self):
74
expected_specs = self.vol_type1_specs.copy()
75
expected_specs['vol_extra3'] = "4"
76
db.api.volume_type_extra_specs_update_or_create(
77
context.get_admin_context(),
80
actual_specs = db.api.volume_type_extra_specs_get(
81
context.get_admin_context(),
83
self.assertEquals(expected_specs, actual_specs)
85
def test_volume_type_extra_specs_create(self):
86
expected_specs = self.vol_type1_specs.copy()
87
expected_specs['vol_extra4'] = 'value4'
88
expected_specs['vol_extra5'] = 'value5'
89
db.api.volume_type_extra_specs_update_or_create(
90
context.get_admin_context(),
92
dict(vol_extra4="value4",
94
actual_specs = db.api.volume_type_extra_specs_get(
95
context.get_admin_context(),
97
self.assertEquals(expected_specs, actual_specs)
99
def test_volume_type_get_with_extra_specs(self):
100
volume_type = db.api.volume_type_get(
101
context.get_admin_context(),
102
self.volume_type1_id)
103
self.assertEquals(volume_type['extra_specs'],
104
self.vol_type1_specs)
106
volume_type = db.api.volume_type_get(
107
context.get_admin_context(),
109
self.assertEquals(volume_type['extra_specs'], {})
111
def test_volume_type_get_by_name_with_extra_specs(self):
112
volume_type = db.api.volume_type_get_by_name(
113
context.get_admin_context(),
114
self.vol_type1['name'])
115
self.assertEquals(volume_type['extra_specs'],
116
self.vol_type1_specs)
118
volume_type = db.api.volume_type_get_by_name(
119
context.get_admin_context(),
120
self.vol_type2_noextra['name'])
121
self.assertEquals(volume_type['extra_specs'], {})
123
def test_volume_type_get_all(self):
124
expected_specs = self.vol_type1_specs.copy()
126
types = db.api.volume_type_get_all(context.get_admin_context())
129
types[self.vol_type1['name']]['extra_specs'], expected_specs)
132
types[self.vol_type2_noextra['name']]['extra_specs'], {})