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
26
class VolumeTypeExtraSpecsTestCase(test.TestCase):
29
super(VolumeTypeExtraSpecsTestCase, self).setUp()
30
self.context = context.get_admin_context()
31
self.vol_type1 = dict(name="TEST: Regular volume test")
32
self.vol_type1_specs = dict(vol_extra1="value1",
35
self.vol_type1['extra_specs'] = self.vol_type1_specs
36
ref = db.volume_type_create(self.context, self.vol_type1)
37
self.volume_type1_id = ref.id
38
for k, v in self.vol_type1_specs.iteritems():
39
self.vol_type1_specs[k] = str(v)
41
self.vol_type2_noextra = dict(name="TEST: Volume type without extra")
42
ref = db.volume_type_create(self.context, self.vol_type2_noextra)
43
self.vol_type2_id = ref.id
46
# Remove the volume type from the database
47
db.volume_type_destroy(context.get_admin_context(),
48
self.vol_type1['name'])
49
db.volume_type_destroy(context.get_admin_context(),
50
self.vol_type2_noextra['name'])
51
super(VolumeTypeExtraSpecsTestCase, self).tearDown()
53
def test_volume_type_specs_get(self):
54
expected_specs = self.vol_type1_specs.copy()
55
actual_specs = db.volume_type_extra_specs_get(
56
context.get_admin_context(),
58
self.assertEquals(expected_specs, actual_specs)
60
def test_volume_type_extra_specs_delete(self):
61
expected_specs = self.vol_type1_specs.copy()
62
del expected_specs['vol_extra2']
63
db.volume_type_extra_specs_delete(context.get_admin_context(),
66
actual_specs = db.volume_type_extra_specs_get(
67
context.get_admin_context(),
69
self.assertEquals(expected_specs, actual_specs)
71
def test_volume_type_extra_specs_update(self):
72
expected_specs = self.vol_type1_specs.copy()
73
expected_specs['vol_extra3'] = "4"
74
db.volume_type_extra_specs_update_or_create(
75
context.get_admin_context(),
78
actual_specs = db.volume_type_extra_specs_get(
79
context.get_admin_context(),
81
self.assertEquals(expected_specs, actual_specs)
83
def test_volume_type_extra_specs_create(self):
84
expected_specs = self.vol_type1_specs.copy()
85
expected_specs['vol_extra4'] = 'value4'
86
expected_specs['vol_extra5'] = 'value5'
87
db.volume_type_extra_specs_update_or_create(
88
context.get_admin_context(),
90
dict(vol_extra4="value4",
92
actual_specs = db.volume_type_extra_specs_get(
93
context.get_admin_context(),
95
self.assertEquals(expected_specs, actual_specs)
97
def test_volume_type_get_with_extra_specs(self):
98
volume_type = db.volume_type_get(
99
context.get_admin_context(),
100
self.volume_type1_id)
101
self.assertEquals(volume_type['extra_specs'],
102
self.vol_type1_specs)
104
volume_type = db.volume_type_get(
105
context.get_admin_context(),
107
self.assertEquals(volume_type['extra_specs'], {})
109
def test_volume_type_get_by_name_with_extra_specs(self):
110
volume_type = db.volume_type_get_by_name(
111
context.get_admin_context(),
112
self.vol_type1['name'])
113
self.assertEquals(volume_type['extra_specs'],
114
self.vol_type1_specs)
116
volume_type = db.volume_type_get_by_name(
117
context.get_admin_context(),
118
self.vol_type2_noextra['name'])
119
self.assertEquals(volume_type['extra_specs'], {})
121
def test_volume_type_get_all(self):
122
expected_specs = self.vol_type1_specs.copy()
124
types = db.volume_type_get_all(context.get_admin_context())
127
types[self.vol_type1['name']]['extra_specs'], expected_specs)
130
types[self.vol_type2_noextra['name']]['extra_specs'], {})