Skip to content

Commit

Permalink
Always use bdm in instance_block_mapping on Xen
Browse files Browse the repository at this point in the history
It doesn't seem that Xen will set the 'root_device_name' property on
instances.  This is causing instance_block_mapping to return early
without evaluating the bdm before returning the list of device_names
in use.  I'm not sure why instance_block_mapping does this
(optimization?) but on Xen at least it seems that it should not.

Added a check for Xen compute_driver flag in instance_block_mapping to
"guess" the root_device_name (similarlly to what is done in
compute.utils for swap and ephemeral).

fixes bug #1061944

Change-Id: If5b1a2b7377232c78f0629a3624552ecf6ceb0ee
(cherry picked from commit 07845ad)
  • Loading branch information
clayg authored and vishvananda committed Nov 22, 2012
1 parent 1581505 commit a369303
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 13 deletions.
9 changes: 8 additions & 1 deletion nova/block_device.py
Expand Up @@ -17,6 +17,9 @@

import re

from nova import flags

FLAGS = flags.FLAGS

DEFAULT_ROOT_DEV_NAME = '/dev/sda1'
_DEFAULT_MAPPINGS = {'ami': 'sda1',
Expand Down Expand Up @@ -89,8 +92,12 @@ def strip_prefix(device_name):

def instance_block_mapping(instance, bdms):
root_device_name = instance['root_device_name']
# NOTE(clayg): remove this when xenapi is setting default_root_device
if root_device_name is None:
return _DEFAULT_MAPPINGS
if FLAGS.compute_driver.endswith('xenapi.XenAPIDriver'):
root_device_name = '/dev/xvda'
else:
return _DEFAULT_MAPPINGS

mappings = {}
mappings['ami'] = strip_dev(root_device_name)
Expand Down
40 changes: 28 additions & 12 deletions nova/tests/compute/test_compute_utils.py
Expand Up @@ -44,12 +44,21 @@ class ComputeValidateDeviceTestCase(test.TestCase):
def setUp(self):
super(ComputeValidateDeviceTestCase, self).setUp()
self.context = context.RequestContext('fake', 'fake')
self.instance = {
'uuid': 'fake',
'root_device_name': '/dev/vda',
'default_ephemeral_device': '/dev/vdb',
'instance_type_id': 'fake',
}
# check if test name includes "xen"
if 'xen' in self.id():
self.flags(compute_driver='xenapi.XenAPIDriver')
self.instance = {
'uuid': 'fake',
'root_device_name': None,
'instance_type_id': 'fake',
}
else:
self.instance = {
'uuid': 'fake',
'root_device_name': '/dev/vda',
'default_ephemeral_device': '/dev/vdb',
'instance_type_id': 'fake',
}
self.data = []

def fake_get(instance_type_id, ctxt=None):
Expand Down Expand Up @@ -150,8 +159,6 @@ def test_swap_no_ephemeral(self):
self.assertEqual(device, '/dev/vdc')

def test_ephemeral_xenapi(self):
self.flags(compute_driver='xenapi.XenAPIDriver')
del self.instance['default_ephemeral_device']
self.instance_type = {
'ephemeral_gb': 10,
'swap': 0,
Expand All @@ -162,8 +169,6 @@ def test_ephemeral_xenapi(self):
self.assertEqual(device, '/dev/xvdc')

def test_swap_xenapi(self):
self.flags(compute_driver='xenapi.XenAPIDriver')
del self.instance['default_ephemeral_device']
self.instance_type = {
'ephemeral_gb': 0,
'swap': 10,
Expand All @@ -174,8 +179,6 @@ def test_swap_xenapi(self):
self.assertEqual(device, '/dev/xvdb')

def test_swap_and_ephemeral_xenapi(self):
self.flags(compute_driver='xenapi.XenAPIDriver')
del self.instance['default_ephemeral_device']
self.instance_type = {
'ephemeral_gb': 10,
'swap': 10,
Expand All @@ -185,6 +188,19 @@ def test_swap_and_ephemeral_xenapi(self):
device = self._validate_device()
self.assertEqual(device, '/dev/xvdd')

def test_swap_and_one_attachment_xenapi(self):
self.instance_type = {
'ephemeral_gb': 0,
'swap': 10,
}
self.stubs.Set(instance_types, 'get_instance_type',
lambda instance_type_id, ctxt=None: self.instance_type)
device = self._validate_device()
self.assertEqual(device, '/dev/xvdb')
self.data.append(self._fake_bdm(device))
device = self._validate_device()
self.assertEqual(device, '/dev/xvdd')


class UsageInfoTestCase(test.TestCase):

Expand Down

0 comments on commit a369303

Please sign in to comment.