summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2013-03-14 22:58:15 +0000
committerGerrit Code Review <review@openstack.org>2013-03-14 22:58:15 +0000
commita95b62b51c55541e0c856de01e78bb9f49bf73a7 (patch)
tree1f5a4f07b59d554cd44d3833547a4c0d7f5cb345
parent66a8721c4319d971ea9ca1dc0de285c195f244df (diff)
parent2d0578c539d000981e50ba0c143385974d10e2e2 (diff)
downloadnova-a95b62b51c55541e0c856de01e78bb9f49bf73a7.tar.gz
nova-a95b62b51c55541e0c856de01e78bb9f49bf73a7.tar.xz
nova-a95b62b51c55541e0c856de01e78bb9f49bf73a7.zip
Merge "Add the serial to connection info for boot volumes"
-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 0c720c4ce..ad8064041 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.
@@ -711,6 +711,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 3fdd79731..0ca9e5589 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
@@ -244,6 +244,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"}
@@ -6968,7 +7022,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', {})