nova/nova/tests/unit/fake_flavor.py
Matt Riedemann 3ca7eaab02 Add Flavor.description attribute
This adds the description attribute to the Flavor object
and the accompanying database schema upgrade.

This is the first field on a flavor that we've allowed
to be updated, so it requires some new plumbing for doing
an update on the flavor record itself during save(). The
updateable fields are whitelisted so we don't leak other
updates in here, like name, flavorid, vcpus, etc.

As part of this change, we also have to be sure to not
persist the description in the embedded instance.flavor
since (1) it's a large field and (2) we are not going
to expose the instance.flavor.description out of the
servers API.

Versioned notifications will be handled in a later change.

Part of blueprint flavor-description

Change-Id: I6db4eb46df0d7ec025b969a46621823957503958
2017-11-05 01:24:01 -05:00

57 lines
1.7 KiB
Python

# Copyright 2015 IBM Corp.
#
# 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.
from nova import objects
from nova.objects import fields
def fake_db_flavor(**updates):
db_flavor = {
'id': 1,
'name': 'fake_flavor',
'memory_mb': 1024,
'vcpus': 1,
'root_gb': 100,
'ephemeral_gb': 0,
'flavorid': 'abc',
'swap': 0,
'disabled': False,
'is_public': True,
'extra_specs': {},
'projects': [],
'description': None
}
for name, field in objects.Flavor.fields.items():
if name in db_flavor:
continue
if field.nullable:
db_flavor[name] = None
elif field.default != fields.UnspecifiedDefault:
db_flavor[name] = field.default
else:
raise Exception('fake_db_flavor needs help with %s' % name)
if updates:
db_flavor.update(updates)
return db_flavor
def fake_flavor_obj(context, **updates):
expected_attrs = updates.pop('expected_attrs', None)
return objects.Flavor._from_db_object(context,
objects.Flavor(), fake_db_flavor(**updates),
expected_attrs=expected_attrs)