Preserve network order when using ConfigDrive
Pass network_info to be used by InstanceMetadata instead of fetching it by API and losing originally requested network order. This is similar to what has been done for "content" where the original data is lost after the initial call. This issue only affects the ConfigDrive code path as the original network_info is used when using file injection. HyperV and XenApi are still probably affected by the bug but unaffected by this fix. The fix is the same for these drivers. Simply pass a network_info and it will be used instead of fetching the network info by API. Change-Id: Ie673b725cb47bf491009db99f6cb1258d46b0a69 Fixes: bug #1156844
This commit is contained in:
@@ -86,7 +86,7 @@ class InstanceMetadata():
|
||||
"""Instance metadata."""
|
||||
|
||||
def __init__(self, instance, address=None, content=None, extra_md=None,
|
||||
conductor_api=None):
|
||||
conductor_api=None, network_info=None):
|
||||
"""Creation of this object should basically cover all time consuming
|
||||
collection. Methods after that should not cause time delays due to
|
||||
network operations or lengthy cpu operations.
|
||||
@@ -139,7 +139,8 @@ class InstanceMetadata():
|
||||
self.files = []
|
||||
|
||||
# get network info, and the rendered network template
|
||||
network_info = network.API().get_instance_nw_info(ctxt, instance,
|
||||
if network_info is None:
|
||||
network_info = network.API().get_instance_nw_info(ctxt, instance,
|
||||
conductor_api=capi)
|
||||
|
||||
self.network_config = None
|
||||
|
||||
@@ -30,6 +30,7 @@ try:
|
||||
except ImportError:
|
||||
import pickle
|
||||
|
||||
import mox
|
||||
from oslo.config import cfg
|
||||
import webob
|
||||
|
||||
@@ -46,6 +47,7 @@ from nova.network import api as network_api
|
||||
from nova import test
|
||||
from nova.tests import fake_network
|
||||
from nova import utils
|
||||
from nova.virt import netutils
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -271,6 +273,34 @@ class MetadataTestCase(test.TestCase):
|
||||
|
||||
self.assertTrue(md._check_version('2009-04-04', '2009-04-04'))
|
||||
|
||||
def test_InstanceMetadata_uses_passed_network_info(self):
|
||||
network_info = {"a": "b"}
|
||||
|
||||
self.mox.StubOutWithMock(netutils, "get_injected_network_template")
|
||||
netutils.get_injected_network_template(network_info).AndReturn(False)
|
||||
self.mox.ReplayAll()
|
||||
|
||||
base.InstanceMetadata(INSTANCES[0], network_info=network_info)
|
||||
|
||||
def test_InstanceMetadata_queries_network_API_when_needed(self):
|
||||
network_info_from_api = {"c": "d"}
|
||||
|
||||
self.mox.StubOutWithMock(network_api.API, "get_instance_nw_info")
|
||||
|
||||
network_api.API.get_instance_nw_info(
|
||||
mox.IgnoreArg(),
|
||||
mox.IgnoreArg(),
|
||||
conductor_api=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(INSTANCES[0])
|
||||
|
||||
|
||||
class OpenStackMetadataTestCase(test.TestCase):
|
||||
def setUp(self):
|
||||
|
||||
@@ -1918,7 +1918,7 @@ class LibvirtDriver(driver.ComputeDriver):
|
||||
extra_md['admin_pass'] = admin_pass
|
||||
|
||||
inst_md = instance_metadata.InstanceMetadata(instance,
|
||||
content=files, extra_md=extra_md)
|
||||
content=files, extra_md=extra_md, network_info=network_info)
|
||||
with configdrive.ConfigDriveBuilder(instance_md=inst_md) as cdb:
|
||||
configdrive_path = basepath(fname='disk.config')
|
||||
LOG.info(_('Creating config drive at %(path)s'),
|
||||
|
||||
Reference in New Issue
Block a user