Make floating_ips module use FloatingIP for all get queries
This makes the network.floating_ips module use the FloatingIP object for all get_* queries instead of direct database access. Related to blueprint nova-network-objects Change-Id: I862f2f3abc078b477bea6bf86d0d622c4e78881f
This commit is contained in:
parent
6314435abd
commit
a9a59ccbac
|
@ -24,6 +24,7 @@ from nova import exception
|
|||
from nova.network import rpcapi as network_rpcapi
|
||||
from nova.objects import dns_domain as dns_domain_obj
|
||||
from nova.objects import fixed_ip as fixed_ip_obj
|
||||
from nova.objects import floating_ip as floating_ip_obj
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import network as network_obj
|
||||
from nova.objects import service as service_obj
|
||||
|
@ -76,25 +77,22 @@ class FloatingIP(object):
|
|||
|
||||
admin_context = context.get_admin_context()
|
||||
try:
|
||||
floating_ips = self.db.floating_ip_get_all_by_host(admin_context,
|
||||
self.host)
|
||||
floating_ips = floating_ip_obj.FloatingIPList.get_by_host(
|
||||
admin_context, self.host)
|
||||
except exception.NotFound:
|
||||
return
|
||||
|
||||
for floating_ip in floating_ips:
|
||||
fixed_ip_id = floating_ip.get('fixed_ip_id')
|
||||
if fixed_ip_id:
|
||||
if floating_ip.fixed_ip_id:
|
||||
try:
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(
|
||||
admin_context, fixed_ip_id,
|
||||
expected_attrs=['network'])
|
||||
fixed_ip = floating_ip.fixed_ip
|
||||
except exception.FixedIpNotFound:
|
||||
msg = _('Fixed ip %s not found') % fixed_ip_id
|
||||
msg = _('Fixed ip %s not found') % floating_ip.fixed_ip_id
|
||||
LOG.debug(msg)
|
||||
continue
|
||||
interface = CONF.public_interface or floating_ip['interface']
|
||||
interface = CONF.public_interface or floating_ip.interface
|
||||
try:
|
||||
self.l3driver.add_floating_ip(floating_ip['address'],
|
||||
self.l3driver.add_floating_ip(floating_ip.address,
|
||||
fixed_ip.address,
|
||||
interface,
|
||||
fixed_ip.network)
|
||||
|
@ -168,8 +166,8 @@ class FloatingIP(object):
|
|||
kwargs['fixed_ips'] = fixed_ips
|
||||
for fixed_ip in fixed_ips:
|
||||
fixed_id = fixed_ip.id
|
||||
floating_ips = self.db.floating_ip_get_by_fixed_ip_id(context,
|
||||
fixed_id)
|
||||
floating_ips = floating_ip_obj.FloatingIPList.get_by_fixed_ip_id(
|
||||
context, fixed_id)
|
||||
# disassociate floating ips related to fixed_ip
|
||||
for floating_ip in floating_ips:
|
||||
address = str(floating_ip.address)
|
||||
|
@ -180,7 +178,7 @@ class FloatingIP(object):
|
|||
except exception.FloatingIpNotAssociated:
|
||||
LOG.exception(_("Floating IP is not associated. Ignore."))
|
||||
# deallocate if auto_assigned
|
||||
if floating_ip['auto_assigned']:
|
||||
if floating_ip.auto_assigned:
|
||||
self.deallocate_floating_ip(context, address,
|
||||
affect_auto_assigned=True)
|
||||
|
||||
|
@ -194,15 +192,15 @@ class FloatingIP(object):
|
|||
if context.is_admin:
|
||||
return
|
||||
|
||||
if floating_ip['project_id'] != context.project_id:
|
||||
if floating_ip['project_id'] is None:
|
||||
if floating_ip.project_id != context.project_id:
|
||||
if floating_ip.project_id is None:
|
||||
LOG.warn(_('Address |%(address)s| is not allocated'),
|
||||
{'address': floating_ip['address']})
|
||||
{'address': floating_ip.address})
|
||||
raise exception.NotAuthorized()
|
||||
else:
|
||||
LOG.warn(_('Address |%(address)s| is not allocated to your '
|
||||
'project |%(project)s|'),
|
||||
{'address': floating_ip['address'],
|
||||
{'address': floating_ip.address,
|
||||
'project': context.project_id})
|
||||
raise exception.NotAuthorized()
|
||||
|
||||
|
@ -246,29 +244,30 @@ class FloatingIP(object):
|
|||
def deallocate_floating_ip(self, context, address,
|
||||
affect_auto_assigned=False):
|
||||
"""Returns a floating ip to the pool."""
|
||||
floating_ip = self.db.floating_ip_get_by_address(context, address)
|
||||
floating_ip = floating_ip_obj.FloatingIP.get_by_address(context,
|
||||
address)
|
||||
|
||||
# handle auto_assigned
|
||||
if not affect_auto_assigned and floating_ip.get('auto_assigned'):
|
||||
if not affect_auto_assigned and floating_ip.auto_assigned:
|
||||
return
|
||||
use_quota = not floating_ip.get('auto_assigned')
|
||||
use_quota = not floating_ip.auto_assigned
|
||||
|
||||
# make sure project owns this floating ip (allocated)
|
||||
self._floating_ip_owned_by_project(context, floating_ip)
|
||||
|
||||
# make sure floating ip is not associated
|
||||
if floating_ip['fixed_ip_id']:
|
||||
floating_address = floating_ip['address']
|
||||
if floating_ip.fixed_ip_id:
|
||||
floating_address = floating_ip.address
|
||||
raise exception.FloatingIpAssociated(address=floating_address)
|
||||
|
||||
# clean up any associated DNS entries
|
||||
self._delete_all_entries_for_ip(context,
|
||||
floating_ip['address'])
|
||||
payload = dict(project_id=floating_ip['project_id'],
|
||||
floating_ip=floating_ip['address'])
|
||||
floating_ip.address)
|
||||
payload = dict(project_id=floating_ip.project_id,
|
||||
floating_ip=str(floating_ip.address))
|
||||
self.notifier.info(context, 'network.floating_ip.deallocate', payload)
|
||||
|
||||
project_id = floating_ip['project_id']
|
||||
project_id = floating_ip.project_id
|
||||
# Get reservations...
|
||||
try:
|
||||
if use_quota:
|
||||
|
@ -301,10 +300,10 @@ class FloatingIP(object):
|
|||
side has already verified that the fixed_address is legal by
|
||||
checking access to the instance.
|
||||
"""
|
||||
floating_ip = self.db.floating_ip_get_by_address(context,
|
||||
floating_address)
|
||||
floating_ip = floating_ip_obj.FloatingIP.get_by_address(
|
||||
context, floating_address)
|
||||
# handle auto_assigned
|
||||
if not affect_auto_assigned and floating_ip.get('auto_assigned'):
|
||||
if not affect_auto_assigned and floating_ip.auto_assigned:
|
||||
return
|
||||
|
||||
# make sure project owns this floating ip (allocated)
|
||||
|
@ -312,10 +311,9 @@ class FloatingIP(object):
|
|||
|
||||
# disassociate any already associated
|
||||
orig_instance_uuid = None
|
||||
if floating_ip['fixed_ip_id']:
|
||||
if floating_ip.fixed_ip_id:
|
||||
# find previously associated instance
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(
|
||||
context, floating_ip['fixed_ip_id'])
|
||||
fixed_ip = floating_ip.fixed_ip
|
||||
if str(fixed_ip.address) == fixed_address:
|
||||
# NOTE(vish): already associated to this address
|
||||
return
|
||||
|
@ -336,7 +334,7 @@ class FloatingIP(object):
|
|||
else:
|
||||
host = network.host
|
||||
|
||||
interface = floating_ip.get('interface')
|
||||
interface = floating_ip.interface
|
||||
if host == self.host:
|
||||
# i'm the correct host
|
||||
self._associate_floating_ip(context, floating_address,
|
||||
|
@ -401,27 +399,28 @@ class FloatingIP(object):
|
|||
Makes sure everything makes sense then calls _disassociate_floating_ip,
|
||||
rpc'ing to correct host if i'm not it.
|
||||
"""
|
||||
floating_ip = self.db.floating_ip_get_by_address(context, address)
|
||||
floating_ip = floating_ip_obj.FloatingIP.get_by_address(context,
|
||||
address)
|
||||
|
||||
# handle auto assigned
|
||||
if not affect_auto_assigned and floating_ip.get('auto_assigned'):
|
||||
if not affect_auto_assigned and floating_ip.auto_assigned:
|
||||
raise exception.CannotDisassociateAutoAssignedFloatingIP()
|
||||
|
||||
# make sure project owns this floating ip (allocated)
|
||||
self._floating_ip_owned_by_project(context, floating_ip)
|
||||
|
||||
# make sure floating ip is associated
|
||||
if not floating_ip.get('fixed_ip_id'):
|
||||
floating_address = floating_ip['address']
|
||||
if not floating_ip.fixed_ip_id:
|
||||
floating_address = floating_ip.address
|
||||
raise exception.FloatingIpNotAssociated(address=floating_address)
|
||||
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(context,
|
||||
floating_ip['fixed_ip_id'])
|
||||
floating_ip.fixed_ip_id)
|
||||
|
||||
# send to correct host, unless i'm the correct host
|
||||
network = network_obj.Network.get_by_id(context.elevated(),
|
||||
fixed_ip.network_id)
|
||||
interface = floating_ip.get('interface')
|
||||
interface = floating_ip.interface
|
||||
if network.multi_host:
|
||||
instance = instance_obj.Instance.get_by_uuid(
|
||||
context, fixed_ip.instance_uuid)
|
||||
|
@ -483,7 +482,8 @@ class FloatingIP(object):
|
|||
"""Returns a floating IP as a dict."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
return dict(self.db.floating_ip_get(context, id).iteritems())
|
||||
return dict(floating_ip_obj.FloatingIP.get_by_id(
|
||||
context, id).iteritems())
|
||||
|
||||
def get_floating_pools(self, context):
|
||||
"""Returns list of floating pools."""
|
||||
|
@ -495,13 +495,14 @@ class FloatingIP(object):
|
|||
"""Returns list of floating ip pools."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
pools = self.db.floating_ip_get_pools(context)
|
||||
return [dict(pool.iteritems()) for pool in pools]
|
||||
pools = floating_ip_obj.FloatingIP.get_pool_names(context)
|
||||
return [dict(name=name) for name in pools]
|
||||
|
||||
def get_floating_ip_by_address(self, context, address):
|
||||
"""Returns a floating IP as a dict."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
# NOTE(danms): Not converting to objects since it's not used
|
||||
return dict(self.db.floating_ip_get_by_address(context,
|
||||
address).iteritems())
|
||||
|
||||
|
@ -509,6 +510,7 @@ class FloatingIP(object):
|
|||
"""Returns the floating IPs allocated to a project."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
# NOTE(danms): Not converting to objects since it's not used
|
||||
ips = self.db.floating_ip_get_all_by_project(context,
|
||||
context.project_id)
|
||||
return [dict(ip.iteritems()) for ip in ips]
|
||||
|
@ -517,6 +519,7 @@ class FloatingIP(object):
|
|||
"""Returns the floating IPs associated with a fixed_address."""
|
||||
# NOTE(vish): This is no longer used but can't be removed until
|
||||
# we major version the network_rpcapi.
|
||||
# NOTE(danms): Not converting to objects since it's not used
|
||||
floating_ips = self.db.floating_ip_get_by_fixed_address(context,
|
||||
fixed_address)
|
||||
return [floating_ip['address'] for floating_ip in floating_ips]
|
||||
|
@ -540,8 +543,8 @@ class FloatingIP(object):
|
|||
LOG.info(_("Starting migration network for instance %s"),
|
||||
instance_uuid)
|
||||
for address in floating_addresses:
|
||||
floating_ip = self.db.floating_ip_get_by_address(context,
|
||||
address)
|
||||
floating_ip = floating_ip_obj.FloatingIP.get_by_address(context,
|
||||
address)
|
||||
|
||||
if self._is_stale_floating_ip_address(context, floating_ip):
|
||||
LOG.warn(_("Floating ip address |%(address)s| no longer "
|
||||
|
@ -550,23 +553,21 @@ class FloatingIP(object):
|
|||
{'address': address, 'instance_uuid': instance_uuid})
|
||||
continue
|
||||
|
||||
interface = CONF.public_interface or floating_ip['interface']
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(
|
||||
context, floating_ip['fixed_ip_id'],
|
||||
expected_attrs=['network'])
|
||||
self.l3driver.remove_floating_ip(floating_ip['address'],
|
||||
interface = CONF.public_interface or floating_ip.interface
|
||||
fixed_ip = floating_ip.fixed_ip
|
||||
self.l3driver.remove_floating_ip(floating_ip.address,
|
||||
fixed_ip.address,
|
||||
interface,
|
||||
fixed_ip.network)
|
||||
|
||||
# NOTE(ivoks): Destroy conntrack entries on source compute
|
||||
# host.
|
||||
self.l3driver.clean_conntrack(fixed_ip['address'])
|
||||
self.l3driver.clean_conntrack(fixed_ip.address)
|
||||
|
||||
# NOTE(wenjianhn): Make this address will not be bound to public
|
||||
# interface when restarts nova-network on dest compute node
|
||||
self.db.floating_ip_update(context,
|
||||
floating_ip['address'],
|
||||
floating_ip.address,
|
||||
{'host': None})
|
||||
|
||||
def migrate_instance_finish(self, context, instance_uuid,
|
||||
|
@ -584,8 +585,8 @@ class FloatingIP(object):
|
|||
instance_uuid)
|
||||
|
||||
for address in floating_addresses:
|
||||
floating_ip = self.db.floating_ip_get_by_address(context,
|
||||
address)
|
||||
floating_ip = floating_ip_obj.FloatingIP.get_by_address(context,
|
||||
address)
|
||||
|
||||
if self._is_stale_floating_ip_address(context, floating_ip):
|
||||
LOG.warn(_("Floating ip address |%(address)s| no longer "
|
||||
|
@ -595,14 +596,12 @@ class FloatingIP(object):
|
|||
continue
|
||||
|
||||
self.db.floating_ip_update(context,
|
||||
floating_ip['address'],
|
||||
floating_ip.address,
|
||||
{'host': dest})
|
||||
|
||||
interface = CONF.public_interface or floating_ip['interface']
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_id(
|
||||
context, floating_ip['fixed_ip_id'],
|
||||
expected_attrs=['network'])
|
||||
self.l3driver.add_floating_ip(floating_ip['address'],
|
||||
interface = CONF.public_interface or floating_ip.interface
|
||||
fixed_ip = floating_ip.fixed_ip
|
||||
self.l3driver.add_floating_ip(floating_ip.address,
|
||||
fixed_ip.address,
|
||||
interface,
|
||||
fixed_ip.network)
|
||||
|
|
|
@ -49,6 +49,18 @@ class FloatingIP(obj_base.NovaPersistentObject, obj_base.NovaObject):
|
|||
floatingip.obj_reset_changes()
|
||||
return floatingip
|
||||
|
||||
def obj_load_attr(self, attrname):
|
||||
if attrname not in FLOATING_IP_OPTIONAL_ATTRS:
|
||||
raise exception.ObjectActionError(
|
||||
action='obj_load_attr',
|
||||
reason='attribute %s is not lazy-loadable' % attrname)
|
||||
if not self._context:
|
||||
raise exception.OrphanedObjectError(method='obj_load_attr',
|
||||
objtype=self.obj_name())
|
||||
self.fixed_ip = fixed_ip.FixedIP.get_by_id(self._context,
|
||||
self.fixed_ip_id,
|
||||
expected_attrs=['network'])
|
||||
|
||||
@obj_base.remotable_classmethod
|
||||
def get_by_id(cls, context, id):
|
||||
db_floatingip = db.floating_ip_get(context, id)
|
||||
|
|
|
@ -32,6 +32,7 @@ from nova.network import linux_net
|
|||
from nova.network import manager as network_manager
|
||||
from nova.network import model as net_model
|
||||
from nova.objects import fixed_ip as fixed_ip_obj
|
||||
from nova.objects import floating_ip as floating_ip_obj
|
||||
from nova.objects import network as network_obj
|
||||
from nova.openstack.common.db import exception as db_exc
|
||||
from nova.openstack.common import importutils
|
||||
|
@ -44,6 +45,7 @@ from nova.tests import fake_ldap
|
|||
from nova.tests import fake_network
|
||||
from nova.tests import matchers
|
||||
from nova.tests.objects import test_fixed_ip
|
||||
from nova.tests.objects import test_floating_ip
|
||||
from nova.tests.objects import test_network
|
||||
from nova.tests.objects import test_service
|
||||
from nova import utils
|
||||
|
@ -836,37 +838,37 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
is_admin=False)
|
||||
|
||||
# raises because floating_ip project_id is None
|
||||
floating_ip = {'address': '10.0.0.1',
|
||||
'project_id': None}
|
||||
floating_ip = floating_ip_obj.FloatingIP(address='10.0.0.1',
|
||||
project_id=None)
|
||||
self.assertRaises(exception.NotAuthorized,
|
||||
self.network._floating_ip_owned_by_project,
|
||||
ctxt,
|
||||
floating_ip)
|
||||
|
||||
# raises because floating_ip project_id is not equal to ctxt project_id
|
||||
floating_ip = {'address': '10.0.0.1',
|
||||
'project_id': ctxt.project_id + '1'}
|
||||
floating_ip = floating_ip_obj.FloatingIP(
|
||||
address='10.0.0.1', project_id=ctxt.project_id + '1')
|
||||
self.assertRaises(exception.NotAuthorized,
|
||||
self.network._floating_ip_owned_by_project,
|
||||
ctxt,
|
||||
floating_ip)
|
||||
|
||||
# does not raise (floating ip is owned by ctxt project)
|
||||
floating_ip = {'address': '10.0.0.1',
|
||||
'project_id': ctxt.project_id}
|
||||
floating_ip = floating_ip_obj.FloatingIP(address='10.0.0.1',
|
||||
project_id=ctxt.project_id)
|
||||
self.network._floating_ip_owned_by_project(ctxt, floating_ip)
|
||||
|
||||
ctxt = context.RequestContext(None, None,
|
||||
is_admin=True)
|
||||
|
||||
# does not raise (ctxt is admin)
|
||||
floating_ip = {'address': '10.0.0.1',
|
||||
'project_id': None}
|
||||
floating_ip = floating_ip_obj.FloatingIP(address='10.0.0.1',
|
||||
project_id=None)
|
||||
self.network._floating_ip_owned_by_project(ctxt, floating_ip)
|
||||
|
||||
# does not raise (ctxt is admin)
|
||||
floating_ip = {'address': '10.0.0.1',
|
||||
'project_id': 'testproject'}
|
||||
floating_ip = floating_ip_obj.FloatingIP(address='10.0.0.1',
|
||||
project_id='testproject')
|
||||
self.network._floating_ip_owned_by_project(ctxt, floating_ip)
|
||||
|
||||
def test_allocate_floating_ip(self):
|
||||
|
@ -889,11 +891,13 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
pass
|
||||
|
||||
def fake2(*args, **kwargs):
|
||||
return {'address': '10.0.0.1', 'fixed_ip_id': 1}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1', fixed_ip_id=1)
|
||||
|
||||
def fake3(*args, **kwargs):
|
||||
return {'address': '10.0.0.1', 'fixed_ip_id': None,
|
||||
'project_id': ctxt.project_id}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1', fixed_ip_id=None,
|
||||
project_id=ctxt.project_id)
|
||||
|
||||
self.stubs.Set(self.network.db, 'floating_ip_deallocate', fake1)
|
||||
self.stubs.Set(self.network, '_floating_ip_owned_by_project', fake1)
|
||||
|
@ -915,21 +919,24 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
is_admin=False)
|
||||
|
||||
def fake1(*args, **kwargs):
|
||||
return {'address': '10.0.0.1', 'network': 'fakenet'}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1', network='fakenet')
|
||||
|
||||
# floating ip that's already associated
|
||||
def fake2(*args, **kwargs):
|
||||
return {'address': '10.0.0.1',
|
||||
'pool': 'nova',
|
||||
'interface': 'eth0',
|
||||
'fixed_ip_id': 1}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1',
|
||||
pool='nova',
|
||||
interface='eth0',
|
||||
fixed_ip_id=1)
|
||||
|
||||
# floating ip that isn't associated
|
||||
def fake3(*args, **kwargs):
|
||||
return {'address': '10.0.0.1',
|
||||
'pool': 'nova',
|
||||
'interface': 'eth0',
|
||||
'fixed_ip_id': None}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1',
|
||||
pool='nova',
|
||||
interface='eth0',
|
||||
fixed_ip_id=None)
|
||||
|
||||
# fixed ip with remote host
|
||||
def fake4(*args, **kwargs):
|
||||
|
@ -992,7 +999,8 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
|
||||
fixed_get.return_value = dict(test_fixed_ip.fake_fixed_ip,
|
||||
address='1.2.3.4',
|
||||
instance_uuid='fake_uuid')
|
||||
instance_uuid='fake_uuid',
|
||||
network=test_network.fake_network)
|
||||
|
||||
# doesn't raise because we exit early if the address is the same
|
||||
self.network.associate_floating_ip(ctxt, mox.IgnoreArg(), '1.2.3.4')
|
||||
|
@ -1062,19 +1070,24 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
'fakeiface',
|
||||
'fakenet')
|
||||
|
||||
def _test_floating_ip_init_host(self, public_interface, expected_arg):
|
||||
@mock.patch('nova.db.floating_ip_get_all_by_host')
|
||||
@mock.patch('nova.db.fixed_ip_get')
|
||||
def _test_floating_ip_init_host(self, fixed_get, floating_get,
|
||||
public_interface, expected_arg):
|
||||
|
||||
def get_all_by_host(_context, _host):
|
||||
return [{'interface': 'foo',
|
||||
'address': 'foo'},
|
||||
{'interface': 'fakeiface',
|
||||
'address': 'fakefloat',
|
||||
'fixed_ip_id': 1},
|
||||
{'interface': 'bar',
|
||||
'address': 'bar',
|
||||
'fixed_ip_id': 2}]
|
||||
self.stubs.Set(self.network.db, 'floating_ip_get_all_by_host',
|
||||
get_all_by_host)
|
||||
floating_get.return_value = [
|
||||
dict(test_floating_ip.fake_floating_ip,
|
||||
interface='foo',
|
||||
address='1.2.3.4'),
|
||||
dict(test_floating_ip.fake_floating_ip,
|
||||
interface='fakeiface',
|
||||
address='1.2.3.5',
|
||||
fixed_ip_id=1),
|
||||
dict(test_floating_ip.fake_floating_ip,
|
||||
interface='bar',
|
||||
address='1.2.3.6',
|
||||
fixed_ip_id=2),
|
||||
]
|
||||
|
||||
def fixed_ip_get(_context, fixed_ip_id, get_network):
|
||||
if fixed_ip_id == 1:
|
||||
|
@ -1082,11 +1095,11 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
address='1.2.3.4',
|
||||
network=test_network.fake_network)
|
||||
raise exception.FixedIpNotFound(id=fixed_ip_id)
|
||||
self.stubs.Set(self.network.db, 'fixed_ip_get', fixed_ip_get)
|
||||
fixed_get.side_effect = fixed_ip_get
|
||||
|
||||
self.mox.StubOutWithMock(self.network.l3driver, 'add_floating_ip')
|
||||
self.flags(public_interface=public_interface)
|
||||
self.network.l3driver.add_floating_ip('fakefloat',
|
||||
self.network.l3driver.add_floating_ip(netaddr.IPAddress('1.2.3.5'),
|
||||
netaddr.IPAddress('1.2.3.4'),
|
||||
expected_arg,
|
||||
mox.IsA(network_obj.Network))
|
||||
|
@ -1112,18 +1125,20 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
|
||||
# floating ip that isn't associated
|
||||
def fake2(*args, **kwargs):
|
||||
return {'address': '10.0.0.1',
|
||||
'pool': 'nova',
|
||||
'interface': 'eth0',
|
||||
'fixed_ip_id': None}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1',
|
||||
pool='nova',
|
||||
interface='eth0',
|
||||
fixed_ip_id=None)
|
||||
|
||||
# floating ip that is associated
|
||||
def fake3(*args, **kwargs):
|
||||
return {'address': '10.0.0.1',
|
||||
'pool': 'nova',
|
||||
'interface': 'eth0',
|
||||
'fixed_ip_id': 1,
|
||||
'project_id': ctxt.project_id}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1',
|
||||
pool='nova',
|
||||
interface='eth0',
|
||||
fixed_ip_id=1,
|
||||
project_id=ctxt.project_id)
|
||||
|
||||
# fixed ip with remote host
|
||||
def fake4(*args, **kwargs):
|
||||
|
@ -1159,12 +1174,13 @@ class VlanNetworkTestCase(test.TestCase):
|
|||
self.local = True
|
||||
|
||||
def fake8(*args, **kwargs):
|
||||
return {'address': '10.0.0.1',
|
||||
'pool': 'nova',
|
||||
'interface': 'eth0',
|
||||
'fixed_ip_id': 1,
|
||||
'auto_assigned': True,
|
||||
'project_id': ctxt.project_id}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address='10.0.0.1',
|
||||
pool='nova',
|
||||
interface='eth0',
|
||||
fixed_ip_id=1,
|
||||
auto_assigned=True,
|
||||
project_id=ctxt.project_id)
|
||||
|
||||
self.stubs.Set(self.network, '_floating_ip_owned_by_project', fake1)
|
||||
|
||||
|
@ -2215,12 +2231,13 @@ class FloatingIPTestCase(test.TestCase):
|
|||
@mock.patch('nova.db.network_get')
|
||||
@mock.patch('nova.db.instance_get_by_uuid')
|
||||
@mock.patch('nova.db.service_get_by_host_and_topic')
|
||||
def test_disassociate_floating_ip_multi_host_calls(self, service_get,
|
||||
@mock.patch('nova.db.floating_ip_get_by_address')
|
||||
def test_disassociate_floating_ip_multi_host_calls(self, floating_get,
|
||||
service_get,
|
||||
inst_get, net_get,
|
||||
fixed_get):
|
||||
floating_ip = {
|
||||
'fixed_ip_id': 12
|
||||
}
|
||||
floating_ip = dict(test_floating_ip.fake_floating_ip,
|
||||
fixed_ip_id=12)
|
||||
|
||||
fixed_ip = dict(test_fixed_ip.fake_fixed_ip,
|
||||
network_id=None,
|
||||
|
@ -2234,14 +2251,11 @@ class FloatingIPTestCase(test.TestCase):
|
|||
ctxt = context.RequestContext('testuser', 'testproject',
|
||||
is_admin=False)
|
||||
|
||||
self.stubs.Set(self.network.db,
|
||||
'floating_ip_get_by_address',
|
||||
lambda _x, _y: floating_ip)
|
||||
|
||||
self.stubs.Set(self.network,
|
||||
'_floating_ip_owned_by_project',
|
||||
lambda _x, _y: True)
|
||||
|
||||
floating_get.return_value = floating_ip
|
||||
fixed_get.return_value = fixed_ip
|
||||
net_get.return_value = network
|
||||
inst_get.return_value = instance
|
||||
|
@ -2263,11 +2277,12 @@ class FloatingIPTestCase(test.TestCase):
|
|||
@mock.patch('nova.db.fixed_ip_get_by_address')
|
||||
@mock.patch('nova.db.network_get')
|
||||
@mock.patch('nova.db.instance_get_by_uuid')
|
||||
def test_associate_floating_ip_multi_host_calls(self, inst_get, net_get,
|
||||
@mock.patch('nova.db.floating_ip_get_by_address')
|
||||
def test_associate_floating_ip_multi_host_calls(self, floating_get,
|
||||
inst_get, net_get,
|
||||
fixed_get):
|
||||
floating_ip = {
|
||||
'fixed_ip_id': None
|
||||
}
|
||||
floating_ip = dict(test_floating_ip.fake_floating_ip,
|
||||
fixed_ip_id=None)
|
||||
|
||||
fixed_ip = dict(test_fixed_ip.fake_fixed_ip,
|
||||
network_id=None,
|
||||
|
@ -2281,14 +2296,11 @@ class FloatingIPTestCase(test.TestCase):
|
|||
ctxt = context.RequestContext('testuser', 'testproject',
|
||||
is_admin=False)
|
||||
|
||||
self.stubs.Set(self.network.db,
|
||||
'floating_ip_get_by_address',
|
||||
lambda _x, _y: floating_ip)
|
||||
|
||||
self.stubs.Set(self.network,
|
||||
'_floating_ip_owned_by_project',
|
||||
lambda _x, _y: True)
|
||||
|
||||
floating_get.return_value = floating_ip
|
||||
fixed_get.return_value = fixed_ip
|
||||
net_get.return_value = network
|
||||
inst_get.return_value = instance
|
||||
|
@ -2356,16 +2368,19 @@ class FloatingIPTestCase(test.TestCase):
|
|||
instance_id=instance['uuid'])
|
||||
|
||||
@mock.patch('nova.db.fixed_ip_get')
|
||||
def test_migrate_instance_start(self, fixed_get):
|
||||
@mock.patch('nova.db.floating_ip_get_by_address')
|
||||
def test_migrate_instance_start(self, floating_get, fixed_get):
|
||||
called = {'count': 0}
|
||||
|
||||
def fake_floating_ip_get_by_address(context, address):
|
||||
return {'address': address,
|
||||
'fixed_ip_id': 0}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address=address,
|
||||
fixed_ip_id=0)
|
||||
|
||||
def fake_is_stale_floating_ip_address(context, floating_ip):
|
||||
return floating_ip['address'] == '172.24.4.23'
|
||||
return str(floating_ip.address) == '172.24.4.23'
|
||||
|
||||
floating_get.side_effect = fake_floating_ip_get_by_address
|
||||
fixed_get.return_value = dict(test_fixed_ip.fake_fixed_ip,
|
||||
instance_uuid='fake_uuid',
|
||||
address='10.0.0.2',
|
||||
|
@ -2382,8 +2397,6 @@ class FloatingIPTestCase(test.TestCase):
|
|||
def fake_floating_ip_update(context, address, args):
|
||||
pass
|
||||
|
||||
self.stubs.Set(self.network.db, 'floating_ip_get_by_address',
|
||||
fake_floating_ip_get_by_address)
|
||||
self.stubs.Set(self.network, '_is_stale_floating_ip_address',
|
||||
fake_is_stale_floating_ip_address)
|
||||
self.stubs.Set(self.network.db, 'floating_ip_update',
|
||||
|
@ -2409,11 +2422,12 @@ class FloatingIPTestCase(test.TestCase):
|
|||
called = {'count': 0}
|
||||
|
||||
def fake_floating_ip_get_by_address(context, address):
|
||||
return {'address': address,
|
||||
'fixed_ip_id': 0}
|
||||
return dict(test_floating_ip.fake_floating_ip,
|
||||
address=address,
|
||||
fixed_ip_id=0)
|
||||
|
||||
def fake_is_stale_floating_ip_address(context, floating_ip):
|
||||
return floating_ip['address'] == '172.24.4.23'
|
||||
return str(floating_ip.address) == '172.24.4.23'
|
||||
|
||||
fixed_get.return_value = dict(test_fixed_ip.fake_fixed_ip,
|
||||
instance_uuid='fake_uuid',
|
||||
|
|
Loading…
Reference in New Issue