diff options
| author | vladimir.p <vladimir@zadarastorage.com> | 2011-08-18 14:40:05 -0700 |
|---|---|---|
| committer | vladimir.p <vladimir@zadarastorage.com> | 2011-08-18 14:40:05 -0700 |
| commit | b703b33cdd48c2409205504ef09cc91d287862bf (patch) | |
| tree | e3ced2c0bfd000baf94e08ca33e7a02e2f11cf93 | |
| parent | 7399805b96cefd9d0f88cec202edd9fdb2c91ec0 (diff) | |
added unittests for volume_extra_data
| -rw-r--r-- | nova/db/sqlalchemy/api.py | 26 | ||||
| -rw-r--r-- | nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py | 9 | ||||
| -rw-r--r-- | nova/tests/test_volume_types_extra_specs.py | 131 |
3 files changed, 144 insertions, 22 deletions
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py index ce1066e42..a57133b72 100644 --- a/nova/db/sqlalchemy/api.py +++ b/nova/db/sqlalchemy/api.py @@ -3500,50 +3500,50 @@ def volume_type_get_all(context, inactive=False): """ session = get_session() if inactive: - inst_types = session.query(models.VolumeTypes).\ + vol_types = session.query(models.VolumeTypes).\ options(joinedload('extra_specs')).\ order_by("name").\ all() else: - inst_types = session.query(models.VolumeTypes).\ + vol_types = session.query(models.VolumeTypes).\ options(joinedload('extra_specs')).\ filter_by(deleted=False).\ order_by("name").\ all() - inst_dict = {} - if inst_types: - for i in inst_types: - inst_dict[i['name']] = _dict_with_extra_specs(i) - return inst_dict + vol_dict = {} + if vol_types: + for i in vol_types: + vol_dict[i['name']] = _dict_with_extra_specs(i) + return vol_dict @require_context def volume_type_get(context, id): """Returns a dict describing specific volume_type""" session = get_session() - inst_type = session.query(models.VolumeTypes).\ + vol_type = session.query(models.VolumeTypes).\ options(joinedload('extra_specs')).\ filter_by(id=id).\ first() - if not inst_type: + if not vol_type: raise exception.VolumeTypeNotFound(volume_type=id) else: - return _dict_with_extra_specs(inst_type) + return _dict_with_extra_specs(vol_type) @require_context def volume_type_get_by_name(context, name): """Returns a dict describing specific volume_type""" session = get_session() - inst_type = session.query(models.VolumeTypes).\ + vol_type = session.query(models.VolumeTypes).\ options(joinedload('extra_specs')).\ filter_by(name=name).\ first() - if not inst_type: + if not vol_type: raise exception.VolumeTypeNotFoundByName(volume_type_name=name) else: - return _dict_with_extra_specs(inst_type) + return _dict_with_extra_specs(vol_type) @require_admin_context diff --git a/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py b/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py index 1bfa26845..ed8eeb172 100644 --- a/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py +++ b/nova/db/sqlalchemy/migrate_repo/versions/037_add_volume_types_and_extradata.py @@ -73,15 +73,6 @@ new_tables = (volume_types, volume_type_extra_specs_table) def upgrade(migrate_engine): - - from nova import context - from nova import db - from nova import flags - - FLAGS = flags.FLAGS - - # Upgrade operations go here. Don't create your own engine; - # bind migrate_engine to your metadata meta.bind = migrate_engine for table in new_tables: diff --git a/nova/tests/test_volume_types_extra_specs.py b/nova/tests/test_volume_types_extra_specs.py new file mode 100644 index 000000000..c48ed789e --- /dev/null +++ b/nova/tests/test_volume_types_extra_specs.py @@ -0,0 +1,131 @@ +# vim: tabstop=4 shiftwidth=4 softtabstop=4 + +# Copyright (c) 2011 Zadara Storage Inc. +# Copyright (c) 2011 OpenStack LLC. +# Copyright 2011 University of Southern California +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. +""" +Unit Tests for volume types extra specs code +""" + +from nova import context +from nova import db +from nova import test +from nova.db.sqlalchemy.session import get_session +from nova.db.sqlalchemy import models + + +class VolumeTypeExtraSpecsTestCase(test.TestCase): + + def setUp(self): + super(VolumeTypeExtraSpecsTestCase, self).setUp() + self.context = context.get_admin_context() + self.vol_type1 = dict(name="TEST: Regular volume test") + self.vol_type1_specs = dict(vol_extra1="value1", + vol_extra2="value2", + vol_extra3=3) + self.vol_type1['extra_specs'] = self.vol_type1_specs + ref = db.api.volume_type_create(self.context, self.vol_type1) + self.volume_type1_id = ref.id + + self.vol_type2_noextra = dict(name="TEST: Volume type without extra") + ref = db.api.volume_type_create(self.context, self.vol_type2_noextra) + self.vol_type2_id = ref.id + + + def tearDown(self): + # Remove the instance type from the database + db.api.volume_type_purge(context.get_admin_context(), + self.vol_type1['name']) + db.api.volume_type_purge(context.get_admin_context(), + self.vol_type2_noextra['name']) + super(VolumeTypeExtraSpecsTestCase, self).tearDown() + + def test_volume_type_specs_get(self): + expected_specs = self.vol_type1_specs.copy() + actual_specs = db.api.volume_type_extra_specs_get( + context.get_admin_context(), + self.volume_type1_id) + self.assertEquals(expected_specs, actual_specs) + + def test_volume_type_extra_specs_delete(self): + expected_specs = self.vol_type1_specs.copy() + del expected_specs['vol_extra2'] + db.api.volume_type_extra_specs_delete(context.get_admin_context(), + self.volume_type1_id, + 'vol_extra2') + actual_specs = db.api.volume_type_extra_specs_get( + context.get_admin_context(), + self.volume_type1_id) + self.assertEquals(expected_specs, actual_specs) + + def test_volume_type_extra_specs_update(self): + expected_specs = self.vol_type1_specs.copy() + expected_specs['vol_extra3'] = 4 + db.api.volume_type_extra_specs_update_or_create( + context.get_admin_context(), + self.volume_type1_id, + dict(vol_extra3=4)) + actual_specs = db.api.volume_type_extra_specs_get( + context.get_admin_context(), + self.volume_type1_id) + self.assertEquals(expected_specs, actual_specs) + + def test_volume_type_extra_specs_create(self): + expected_specs = self.vol_type1_specs.copy() + expected_specs['vol_extra4'] = 'value4' + expected_specs['vol_extra5'] = 'value5' + db.api.volume_type_extra_specs_update_or_create( + context.get_admin_context(), + self.volume_type1_id, + dict(vol_extra4="value4", + vol_extra5=5)) + actual_specs = db.api.volume_type_extra_specs_get( + context.get_admin_context(), + self.volume_type1_id) + self.assertEquals(expected_specs, actual_specs) + + def test_volume_type_get_with_extra_specs(self): + volume_type = db.api.volume_type_get( + context.get_admin_context(), + self.volume_type1_id) + self.assertEquals(volume_type['extra_specs'], + self.vol_type1_specs) + + volume_type = db.api.volume_type_get( + context.get_admin_context(), + self.vol_type2_id) + self.assertEquals(volume_type['extra_specs'], {}) + + def test_volume_type_get_by_name_with_extra_specs(self): + volume_type = db.api.volume_type_get_by_name( + context.get_admin_context(), + self.vol_type1['name']) + self.assertEquals(volume_type['extra_specs'], + self.vol_type1_specs) + + volume_type = db.api.volume_type_get_by_name( + context.get_admin_context(), + self.vol_type2_noextra['name']) + self.assertEquals(volume_type['extra_specs'], {}) + + def test_volume_type_get_all(self): + expected_specs = self.vol_type1_specs.copy() + + types = db.api.volume_type_get_all(context.get_admin_context()) + + self.assertEquals( + types[self.vol_type1['name']]['extra_specs'], expected_specs) + + self.assertEquals( + types[self.vol_type2_noextra['name']]['extra_specs'], {}) |
