summaryrefslogtreecommitdiff
path: root/nova/tests/unit/objects/test_flavor.py
diff options
context:
space:
mode:
authorMatt Riedemann <mriedem.os@gmail.com>2017-10-23 12:17:32 -0400
committerMatt Riedemann <mriedem.os@gmail.com>2017-11-05 01:24:01 -0500
commit3ca7eaab0287ce3f6d556baf0d1e0bb2f9d8aeb5 (patch)
tree3528f6b62b6b1fc020ab400efdc225c4069f5530 /nova/tests/unit/objects/test_flavor.py
parentf3c1db09b71c8087f4967d87b2eb55f065a196e3 (diff)
downloadnova-3ca7eaab0287ce3f6d556baf0d1e0bb2f9d8aeb5.tar.gz
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
Diffstat (limited to 'nova/tests/unit/objects/test_flavor.py')
-rw-r--r--nova/tests/unit/objects/test_flavor.py44
1 files changed, 44 insertions, 0 deletions
diff --git a/nova/tests/unit/objects/test_flavor.py b/nova/tests/unit/objects/test_flavor.py
index e6291cf29c..1162f3be0f 100644
--- a/nova/tests/unit/objects/test_flavor.py
+++ b/nova/tests/unit/objects/test_flavor.py
@@ -16,7 +16,9 @@ import datetime
import mock
from oslo_db import exception as db_exc
+from oslo_utils import uuidutils
+from nova import context as nova_context
from nova.db.sqlalchemy import api as db_api
from nova.db.sqlalchemy import api_models
from nova import exception
@@ -41,6 +43,7 @@ fake_flavor = {
'disabled': False,
'is_public': True,
'extra_specs': {'foo': 'bar'},
+ 'description': None
}
@@ -321,6 +324,47 @@ class TestFlavor(test_objects._LocalTest, _TestFlavor):
flavor = objects.Flavor.get_by_id(self.context, db_flavor['id'])
self.assertEqual({'marty': 'mcfly'}, flavor.extra_specs)
+ # NOTE(mriedem): There is no remotable method for updating the description
+ # in a flavor so we test this local-only.
+ @mock.patch('nova.objects.Flavor._send_notification')
+ def test_description(self, mock_notify):
+ # Create a flavor with a description.
+ ctxt = nova_context.get_admin_context()
+ flavorid = uuidutils.generate_uuid()
+ dict_flavor = dict(fake_flavor, name=flavorid, flavorid=flavorid)
+ del dict_flavor['id']
+ flavor = flavor_obj.Flavor(ctxt, **dict_flavor)
+ flavor.description = 'rainbows and unicorns'
+ flavor.create()
+ mock_notify.assert_called_once_with('create')
+ # Lookup the flavor to make sure the description is set.
+ flavor = flavor_obj.Flavor.get_by_flavor_id(ctxt, flavorid)
+ self.assertEqual('rainbows and unicorns', flavor.description)
+
+ # Now reset the flavor.description since it's nullable=True.
+ mock_notify.reset_mock()
+ self.assertEqual(0, len(flavor.obj_what_changed()),
+ flavor.obj_what_changed())
+ flavor.description = None
+ self.assertEqual(['description'], list(flavor.obj_what_changed()),
+ flavor.obj_what_changed())
+ old_updated_at = flavor.updated_at
+ flavor.save()
+ # Make sure we reloaded the flavor from the database.
+ self.assertNotEqual(old_updated_at, flavor.updated_at)
+ mock_notify.assert_called_once_with('update')
+ self.assertEqual(0, len(flavor.obj_what_changed()),
+ flavor.obj_what_changed())
+ # Lookup the flavor to make sure the description is gone.
+ flavor = flavor_obj.Flavor.get_by_flavor_id(ctxt, flavorid)
+ self.assertIsNone(flavor.description)
+
+ # Test compatibility.
+ flavor.description = 'flavor descriptions are not backward compatible'
+ flavor_primitive = flavor.obj_to_primitive()
+ flavor.obj_make_compatible(flavor_primitive, '1.1')
+ self.assertNotIn('description', flavor_primitive)
+
class TestFlavorRemote(test_objects._RemoteTest, _TestFlavor):
pass