Add more logging to nova-network.

As requested to help debug gate issues.

Related-Bug: #1298472

Change-Id: I5640df721345fe9a878c7c6f8e1c13cfed484112
This commit is contained in:
Michael Still 2014-06-10 19:17:00 +10:00
parent 9721a54c2e
commit 80c5c87fa2
2 changed files with 45 additions and 8 deletions

View File

@ -338,6 +338,7 @@ class NetworkManager(manager.Manager):
def get_dhcp_leases(self, ctxt, network_ref):
"""Broker the request to the driver to fetch the dhcp leases."""
LOG.debug('Get DHCP leases for network %s', network_ref['uuid'])
return self.driver.get_dhcp_leases(ctxt, network_ref)
def init_host(self):
@ -348,8 +349,12 @@ class NetworkManager(manager.Manager):
# an ip address.
ctxt = context.get_admin_context()
for network in network_obj.NetworkList.get_by_host(ctxt, self.host):
LOG.debug('Setup network %s on host %s', network['uuid'],
self.host)
self._setup_network_on_host(ctxt, network)
if CONF.update_dns_entries:
LOG.debug('Update DNS on network %s for host %s',
network['uuid'], self.host)
dev = self.driver.get_dev(network)
self.driver.update_dns(ctxt, dev, network)
@ -370,7 +375,8 @@ class NetworkManager(manager.Manager):
if not isinstance(network_ref, network_obj.Network):
network_ref = network_obj.Network._from_db_object(
context, network_obj.Network(), network_ref)
LOG.debug('setting network host', context=context)
LOG.debug('Setting host %s for network %s', self.host,
network_ref['uuid'], context=context)
network_ref.host = self.host
network_ref.save()
return self.host
@ -412,6 +418,9 @@ class NetworkManager(manager.Manager):
fixed_ip_filter = filters.get('fixed_ip')
ip_filter = re.compile(str(filters.get('ip')))
ipv6_filter = re.compile(str(filters.get('ip6')))
LOG.debug('Get instance uuids by IP filters. Fixed IP filter: %s. '
'IP filter: %s. IPv6 filter: %s', fixed_ip_filter,
str(filters.get('ip')), str(filters.get('ip6')))
# NOTE(jkoelker) Should probably figure out a better way to do
# this. But for now it "works", this could suck on
@ -490,14 +499,14 @@ class NetworkManager(manager.Manager):
vpn = kwargs['vpn']
macs = kwargs['macs']
admin_context = context.elevated()
LOG.debug("network allocations", instance_uuid=instance_uuid,
LOG.debug("Allocate network for instance", instance_uuid=instance_uuid,
context=context)
networks = self._get_networks_for_instance(admin_context,
instance_uuid, project_id,
requested_networks=requested_networks)
networks_list = [self._get_network_dict(network)
for network in networks]
LOG.debug('networks retrieved for instance: |%s|',
LOG.debug('Networks retrieved for instance: |%s|',
networks_list, context=context, instance_uuid=instance_uuid)
try:
@ -555,7 +564,7 @@ class NetworkManager(manager.Manager):
read_deleted_context, instance_uuid)
except exception.FixedIpNotFoundForInstance:
fixed_ips = []
LOG.debug("network deallocation for instance",
LOG.debug("Network deallocation for instance",
context=context, instance_uuid=instance_uuid)
# deallocate fixed ips
for fixed_ip in fixed_ips:
@ -586,6 +595,7 @@ class NetworkManager(manager.Manager):
if not uuidutils.is_uuid_like(instance_id):
instance_id = instance_uuid
instance_uuid = instance_id
LOG.debug('Get instance network info', instance_uuid=instance_uuid)
vifs = vif_obj.VirtualInterfaceList.get_by_instance_uuid(context,
instance_uuid, use_slave=use_slave)
@ -675,6 +685,7 @@ class NetworkManager(manager.Manager):
vif = network_model.VIF(**vif_dict)
nw_info.append(vif)
LOG.debug('Built network info: |%s|', nw_info)
return nw_info
def _get_network_dict(self, network):
@ -782,6 +793,8 @@ class NetworkManager(manager.Manager):
network = self.get_network(context, network_id)
else:
network = self._get_network_by_id(context, network_id)
LOG.debug('Add fixed ip on network %s', network['uuid'],
instance_uuid=instance_id)
self._allocate_fixed_ips(context, instance_id, host, [network])
return self.get_instance_nw_info(context, instance_id, rxtx_factor,
host)
@ -795,6 +808,7 @@ class NetworkManager(manager.Manager):
def remove_fixed_ip_from_instance(self, context, instance_id, host,
address, rxtx_factor=None):
"""Removes a fixed ip from an instance from specified network."""
LOG.debug('Remove fixed ip %s', address, instance_uuid=instance_id)
fixed_ips = fixed_ip_obj.FixedIPList.get_by_instance_uuid(context,
instance_id)
for fixed_ip in fixed_ips:
@ -849,6 +863,8 @@ class NetworkManager(manager.Manager):
# NOTE(vish) This db query could be removed if we pass az and name
# (or the whole instance object).
instance = instance_obj.Instance.get_by_uuid(context, instance_id)
LOG.debug('Allocate fixed ip on network %s', network['uuid'],
instance=instance)
# Check the quota; can't put this in the API because we get
# called into from other places
@ -893,6 +909,8 @@ class NetworkManager(manager.Manager):
self._setup_network_on_host(context, network)
quotas.commit(context)
LOG.debug('Allocated fixed ip %s on network %s', address,
network['uuid'], instance=instance)
return address
except Exception:
@ -906,6 +924,8 @@ class NetworkManager(manager.Manager):
context, address, expected_attrs=['network'])
instance_uuid = fixed_ip_ref.instance_uuid
vif_id = fixed_ip_ref.virtual_interface_id
LOG.debug('Deallocate fixed ip %s', address,
instance_uuid=instance_uuid)
if not instance:
# NOTE(vish) This db query could be removed if we pass az and name
@ -1091,6 +1111,7 @@ class NetworkManager(manager.Manager):
if kwargs["fixed_cidr"]:
kwargs["fixed_cidr"] = netaddr.IPNetwork(kwargs["fixed_cidr"])
LOG.debug('Create network: |%s|', kwargs)
return self._do_create_networks(context, **kwargs)
def _do_create_networks(self, context,
@ -1246,6 +1267,7 @@ class NetworkManager(manager.Manager):
network = network_obj.Network.get_by_uuid(elevated, uuid)
elif fixed_range:
network = network_obj.Network.get_by_cidr(elevated, fixed_range)
LOG.debug('Delete network %s', network['uuid'])
if require_disassociated and network.project_id is not None:
raise ValueError(_('Network must be disassociated from project %s'
@ -1303,6 +1325,7 @@ class NetworkManager(manager.Manager):
instance = instance_obj.Instance.get_by_id(context, instance_id)
vifs = vif_obj.VirtualInterfaceList.get_by_instance_uuid(context,
instance['uuid'])
LOG.debug('Setup networks on host', instance=instance)
for vif in vifs:
network = network_obj.Network.get_by_id(context, vif.network_id)
if not network.multi_host:
@ -1344,6 +1367,7 @@ class NetworkManager(manager.Manager):
"""check if the networks exists and host
is set to each network.
"""
LOG.debug('Validate networks')
if networks is None or len(networks) == 0:
return
@ -1384,6 +1408,8 @@ class NetworkManager(manager.Manager):
# NOTE(vish): This is no longer used but can't be removed until
# we major version the network_rpcapi to 2.0.
instance = instance_obj.Instance.get_by_id(context, instance_id)
LOG.debug('Get VIFs for instance', instance=instance)
# NOTE(russellb) No need to object-ify this since
# get_vifs_by_instance() is unused and set to be removed.
vifs = vif_obj.VirtualInterfaceList.get_by_instance_uuid(context,
@ -1398,6 +1424,7 @@ class NetworkManager(manager.Manager):
"""Returns the instance id a floating ip's fixed ip is allocated to."""
# NOTE(vish): This is no longer used but can't be removed until
# we major version the network_rpcapi to 2.0.
LOG.debug('Get instance for floating address %s', address)
fixed_ip = fixed_ip_obj.FixedIP.get_by_floating_address(context,
address)
if fixed_ip is None:
@ -1463,6 +1490,7 @@ class NetworkManager(manager.Manager):
if CONF.fake_network:
return
LOG.debug('Update DNS for network ids: %s', network_ids)
networks = [network for network in
network_obj.NetworkList.get_by_host(context, self.host)
if network.multi_host and network.id in network_ids]
@ -1732,6 +1760,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
standalone service.
"""
LOG.debug('Setup network on host %s', self.host)
ctxt = context.get_admin_context()
networks = network_obj.NetworkList.get_by_host(ctxt, self.host)
@ -1746,6 +1775,8 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
def allocate_fixed_ip(self, context, instance_id, network, **kwargs):
"""Gets a fixed ip from the pool."""
LOG.debug('Allocate fixed ip on network %s', network['uuid'],
instance_uuid=instance_id)
if kwargs.get('vpn', None):
address = network['vpn_private_address']
fip = fixed_ip_obj.FixedIP.associate(context, str(address),
@ -1787,10 +1818,13 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
self.instance_dns_domain)
self._setup_network_on_host(context, network)
LOG.debug('Allocated fixed ip %s on network %s', address,
network['uuid'], instance=instance)
return address
def add_network_to_project(self, context, project_id, network_uuid=None):
"""Force adds another network to a project."""
LOG.debug('Add network %s to project %s', network_uuid, project_id)
if network_uuid is not None:
network_id = self.get_network(context, network_uuid).id
else:
@ -1802,6 +1836,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
"""Associate or disassociate host or project to network."""
# NOTE(vish): This is no longer used but can't be removed until
# we major version the network_rpcapi to 2.0.
LOG.debug('Associate network %s: |%s|', network_uuid, associations)
network = self.get_network(context, network_uuid)
network_id = network.id
if 'host' in associations:
@ -1872,6 +1907,7 @@ class VlanManager(RPCAllocateFixedIP, floating_ips.FloatingIP, NetworkManager):
kwargs['bridge_interface'] = (kwargs.get('bridge_interface') or
CONF.vlan_interface)
LOG.debug('Create network: |%s|', kwargs)
return NetworkManager.create_networks(
self, context, vpn=True, **kwargs)

View File

@ -642,12 +642,13 @@ class FlatNetworkTestCase(test.TestCase):
def test_allocate_calculates_quota_auth(self, util_method, reserve,
get_by_uuid):
inst = instance_obj.Instance()
inst['uuid'] = 'nosuch'
get_by_uuid.return_value = inst
reserve.side_effect = exception.OverQuota(overs='testing')
util_method.return_value = ('foo', 'bar')
self.assertRaises(exception.FixedIpLimitExceeded,
self.network.allocate_fixed_ip,
self.context, 123, None)
self.context, 123, {'uuid': 'nosuch'})
util_method.assert_called_once_with(self.context, inst)
@mock.patch('nova.objects.fixed_ip.FixedIP.get_by_address')
@ -678,7 +679,7 @@ class FlatNetworkTestCase(test.TestCase):
self.assertRaises(test.TestingException,
self.network.allocate_fixed_ip,
self.context, instance.uuid,
{'cidr': '24', 'id': 1},
{'cidr': '24', 'id': 1, 'uuid': 'nosuch'},
address=netaddr.IPAddress('1.2.3.4'))
mock_associate.assert_called_once_with(self.context,
'1.2.3.4',
@ -840,7 +841,7 @@ class VlanNetworkTestCase(test.TestCase):
self.assertRaises(test.TestingException,
self.network.allocate_fixed_ip,
self.context, instance.uuid,
{'cidr': '24', 'id': 1},
{'cidr': '24', 'id': 1, 'uuid': 'nosuch'},
address=netaddr.IPAddress('1.2.3.4'))
mock_associate.assert_called_once_with(self.context,
'1.2.3.4',
@ -858,7 +859,7 @@ class VlanNetworkTestCase(test.TestCase):
self.assertRaises(test.TestingException,
self.network.allocate_fixed_ip,
self.context, instance.uuid,
{'cidr': '24', 'id': 1,
{'cidr': '24', 'id': 1, 'uuid': 'nosuch',
'vpn_private_address': netaddr.IPAddress('1.2.3.4')
}, vpn=1)
mock_associate.assert_called_once_with(self.context,