Merge "Prevent caller from specifying id during Migration.create()"
This commit is contained in:
commit
970cafb0cc
@ -13,6 +13,7 @@
|
||||
# under the License.
|
||||
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import base
|
||||
from nova.objects import fields
|
||||
from nova.objects import instance as instance_obj
|
||||
@ -57,6 +58,9 @@ class Migration(base.NovaPersistentObject, base.NovaObject):
|
||||
|
||||
@base.remotable
|
||||
def create(self, context):
|
||||
if self.obj_attr_is_set('id'):
|
||||
raise exception.ObjectActionError(action='create',
|
||||
reason='already created')
|
||||
updates = self.obj_get_changes()
|
||||
updates.pop('id', None)
|
||||
db_migration = db.migration_create(context, updates)
|
||||
|
@ -14,6 +14,7 @@
|
||||
|
||||
from nova import context
|
||||
from nova import db
|
||||
from nova import exception
|
||||
from nova.objects import migration
|
||||
from nova.openstack.common import timeutils
|
||||
from nova.tests import fake_instance
|
||||
@ -81,6 +82,19 @@ class _TestMigrationObject(object):
|
||||
mig.create(ctxt)
|
||||
self.assertEqual(fake_migration['dest_compute'], mig.dest_compute)
|
||||
|
||||
def test_recreate_fails(self):
|
||||
ctxt = context.get_admin_context()
|
||||
fake_migration = fake_db_migration()
|
||||
self.mox.StubOutWithMock(db, 'migration_create')
|
||||
db.migration_create(ctxt, {'source_compute': 'foo'}).AndReturn(
|
||||
fake_migration)
|
||||
self.mox.ReplayAll()
|
||||
mig = migration.Migration()
|
||||
mig.source_compute = 'foo'
|
||||
mig.create(ctxt)
|
||||
self.assertRaises(exception.ObjectActionError, mig.create,
|
||||
self.context)
|
||||
|
||||
def test_save(self):
|
||||
ctxt = context.get_admin_context()
|
||||
fake_migration = fake_db_migration()
|
||||
|
Loading…
x
Reference in New Issue
Block a user