Auto assign volume device name during attachment
In current powervc driver code, our sync code will always set the nova instance root_device_name as None, this will break nova framework's device name auto-assign function if the device name is not provide while volume attachment. PowerVC itself will not set it's instance root_device_name from it's implemenation, for PowerVC driver, we just get the device name of the boot volume from the powervc side, and make it as the root_device_name of the nova instance. Closes-Bug: #1369577 Change-Id: I7e71573e7b83ec9f8c34cfa4f0a1736b90402a90
This commit is contained in:
parent
2b714e12e5
commit
e7c995a588
@ -359,7 +359,10 @@ class PowerVCCloudManager(manager.Manager):
|
||||
else:
|
||||
ephemeral_gb = flavor.get('ephemeral_gb')
|
||||
|
||||
root_device_name = None # Don't know what is this for.
|
||||
# need to set the root_device_name for the volume attachment auto
|
||||
# assigned device name purpose
|
||||
root_device_name = self._get_instance_root_device_name(pvc_instance,
|
||||
db_instance)
|
||||
|
||||
address4 = pvc_instance['accessIPv4']
|
||||
# Has to be a valid IP, or null
|
||||
@ -1921,3 +1924,23 @@ class PowerVCCloudManager(manager.Manager):
|
||||
nets,
|
||||
port_ids)
|
||||
LOG.info("_fix_instance_nw_info" + str(nw_info))
|
||||
|
||||
def _get_instance_root_device_name(self, pvc_instance, db_instance):
|
||||
root_device_name = '/dev/sda'
|
||||
if db_instance and db_instance.get('root_device_name'):
|
||||
LOG.info("root_device_name %s from local db"
|
||||
% db_instance.get('root_device_name'))
|
||||
return db_instance.get('root_device_name')
|
||||
if not pvc_instance:
|
||||
LOG.info("set root_device_name as default: %s " % root_device_name)
|
||||
return root_device_name
|
||||
pvc_id = pvc_instance.get('id')
|
||||
if not pvc_id:
|
||||
LOG.info("set root_device_name as default: %s " % root_device_name)
|
||||
return root_device_name
|
||||
pvc_root_device_name = self.driver.get_pvc_root_device_name(pvc_id)
|
||||
if pvc_root_device_name:
|
||||
root_device_name = pvc_root_device_name
|
||||
LOG.info("set root_device_name as powervc boot volume device "
|
||||
"name: %s " % root_device_name)
|
||||
return root_device_name
|
||||
|
@ -39,6 +39,7 @@ class PowerVCDriver(driver.ComputeDriver):
|
||||
password for the target IBM PowerVC system.
|
||||
"""
|
||||
nc = None
|
||||
cached_root_device_map = {}
|
||||
|
||||
def __init__(self, virtapi):
|
||||
self.virtapi = virtapi
|
||||
@ -1431,3 +1432,18 @@ class PowerVCDriver(driver.ComputeDriver):
|
||||
|
||||
localvolume = localvolumes[0]
|
||||
return localvolume.id
|
||||
|
||||
def get_pvc_root_device_name(self, pvc_id):
|
||||
if not self.cached_root_device_map.get(pvc_id):
|
||||
return self.cached_root_device_map.get(pvc_id)
|
||||
list_all_volumes = self._service._pvccinderclient.\
|
||||
volumes.list_all_volumes
|
||||
volume_search_opts = {'metadata': {'is_boot_volume': 'True'}}
|
||||
pvcvolumes = list_all_volumes(search_opts=volume_search_opts)
|
||||
for pvcvolume in pvcvolumes:
|
||||
pvcvolume_attachments = pvcvolume.attachments
|
||||
if len(pvcvolume_attachments) == 0:
|
||||
continue
|
||||
device_name = pvcvolume_attachments[0].get('device')
|
||||
self.cached_root_device_map[pvc_id] = device_name
|
||||
return self.cached_root_device_map.get(pvc_id)
|
||||
|
@ -54,6 +54,8 @@ class PowerVCService(object):
|
||||
from powervc.common.client import factory
|
||||
self._cinderclient = factory.\
|
||||
LOCAL.new_client(str(common_constants.SERVICE_TYPES.volume))
|
||||
self._pvccinderclient = factory.\
|
||||
POWERVC.new_client(str(common_constants.SERVICE_TYPES.volume))
|
||||
self.max_tries = CONF.powervc.volume_max_try_times
|
||||
|
||||
self.longrun_loop_interval = CONF.powervc.longrun_loop_interval
|
||||
|
@ -97,6 +97,12 @@ class TestSyncInstance(unittest.TestCase):
|
||||
flavors.save_flavor_info(dict(), self.osflavor.os_flavor)\
|
||||
.AndReturn("system_metadata")
|
||||
|
||||
self.moxer.StubOutWithMock(self.PowerVCCloudManager,
|
||||
"_get_instance_root_device_name")
|
||||
|
||||
getInsRDN = self.PowerVCCloudManager._get_instance_root_device_name
|
||||
getInsRDN(pvc_instance, None).AndReturn("/dev/sda")
|
||||
|
||||
self.moxer.ReplayAll()
|
||||
|
||||
ins, image, flavor = self.PowerVCCloudManager.\
|
||||
|
@ -76,7 +76,7 @@ class FakeOSInstance():
|
||||
"72bb2b5af241413172ad4cf38354e727ce317843ee2432c36439643c"
|
||||
self.os_instance['hostname'] = "IVT-Test17"
|
||||
self.os_instance['access_ip_v4'] = None
|
||||
self.os_instance['root_device_name'] = None
|
||||
self.os_instance['root_device_name'] = "/dev/sda"
|
||||
self.os_instance['system_metadata'] = "system_metadata"
|
||||
self.os_instance['vm_state'] = "active"
|
||||
self.os_instance['task_state'] = None
|
||||
|
Loading…
x
Reference in New Issue
Block a user