Fix add-fixed-ip and remove-fixed-ip.

There were various places that were passing an integer id from
network api to network manager. On the manager side we need the
uuid so this patch updates everything to send the uuid.

Secondarily, the network info cache wasn't being properly updated
upon return from add-fixed-ip and remove-fixed-ip, so this
changes the code to update the info cache as well.

Fixes bug 1124674

Change-Id: I632b39eb3963998cf42c02584dc9275a8aae243d
This commit is contained in:
Vishvananda Ishaya
2013-02-13 12:53:06 -08:00
parent 20424b9879
commit 65dbf21c91
8 changed files with 216 additions and 166 deletions

View File

@@ -260,8 +260,7 @@ class API(base.Base):
args = {}
args['vpn'] = vpn
args['requested_networks'] = requested_networks
args['instance_id'] = instance['id']
args['instance_uuid'] = instance['uuid']
args['instance_id'] = instance['uuid']
args['project_id'] = instance['project_id']
args['host'] = instance['host']
args['rxtx_factor'] = instance['instance_type']['rxtx_factor']
@@ -278,7 +277,7 @@ class API(base.Base):
# have db access so we do it on the other side of the
# rpc.
args = {}
args['instance_id'] = instance['id']
args['instance_id'] = instance['uuid']
args['project_id'] = instance['project_id']
args['host'] = instance['host']
self.network_rpcapi.deallocate_for_instance(context, **args)
@@ -289,6 +288,7 @@ class API(base.Base):
conductor_api=None):
"""Adds a fixed ip to instance from specified network."""
args = {'instance_id': instance['uuid'],
'rxtx_factor': instance['instance_type']['rxtx_factor'],
'host': instance['host'],
'network_id': network_id}
self.network_rpcapi.add_fixed_ip_to_instance(context, **args)
@@ -300,6 +300,7 @@ class API(base.Base):
"""Removes a fixed ip from instance from specified network."""
args = {'instance_id': instance['uuid'],
'rxtx_factor': instance['instance_type']['rxtx_factor'],
'host': instance['host'],
'address': address}
self.network_rpcapi.remove_fixed_ip_from_instance(context, **args)
@@ -342,8 +343,7 @@ class API(base.Base):
def _get_instance_nw_info(self, context, instance):
"""Returns all network info related to an instance."""
args = {'instance_id': instance['id'],
'instance_uuid': instance['uuid'],
args = {'instance_id': instance['uuid'],
'rxtx_factor': instance['instance_type']['rxtx_factor'],
'host': instance['host'],
'project_id': instance['project_id']}

View File

@@ -28,6 +28,7 @@ from nova.openstack.common import lockutils
from nova.openstack.common import log as logging
from nova.openstack.common.notifier import api as notifier
from nova.openstack.common.rpc import common as rpc_common
from nova.openstack.common import uuidutils
from nova import quota
from nova import servicegroup
@@ -102,8 +103,9 @@ class FloatingIP(object):
rpc.called by network_api
"""
instance_id = kwargs.get('instance_id')
instance_uuid = kwargs.get('instance_uuid')
instance_uuid = kwargs.get('instance_id')
if not uuidutils.is_uuid_like(instance_uuid):
instance_uuid = kwargs.get('instance_uuid')
project_id = kwargs.get('project_id')
requested_networks = kwargs.get('requested_networks')
# call the next inherited class's allocate_for_instance()
@@ -143,17 +145,19 @@ class FloatingIP(object):
rpc.called by network_api
"""
instance_id = kwargs.get('instance_id')
instance_uuid = kwargs.get('instance_id')
# NOTE(francois.charlier): in some cases the instance might be
# deleted before the IPs are released, so we need to get deleted
# instances too
instance = self.db.instance_get(
context.elevated(read_deleted='yes'), instance_id)
if not uuidutils.is_uuid_like(instance_uuid):
# NOTE(francois.charlier): in some cases the instance might be
# deleted before the IPs are released, so we need to get deleted
# instances too
instance = self.db.instance_get(
context.elevated(read_deleted='yes'), instance_uuid)
instance_uuid = instance['uuid']
try:
fixed_ips = self.db.fixed_ip_get_by_instance(context,
instance['uuid'])
instance_uuid)
except exception.FixedIpNotFoundForInstance:
fixed_ips = []
# add to kwargs so we can pass to super to save a db lookup there

View File

@@ -263,7 +263,7 @@ class NetworkManager(manager.SchedulerDependentManager):
The one at a time part is to flatten the layout to help scale
"""
RPC_API_VERSION = '1.8'
RPC_API_VERSION = '1.9'
# If True, this manager requires VIF to create a bridge.
SHOULD_CREATE_BRIDGE = False
@@ -472,8 +472,9 @@ class NetworkManager(manager.SchedulerDependentManager):
rpc.called by network_api
"""
instance_id = kwargs['instance_id']
instance_uuid = kwargs['instance_uuid']
instance_uuid = kwargs['instance_id']
if not uuidutils.is_uuid_like(instance_uuid):
instance_uuid = kwargs.get('instance_uuid')
host = kwargs['host']
project_id = kwargs['project_id']
rxtx_factor = kwargs['rxtx_factor']
@@ -484,7 +485,7 @@ class NetworkManager(manager.SchedulerDependentManager):
LOG.debug(_("network allocations"), instance_uuid=instance_uuid,
context=context)
networks = self._get_networks_for_instance(admin_context,
instance_id, project_id,
instance_uuid, project_id,
requested_networks=requested_networks)
networks_list = [self._get_network_dict(network)
for network in networks]
@@ -501,7 +502,7 @@ class NetworkManager(manager.SchedulerDependentManager):
self.db.virtual_interface_delete_by_instance(context,
instance_uuid)
self._allocate_fixed_ips(admin_context, instance_id,
self._allocate_fixed_ips(admin_context, instance_uuid,
host, networks, vpn=vpn,
requested_networks=requested_networks)
@@ -509,8 +510,8 @@ class NetworkManager(manager.SchedulerDependentManager):
network_ids = [network['id'] for network in networks]
self.network_rpcapi.update_dns(context, network_ids)
return self.get_instance_nw_info(context, instance_id, instance_uuid,
rxtx_factor, host)
return self.get_instance_nw_info(context, instance_uuid, rxtx_factor,
host)
def deallocate_for_instance(self, context, **kwargs):
"""Handles deallocating various network resources for an instance.
@@ -522,19 +523,22 @@ class NetworkManager(manager.SchedulerDependentManager):
# deleted before the IPs are released, so we need to get deleted
# instances too
read_deleted_context = context.elevated(read_deleted='yes')
instance_uuid = kwargs['instance_id']
if not uuidutils.is_uuid_like(instance_uuid):
instance = self.db.instance_get(read_deleted_context,
instance_uuid)
instance_uuid = instance['uuid']
instance_id = kwargs.pop('instance_id')
instance = self.db.instance_get(read_deleted_context, instance_id)
host = kwargs.get('host')
try:
fixed_ips = (kwargs.get('fixed_ips') or
self.db.fixed_ip_get_by_instance(read_deleted_context,
instance['uuid']))
instance_uuid))
except exception.FixedIpNotFoundForInstance:
fixed_ips = []
LOG.debug(_("network deallocation for instance"), instance=instance,
context=read_deleted_context)
LOG.debug(_("network deallocation for instance"),
context=context, instance_uuid=instance_uuid)
# deallocate fixed ips
for fixed_ip in fixed_ips:
self.deallocate_fixed_ip(context, fixed_ip['address'], host=host)
@@ -545,10 +549,10 @@ class NetworkManager(manager.SchedulerDependentManager):
# deallocate vifs (mac addresses)
self.db.virtual_interface_delete_by_instance(read_deleted_context,
instance['uuid'])
instance_uuid)
def get_instance_nw_info(self, context, instance_id, instance_uuid,
rxtx_factor, host, **kwargs):
def get_instance_nw_info(self, context, instance_id, rxtx_factor,
host, instance_uuid=None, **kwargs):
"""Creates network info list for instance.
called by allocate_for_instance and network_api
@@ -557,6 +561,11 @@ class NetworkManager(manager.SchedulerDependentManager):
where network = dict containing pertinent data from a network db object
and info = dict containing pertinent networking data
"""
if not uuidutils.is_uuid_like(instance_id):
instance_id = instance_uuid
instance_uuid = instance_id
host = kwargs.get('host')
vifs = self.db.virtual_interface_get_by_instance(context,
instance_uuid)
networks = {}
@@ -747,30 +756,36 @@ class NetworkManager(manager.SchedulerDependentManager):
else:
raise exception.VirtualInterfaceMacAddressException()
def add_fixed_ip_to_instance(self, context, instance_id, host, network_id):
def add_fixed_ip_to_instance(self, context, instance_id, host, network_id,
rxtx_factor=None):
"""Adds a fixed ip to an instance from specified network."""
if uuidutils.is_uuid_like(network_id):
network = self.get_network(context, network_id)
else:
network = self._get_network_by_id(context, network_id)
self._allocate_fixed_ips(context, instance_id, host, [network])
return self.get_instance_nw_info(context, instance_id, rxtx_factor,
host)
def get_backdoor_port(self, context):
"""Return backdoor port for eventlet_backdoor."""
return self.backdoor_port
def remove_fixed_ip_from_instance(self, context, instance_id, host,
address):
address, rxtx_factor=None):
"""Removes a fixed ip from an instance from specified network."""
fixed_ips = self.db.fixed_ip_get_by_instance(context, instance_id)
for fixed_ip in fixed_ips:
if fixed_ip['address'] == address:
self.deallocate_fixed_ip(context, address, host)
return
return self.get_instance_nw_info(context, instance_id,
rxtx_factor, host)
raise exception.FixedIpNotFoundForSpecificInstance(
instance_uuid=instance_id, ip=address)
def _validate_instance_zone_for_dns_domain(self, context, instance):
# FIXME(vish): The zone isn't usually set in the instance so I
# believe this code needs to be changed.
instance_zone = instance.get('availability_zone')
if not self.instance_dns_domain:
return True
@@ -798,37 +813,38 @@ class NetworkManager(manager.SchedulerDependentManager):
# and use that network here with a method like
# network_get_by_compute_host
address = None
instance_ref = self.db.instance_get(context, instance_id)
if network['cidr']:
address = kwargs.get('address', None)
if address:
address = self.db.fixed_ip_associate(context,
address,
instance_ref['uuid'],
instance_id,
network['id'])
else:
address = self.db.fixed_ip_associate_pool(context.elevated(),
network['id'],
instance_ref['uuid'])
instance_id)
self._do_trigger_security_group_members_refresh_for_instance(
instance_id)
self._do_trigger_security_group_handler(
'instance_add_security_group', instance_id)
get_vif = self.db.virtual_interface_get_by_instance_and_network
vif = get_vif(context, instance_ref['uuid'], network['id'])
vif = get_vif(context, instance_id, network['id'])
values = {'allocated': True,
'virtual_interface_id': vif['id']}
self.db.fixed_ip_update(context, address, values)
name = instance_ref['display_name']
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = self.db.instance_get_by_uuid(context, instance_id)
name = instance['display_name']
if self._validate_instance_zone_for_dns_domain(context, instance_ref):
uuid = instance_ref['uuid']
if self._validate_instance_zone_for_dns_domain(context, instance):
self.instance_dns_manager.create_entry(name, address,
"A",
self.instance_dns_domain)
self.instance_dns_manager.create_entry(uuid, address,
self.instance_dns_manager.create_entry(instance_id, address,
"A",
self.instance_dns_domain)
self._setup_network_on_host(context, network)
@@ -837,15 +853,18 @@ class NetworkManager(manager.SchedulerDependentManager):
def deallocate_fixed_ip(self, context, address, host=None, teardown=True):
"""Returns a fixed ip to the pool."""
fixed_ip_ref = self.db.fixed_ip_get_by_address(context, address)
instance_uuid = fixed_ip_ref['instance_uuid']
vif_id = fixed_ip_ref['virtual_interface_id']
self._do_trigger_security_group_members_refresh_for_instance(
instance_uuid)
self._do_trigger_security_group_handler(
'instance_remove_security_group', instance_uuid)
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = self.db.instance_get_by_uuid(
context.elevated(read_deleted='yes'),
fixed_ip_ref['instance_uuid'])
self._do_trigger_security_group_members_refresh_for_instance(
instance['uuid'])
self._do_trigger_security_group_handler(
'instance_remove_security_group', instance['uuid'])
instance_uuid)
if self._validate_instance_zone_for_dns_domain(context, instance):
for n in self.instance_dns_manager.get_entries_by_address(address,
@@ -1577,41 +1596,44 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
def allocate_fixed_ip(self, context, instance_id, network, **kwargs):
"""Gets a fixed ip from the pool."""
instance = self.db.instance_get(context, instance_id)
if kwargs.get('vpn', None):
address = network['vpn_private_address']
self.db.fixed_ip_associate(context,
address,
instance['uuid'],
instance_id,
network['id'],
reserved=True)
else:
address = kwargs.get('address', None)
if address:
address = self.db.fixed_ip_associate(context, address,
instance['uuid'],
instance_id,
network['id'])
else:
address = self.db.fixed_ip_associate_pool(context,
network['id'],
instance['uuid'])
instance_id)
self._do_trigger_security_group_members_refresh_for_instance(
instance_id)
vif = self.db.virtual_interface_get_by_instance_and_network(
context, instance['uuid'], network['id'])
context, instance_id, network['id'])
values = {'allocated': True,
'virtual_interface_id': vif['id']}
self.db.fixed_ip_update(context, address, values)
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = self.db.instance_get_by_uuid(context, instance_id)
name = instance['display_name']
if self._validate_instance_zone_for_dns_domain(context, instance):
name = instance['display_name']
uuid = instance['uuid']
self.instance_dns_manager.create_entry(name, address,
"A",
self.instance_dns_domain)
self.instance_dns_manager.create_entry(uuid, address,
self.instance_dns_manager.create_entry(instance_id, address,
"A",
self.instance_dns_domain)

View File

@@ -51,6 +51,8 @@ class NetworkAPI(rpc_proxy.RpcProxy):
1.6 - Adds instance_uuid to _{dis,}associate_floating_ip
1.7 - Adds method get_floating_ip_pools to replace get_floating_pools
1.8 - Adds macs to allocate_for_instance
1.9 - Adds rxtx_factor to [add|remove]_fixed_ip, removes instance_uuid
from allocate_for_instance and instance_get_nw_info
'''
#
@@ -154,18 +156,17 @@ class NetworkAPI(rpc_proxy.RpcProxy):
return self.call(ctxt, self.make_msg('disassociate_floating_ip',
address=address, affect_auto_assigned=affect_auto_assigned))
def allocate_for_instance(self, ctxt, instance_id, instance_uuid,
project_id, host, rxtx_factor, vpn,
requested_networks, macs=None):
def allocate_for_instance(self, ctxt, instance_id, project_id, host,
rxtx_factor, vpn, requested_networks, macs=None):
if CONF.multi_host:
topic = rpc.queue_get_for(ctxt, self.topic, host)
else:
topic = None
return self.call(ctxt, self.make_msg('allocate_for_instance',
instance_id=instance_id, instance_uuid=instance_uuid,
project_id=project_id, host=host, rxtx_factor=rxtx_factor,
vpn=vpn, requested_networks=requested_networks, macs=macs),
topic=topic, version='1.8')
instance_id=instance_id, project_id=project_id, host=host,
rxtx_factor=rxtx_factor, vpn=vpn,
requested_networks=requested_networks, macs=macs),
topic=topic, version='1.9')
def deallocate_for_instance(self, ctxt, instance_id, project_id, host):
if CONF.multi_host:
@@ -176,13 +177,17 @@ class NetworkAPI(rpc_proxy.RpcProxy):
instance_id=instance_id, project_id=project_id, host=host),
topic=topic)
def add_fixed_ip_to_instance(self, ctxt, instance_id, host, network_id):
def add_fixed_ip_to_instance(self, ctxt, instance_id, rxtx_factor,
host, network_id):
return self.call(ctxt, self.make_msg('add_fixed_ip_to_instance',
instance_id=instance_id, host=host, network_id=network_id))
instance_id=instance_id, rxtx_factor=rxtx_factor,
host=host, network_id=network_id), version='1.9')
def remove_fixed_ip_from_instance(self, ctxt, instance_id, host, address):
def remove_fixed_ip_from_instance(self, ctxt, instance_id, rxtx_factor,
host, address):
return self.call(ctxt, self.make_msg('remove_fixed_ip_from_instance',
instance_id=instance_id, host=host, address=address))
instance_id=instance_id, rxtx_factor=rxtx_factor,
host=host, address=address), version='1.9')
def add_network_to_project(self, ctxt, project_id, network_uuid):
return self.call(ctxt, self.make_msg('add_network_to_project',
@@ -191,13 +196,13 @@ class NetworkAPI(rpc_proxy.RpcProxy):
def associate(self, ctxt, network_uuid, associations):
return self.call(ctxt, self.make_msg('associate',
network_uuid=network_uuid, associations=associations),
self.topic, version="1.5")
self.topic, version='1.5')
def get_instance_nw_info(self, ctxt, instance_id, instance_uuid,
rxtx_factor, host, project_id):
def get_instance_nw_info(self, ctxt, instance_id, rxtx_factor, host,
project_id):
return self.call(ctxt, self.make_msg('get_instance_nw_info',
instance_id=instance_id, instance_uuid=instance_uuid,
rxtx_factor=rxtx_factor, host=host, project_id=project_id))
instance_id=instance_id, rxtx_factor=rxtx_factor, host=host,
project_id=project_id), version='1.9')
def validate_networks(self, ctxt, networks):
return self.call(ctxt, self.make_msg('validate_networks',

View File

@@ -163,6 +163,10 @@ class FakeNetworkManager(network_manager.NetworkManager):
def _create_fixed_ips(self, context, network_id, fixed_cidr=None):
pass
def get_instance_nw_info(context, instance_id, rxtx_factor,
host, instance_uuid=None, **kwargs):
pass
def fake_network(network_id, ipv6=None):
if ipv6 is None:
@@ -360,7 +364,7 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
nw_model = network.get_instance_nw_info(
FakeContext('fakeuser', 'fake_project'),
0, 0, 3, None)
0, 3, None)
if spectacular:
return nw_model
return nw_model.legacy()

View File

@@ -74,9 +74,9 @@ class ApiTestCase(test.TestCase):
macs = set(['ab:cd:ef:01:23:34'])
self.mox.StubOutWithMock(
self.network_api.network_rpcapi, "allocate_for_instance")
kwargs = dict(zip(['host', 'instance_id', 'instance_uuid',
'project_id', 'requested_networks', 'rxtx_factor', 'vpn', 'macs'],
itertools.repeat(mox.IgnoreArg())))
kwargs = dict(zip(['host', 'instance_id', 'project_id',
'requested_networks', 'rxtx_factor', 'vpn', 'macs'],
itertools.repeat(mox.IgnoreArg())))
self.network_api.network_rpcapi.allocate_for_instance(
mox.IgnoreArg(), **kwargs).AndReturn([])
self.mox.ReplayAll()

View File

@@ -284,70 +284,81 @@ class FlatNetworkTestCase(test.TestCase):
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_update')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(self.network, 'get_instance_nw_info')
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.101')
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get_by_uuid(self.context,
mox.IgnoreArg()).AndReturn({'display_name': HOST})
db.instance_get(self.context,
1).AndReturn({'display_name': HOST,
'uuid': 'test-00001'})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.101')
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg(),
project_only=mox.IgnoreArg()).AndReturn(networks[0])
db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self.network.get_instance_nw_info(mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
self.network.add_fixed_ip_to_instance(self.context, FAKEUUID, HOST,
networks[0]['id'])
def test_add_fixed_ip_instance_using_uuid_without_vpn(self):
self.mox.StubOutWithMock(db, 'network_get_by_uuid')
self.mox.StubOutWithMock(db, 'network_update')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get(self.context,
1).AndReturn({'display_name': HOST,
'uuid': 'test-00001'})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(self.network, 'get_instance_nw_info')
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.101')
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.instance_get_by_uuid(self.context,
mox.IgnoreArg()).AndReturn({'display_name': HOST})
db.network_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks[0])
db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self.network.get_instance_nw_info(mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
self.network.add_fixed_ip_to_instance(self.context, FAKEUUID, HOST,
networks[0]['uuid'])
def test_mini_dns_driver(self):
@@ -396,48 +407,51 @@ class FlatNetworkTestCase(test.TestCase):
def test_instance_dns(self):
fixedip = '192.168.0.101'
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'network_get_by_uuid')
self.mox.StubOutWithMock(db, 'network_update')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get(self.context,
1).AndReturn({'display_name': HOST,
'uuid': 'test-00001'})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(self.network, 'get_instance_nw_info')
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(fixedip)
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg(),
project_only=mox.IgnoreArg()).AndReturn(networks[0])
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id':0, 'name':'test'}]})
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.instance_get_by_uuid(self.context,
mox.IgnoreArg()).AndReturn({'display_name': HOST})
db.network_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn(networks[0])
db.network_update(mox.IgnoreArg(), mox.IgnoreArg(), mox.IgnoreArg())
self.network.get_instance_nw_info(mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
networks[0]['id'])
self.network.add_fixed_ip_to_instance(self.context, FAKEUUID, HOST,
networks[0]['uuid'])
instance_manager = self.network.instance_dns_manager
addresses = instance_manager.get_entries_by_name(HOST,
self.network.instance_dns_domain)
self.assertEqual(len(addresses), 1)
self.assertEqual(addresses[0], fixedip)
addresses = instance_manager.get_entries_by_name('test-00001',
addresses = instance_manager.get_entries_by_name(FAKEUUID,
self.network.instance_dns_domain)
self.assertEqual(len(addresses), 1)
self.assertEqual(addresses[0], fixedip)
@@ -452,15 +466,12 @@ class VlanNetworkTestCase(test.TestCase):
is_admin=False)
def test_vpn_allocate_fixed_ip(self):
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db, 'fixed_ip_associate')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'uuid': '42',
'display_name': HOST})
db.fixed_ip_associate(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg(),
@@ -471,11 +482,14 @@ class VlanNetworkTestCase(test.TestCase):
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'display_name': HOST})
self.mox.ReplayAll()
network = dict(networks[0])
network['vpn_private_address'] = '192.168.0.2'
self.network.allocate_fixed_ip(self.context, 0, network, vpn=True)
self.network.allocate_fixed_ip(self.context, FAKEUUID, network,
vpn=True)
def test_vpn_allocate_fixed_ip_no_network_id(self):
network = dict(networks[0])
@@ -487,7 +501,7 @@ class VlanNetworkTestCase(test.TestCase):
self.assertRaises(exception.FixedIpNotFoundForNetwork,
self.network.allocate_fixed_ip,
context_admin,
instance['id'],
instance['uuid'],
network,
vpn=True)
@@ -496,12 +510,9 @@ class VlanNetworkTestCase(test.TestCase):
self.mox.StubOutWithMock(db, 'fixed_ip_update')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'display_name': HOST,
'uuid': FAKEUUID})
db.instance_get(mox.IgnoreArg(),
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}]})
db.fixed_ip_associate_pool(mox.IgnoreArg(),
@@ -512,11 +523,13 @@ class VlanNetworkTestCase(test.TestCase):
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'display_name': HOST})
self.mox.ReplayAll()
network = dict(networks[0])
network['vpn_private_address'] = '192.168.0.2'
self.network.allocate_fixed_ip(self.context, 0, network)
self.network.allocate_fixed_ip(self.context, FAKEUUID, network)
def test_create_networks_too_big(self):
self.assertRaises(ValueError, self.network.create_networks, None,
@@ -952,33 +965,34 @@ class VlanNetworkTestCase(test.TestCase):
def test_add_fixed_ip_instance_without_vpn_requested_networks(self):
self.mox.StubOutWithMock(db, 'network_get')
self.mox.StubOutWithMock(db, 'fixed_ip_associate_pool')
self.mox.StubOutWithMock(db, 'instance_get')
self.mox.StubOutWithMock(db,
'virtual_interface_get_by_instance_and_network')
self.mox.StubOutWithMock(db, 'fixed_ip_update')
self.mox.StubOutWithMock(db, 'instance_get_by_uuid')
self.mox.StubOutWithMock(self.network, 'get_instance_nw_info')
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'uuid': FAKEUUID,
'display_name': HOST})
db.fixed_ip_update(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg())
db.virtual_interface_get_by_instance_and_network(mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg()).AndReturn({'id': 0})
db.instance_get(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups':
[{'id': 0}],
'availability_zone': '',
'uuid': FAKEUUID})
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'security_groups': [{'id': 0}],
'availability_zone': '',
'uuid': FAKEUUID})
db.fixed_ip_associate_pool(mox.IgnoreArg(),
mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn('192.168.0.101')
db.network_get(mox.IgnoreArg(),
mox.IgnoreArg(),
project_only=mox.IgnoreArg()).AndReturn(networks[0])
db.instance_get_by_uuid(mox.IgnoreArg(),
mox.IgnoreArg()).AndReturn({'display_name': HOST})
self.network.get_instance_nw_info(mox.IgnoreArg(), mox.IgnoreArg(),
mox.IgnoreArg(), mox.IgnoreArg())
self.mox.ReplayAll()
self.network.add_fixed_ip_to_instance(self.context, 1, HOST,
self.network.add_fixed_ip_to_instance(self.context, FAKEUUID, HOST,
networks[0]['id'])
def test_ip_association_and_allocation_of_other_project(self):
@@ -1194,7 +1208,8 @@ class CommonNetworkTestCase(test.TestCase):
def test_remove_fixed_ip_from_instance(self):
manager = fake_network.FakeNetworkManager()
manager.remove_fixed_ip_from_instance(self.context, 99, HOST,
manager.remove_fixed_ip_from_instance(self.context, 99,
HOST,
'10.0.0.1')
self.assertEquals(manager.deallocate_called, '10.0.0.1')
@@ -1852,7 +1867,7 @@ class FloatingIPTestCase(test.TestCase):
'fixed_ip_id': fixed['id'],
'project_id': self.project_id})
self.network.deallocate_for_instance(self.context,
instance_id=instance['id'])
instance_id=instance['uuid'])
def test_deallocation_duplicate_floating_ip(self):
self.stubs.Set(self.network, '_teardown_network_on_host',
@@ -1874,7 +1889,7 @@ class FloatingIPTestCase(test.TestCase):
'fixed_ip_id': fixed['id'],
'project_id': self.project_id})
self.network.deallocate_for_instance(self.context,
instance_id=instance['id'])
instance_id=instance['uuid'])
def test_migrate_instance_start(self):
called = {'count': 0}

View File

@@ -178,10 +178,9 @@ class NetworkRpcAPITestCase(test.TestCase):
def test_allocate_for_instance(self):
self._test_network_api('allocate_for_instance', rpc_method='call',
instance_id='fake_id', instance_uuid='fake_uuid',
project_id='fake_id', host='fake_host',
instance_id='fake_id', project_id='fake_id', host='fake_host',
rxtx_factor='fake_factor', vpn=False, requested_networks={},
macs=set(), version="1.8")
macs=set(), version='1.9')
def test_deallocate_for_instance(self):
self._test_network_api('deallocate_for_instance', rpc_method='call',
@@ -189,12 +188,14 @@ class NetworkRpcAPITestCase(test.TestCase):
def test_add_fixed_ip_to_instance(self):
self._test_network_api('add_fixed_ip_to_instance', rpc_method='call',
instance_id='fake_id', host='fake_host', network_id='fake_id')
instance_id='fake_id', rxtx_factor='fake_factor',
host='fake_host', network_id='fake_id', version='1.9')
def test_remove_fixed_ip_from_instance(self):
self._test_network_api('remove_fixed_ip_from_instance',
rpc_method='call', instance_id='fake_id', host='fake_host',
address='fake_address')
rpc_method='call', instance_id='fake_id',
rxtx_factor='fake_factor', host='fake_host',
address='fake_address', version='1.9')
def test_add_network_to_project(self):
self._test_network_api('add_network_to_project', rpc_method='call',
@@ -202,9 +203,8 @@ class NetworkRpcAPITestCase(test.TestCase):
def test_get_instance_nw_info(self):
self._test_network_api('get_instance_nw_info', rpc_method='call',
instance_id='fake_id', instance_uuid='fake_uuid',
rxtx_factor='fake_factor', host='fake_host',
project_id='fake_id')
instance_id='fake_id', rxtx_factor='fake_factor',
host='fake_host', project_id='fake_id', version='1.9')
def test_validate_networks(self):
self._test_network_api('validate_networks', rpc_method='call',