summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrey Morris <treyemorris@gmail.com>2012-02-13 18:33:18 -0600
committerTrey Morris <treyemorris@gmail.com>2012-02-15 17:45:51 -0600
commit3e1cff368a6445ea3ae176dcab6fd485c9280ad0 (patch)
tree00d0fca444634f8da43c0e49dd1d465210b50ed0
parentf69b0923b8a81bad075d1972cd342d4d018f8170 (diff)
misc networking fixes
o fixed dns bug where dns was gotten from the wrong subnet o project_id passed to get_instance_nw_info for when context.project_id is null o removed line breaks around quantum client request to improve readability o project_id passed into vif creation instead of using context o exception handling around get_attached_ports in quantum connection o updated object id generation to start with 1 in network_fake o updated the fake subnets returned in the network_fake o added proper v6 address generation to network_fake o improved get_instance_nw_info test o update api.openstack.compute.test_servers around improved network fake Change-Id: I74d0a9dbfcbd38e2fbc7d7fefc2587e578980b6e
-rw-r--r--nova/compute/utils.py2
-rw-r--r--nova/network/api.py3
-rw-r--r--nova/network/manager.py7
-rw-r--r--nova/network/quantum/client.py2
-rw-r--r--nova/network/quantum/manager.py23
-rw-r--r--nova/network/quantum/quantum_connection.py17
-rw-r--r--nova/tests/api/openstack/compute/test_servers.py82
-rw-r--r--nova/tests/fake_network.py37
-rw-r--r--nova/tests/test_network.py43
-rw-r--r--nova/tests/test_quantum.py3
10 files changed, 121 insertions, 98 deletions
diff --git a/nova/compute/utils.py b/nova/compute/utils.py
index 1358160e8..1ecc1c217 100644
--- a/nova/compute/utils.py
+++ b/nova/compute/utils.py
@@ -168,7 +168,7 @@ def legacy_network_info(network_model):
mac=vif['address'],
vif_uuid=vif['id'],
rxtx_cap=get_meta(network, 'rxtx_cap', 0),
- dns=[get_ip(ip) for ip in subnet['dns']],
+ dns=[get_ip(ip) for ip in subnet_v4['dns']],
ips=[fixed_ip_dict(ip, subnet)
for subnet in v4_subnets
for ip in subnet['ips']],
diff --git a/nova/network/api.py b/nova/network/api.py
index 9326c4ee8..babffc09f 100644
--- a/nova/network/api.py
+++ b/nova/network/api.py
@@ -202,7 +202,8 @@ class API(base.Base):
args = {'instance_id': instance['id'],
'instance_uuid': instance['uuid'],
'rxtx_factor': instance['instance_type']['rxtx_factor'],
- 'host': instance['host']}
+ 'host': instance['host'],
+ 'project_id': instance['project_id']}
try:
nw_info = rpc.call(context, FLAGS.network_topic,
{'method': 'get_instance_nw_info',
diff --git a/nova/network/manager.py b/nova/network/manager.py
index a8d5593d9..760aff0b9 100644
--- a/nova/network/manager.py
+++ b/nova/network/manager.py
@@ -857,11 +857,14 @@ class NetworkManager(manager.SchedulerDependentManager):
requested_networks = kwargs.get('requested_networks')
vpn = kwargs['vpn']
admin_context = context.elevated()
- LOG.debug(_("network allocations for instance %s"), instance_id,
+ LOG.debug(_("network allocations for instance |%s|"), instance_id,
context=context)
networks = self._get_networks_for_instance(admin_context,
instance_id, project_id,
requested_networks=requested_networks)
+ msg = _('networks retrieved for instance |%(instance_id)s|: '
+ '|%(networks)s|')
+ LOG.debug(msg, locals(), context=context)
self._allocate_mac_addresses(context, instance_id, networks)
self._allocate_fixed_ips(admin_context, instance_id,
host, networks, vpn=vpn,
@@ -894,7 +897,7 @@ class NetworkManager(manager.SchedulerDependentManager):
@wrap_check_policy
def get_instance_nw_info(self, context, instance_id, instance_uuid,
- rxtx_factor, host):
+ rxtx_factor, host, **kwargs):
"""Creates network info list for instance.
called by allocate_for_instance and network_api
diff --git a/nova/network/quantum/client.py b/nova/network/quantum/client.py
index f67b6feb8..1f7a70c66 100644
--- a/nova/network/quantum/client.py
+++ b/nova/network/quantum/client.py
@@ -177,7 +177,7 @@ class Client(object):
if self.logger:
self.logger.debug(
- _("Quantum Client Request:\n%(method)s %(action)s\n" %
+ _("Quantum Client Request: %(method)s %(action)s" %
locals()))
if body:
self.logger.debug(body)
diff --git a/nova/network/quantum/manager.py b/nova/network/quantum/manager.py
index 267c70b8c..1bff7c7ac 100644
--- a/nova/network/quantum/manager.py
+++ b/nova/network/quantum/manager.py
@@ -327,7 +327,8 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
# network ID and it is not nullable
vif_rec = self.add_virtual_interface(context,
instance_id,
- network_ref['id'])
+ network_ref['id'],
+ project_id)
# talk to Quantum API to create and attach port.
instance = db.instance_get(context, instance_id)
@@ -357,7 +358,8 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
vif_rec, net_tenant_id)
return self.get_instance_nw_info(context, instance_id,
instance['uuid'],
- rxtx_factor, host)
+ rxtx_factor, host,
+ project_id=project_id)
@utils.synchronized('quantum-enable-dhcp')
def enable_dhcp(self, context, quantum_net_id, network_ref, vif_rec,
@@ -415,17 +417,19 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
self.driver.update_dhcp_hostfile_with_text(interface_id, hosts)
self.driver.restart_dhcp(context, interface_id, network_ref)
- def add_virtual_interface(self, context, instance_id, network_id):
+ def add_virtual_interface(self, context, instance_id, network_id,
+ net_tenant_id):
# If we're not using melange, use the default means...
if FLAGS.use_melange_mac_generation:
return self._add_virtual_interface(context, instance_id,
- network_id)
+ network_id, net_tenant_id)
return super(QuantumManager, self).add_virtual_interface(context,
instance_id,
network_id)
- def _add_virtual_interface(self, context, instance_id, network_id):
+ def _add_virtual_interface(self, context, instance_id, network_id,
+ net_tenant_id):
vif = {'instance_id': instance_id,
'network_id': network_id,
'uuid': str(utils.gen_uuid())}
@@ -437,12 +441,12 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
m_ipam = melange_ipam_lib.get_ipam_lib(self)
vif['address'] = m_ipam.create_vif(vif['uuid'],
vif['instance_id'],
- context.project_id)
+ net_tenant_id)
return self.db.virtual_interface_create(context, vif)
def get_instance_nw_info(self, context, instance_id, instance_uuid,
- rxtx_factor, host):
+ rxtx_factor, host, **kwargs):
"""This method is used by compute to fetch all network data
that should be used when creating the VM.
@@ -455,8 +459,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
Ideally this 'interface' will be more formally defined
in the future.
"""
- admin_context = context.elevated()
- project_id = context.project_id
+ project_id = kwargs['project_id']
vifs = db.virtual_interface_get_by_instance(context, instance_id)
net_tenant_dict = dict((net_id, tenant_id)
@@ -466,7 +469,7 @@ class QuantumManager(manager.FloatingIP, manager.FlatManager):
networks = {}
for vif in vifs:
if vif.get('network_id') is not None:
- network = db.network_get(admin_context, vif['network_id'])
+ network = db.network_get(context.elevated(), vif['network_id'])
net_tenant_id = net_tenant_dict[network['uuid']]
if net_tenant_id is None:
net_tenant_id = FLAGS.quantum_default_tenant_id
diff --git a/nova/network/quantum/quantum_connection.py b/nova/network/quantum/quantum_connection.py
index ad14d932c..487a53af2 100644
--- a/nova/network/quantum/quantum_connection.py
+++ b/nova/network/quantum/quantum_connection.py
@@ -141,12 +141,15 @@ class QuantumClientConnection(object):
rv = []
port_list = self.client.list_ports(network_id, tenant=tenant_id)
for p in port_list["ports"]:
- port_id = p["id"]
- port = self.client.show_port_attachment(network_id,
+ try:
+ port_id = p["id"]
+ port = self.client.show_port_attachment(network_id,
port_id, tenant=tenant_id)
- # Skip ports without an attachment
- if "id" not in port["attachment"]:
- continue
- rv.append({'port-id': port_id, 'attachment':
- port["attachment"]["id"]})
+ # Skip ports without an attachment
+ if "id" not in port["attachment"]:
+ continue
+ rv.append({'port-id': port_id,
+ 'attachment': port["attachment"]["id"]})
+ except quantum_client.QuantumNotFoundException:
+ pass
return rv
diff --git a/nova/tests/api/openstack/compute/test_servers.py b/nova/tests/api/openstack/compute/test_servers.py
index a9ec67b22..3540a006c 100644
--- a/nova/tests/api/openstack/compute/test_servers.py
+++ b/nova/tests/api/openstack/compute/test_servers.py
@@ -281,9 +281,9 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {
@@ -349,9 +349,9 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {
@@ -420,9 +420,9 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {
@@ -490,9 +490,9 @@ class ServersControllerTest(test.TestCase):
expected = {
'addresses': {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
}
@@ -562,9 +562,9 @@ class ServersControllerTest(test.TestCase):
expected = {
'addresses': {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'},
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'},
{'version': 4, 'addr': '10.10.10.100'},
],
},
@@ -583,14 +583,14 @@ class ServersControllerTest(test.TestCase):
floaters)
self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
- url = '/v2/fake/servers/%s/ips/test0' % FAKE_UUID
+ url = '/v2/fake/servers/%s/ips/test1' % FAKE_UUID
req = fakes.HTTPRequest.blank(url)
- res_dict = self.ips_controller.show(req, FAKE_UUID, 'test0')
+ res_dict = self.ips_controller.show(req, FAKE_UUID, 'test1')
expected = {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
}
self.assertDictMatch(res_dict, expected)
@@ -2864,9 +2864,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -2933,9 +2933,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -3010,9 +3010,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -3074,9 +3074,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -3136,9 +3136,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -3200,9 +3200,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {},
@@ -3268,9 +3268,9 @@ class ServersViewBuilderTest(test.TestCase):
],
},
"addresses": {
- 'test0': [
- {'version': 4, 'addr': '192.168.0.100'},
- {'version': 6, 'addr': 'fe80::dcad:beff:feef:1'}
+ 'test1': [
+ {'version': 4, 'addr': '192.168.1.100'},
+ {'version': 6, 'addr': '2001:db8:0:1::1'}
]
},
"metadata": {"Open": "Stack"},
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py
index 86167520c..3eccf9703 100644
--- a/nova/tests/fake_network.py
+++ b/nova/tests/fake_network.py
@@ -187,7 +187,7 @@ def fake_network(network_id, ipv6=None):
def vifs(n):
- for x in xrange(n):
+ for x in xrange(1, n + 1):
yield {'id': x,
'address': 'DE:AD:BE:EF:00:%02x' % x,
'uuid': '00000000-0000-0000-0000-00000000000000%02d' % x,
@@ -196,12 +196,12 @@ def vifs(n):
def floating_ip_ids():
- for i in xrange(99):
+ for i in xrange(1, 100):
yield i
def fixed_ip_ids():
- for i in xrange(99):
+ for i in xrange(1, 100):
yield i
@@ -215,8 +215,8 @@ def next_fixed_ip(network_id, num_floating_ips=0):
for i in xrange(num_floating_ips)]
return {'id': next_id,
'network_id': network_id,
- 'address': '192.168.%d.1%02d' % (network_id, next_id),
- 'instance_id': 0,
+ 'address': '192.168.%d.%03d' % (network_id, (next_id + 99)),
+ 'instance_id': 1,
'allocated': False,
# and since network_id and vif_id happen to be equivalent
'virtual_interface_id': network_id,
@@ -226,7 +226,7 @@ def next_fixed_ip(network_id, num_floating_ips=0):
def next_floating_ip(fixed_ip_id):
next_id = floating_ip_id.next()
return {'id': next_id,
- 'address': '10.10.10.1%02d' % next_id,
+ 'address': '10.10.10.%03d' % (next_id + 99),
'fixed_ip_id': fixed_ip_id,
'project_id': None,
'auto_assigned': False}
@@ -259,12 +259,13 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
fixed_ip_id = fixed_ip_ids()
fixed_ips = []
- networks = [fake_network(x) for x in xrange(num_networks)]
+ networks = [fake_network(x) for x in xrange(1, num_networks + 1)]
def fixed_ips_fake(*args, **kwargs):
global fixed_ips
ips = [next_fixed_ip(i, floating_ips_per_fixed_ip)
- for i in xrange(num_networks) for j in xrange(ips_per_vif)]
+ for i in xrange(1, num_networks + 1)
+ for j in xrange(ips_per_vif)]
fixed_ips = ips
return ips
@@ -274,6 +275,10 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
return ip['floating_ips']
return []
+ def fixed_ips_v6_fake():
+ return ['2001:db8:0:%x::1' % i
+ for i in xrange(1, num_networks + 1)]
+
def virtual_interfaces_fake(*args, **kwargs):
return [vif for vif in vifs(num_networks)]
@@ -296,14 +301,15 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
def get_subnets_by_net_id(self, context, project_id, network_uuid,
vif_uuid):
+ i = int(network_uuid[-2:])
subnet_v4 = dict(
- cidr='192.168.0.0/24',
- dns1='1.2.3.4',
- dns2='2.3.4.5',
- gateway='192.168.0.1')
+ cidr='192.168.%d.0/24' % i,
+ dns1='192.168.%d.3' % i,
+ dns2='192.168.%d.4' % i,
+ gateway='192.168.%d.1' % i)
subnet_v6 = dict(
- cidr='fe80::/64',
+ cidr='2001:db8:0:%x::/64' % i,
gateway='fe80::def')
return [subnet_v4, subnet_v6]
@@ -317,6 +323,9 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
ips = fixed_ips_fake(*args, **kwargs)
return [ip['address'] for ip in ips]
+ def get_v6_fake(*args, **kwargs):
+ return fixed_ips_v6_fake()
+
stubs.Set(db, 'fixed_ip_get_by_instance', fixed_ips_fake)
stubs.Set(db, 'floating_ip_get_by_fixed_address', floating_ips_fake)
stubs.Set(db, 'virtual_interface_get_by_uuid', vif_by_uuid_fake)
@@ -329,6 +338,8 @@ def fake_get_instance_nw_info(stubs, num_networks=1, ips_per_vif=2,
get_subnets_by_net_id)
stubs.Set(nova_ipam_lib.QuantumNovaIPAMLib, 'get_v4_ips_by_interface',
get_v4_fake)
+ stubs.Set(nova_ipam_lib.QuantumNovaIPAMLib, 'get_v6_ips_by_interface',
+ get_v6_fake)
class FakeContext(nova.context.RequestContext):
def is_admin(self):
diff --git a/nova/tests/test_network.py b/nova/tests/test_network.py
index 9e313ae5c..c41a7a9e8 100644
--- a/nova/tests/test_network.py
+++ b/nova/tests/test_network.py
@@ -146,45 +146,46 @@ class FlatNetworkTestCase(test.TestCase):
nw_info = fake_get_instance_nw_info(self.stubs, 1, 2)
for i, (nw, info) in enumerate(nw_info):
- check = {'bridge': 'fake_br%d' % i,
- 'cidr': '192.168.%s.0/24' % i,
- 'cidr_v6': 'DONTCARE',
- 'id': 'DONTCARE',
+ nid = i + 1
+ check = {'bridge': 'fake_br%d' % nid,
+ 'cidr': '192.168.%s.0/24' % nid,
+ 'cidr_v6': '2001:db8:0:%x::/64' % nid,
+ 'id': '00000000-0000-0000-0000-00000000000000%02d' % nid,
'multi_host': False,
'injected': False,
- 'bridge_interface': 'DONTCARE',
+ 'bridge_interface': None,
'vlan': None}
self.assertDictMatch(nw, check)
- check = {'broadcast': '192.168.%d.255' % i,
- 'dhcp_server': '192.168.%d.1' % i,
- 'dns': 'DONTCARE',
- 'gateway': '192.168.%d.1' % i,
- 'gateway_v6': 'DONTCARE',
+ check = {'broadcast': '192.168.%d.255' % nid,
+ 'dhcp_server': '192.168.%d.1' % nid,
+ 'dns': ['192.168.%d.3' % nid, '192.168.%d.4' % nid],
+ 'gateway': '192.168.%d.1' % nid,
+ 'gateway_v6': 'fe80::def',
'ip6s': 'DONTCARE',
'ips': 'DONTCARE',
- 'label': 'test%d' % i,
- 'mac': 'DE:AD:BE:EF:00:%02x' % i,
- 'vif_uuid':
- '00000000-0000-0000-0000-00000000000000%02d' % i,
+ 'label': 'test%d' % nid,
+ 'mac': 'DE:AD:BE:EF:00:%02x' % nid,
'rxtx_cap': 0,
+ 'vif_uuid':
+ '00000000-0000-0000-0000-00000000000000%02d' % nid,
'should_create_vlan': False,
'should_create_bridge': False}
self.assertDictMatch(info, check)
check = [{'enabled': 'DONTCARE',
- 'ip': 'DONTCARE',
- 'gateway': 'DONTCARE',
- 'netmask': 64}]
+ 'ip': '2001:db8:0:1::%x' % nid,
+ 'netmask': 64,
+ 'gateway': 'fe80::def'}]
self.assertDictListMatch(info['ip6s'], check)
num_fixed_ips = len(info['ips'])
check = [{'enabled': 'DONTCARE',
- 'ip': '192.168.%d.1%02d' % (i, ip_num),
- 'gateway': 'DONTCARE',
- 'netmask': '255.255.255.0'}
- for ip_num in xrange(num_fixed_ips)]
+ 'ip': '192.168.%d.%03d' % (nid, ip_num + 99),
+ 'netmask': '255.255.255.0',
+ 'gateway': '192.168.%d.1' % nid}
+ for ip_num in xrange(1, num_fixed_ips + 1)]
self.assertDictListMatch(info['ips'], check)
def test_validate_networks(self):
diff --git a/nova/tests/test_quantum.py b/nova/tests/test_quantum.py
index cf15cc02f..7a2dc07d2 100644
--- a/nova/tests/test_quantum.py
+++ b/nova/tests/test_quantum.py
@@ -301,7 +301,8 @@ class QuantumManagerTestCase(QuantumNovaTestCase):
nw_info = self.net_man.get_instance_nw_info(ctx, instance_ref['id'],
instance_ref['uuid'],
- instance_ref['instance_type_id'], "")
+ instance_ref['instance_type_id'], "",
+ project_id=project_id)
self._check_vifs(len(nw_info))
self._validate_nw_info(nw_info, expected_labels)