summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2011-10-27 17:55:27 +0000
committerGerrit Code Review <review@openstack.org>2011-10-27 17:55:27 +0000
commit16bacc3252b9a792159b247dcf9d2f3ebb6842ac (patch)
tree9cd8f3c556fbdd2a300baec64ff91547d50b454e
parent3f319ebe4a47843c83de2403e8fcbef3d499b657 (diff)
parent61e5b8e7da3b36db9a09f80d62ebf2e276bbe88b (diff)
downloadnova-16bacc3252b9a792159b247dcf9d2f3ebb6842ac.tar.gz
nova-16bacc3252b9a792159b247dcf9d2f3ebb6842ac.tar.xz
nova-16bacc3252b9a792159b247dcf9d2f3ebb6842ac.zip
Merge "Revert how APIs get IP address info for instances"
-rw-r--r--nova/api/ec2/cloud.py96
-rw-r--r--nova/api/openstack/common.py62
-rw-r--r--nova/compute/api.py16
-rw-r--r--nova/db/sqlalchemy/api.py24
-rw-r--r--nova/tests/api/ec2/test_cloud.py71
-rw-r--r--nova/tests/api/openstack/contrib/test_createserverext.py3
-rw-r--r--nova/tests/api/openstack/contrib/test_floating_ips.py1
-rw-r--r--nova/tests/api/openstack/contrib/test_volumes.py3
-rw-r--r--nova/tests/api/openstack/test_server_actions.py11
-rw-r--r--nova/tests/api/openstack/test_server_metadata.py4
-rw-r--r--nova/tests/api/openstack/test_servers.py448
-rw-r--r--nova/tests/test_compute.py38
-rw-r--r--nova/tests/test_metadata.py1
13 files changed, 338 insertions, 440 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index b0130a0ad..a2bd2c32f 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -238,58 +238,43 @@ class CloudController(object):
utils.runthis(_("Generating root CA: %s"), "sh", genrootca_sh_path)
os.chdir(start)
- def _get_floaters_for_fixed_ip(self, context, fixed_ip):
- """Return all floating IPs given a fixed IP"""
- return self.network_api.get_floating_ips_by_fixed_address(context,
- fixed_ip)
-
- def _get_fixed_ips_for_instance(self, context, instance):
+ def _get_ip_info_for_instance(self, context, instance):
"""Return a list of all fixed IPs for an instance"""
- ret_ips = []
- ret_ip6s = []
- nw_info = self.network_api.get_instance_nw_info(context, instance)
- for net, info in nw_info:
- if not info:
+ ip_info = dict(fixed_ips=[], fixed_ip6s=[], floating_ips=[])
+
+ fixed_ips = instance['fixed_ips']
+ for fixed_ip in fixed_ips:
+ fixed_addr = fixed_ip['address']
+ network = fixed_ip.get('network')
+ vif = fixed_ip.get('virtual_interface')
+ if not network or not vif:
+ name = instance['name']
+ ip = fixed_ip['address']
+ LOG.warn(_("Instance %(name)s has stale IP "
+ "address: %(ip)s (no network or vif)") % locals())
continue
- ips = info.get('ips', [])
- for ip in ips:
- try:
- ret_ips.append(ip['ip'])
- except KeyError:
- pass
- if FLAGS.use_ipv6:
- ip6s = info.get('ip6s', [])
- for ip6 in ip6s:
- try:
- ret_ip6s.append(ip6['ip'])
- except KeyError:
- pass
- return (ret_ips, ret_ip6s)
-
- def _get_floaters_for_instance(self, context, instance, return_all=True):
- """Return all floating IPs for an instance"""
-
- ret_floaters = []
- # only loop through ipv4 addresses
- fixed_ips = self._get_fixed_ips_for_instance(context, instance)[0]
- for ip in fixed_ips:
- floaters = self._get_floaters_for_fixed_ip(context, ip)
- # Allows a short circuit if we just need any floater.
- if floaters and not return_all:
- return floaters
- ret_floaters.extend(floaters)
- if floaters and only_one:
- return ret_floaters
- return ret_floaters
+ cidr_v6 = network.get('cidr_v6')
+ if FLAGS.use_ipv6 and cidr_v6:
+ ipv6_addr = ipv6.to_global(cidr_v6, vif['address'],
+ network['project_id'])
+ if ipv6_addr not in ip_info['fixed_ip6s']:
+ ip_info['fixed_ip6s'].append(ipv6_addr)
+
+ for floating_ip in fixed_ip.get('floating_ips', []):
+ float_addr = floating_ip['address']
+ ip_info['floating_ips'].append(float_addr)
+ ip_info['fixed_ips'].append(fixed_addr)
+ return ip_info
def _get_mpi_data(self, context, project_id):
result = {}
search_opts = {'project_id': project_id, 'deleted': False}
for instance in self.compute_api.get_all(context,
search_opts=search_opts):
+ ip_info = self._get_ip_info_for_instance(context, instance)
# only look at ipv4 addresses
- fixed_ips = self._get_fixed_ips_for_instance(context, instance)[0]
+ fixed_ips = ip_info['fixed_ips']
if fixed_ips:
line = '%s slots=%d' % (fixed_ips[0], instance['vcpus'])
key = str(instance['key_name'])
@@ -378,9 +363,9 @@ class CloudController(object):
host = instance_ref['host']
availability_zone = self._get_availability_zone_by_host(ctxt, host)
- floaters = self._get_floaters_for_instance(ctxt, instance_ref,
- return_all=False)
- floating_ip = floaters and floaters[0] or ''
+ ip_info = self._get_ip_info_for_instance(ctxt, instance_ref)
+ floating_ips = ip_info['floating_ips']
+ floating_ip = floating_ips and floating_ips[0] or ''
ec2_id = ec2utils.id_to_ec2_id(instance_ref['id'])
image_ec2_id = self.image_ec2_id(instance_ref['image_ref'])
@@ -1309,20 +1294,13 @@ class CloudController(object):
fixed_ip = None
floating_ip = None
- (fixed_ips, fixed_ip6s) = self._get_fixed_ips_for_instance(context,
- instance)
- if fixed_ips:
- fixed_ip = fixed_ips[0]
- # Now look for a floater.
- for ip in fixed_ips:
- floating_ips = self._get_floaters_for_fixed_ip(context, ip)
- # NOTE(comstud): Will it float?
- if floating_ips:
- floating_ip = floating_ips[0]
- # Got one, exit out.
- break
- if fixed_ip6s:
- i['dnsNameV6'] = fixed_ip6s[0]
+ ip_info = self._get_ip_info_for_instance(context, instance)
+ if ip_info['fixed_ips']:
+ fixed_ip = ip_info['fixed_ips'][0]
+ if ip_info['floating_ips']:
+ floating_ip = ip_info['floating_ips'][0]
+ if ip_info['fixed_ip6s']:
+ i['dnsNameV6'] = ip_info['fixed_ip6s'][0]
i['privateDnsName'] = fixed_ip
i['privateIpAddress'] = fixed_ip
i['publicDnsName'] = floating_ip
diff --git a/nova/api/openstack/common.py b/nova/api/openstack/common.py
index 45987d40e..0f3f1fff7 100644
--- a/nova/api/openstack/common.py
+++ b/nova/api/openstack/common.py
@@ -16,9 +16,10 @@
# under the License.
import functools
-from lxml import etree
import re
import urlparse
+
+from lxml import etree
import webob
from xml.dom import minidom
@@ -28,6 +29,7 @@ from nova.compute import vm_states
from nova.compute import task_states
from nova import exception
from nova import flags
+from nova import ipv6
from nova import log as logging
import nova.network
from nova import quota
@@ -293,40 +295,42 @@ def get_networks_for_instance(context, instance):
...}
"""
- network_api = nova.network.API()
-
- def _get_floats(ip):
- return network_api.get_floating_ips_by_fixed_address(context, ip)
-
def _emit_addr(ip, version):
return {'addr': ip, 'version': version}
- nw_info = network_api.get_instance_nw_info(context, instance)
-
networks = {}
- for net, info in nw_info:
- if not info:
- continue
- try:
- network = {'ips': []}
- network['floating_ips'] = []
- for ip in info['ips']:
- network['ips'].append(_emit_addr(ip['ip'], 4))
- floats = [_emit_addr(addr, 4)
- for addr in _get_floats(ip['ip'])]
- network['floating_ips'].extend(floats)
- if FLAGS.use_ipv6 and 'ip6s' in info:
- network['ips'].extend([_emit_addr(ip['ip'], 6)
- for ip in info['ip6s']])
- # NOTE(comstud): These exception checks are for lp830817
- # (Restoring them after a refactoring removed)
- except TypeError:
- raise
+ fixed_ips = instance['fixed_ips']
+ ipv6_addrs_seen = {}
+ for fixed_ip in fixed_ips:
+ fixed_addr = fixed_ip['address']
+ network = fixed_ip['network']
+ vif = fixed_ip.get('virtual_interface')
+ if not network or not vif:
+ name = instance['name']
+ ip = fixed_ip['address']
+ LOG.warn(_("Instance %(name)s has stale IP "
+ "address: %(ip)s (no network or vif)") % locals())
continue
- except KeyError:
- raise
+ label = network.get('label', None)
+ if label is None:
continue
- networks[info['label']] = network
+ if label not in networks:
+ networks[label] = {'ips': [], 'floating_ips': []}
+ nw_dict = networks[label]
+ cidr_v6 = network.get('cidr_v6')
+ if FLAGS.use_ipv6 and cidr_v6:
+ ipv6_addr = ipv6.to_global(cidr_v6, vif['address'],
+ network['project_id'])
+ # Only add same IPv6 address once. It's possible we've
+ # seen it before if there was a previous fixed_ip with
+ # same network and vif as this one
+ if not ipv6_addrs_seen.get(ipv6_addr):
+ nw_dict['ips'].append(_emit_addr(ipv6_addr, 6))
+ ipv6_addrs_seen[ipv6_addr] = True
+ nw_dict['ips'].append(_emit_addr(fixed_addr, 4))
+ for floating_ip in fixed_ip.get('floating_ips', []):
+ float_addr = floating_ip['address']
+ nw_dict['floating_ips'].append(_emit_addr(float_addr, 4))
return networks
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 57e0d9edd..8b5005e78 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -917,7 +917,11 @@ class API(base.Base):
instance = self.db.instance_get_by_uuid(context, uuid)
else:
instance = self.db.instance_get(context, instance_id)
- return dict(instance.iteritems())
+
+ inst = dict(instance.iteritems())
+ # NOTE(comstud): Doesn't get returned with iteritems
+ inst['name'] = instance['name']
+ return inst
@scheduler_api.reroute_compute("get")
def routing_get(self, context, instance_id):
@@ -986,7 +990,15 @@ class API(base.Base):
local_zone_only = search_opts.get('local_zone_only', False)
- instances = self._get_instances_by_filters(context, filters)
+ inst_models = self._get_instances_by_filters(context, filters)
+
+ # Convert the models to dictionaries
+ instances = []
+ for inst_model in inst_models:
+ instance = dict(inst_model.iteritems())
+ # NOTE(comstud): Doesn't get returned by iteritems
+ instance['name'] = inst_model['name']
+ instances.append(instance)
if local_zone_only:
return instances
diff --git a/nova/db/sqlalchemy/api.py b/nova/db/sqlalchemy/api.py
index f6a147e89..983c48145 100644
--- a/nova/db/sqlalchemy/api.py
+++ b/nova/db/sqlalchemy/api.py
@@ -1217,12 +1217,13 @@ def _build_instance_get(context, session=None):
session = get_session()
partial = session.query(models.Instance).\
- options(joinedload_all('fixed_ips.floating_ips')).\
- options(joinedload_all('fixed_ips.network')).\
- options(joinedload_all('security_groups.rules')).\
- options(joinedload('volumes')).\
- options(joinedload('metadata')).\
- options(joinedload('instance_type'))
+ options(joinedload_all('fixed_ips.floating_ips')).\
+ options(joinedload_all('fixed_ips.network')).\
+ options(joinedload_all('fixed_ips.virtual_interface')).\
+ options(joinedload_all('security_groups.rules')).\
+ options(joinedload('volumes')).\
+ options(joinedload('metadata')).\
+ options(joinedload('instance_type'))
if is_admin_context(context):
partial = partial.filter_by(deleted=can_read_deleted(context))
@@ -1287,10 +1288,13 @@ def instance_get_all_by_filters(context, filters):
session = get_session()
query_prefix = session.query(models.Instance).\
- options(joinedload('security_groups')).\
- options(joinedload('metadata')).\
- options(joinedload('instance_type')).\
- order_by(desc(models.Instance.created_at))
+ options(joinedload_all('fixed_ips.floating_ips')).\
+ options(joinedload_all('fixed_ips.network')).\
+ options(joinedload_all('fixed_ips.virtual_interface')).\
+ options(joinedload('security_groups')).\
+ options(joinedload('metadata')).\
+ options(joinedload('instance_type')).\
+ order_by(desc(models.Instance.created_at))
# Make a copy of the filters dictionary to use going forward, as we'll
# be modifying it and we shouldn't affect the caller's use of it.
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index c9cda5157..772f4dafe 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -50,13 +50,42 @@ flags.DEFINE_string('ajax_proxy_manager',
'nova.tests.api.ec2.test_cloud.AjaxProxyManager', '')
-# Fake ajax proxy service, so that an 'rpc.call' will work.
class AjaxProxyManager(manager.SchedulerDependentManager):
+ """Fake ajax proxy service, so that an 'rpc.call' will work."""
@staticmethod
def authorize_ajax_console(context, **kwargs):
return None
+def get_fake_fixed_ips():
+ vif = {'address': 'aa:bb:cc:dd:ee:ff'}
+ network = {'label': 'private',
+ 'project_id': 'fake',
+ 'cidr_v6': 'fe80:b33f::/64'}
+ floating_ips = [{'address': '1.2.3.4'},
+ {'address': '5.6.7.8'}]
+ fixed_ip1 = {'address': '192.168.0.3',
+ 'floating_ips': floating_ips,
+ 'virtual_interface': vif,
+ 'network': network}
+ fixed_ip2 = {'address': '192.168.0.4',
+ 'network': network}
+ return [fixed_ip1, fixed_ip2]
+
+
+def get_instances_with_fixed_ips(orig_func, *args, **kwargs):
+ """Kludge fixed_ips into instance(s) without having to create DB
+ entries
+ """
+ instances = orig_func(*args, **kwargs)
+ if isinstance(instances, list):
+ for instance in instances:
+ instance['fixed_ips'] = get_fake_fixed_ips()
+ else:
+ instances['fixed_ips'] = get_fake_fixed_ips()
+ return instances
+
+
class CloudTestCase(test.TestCase):
def setUp(self):
super(CloudTestCase, self).setUp()
@@ -92,6 +121,13 @@ class CloudTestCase(test.TestCase):
# ensure that operations complete
self.stubs.Set(rpc, 'cast', rpc.call)
+ def _stub_instance_get_with_fixed_ips(self, func_name):
+ orig_func = getattr(self.cloud.compute_api, func_name)
+
+ def fake_get(*args, **kwargs):
+ return get_instances_with_fixed_ips(orig_func, *args, **kwargs)
+ self.stubs.Set(self.cloud.compute_api, func_name, fake_get)
+
def _create_key(self, name):
# NOTE(vish): create depends on pool, so just call helper directly
return cloud._gen_key(self.context, self.context.user_id, name)
@@ -501,19 +537,8 @@ class CloudTestCase(test.TestCase):
"""Makes sure describe_instances works and filters results."""
self.flags(use_ipv6=True)
- def fake_get_instance_nw_info(self, context, instance):
- return [(None, {'label': 'public',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': [{'ip': 'fe80::beef'}]})]
-
- def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip):
- return ['1.2.3.4', '5.6.7.8']
-
- self.stubs.Set(network.API, 'get_instance_nw_info',
- fake_get_instance_nw_info)
- self.stubs.Set(network.API, 'get_floating_ips_by_fixed_address',
- fake_get_floating_ips_by_fixed_address)
+ self._stub_instance_get_with_fixed_ips('get_all')
+ self._stub_instance_get_with_fixed_ips('get')
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
'image_ref': 1,
@@ -550,7 +575,8 @@ class CloudTestCase(test.TestCase):
self.assertEqual(instance['dnsName'], '1.2.3.4')
self.assertEqual(instance['privateDnsName'], '192.168.0.3')
self.assertEqual(instance['privateIpAddress'], '192.168.0.3')
- self.assertEqual(instance['dnsNameV6'], 'fe80::beef')
+ self.assertEqual(instance['dnsNameV6'],
+ 'fe80:b33f::a8bb:ccff:fedd:eeff')
db.instance_destroy(self.context, inst1['id'])
db.instance_destroy(self.context, inst2['id'])
db.service_destroy(self.context, comp1['id'])
@@ -560,19 +586,8 @@ class CloudTestCase(test.TestCase):
"""Makes sure describe_instances w/ no ipv6 works."""
self.flags(use_ipv6=False)
- def fake_get_instance_nw_info(self, context, instance):
- return [(None, {'label': 'public',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': [{'ip': 'fe80::beef'}]})]
-
- def fake_get_floating_ips_by_fixed_address(self, context, fixed_ip):
- return ['1.2.3.4', '5.6.7.8']
-
- self.stubs.Set(network.API, 'get_instance_nw_info',
- fake_get_instance_nw_info)
- self.stubs.Set(network.API, 'get_floating_ips_by_fixed_address',
- fake_get_floating_ips_by_fixed_address)
+ self._stub_instance_get_with_fixed_ips('get_all')
+ self._stub_instance_get_with_fixed_ips('get')
inst1 = db.instance_create(self.context, {'reservation_id': 'a',
'image_ref': 1,
diff --git a/nova/tests/api/openstack/contrib/test_createserverext.py b/nova/tests/api/openstack/contrib/test_createserverext.py
index 3db369a84..7bc830436 100644
--- a/nova/tests/api/openstack/contrib/test_createserverext.py
+++ b/nova/tests/api/openstack/contrib/test_createserverext.py
@@ -46,6 +46,7 @@ INVALID_NETWORKS = [('invalid', 'invalid-ip-address')]
INSTANCE = {
"id": 1,
+ "name": "fake",
"display_name": "test_server",
"uuid": FAKE_UUID,
"user_id": 'fake_user_id',
@@ -55,6 +56,7 @@ INSTANCE = {
"security_groups": [{"id": 1, "name": "test"}],
"progress": 0,
"image_ref": 'http://foo.com/123',
+ "fixed_ips": [],
"instance_type": {"flavorid": '124'},
}
@@ -127,6 +129,7 @@ class CreateserverextTest(test.TestCase):
'project_id': 'fake',
'created_at': "",
'updated_at': "",
+ 'fixed_ips': [],
'progress': 0}], resv_id)
def set_admin_password(self, *args, **kwargs):
diff --git a/nova/tests/api/openstack/contrib/test_floating_ips.py b/nova/tests/api/openstack/contrib/test_floating_ips.py
index 2a2173801..e0008c3f8 100644
--- a/nova/tests/api/openstack/contrib/test_floating_ips.py
+++ b/nova/tests/api/openstack/contrib/test_floating_ips.py
@@ -89,6 +89,7 @@ def network_get_instance_nw_info(self, context, instance):
def fake_instance_get(context, instance_id):
return {
"id": 1,
+ "name": 'fake',
"user_id": 'fakeuser',
"project_id": '123'}
diff --git a/nova/tests/api/openstack/contrib/test_volumes.py b/nova/tests/api/openstack/contrib/test_volumes.py
index bac16e939..419e8be0d 100644
--- a/nova/tests/api/openstack/contrib/test_volumes.py
+++ b/nova/tests/api/openstack/contrib/test_volumes.py
@@ -47,7 +47,8 @@ def fake_compute_api_create(cls, context, instance_type, image_href, **kwargs):
'project_id': 'fake',
'created_at': datetime.datetime(2010, 10, 10, 12, 0, 0),
'updated_at': datetime.datetime(2010, 11, 11, 11, 0, 0),
- 'progress': 0
+ 'progress': 0,
+ 'fixed_ips': []
}], resv_id)
diff --git a/nova/tests/api/openstack/test_server_actions.py b/nova/tests/api/openstack/test_server_actions.py
index e5b2ba025..25bea252b 100644
--- a/nova/tests/api/openstack/test_server_actions.py
+++ b/nova/tests/api/openstack/test_server_actions.py
@@ -65,6 +65,7 @@ def stub_instance(id, metadata=None, image_ref="10", flavor_id="1",
instance = {
"id": int(id),
+ "name": str(id),
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"admin_pass": "",
@@ -102,10 +103,12 @@ def stub_instance(id, metadata=None, image_ref="10", flavor_id="1",
"progress": 0,
}
- instance["fixed_ips"] = {
- "address": '192.168.0.1',
- "floating_ips": [],
- }
+ instance["fixed_ips"] = [{"address": '192.168.0.1',
+ "network":
+ {'label': 'public', 'cidr_v6': None},
+ "virtual_interface":
+ {'address': 'aa:aa:aa:aa:aa:aa'},
+ "floating_ips": []}]
return instance
diff --git a/nova/tests/api/openstack/test_server_metadata.py b/nova/tests/api/openstack/test_server_metadata.py
index f55e25e99..1e0cba541 100644
--- a/nova/tests/api/openstack/test_server_metadata.py
+++ b/nova/tests/api/openstack/test_server_metadata.py
@@ -70,11 +70,11 @@ def stub_max_server_metadata():
def return_server(context, server_id):
- return {'id': server_id}
+ return {'id': server_id, 'name': 'fake'}
def return_server_by_uuid(context, server_uuid):
- return {'id': 1}
+ return {'id': 1, 'name': 'fake'}
def return_server_nonexistant(context, server_id):
diff --git a/nova/tests/api/openstack/test_servers.py b/nova/tests/api/openstack/test_servers.py
index 7ce34e24c..29c0f2fcc 100644
--- a/nova/tests/api/openstack/test_servers.py
+++ b/nova/tests/api/openstack/test_servers.py
@@ -80,8 +80,14 @@ def return_server_by_uuid(context, uuid):
def return_server_with_attributes(**kwargs):
- def _return_server(context, id):
- return stub_instance(id, **kwargs)
+ def _return_server(context, instance_id):
+ return stub_instance(instance_id, **kwargs)
+ return _return_server
+
+
+def return_server_with_attributes_by_uuid(**kwargs):
+ def _return_server(context, uuid):
+ return stub_instance(1, uuid=uuid, **kwargs)
return _return_server
@@ -149,11 +155,45 @@ def instance_addresses(context, instance_id):
return None
+def create_fixed_ips(project_id, publics, privates, publics_are_floating):
+ if publics is None:
+ publics = []
+ if privates is None:
+ privates = []
+
+ fixed_ips = []
+ private_vif = dict(address='aa:bb:cc:dd:ee:ff')
+ private_net = dict(label='private', project_id=project_id, cidr_v6=None)
+
+ for private in privates:
+ entry = dict(address=private, network=private_net,
+ virtual_interface=private_vif, floating_ips=[])
+ if publics_are_floating:
+ for public in publics:
+ entry['floating_ips'].append(dict(address=public))
+ # Only add them once
+ publics = []
+ fixed_ips.append(entry)
+
+ if not publics_are_floating:
+ public_vif = dict(address='ff:ee:dd:cc:bb:aa')
+ public_net = dict(label='public', project_id=project_id,
+ cidr_v6='b33f::/64')
+ for public in publics:
+ entry = dict(address=public, network=public_net,
+ virtual_interface=public_vif, floating_ips=[])
+ fixed_ips.append(entry)
+ return fixed_ips
+
+
def stub_instance(id, user_id='fake', project_id='fake', host=None,
vm_state=None, task_state=None,
reservation_id="", uuid=FAKE_UUID, image_ref="10",
flavor_id="1", name=None, key_name='',
- access_ipv4=None, access_ipv6=None, progress=0):
+ access_ipv4=None, access_ipv6=None, progress=0,
+ public_ips=None, private_ips=None,
+ public_ips_are_floating=False):
+
metadata = []
metadata.append(InstanceMetadata(key='seq', value=id))
@@ -167,12 +207,16 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
else:
key_data = ''
+ fixed_ips = create_fixed_ips(project_id, public_ips, private_ips,
+ public_ips_are_floating)
+
# ReservationID isn't sent back, hack it in there.
server_name = name or "server%s" % id
if reservation_id != "":
server_name = "reservation_%s" % (reservation_id, )
instance = {
+ "name": str(id),
"id": int(id),
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
@@ -207,7 +251,8 @@ def stub_instance(id, user_id='fake', project_id='fake', host=None,
"access_ip_v4": access_ipv4,
"access_ip_v6": access_ipv6,
"uuid": uuid,
- "progress": progress}
+ "progress": progress,
+ "fixed_ips": fixed_ips}
return instance
@@ -234,13 +279,12 @@ class ServersControllerTest(test.TestCase):
def setUp(self):
self.maxDiff = None
super(ServersControllerTest, self).setUp()
- self.flags(verbose=True)
+ self.flags(verbose=True, use_ipv6=False)
fakes.stub_out_networking(self.stubs)
fakes.stub_out_rate_limiting(self.stubs)
fakes.stub_out_key_pair_funcs(self.stubs)
fakes.stub_out_image_service(self.stubs)
fakes.stub_out_nw_api(self.stubs)
- self.stubs.Set(utils, 'gen_uuid', fake_gen_uuid)
self.stubs.Set(nova.db, 'instance_get_all_by_filters',
return_servers)
self.stubs.Set(nova.db, 'instance_get', return_server_by_id)
@@ -291,27 +335,9 @@ class ServersControllerTest(test.TestCase):
self.assertEqual(res_dict['server']['id'], FAKE_UUID)
def test_get_server_by_id(self):
+ self.flags(use_ipv6=True)
image_bookmark = "http://localhost/fake/images/10"
flavor_bookmark = "http://localhost/fake/flavors/1"
- public_ip = '192.168.0.3'
- private_ip = '172.19.0.1'
-
- nw_info = [(None, {'label': 'public',
- 'ips': [{'ip': public_ip}],
- 'ip6s': []}),
- (None, {'label': 'private',
- 'ips': [{'ip': private_ip}],
- 'ip6s': []})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
uuid = FAKE_UUID
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s' % uuid)
@@ -349,18 +375,6 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- "public": [
- {
- "version": 4,
- "addr": public_ip,
- },
- ],
- "private": [
- {
- "version": 4,
- "addr": private_ip,
- },
- ],
},
"metadata": {
"seq": "1",
@@ -384,25 +398,7 @@ class ServersControllerTest(test.TestCase):
def test_get_server_with_active_status_by_id(self):
image_bookmark = "http://localhost/fake/images/10"
flavor_bookmark = "http://localhost/fake/flavors/1"
- private_ip = "192.168.0.3"
- public_ip = "1.2.3.4"
-
- nw_info = [(None, {'label': 'public',
- 'ips': [{'ip': public_ip}],
- 'ip6s': []}),
- (None, {'label': 'private',
- 'ips': [{'ip': private_ip}],
- 'ip6s': []})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- return []
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
new_return_server = return_server_with_attributes(
vm_state=vm_states.ACTIVE, progress=100)
self.stubs.Set(nova.db, 'instance_get', new_return_server)
@@ -443,18 +439,6 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- "public": [
- {
- "version": 4,
- "addr": public_ip,
- },
- ],
- "private": [
- {
- "version": 4,
- "addr": private_ip,
- },
- ],
},
"metadata": {
"seq": "1",
@@ -480,28 +464,10 @@ class ServersControllerTest(test.TestCase):
image_bookmark = "http://localhost/fake/images/10"
flavor_id = "1"
flavor_bookmark = "http://localhost/fake/flavors/1"
- private_ip = "192.168.0.3"
- public_ip = "1.2.3.4"
-
- nw_info = [(None, {'label': 'public',
- 'ips': [{'ip': public_ip}],
- 'ip6s': []}),
- (None, {'label': 'private',
- 'ips': [{'ip': private_ip}],
- 'ip6s': []})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
- def get_floats(self, context, fixed_ip):
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
new_return_server = return_server_with_attributes(
- vm_state=vm_states.ACTIVE,
- image_ref=image_ref, flavor_id=flavor_id, progress=100)
+ vm_state=vm_states.ACTIVE, image_ref=image_ref,
+ flavor_id=flavor_id, progress=100)
self.stubs.Set(nova.db, 'instance_get', new_return_server)
uuid = FAKE_UUID
@@ -540,18 +506,6 @@ class ServersControllerTest(test.TestCase):
],
},
"addresses": {
- "public": [
- {
- "version": 4,
- "addr": public_ip,
- },
- ],
- "private": [
- {
- "version": 4,
- "addr": private_ip,
- },
- ],
},
"metadata": {
"seq": "1",
@@ -574,20 +528,27 @@ class ServersControllerTest(test.TestCase):
# NOTE(bcwaldon): lp830817
def test_get_server_by_id_malformed_networks(self):
+ def fake_instance_get(context, instance_uuid):
+ instance = return_server_by_uuid(context, instance_uuid)
+ instance['fixed_ips'] = [dict(network=None, address='1.2.3.4')]
+ return instance
- nw_info = [(None, None), (None, None)]
+ self.stubs.Set(nova.db, 'instance_get_by_uuid', fake_instance_get)
- def get_nw_info(*args, **kwargs):
- return nw_info
+ req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s' % FAKE_UUID)
+ res_dict = self.controller.show(req, FAKE_UUID)
- def get_floats(self, context, fixed_ip):
- return []
+ self.assertEqual(res_dict['server']['id'], FAKE_UUID)
+ self.assertEqual(res_dict['server']['name'], 'server1')
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
+ def test_get_server_by_id_malformed_vif(self):
+ def fake_instance_get(context, uuid):
+ instance = return_server_by_uuid(context, uuid)
+ instance['fixed_ips'] = [dict(network={'label': 'meow'},
+ address='1.2.3.4', virtual_interface=None)]
+ return instance
- self.stubs.Set(nova.db, 'instance_get', return_server_by_id)
+ self.stubs.Set(nova.db, 'instance_get_by_uuid', fake_instance_get)
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s' % FAKE_UUID)
res_dict = self.controller.show(req, FAKE_UUID)
@@ -597,24 +558,11 @@ class ServersControllerTest(test.TestCase):
def test_get_server_by_id_with_addresses(self):
self.flags(use_ipv6=True)
- nw_info = [(None, {'label': 'network_1',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': []}),
- (None, {'label': 'network_2',
- 'ips': [{'ip': '172.19.0.1'},
- {'ip': '172.19.0.2'}],
- 'ip6s': [{'ip': '2001:4860::12'}]})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
+ privates = ['192.168.0.3', '192.168.0.4']
+ publics = ['172.19.0.1', '172.19.0.2']
+ new_return_server = return_server_with_attributes(
+ public_ips=publics, private_ips=privates)
+ self.stubs.Set(nova.db, 'instance_get', new_return_server)
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s' % FAKE_UUID)
res_dict = self.controller.show(req, FAKE_UUID)
@@ -623,44 +571,25 @@ class ServersControllerTest(test.TestCase):
self.assertEqual(res_dict['server']['name'], 'server1')
addresses = res_dict['server']['addresses']
expected = {
- 'network_1': [
+ 'private': [
{'addr': '192.168.0.3', 'version': 4},
{'addr': '192.168.0.4', 'version': 4},
],
- 'network_2': [
+ 'public': [
+ {'addr': 'b33f::fdee:ddff:fecc:bbaa', 'version': 6},
{'addr': '172.19.0.1', 'version': 4},
{'addr': '172.19.0.2', 'version': 4},
- {'addr': '2001:4860::12', 'version': 6},
],
}
-
- self.assertTrue('network_1' in addresses)
- self.assertTrue('network_2' in addresses)
-
- for network in ('network_1', 'network_2'):
- for ip in expected[network]:
- self.assertTrue(ip in addresses[network])
+ self.assertDictMatch(addresses, expected)
def test_get_server_by_id_with_addresses_ipv6_disabled(self):
- self.flags(use_ipv6=False)
- nw_info = [(None, {'label': 'network_1',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': []}),
- (None, {'label': 'network_2',
- 'ips': [{'ip': '172.19.0.1'},
- {'ip': '172.19.0.2'}],
- 'ip6s': [{'ip': '2001:4860::12'}]})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
+ # ipv6 flag is off by default
+ privates = ['192.168.0.3', '192.168.0.4']
+ publics = ['172.19.0.1', '172.19.0.2']
+ new_return_server = return_server_with_attributes(
+ public_ips=publics, private_ips=privates)
+ self.stubs.Set(nova.db, 'instance_get', new_return_server)
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s' % FAKE_UUID)
res_dict = self.controller.show(req, FAKE_UUID)
@@ -669,113 +598,66 @@ class ServersControllerTest(test.TestCase):
self.assertEqual(res_dict['server']['name'], 'server1')
addresses = res_dict['server']['addresses']
expected = {
- 'network_1': [
+ 'private': [
{'addr': '192.168.0.3', 'version': 4},
{'addr': '192.168.0.4', 'version': 4},
],
- 'network_2': [
+ 'public': [
{'addr': '172.19.0.1', 'version': 4},
{'addr': '172.19.0.2', 'version': 4},
],
}
-
- self.assertTrue('network_1' in addresses)
- self.assertTrue('network_2' in addresses)
-
- for network in ('network_1', 'network_2'):
- for ip in expected[network]:
- self.assertTrue(ip['version'] != 6)
- self.assertTrue(ip in addresses[network])
+ self.assertDictMatch(addresses, expected)
def test_get_server_addresses(self):
self.flags(use_ipv6=True)
- nw_info = [(None, {'label': 'network_1',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': []}),
- (None, {'label': 'network_2',
- 'ips': [{'ip': '172.19.0.1'},
- {'ip': '172.19.0.2'}],
- 'ip6s': [{'ip': '2001:4860::12'}]})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- if fixed_ip == '172.19.0.1':
- return ['1.2.3.4']
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
+
+ privates = ['192.168.0.3', '192.168.0.4']
+ publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
+ new_return_server = return_server_with_attributes_by_uuid(
+ public_ips=publics, private_ips=privates)
+ self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s/ips' % FAKE_UUID)
res_dict = self.ips_controller.index(req, FAKE_UUID)
expected = {
'addresses': {
- 'network_1': [
+ 'private': [
{'version': 4, 'addr': '192.168.0.3'},
{'version': 4, 'addr': '192.168.0.4'},
],
- 'network_2': [
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '172.19.0.1'},
{'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
- {'version': 6, 'addr': '2001:4860::12'},
],
},
}
-
- self.assertTrue('addresses' in res_dict)
- self.assertTrue('network_1' in res_dict['addresses'])
- self.assertTrue('network_2' in res_dict['addresses'])
-
- for network in ('network_1', 'network_2'):
- for ip in expected['addresses'][network]:
- self.assertTrue(ip in res_dict['addresses'][network])
+ self.assertDictMatch(res_dict, expected)
def test_get_server_addresses_single_network(self):
self.flags(use_ipv6=True)
- nw_info = [(None, {'label': 'network_1',
- 'ips': [{'ip': '192.168.0.3'},
- {'ip': '192.168.0.4'}],
- 'ip6s': []}),
- (None, {'label': 'network_2',
- 'ips': [{'ip': '172.19.0.1'},
- {'ip': '172.19.0.2'}],
- 'ip6s': [{'ip': '2001:4860::12'}]})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- if fixed_ip == '172.19.0.1':
- return ['1.2.3.4']
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
-
- url = '/v1.1/fake/servers/%s/ips/network_2' % FAKE_UUID
+ privates = ['192.168.0.3', '192.168.0.4']
+ publics = ['172.19.0.1', '1.2.3.4', '172.19.0.2']
+ new_return_server = return_server_with_attributes_by_uuid(
+ public_ips=publics, private_ips=privates)
+ self.stubs.Set(nova.db, 'instance_get_by_uuid', new_return_server)
+
+ url = '/v1.1/fake/servers/%s/ips/public' % FAKE_UUID
req = fakes.HTTPRequest.blank(url)
- res_dict = self.ips_controller.show(req, FAKE_UUID, 'network_2')
+ res_dict = self.ips_controller.show(req, FAKE_UUID, 'public')
expected = {
- 'network_2': [
- {'version': 6, 'addr': '2001:4860::12'},
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
{'version': 4, 'addr': '172.19.0.1'},
{'version': 4, 'addr': '1.2.3.4'},
{'version': 4, 'addr': '172.19.0.2'},
],
}
-
- self.assertTrue('network_2' in res_dict)
- self.assertTrue(len(res_dict['network_2']) == 4)
- for ip in expected['network_2']:
- self.assertTrue(ip in res_dict['network_2'])
+ self.assertDictMatch(res_dict, expected)
def test_get_server_addresses_nonexistant_network(self):
url = '/v1.1/fake/servers/%s/ips/network_0' % FAKE_UUID
@@ -784,14 +666,10 @@ class ServersControllerTest(test.TestCase):
req, FAKE_UUID, 'network_0')
def test_get_server_addresses_nonexistant_server(self):
- def fake(*args, **kwargs):
- return []
-
def fake_instance_get(*args, **kwargs):
raise nova.exception.InstanceNotFound()
self.stubs.Set(nova.db, 'instance_get_by_uuid', fake_instance_get)
- self.stubs.Set(nova.network.API, 'get_instance_nw_info', fake)
server_id = str(utils.gen_uuid())
req = fakes.HTTPRequest.blank('/v1.1/fake/servers/%s/ips' % server_id)
@@ -1487,7 +1365,8 @@ class ServersControllerCreateTest(test.TestCase):
"created_at": datetime.datetime(2010, 10, 10, 12, 0, 0),
"updated_at": datetime.datetime(2010, 11, 11, 11, 0, 0),
"config_drive": self.config_drive,
- "progress": 0
+ "progress": 0,
+ "fixed_ips": []
}
self.instance_cache[instance['id']] = instance
return instance
@@ -2484,7 +2363,6 @@ class TestAddressesXMLSerialization(test.TestCase):
],
}
output = self.serializer.serialize(fixture, 'show')
- print output
has_dec = output.startswith("<?xml version='1.0' encoding='UTF-8'?>")
self.assertTrue(has_dec)
@@ -2496,7 +2374,6 @@ class TestAddressesXMLSerialization(test.TestCase):
],
}
output = self.serializer.serialize(fixture, 'show')
- print output
root = etree.XML(output)
network = fixture['network_2']
self.assertEqual(str(root.get('id')), 'network_2')
@@ -2522,7 +2399,6 @@ class TestAddressesXMLSerialization(test.TestCase):
},
}
output = self.serializer.serialize(fixture, 'index')
- print output
root = etree.XML(output)
xmlutil.validate_schema(root, 'addresses')
addresses_dict = fixture['addresses']
@@ -2605,28 +2481,14 @@ class ServersViewBuilderTest(test.TestCase):
self.uuid = self.instance['uuid']
self.view_builder = self._get_view_builder()
- public_ip = '192.168.0.3'
- private_ip = '172.19.0.1'
-
- nw_info = [(None, {'label': 'public',
- 'ips': [{'ip': public_ip}],
- 'ip6s': [{'ip': 'fe80::beef'}]}),
- (None, {'label': 'private',
- 'ips': [{'ip': private_ip}]})]
-
- def get_nw_info(*args, **kwargs):
- return nw_info
-
- def get_floats(self, context, fixed_ip):
- return []
-
- fakes.stub_out_nw_api_get_instance_nw_info(self.stubs, get_nw_info)
- fakes.stub_out_nw_api_get_floating_ips_by_fixed_address(self.stubs,
- get_floats)
-
def _get_instance(self):
created_at = datetime.datetime(2010, 10, 10, 12, 0, 0)
updated_at = datetime.datetime(2010, 11, 11, 11, 0, 0)
+
+ public_ips = ['192.168.0.3']
+ private_ips = ['172.19.0.1']
+ fixed_ips = create_fixed_ips("fake", public_ips, private_ips, False)
+
instance = {
"id": 1,
"created_at": created_at,
@@ -2662,10 +2524,9 @@ class ServersViewBuilderTest(test.TestCase):
"metadata": [],
"accessIPv4": "1.2.3.4",
"accessIPv6": "fead::1234",
- #"address": ,
- #"floating_ips": [{"address":ip} for ip in public_addresses]}
"uuid": "deadbeef-feed-edee-beef-d0ea7beefedd",
- "progress": 0}
+ "progress": 0,
+ "fixed_ips": fixed_ips}
return instance
@@ -2765,12 +2626,15 @@ class ServersViewBuilderTest(test.TestCase):
},
],
},
- "addresses": {'private': [
- {'version': 4, 'addr': '172.19.0.1'}],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'fe80::beef'}]
- },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ],
+ },
"metadata": {},
"config_drive": None,
"links": [
@@ -2827,12 +2691,15 @@ class ServersViewBuilderTest(test.TestCase):
},
],
},
- "addresses": {'private': [
- {'version': 4, 'addr': '172.19.0.1'}],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'fe80::beef'}]
- },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ],
+ },
"metadata": {},
"config_drive": None,
"links": [
@@ -2887,12 +2754,15 @@ class ServersViewBuilderTest(test.TestCase):
},
],
},
- "addresses": {'private': [
- {'version': 4, 'addr': '172.19.0.1'}],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'fe80::beef'}]
- },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ],
+ },
"metadata": {},
"config_drive": None,
"accessIPv4": "1.2.3.4",
@@ -2949,12 +2819,15 @@ class ServersViewBuilderTest(test.TestCase):
},
],
},
- "addresses": {'private': [
- {'version': 4, 'addr': '172.19.0.1'}],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'fe80::beef'}]
- },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ]
+ },
"metadata": {},
"config_drive": None,
"accessIPv4": "",
@@ -3016,12 +2889,15 @@ class ServersViewBuilderTest(test.TestCase):
},
],
},
- "addresses": {'private': [
- {'version': 4, 'addr': '172.19.0.1'}],
- 'public': [
- {'version': 4, 'addr': '192.168.0.3'},
- {'version': 6, 'addr': 'fe80::beef'}]
- },
+ "addresses": {
+ 'private': [
+ {'version': 4, 'addr': '172.19.0.1'}
+ ],
+ 'public': [
+ {'version': 6, 'addr': 'b33f::fdee:ddff:fecc:bbaa'},
+ {'version': 4, 'addr': '192.168.0.3'},
+ ]
+ },
"metadata": {
"Open": "Stack",
"Number": "1",
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index dafaea54a..7faf81602 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -950,27 +950,27 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'name': 'woo.*'})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id1 in instance_ids)
self.assertTrue(instance_id2 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'name': 'woot.*'})
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertEqual(len(instances), 1)
self.assertTrue(instance_id1 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'name': '.*oot.*'})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id1 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'name': 'n.*'})
self.assertEqual(len(instances), 1)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id3 in instance_ids)
instances = self.compute_api.get_all(c,
@@ -997,14 +997,14 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'instance_name': '.*\-\d$'})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id1 in instance_ids)
self.assertTrue(instance_id2 in instance_ids)
instances = self.compute_api.get_all(c,
search_opts={'instance_name': 'i.*2'})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id2)
+ self.assertEqual(instances[0]['id'], instance_id2)
db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2)
@@ -1035,7 +1035,7 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'ip': '.*\.1', 'name': 'not.*'})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id3)
+ self.assertEqual(instances[0]['id'], instance_id3)
# ip ends up matching any ip with a '1' in the last octet..
# so instance 1 and 3.. but name should only match #1
@@ -1043,7 +1043,7 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'ip': '.*\.1$', 'name': '^woo.*'})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id1)
+ self.assertEqual(instances[0]['id'], instance_id1)
# same as above but no match on name (name matches instance_id1
# but the ip query doesn't
@@ -1057,7 +1057,7 @@ class ComputeTestCase(test.TestCase):
'name': 'not.*',
'ip6': '^.*12.*34.*'})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id3)
+ self.assertEqual(instances[0]['id'], instance_id3)
db.instance_destroy(c, instance_id1)
db.instance_destroy(c, instance_id2)
@@ -1082,12 +1082,12 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'image': '1234'})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id1)
+ self.assertEqual(instances[0]['id'], instance_id1)
instances = self.compute_api.get_all(c,
search_opts={'image': '4567'})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id2 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
@@ -1132,12 +1132,12 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'flavor': 3})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id1)
+ self.assertEqual(instances[0]['id'], instance_id1)
instances = self.compute_api.get_all(c,
search_opts={'flavor': 1})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id2 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
@@ -1167,12 +1167,12 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'power_state': power_state.SHUTDOWN})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id1)
+ self.assertEqual(instances[0]['id'], instance_id1)
instances = self.compute_api.get_all(c,
search_opts={'power_state': power_state.RUNNING})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id2 in instance_ids)
self.assertTrue(instance_id3 in instance_ids)
@@ -1220,12 +1220,12 @@ class ComputeTestCase(test.TestCase):
instances = self.compute_api.get_all(c,
search_opts={'metadata': {'key2': 'value2'}})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id2)
+ self.assertEqual(instances[0]['id'], instance_id2)
instances = self.compute_api.get_all(c,
search_opts={'metadata': {'key3': 'value3'}})
self.assertEqual(len(instances), 2)
- instance_ids = [instance.id for instance in instances]
+ instance_ids = [instance['id'] for instance in instances]
self.assertTrue(instance_id3 in instance_ids)
self.assertTrue(instance_id4 in instance_ids)
@@ -1234,14 +1234,14 @@ class ComputeTestCase(test.TestCase):
search_opts={'metadata': {'key3': 'value3',
'key4': 'value4'}})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id4)
+ self.assertEqual(instances[0]['id'], instance_id4)
# multiple criterias as a list
instances = self.compute_api.get_all(c,
search_opts={'metadata': [{'key4': 'value4'},
{'key3': 'value3'}]})
self.assertEqual(len(instances), 1)
- self.assertEqual(instances[0].id, instance_id4)
+ self.assertEqual(instances[0]['id'], instance_id4)
db.instance_destroy(c, instance_id0)
db.instance_destroy(c, instance_id1)
diff --git a/nova/tests/test_metadata.py b/nova/tests/test_metadata.py
index e4c5af897..5aba8a545 100644
--- a/nova/tests/test_metadata.py
+++ b/nova/tests/test_metadata.py
@@ -47,6 +47,7 @@ class MetadataTestCase(test.TestCase):
def setUp(self):
super(MetadataTestCase, self).setUp()
self.instance = ({'id': 1,
+ 'name': 'fake',
'project_id': 'test',
'key_name': None,
'host': 'test',