~renukaapte/nova/sm-driver-d4

« back to all changes in this revision

Viewing changes to nova/tests/test_volume_types_extra_specs.py

  • Committer: Renuka Apte
  • Date: 2011-08-26 21:21:54 UTC
  • mfrom: (1483.1.16 nova)
  • Revision ID: renuka.apte@citrix.com-20110826212154-2i40ivtewy82724v
Merge till rev 1499

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# vim: tabstop=4 shiftwidth=4 softtabstop=4
 
2
 
 
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
 
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
Unit Tests for volume types extra specs code
 
19
"""
 
20
 
 
21
from nova import context
 
22
from nova import db
 
23
from nova import test
 
24
from nova.db.sqlalchemy.session import get_session
 
25
from nova.db.sqlalchemy import models
 
26
 
 
27
 
 
28
class VolumeTypeExtraSpecsTestCase(test.TestCase):
 
29
 
 
30
    def setUp(self):
 
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",
 
35
                                  vol_extra2="value2",
 
36
                                  vol_extra3=3)
 
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)
 
42
 
 
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
 
46
 
 
47
    def tearDown(self):
 
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()
 
54
 
 
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(),
 
59
                              self.volume_type1_id)
 
60
        self.assertEquals(expected_specs, actual_specs)
 
61
 
 
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(),
 
66
                                      self.volume_type1_id,
 
67
                                      'vol_extra2')
 
68
        actual_specs = db.api.volume_type_extra_specs_get(
 
69
                              context.get_admin_context(),
 
70
                              self.volume_type1_id)
 
71
        self.assertEquals(expected_specs, actual_specs)
 
72
 
 
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(),
 
78
                              self.volume_type1_id,
 
79
                              dict(vol_extra3=4))
 
80
        actual_specs = db.api.volume_type_extra_specs_get(
 
81
                              context.get_admin_context(),
 
82
                              self.volume_type1_id)
 
83
        self.assertEquals(expected_specs, actual_specs)
 
84
 
 
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(),
 
91
                              self.volume_type1_id,
 
92
                              dict(vol_extra4="value4",
 
93
                                   vol_extra5="value5"))
 
94
        actual_specs = db.api.volume_type_extra_specs_get(
 
95
                              context.get_admin_context(),
 
96
                              self.volume_type1_id)
 
97
        self.assertEquals(expected_specs, actual_specs)
 
98
 
 
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)
 
105
 
 
106
        volume_type = db.api.volume_type_get(
 
107
                            context.get_admin_context(),
 
108
                            self.vol_type2_id)
 
109
        self.assertEquals(volume_type['extra_specs'], {})
 
110
 
 
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)
 
117
 
 
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'], {})
 
122
 
 
123
    def test_volume_type_get_all(self):
 
124
        expected_specs = self.vol_type1_specs.copy()
 
125
 
 
126
        types = db.api.volume_type_get_all(context.get_admin_context())
 
127
 
 
128
        self.assertEquals(
 
129
            types[self.vol_type1['name']]['extra_specs'], expected_specs)
 
130
 
 
131
        self.assertEquals(
 
132
            types[self.vol_type2_noextra['name']]['extra_specs'], {})