Revert "Fix network-api direct database hits in metadata server"
This reverts commit 79ab96e34b
.
This commit broke the Nova metadata API when using neutron.
Change-Id: I6855b03f00492fdf51e18c0dcb0a73590a71b374
Closes-bug: #1307582
This commit is contained in:
parent
7a1b8ff31d
commit
3a91554650
|
@ -29,9 +29,9 @@ from nova import block_device
|
|||
from nova.compute import flavors
|
||||
from nova import conductor
|
||||
from nova import context
|
||||
from nova import network
|
||||
from nova.objects import base as obj_base
|
||||
from nova.objects import block_device as block_device_obj
|
||||
from nova.objects import fixed_ip as fixed_ip_obj
|
||||
from nova.objects import instance as instance_obj
|
||||
from nova.objects import security_group as secgroup_obj
|
||||
from nova.openstack.common.gettextutils import _
|
||||
|
@ -118,12 +118,9 @@ class InstanceMetadata():
|
|||
|
||||
# NOTE(danms): This should be removed after bp:compute-manager-objects
|
||||
if not isinstance(instance, instance_obj.Instance):
|
||||
expected = ['metadata', 'system_metadata']
|
||||
if 'info_cache' in instance:
|
||||
expected.append('info_cache')
|
||||
instance = instance_obj.Instance._from_db_object(
|
||||
ctxt, instance_obj.Instance(), instance,
|
||||
expected_attrs=expected)
|
||||
expected_attrs=['metadata', 'system_metadata'])
|
||||
|
||||
# The default value of mimeType is set to MIME_TYPE_TEXT_PLAIN
|
||||
self.set_mimetype(MIME_TYPE_TEXT_PLAIN)
|
||||
|
@ -165,7 +162,8 @@ class InstanceMetadata():
|
|||
|
||||
# get network info, and the rendered network template
|
||||
if network_info is None:
|
||||
network_info = instance.info_cache.network_info
|
||||
network_info = network.API().get_instance_nw_info(ctxt,
|
||||
instance)
|
||||
|
||||
self.ip_info = \
|
||||
ec2utils.get_ip_info_for_instance_from_nw_info(network_info)
|
||||
|
@ -509,7 +507,7 @@ class VendorDataDriver(object):
|
|||
|
||||
def get_metadata_by_address(conductor_api, address):
|
||||
ctxt = context.get_admin_context()
|
||||
fixed_ip = fixed_ip_obj.FixedIP.get_by_address(ctxt, address)
|
||||
fixed_ip = network.API().get_fixed_ip_by_address(ctxt, address)
|
||||
|
||||
return get_metadata_by_instance_id(conductor_api,
|
||||
fixed_ip['instance_uuid'],
|
||||
|
|
|
@ -27,7 +27,7 @@ try:
|
|||
except ImportError:
|
||||
import pickle
|
||||
|
||||
import mock
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
||||
|
@ -47,7 +47,6 @@ from nova import test
|
|||
from nova.tests import fake_block_device
|
||||
from nova.tests import fake_instance
|
||||
from nova.tests import fake_network
|
||||
from nova.tests.objects import test_instance_info_cache
|
||||
from nova.tests.objects import test_security_group
|
||||
from nova.virt import netutils
|
||||
|
||||
|
@ -72,7 +71,7 @@ INSTANCE = fake_instance.fake_db_instance(**
|
|||
'vcpus': 1,
|
||||
'fixed_ips': [],
|
||||
'root_device_name': '/dev/sda1',
|
||||
'info_cache': test_instance_info_cache.fake_info_cache,
|
||||
'info_cache': {'network_info': []},
|
||||
'hostname': 'test.novadomain',
|
||||
'display_name': 'my_displayname',
|
||||
'metadata': {},
|
||||
|
@ -83,8 +82,7 @@ INSTANCE = fake_instance.fake_db_instance(**
|
|||
def fake_inst_obj(context):
|
||||
return instance_obj.Instance._from_db_object(
|
||||
context, instance_obj.Instance(), INSTANCE,
|
||||
expected_attrs=['metadata', 'system_metadata',
|
||||
'info_cache'])
|
||||
expected_attrs=['metadata', 'system_metadata'])
|
||||
|
||||
|
||||
def get_default_sys_meta():
|
||||
|
@ -309,11 +307,23 @@ class MetadataTestCase(test.TestCase):
|
|||
for (path, value) in inst_md.metadata_for_config_drive():
|
||||
self.assertIsNotNone(path)
|
||||
|
||||
@mock.patch('nova.virt.netutils.get_injected_network_template')
|
||||
def test_InstanceMetadata_queries_network_API_when_needed(self, mocked):
|
||||
inst_obj = fake_inst_obj(self.context)
|
||||
base.InstanceMetadata(inst_obj)
|
||||
mocked.assert_called_once_with(inst_obj.info_cache.network_info)
|
||||
def test_InstanceMetadata_queries_network_API_when_needed(self):
|
||||
network_info_from_api = []
|
||||
|
||||
self.mox.StubOutWithMock(network_api.API, "get_instance_nw_info")
|
||||
|
||||
network_api.API.get_instance_nw_info(
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg()).AndReturn(network_info_from_api)
|
||||
|
||||
self.mox.StubOutWithMock(netutils, "get_injected_network_template")
|
||||
|
||||
netutils.get_injected_network_template(
|
||||
network_info_from_api).AndReturn(False)
|
||||
|
||||
self.mox.ReplayAll()
|
||||
|
||||
base.InstanceMetadata(fake_inst_obj(self.context))
|
||||
|
||||
def test_local_ipv4_from_nw_info(self):
|
||||
nw_info = fake_network.fake_get_instance_nw_info(self.stubs,
|
||||
|
|
Loading…
Reference in New Issue