Make SecurityGroup receive context

This fixes the SecurityGroup._from_db_object() method to take and set
a context, like most everything else.

Change-Id: Ie86df2cf264a1e75353599a8f9f693ef5fb15bc5
This commit is contained in:
Dan Smith 2013-10-14 14:13:24 -07:00
parent 2e957959ca
commit c5d5b08e3c
2 changed files with 11 additions and 9 deletions

View File

@ -31,24 +31,25 @@ class SecurityGroup(base.NovaPersistentObject, base.NovaObject):
}
@staticmethod
def _from_db_object(secgroup, db_secgroup):
def _from_db_object(context, secgroup, db_secgroup):
# NOTE(danms): These are identical right now
for field in secgroup.fields:
secgroup[field] = db_secgroup[field]
secgroup._context = context
secgroup.obj_reset_changes()
return secgroup
@base.remotable_classmethod
def get(cls, context, secgroup_id):
db_secgroup = db.security_group_get(context, secgroup_id)
return cls._from_db_object(cls(), db_secgroup)
return cls._from_db_object(context, cls(), db_secgroup)
@base.remotable_classmethod
def get_by_name(cls, context, project_id, group_name):
db_secgroup = db.security_group_get_by_name(context,
project_id,
group_name)
return cls._from_db_object(cls(), db_secgroup)
return cls._from_db_object(context, cls(), db_secgroup)
@base.remotable
def in_use(self, context):
@ -59,12 +60,12 @@ class SecurityGroup(base.NovaPersistentObject, base.NovaObject):
updates = self.obj_get_changes()
if updates:
db_secgroup = db.security_group_update(context, self.id, updates)
SecurityGroup._from_db_object(self, db_secgroup)
SecurityGroup._from_db_object(context, self, db_secgroup)
self.obj_reset_changes()
@base.remotable
def refresh(self, context):
SecurityGroup._from_db_object(self,
SecurityGroup._from_db_object(context, self,
db.security_group_get(context,
self.id))
@ -72,7 +73,8 @@ class SecurityGroup(base.NovaPersistentObject, base.NovaObject):
def _make_secgroup_list(context, secgroup_list, db_secgroup_list):
secgroup_list.objects = []
for db_secgroup in db_secgroup_list:
secgroup = SecurityGroup._from_db_object(SecurityGroup(), db_secgroup)
secgroup = SecurityGroup._from_db_object(context, SecurityGroup(),
db_secgroup)
secgroup._context = context
secgroup_list.objects.append(secgroup)
secgroup_list.obj_reset_changes()

View File

@ -76,7 +76,7 @@ class _TestSecurityGroupObject(object):
updated_secgroup)
self.mox.ReplayAll()
secgroup = security_group.SecurityGroup._from_db_object(
security_group.SecurityGroup(), fake_secgroup)
self.context, security_group.SecurityGroup(), fake_secgroup)
secgroup.description = 'foobar'
secgroup.save(self.context)
self.assertEqual(self._fix_deleted(updated_secgroup),
@ -88,7 +88,7 @@ class _TestSecurityGroupObject(object):
self.mox.StubOutWithMock(db, 'security_group_update')
self.mox.ReplayAll()
secgroup = security_group.SecurityGroup._from_db_object(
security_group.SecurityGroup(), fake_secgroup)
self.context, security_group.SecurityGroup(), fake_secgroup)
secgroup.save(self.context)
def test_refresh(self):
@ -97,7 +97,7 @@ class _TestSecurityGroupObject(object):
db.security_group_get(self.context, 1).AndReturn(updated_secgroup)
self.mox.ReplayAll()
secgroup = security_group.SecurityGroup._from_db_object(
security_group.SecurityGroup(), fake_secgroup)
self.context, security_group.SecurityGroup(), fake_secgroup)
secgroup.refresh(self.context)
self.assertEqual(self._fix_deleted(updated_secgroup),
dict(secgroup.items()))