Skip to content

Commit

Permalink
Preserve network order when using ConfigDrive
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Mathieu Mitchell committed Jun 20, 2013
1 parent 3ab42d4 commit b0da1ab
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 3 deletions.
5 changes: 3 additions & 2 deletions nova/api/metadata/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -139,7 +139,8 @@ def __init__(self, instance, address=None, content=None, extra_md=None,
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
Expand Down
30 changes: 30 additions & 0 deletions nova/tests/test_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
except ImportError:
import pickle

import mox
from oslo.config import cfg
import webob

Expand All @@ -46,6 +47,7 @@
from nova import test
from nova.tests import fake_network
from nova import utils
from nova.virt import netutils

CONF = cfg.CONF

Expand Down Expand Up @@ -271,6 +273,34 @@ def test_check_version(self):

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):
Expand Down
2 changes: 1 addition & 1 deletion nova/virt/libvirt/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1918,7 +1918,7 @@ def raw(fname):
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'),
Expand Down

0 comments on commit b0da1ab

Please sign in to comment.