summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVishvananda Ishaya <vishvananda@gmail.com>2013-03-13 13:51:38 -0700
committerVishvananda Ishaya <vishvananda@gmail.com>2013-03-14 11:15:40 -0700
commit2d0578c539d000981e50ba0c143385974d10e2e2 (patch)
tree7d0de5fe41fe2eb62b32c43d50b39ef2f5659264
parent3d5d1f68eadff9f4a49f70c0fcb3e4462044bca4 (diff)
Add the serial to connection info for boot volumes
The serial parameter wasn't being added to volumes specified at boot time. Added tests. Also cleaned up import in test_compute to match the rest of the file. Fixes bug 1148734 Change-Id: I05a623849680c5d0bb530fba4c4e6051d3b000aa
-rwxr-xr-xnova/compute/manager.py4
-rw-r--r--nova/tests/compute/test_compute.py58
2 files changed, 59 insertions, 3 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index e19059542..942070ddc 100755
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -1,4 +1,4 @@
-# vim: tabstop=4 shiftwidth=4 softtabstop=4
+# vim: tabstop=6 shiftwidth=4 softtabstop=4
# Copyright 2010 United States Government as represented by the
# Administrator of the National Aeronautics and Space Administration.
@@ -710,6 +710,8 @@ class ComputeManager(manager.SchedulerDependentManager):
instance,
volume,
bdm['device_name'])
+ if 'serial' not in cinfo:
+ cinfo['serial'] = bdm['volume_id']
self.conductor_api.block_device_mapping_update(
context, bdm['id'],
{'connection_info': jsonutils.dumps(cinfo)})
diff --git a/nova/tests/compute/test_compute.py b/nova/tests/compute/test_compute.py
index f8c0e86f2..b9b63f2e5 100644
--- a/nova/tests/compute/test_compute.py
+++ b/nova/tests/compute/test_compute.py
@@ -56,7 +56,7 @@ from nova.openstack.common import rpc
from nova.openstack.common.rpc import common as rpc_common
from nova.openstack.common import timeutils
from nova.openstack.common import uuidutils
-import nova.policy
+from nova import policy
from nova import quota
from nova import test
from nova.tests.compute import fake_resource_tracker
@@ -238,6 +238,60 @@ class BaseTestCase(test.TestCase):
return db.security_group_create(self.context, values)
+class ComputeVolumeTestCase(BaseTestCase):
+ def setUp(self):
+ super(ComputeVolumeTestCase, self).setUp()
+ self.volume_id = 'fake'
+ self.instance = {
+ 'id': 'fake',
+ 'uuid': 'fake',
+ 'name': 'fake',
+ 'root_device_name': '/dev/vda',
+ }
+ self.stubs.Set(self.compute.volume_api, 'get', lambda *a, **kw:
+ {'id': self.volume_id})
+ self.stubs.Set(self.compute.driver, 'get_volume_connector',
+ lambda *a, **kw: None)
+ self.stubs.Set(self.compute.driver, 'attach_volume',
+ lambda *a, **kw: None)
+ self.stubs.Set(self.compute.volume_api, 'initialize_connection',
+ lambda *a, **kw: {})
+ self.stubs.Set(self.compute.volume_api, 'attach',
+ lambda *a, **kw: None)
+ self.stubs.Set(self.compute.volume_api, 'check_attach',
+ lambda *a, **kw: None)
+
+ def store_cinfo(context, *args):
+ self.cinfo = jsonutils.loads(args[-1].get('connection_info'))
+
+ self.stubs.Set(self.compute.conductor_api,
+ 'block_device_mapping_update',
+ store_cinfo)
+ self.stubs.Set(self.compute.conductor_api,
+ 'block_device_mapping_update_or_create',
+ store_cinfo)
+
+ def test_attach_volume_serial(self):
+
+ self.compute.attach_volume(self.context, self.volume_id,
+ '/dev/vdb', self.instance)
+ self.assertEqual(self.cinfo.get('serial'), self.volume_id)
+
+ def test_boot_volume_serial(self):
+ block_device_mapping = [{
+ 'id': 1,
+ 'no_device': None,
+ 'virtual_name': None,
+ 'snapshot_id': None,
+ 'volume_id': self.volume_id,
+ 'device_name': '/dev/vdb',
+ 'delete_on_termination': False,
+ }]
+ self.compute._setup_block_device_mapping(self.context, self.instance,
+ block_device_mapping)
+ self.assertEqual(self.cinfo.get('serial'), self.volume_id)
+
+
class ComputeTestCase(BaseTestCase):
def test_wrap_instance_fault(self):
inst = {"uuid": "fake_uuid"}
@@ -6883,7 +6937,7 @@ class ComputePolicyTestCase(BaseTestCase):
self.compute_api = compute.API()
def test_actions_are_prefixed(self):
- self.mox.StubOutWithMock(nova.policy, 'enforce')
+ self.mox.StubOutWithMock(policy, 'enforce')
nova.policy.enforce(self.context, 'compute:reboot', {})
self.mox.ReplayAll()
compute_api.check_policy(self.context, 'reboot', {})