diff options
author | Dan Smith <danms@us.ibm.com> | 2013-06-20 11:36:04 -0700 |
---|---|---|
committer | Dan Smith <danms@us.ibm.com> | 2013-06-26 08:03:14 -0700 |
commit | 22c46e5716291924196761aefd569511b1cc5692 (patch) | |
tree | 0f6e4ba650694f779685cd1ce9972d6a52616a86 /nova | |
parent | 8a393e4c6eaf6921f236dda3e35c16674b9723e2 (diff) | |
download | nova-22c46e5716291924196761aefd569511b1cc5692.tar.gz nova-22c46e5716291924196761aefd569511b1cc5692.tar.xz nova-22c46e5716291924196761aefd569511b1cc5692.zip |
Make fake_network tolerant of objects
This makes fake_network not break if passed an instance object or
list of instance objects.
Related to blueprint unified-object-model
Change-Id: Ic484e850966d514c758baedb46571b5296e89580
Diffstat (limited to 'nova')
-rw-r--r-- | nova/tests/fake_network.py | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/nova/tests/fake_network.py b/nova/tests/fake_network.py index 79af362bb..f4e8d3841 100644 --- a/nova/tests/fake_network.py +++ b/nova/tests/fake_network.py @@ -27,6 +27,9 @@ from nova.network import manager as network_manager from nova.network import model as network_model from nova.network import nova_ipam_lib from nova.network import rpcapi as network_rpcapi +from nova.objects import base as obj_base +from nova.objects import instance_info_cache +from nova.openstack.common import jsonutils from nova.virt.libvirt import config as libvirt_config @@ -456,7 +459,7 @@ def _get_fake_cache(): ipv6_addr = 'fe80:b33f::a8bb:ccff:fedd:eeff' info[0]['network']['subnets'].append({'cidr': 'fe80:b33f::/64', 'ips': [_ip(ipv6_addr)]}) - return info + return jsonutils.dumps(info) def _get_instances_with_cached_ips(orig_func, *args, **kwargs): @@ -464,9 +467,22 @@ def _get_instances_with_cached_ips(orig_func, *args, **kwargs): entries """ instances = orig_func(*args, **kwargs) - if isinstance(instances, list): + context = args[0] + + def _info_cache_for(instance): + info_cache = {'network_info': _get_fake_cache(), + 'instance_uuid': instance['uuid']} + if isinstance(instance, obj_base.NovaObject): + _info_cache = instance_info_cache.InstanceInfoCache() + instance_info_cache.InstanceInfoCache._from_db_object(context, + _info_cache, + info_cache) + info_cache = _info_cache + instance['info_cache'] = info_cache + + if isinstance(instances, (list, obj_base.ObjectListBase)): for instance in instances: - instance['info_cache'] = {'network_info': _get_fake_cache()} + _info_cache_for(instance) else: - instances['info_cache'] = {'network_info': _get_fake_cache()} + _info_cache_for(instances) return instances |