Convert address to str in fixed_ip_obj.associate
A caller of associate may pass in a netaddr.IPAddress argument which will currently fail when it gets to sqlalchemy. Following the convention of other methods the netaddr.IPAddress will be cast to a string. Change-Id: I67c1876b447217b37104660ba87ed967f477b863 Closes-bug: 1317668
This commit is contained in:
parent
2a2178e767
commit
5268c1136e
|
@ -104,9 +104,19 @@ class FixedIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
|
|||
db_fixedip = db.fixed_ip_get_by_network_host(context, network_id, host)
|
||||
return cls._from_db_object(context, cls(), db_fixedip)
|
||||
|
||||
@obj_base.remotable_classmethod
|
||||
@classmethod
|
||||
def associate(cls, context, address, instance_uuid, network_id=None,
|
||||
reserved=False):
|
||||
# NOTE(alaski): address may be a netaddr.IPAddress which is not
|
||||
# serializable for RPC, and fails in SQLAlchemy.
|
||||
str_address = str(address)
|
||||
fixedip = cls._associate(context, str_address, instance_uuid,
|
||||
network_id=network_id, reserved=reserved)
|
||||
return fixedip
|
||||
|
||||
@obj_base.remotable_classmethod
|
||||
def _associate(cls, context, address, instance_uuid, network_id=None,
|
||||
reserved=False):
|
||||
db_fixedip = db.fixed_ip_associate(context, address, instance_uuid,
|
||||
network_id=network_id,
|
||||
reserved=reserved)
|
||||
|
|
|
@ -155,6 +155,16 @@ class _TestFixedIPObject(object):
|
|||
network_id=None, reserved=False)
|
||||
self._compare(fixedip, fake_fixed_ip)
|
||||
|
||||
@mock.patch('nova.db.fixed_ip_associate')
|
||||
def test_associate_with_IPAddress(self, associate):
|
||||
associate.return_value = fake_fixed_ip
|
||||
address = netaddr.IPAddress('1.2.3.4')
|
||||
fixedip = fixed_ip.FixedIP.associate(self.context, address,
|
||||
'fake-uuid')
|
||||
associate.assert_called_with(self.context, '1.2.3.4', 'fake-uuid',
|
||||
network_id=None, reserved=False)
|
||||
self._compare(fixedip, fake_fixed_ip)
|
||||
|
||||
@mock.patch('nova.db.fixed_ip_associate_pool')
|
||||
def test_associate_pool(self, associate):
|
||||
associate.return_value = fake_fixed_ip
|
||||
|
|
Loading…
Reference in New Issue