Add SecurityGroup.identifier to prefer uuid over name
This gives us a quick identifier property on SecurityGroup that will prefer uuid if set, otherwise use the name field. Change-Id: If7153f6470dc94d600731335f59260e31d1a0392
This commit is contained in:
parent
979639b21c
commit
5ce65fa4bb
|
@ -88,6 +88,10 @@ class SecurityGroup(base.NovaPersistentObject, base.NovaObject):
|
|||
self._from_db_object(self._context, self,
|
||||
db.security_group_get(self._context, self.id))
|
||||
|
||||
@property
|
||||
def identifier(self):
|
||||
return self.uuid if 'uuid' in self else self.name
|
||||
|
||||
|
||||
@base.NovaObjectRegistry.register
|
||||
class SecurityGroupList(base.ObjectListBase, base.NovaObject):
|
||||
|
|
|
@ -123,6 +123,12 @@ class _TestSecurityGroupObject(object):
|
|||
secgroup.save()
|
||||
self.assertFalse(mock_db_update.called)
|
||||
|
||||
def test_identifier(self):
|
||||
secgroup = security_group.SecurityGroup(name='foo')
|
||||
self.assertEqual('foo', secgroup.identifier)
|
||||
secgroup.uuid = uuids.secgroup
|
||||
self.assertEqual(uuids.secgroup, secgroup.identifier)
|
||||
|
||||
|
||||
class TestSecurityGroupObject(test_objects._LocalTest,
|
||||
_TestSecurityGroupObject):
|
||||
|
|
Loading…
Reference in New Issue