Merge "libvirt: Delete the lase_device of find_disk_dev_for_disk_bus" into stable/newton

This commit is contained in:
Jenkins 2016-12-15 12:25:39 +00:00 committed by Gerrit Code Review
commit c80c8e6dbf
3 changed files with 24 additions and 38 deletions

View File

@ -124,10 +124,6 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
dev = blockinfo.find_disk_dev_for_disk_bus(mapping, 'scsi')
self.assertEqual('sdb', dev)
dev = blockinfo.find_disk_dev_for_disk_bus(mapping, 'scsi',
last_device=True)
self.assertEqual('sdz', dev)
dev = blockinfo.find_disk_dev_for_disk_bus(mapping, 'virtio')
self.assertEqual('vda', dev)
@ -164,9 +160,8 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
mapping['disk.config'] = blockinfo.get_next_disk_info(mapping,
'ide',
'cdrom',
True)
self.assertEqual({'dev': 'hdd', 'bus': 'ide', 'type': 'cdrom'},
'cdrom')
self.assertEqual({'dev': 'hda', 'bus': 'ide', 'type': 'cdrom'},
mapping['disk.config'])
def test_get_next_disk_dev_boot_index(self):
@ -262,7 +257,7 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
'disk.rescue': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
'disk': {'bus': 'virtio', 'dev': 'vdb', 'type': 'disk'},
'disk.config.rescue': {'bus': 'ide', 'dev': 'hdd',
'disk.config.rescue': {'bus': 'ide', 'dev': 'hda',
'type': 'cdrom'},
'root': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
@ -379,17 +374,17 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
"virtio", "ide",
image_meta)
# The last device is selected for this. on x86 is the last ide
# device (hdd). Since power only support scsi, the last device
# is sdz
# Pick the first drive letter on the bus that is available
# as the config drive. Delete the last device hardcode as
# the config drive here.
bus_ppc = ("scsi", "sdz")
bus_aarch64 = ("scsi", "sdz")
bus_ppc = ("scsi", "sda")
bus_aarch64 = ("scsi", "sda")
expect_bus = {"ppc": bus_ppc, "ppc64": bus_ppc,
"ppc64le": bus_ppc, "aarch64": bus_aarch64}
bus, dev = expect_bus.get(blockinfo.libvirt_utils.get_arch({}),
("ide", "hdd"))
("ide", "hda"))
expect = {
'disk': {'bus': 'virtio', 'dev': 'vda',
@ -418,13 +413,13 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
"virtio", "ide",
image_meta)
bus_ppc = ("scsi", "sdz")
bus_aarch64 = ("scsi", "sdz")
bus_ppc = ("scsi", "sda")
bus_aarch64 = ("scsi", "sda")
expect_bus = {"ppc": bus_ppc, "ppc64": bus_ppc,
"ppc64le": bus_ppc, "aarch64": bus_aarch64}
bus, dev = expect_bus.get(blockinfo.libvirt_utils.get_arch({}),
("ide", "hdd"))
("ide", "hda"))
expect = {
'disk': {'bus': 'virtio', 'dev': 'vda',
@ -454,7 +449,7 @@ class LibvirtBlockInfoTest(test.NoDBTestCase):
'disk': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
'disk.local': {'bus': 'virtio', 'dev': 'vdb', 'type': 'disk'},
'disk.config': {'bus': 'virtio', 'dev': 'vdz', 'type': 'disk'},
'disk.config': {'bus': 'virtio', 'dev': 'vdc', 'type': 'disk'},
'root': {'bus': 'virtio', 'dev': 'vda',
'type': 'disk', 'boot_index': '1'},
}

View File

@ -3344,13 +3344,13 @@ class LibvirtConnTestCase(test.NoDBTestCase):
cfg = drvr._get_guest_config(instance_ref, [],
image_meta, disk_info)
# The last device is selected for this. on x86 is the last ide
# device (hdd). Since power only support scsi, the last device
# is sdz
# Pick the first drive letter on the bus that is available
# as the config drive. Delete the last device hardcode as
# the config drive here.
expect = {"ppc": "sdz", "ppc64": "sdz",
"ppc64le": "sdz", "aarch64": "sdz"}
disk = expect.get(blockinfo.libvirt_utils.get_arch({}), "hdd")
expect = {"ppc": "sda", "ppc64": "sda",
"ppc64le": "sda", "aarch64": "sda"}
disk = expect.get(blockinfo.libvirt_utils.get_arch({}), "hda")
self.assertIsInstance(cfg.devices[2],
vconfig.LibvirtConfigGuestDisk)
self.assertEqual(cfg.devices[2].target_dev, disk)
@ -14851,7 +14851,7 @@ class LibvirtConnTestCase(test.NoDBTestCase):
mock_rbd_image.exists.return_value = False
instance = objects.Instance()
disk_mapping = {'disk.config': {'bus': 'ide',
'dev': 'hdd',
'dev': 'hda',
'type': 'file'}}
flavor = objects.Flavor(extra_specs={})

View File

@ -164,15 +164,13 @@ def get_dev_count_for_disk_bus(disk_bus):
def find_disk_dev_for_disk_bus(mapping, bus,
last_device=False,
assigned_devices=None):
"""Identify a free disk dev name for a bus.
Determines the possible disk dev names for
the bus, and then checks them in order until
it identifies one that is not yet used in the
disk mapping. If 'last_device' is set, it will
only consider the last available disk dev name.
disk mapping.
Returns the chosen disk_dev name, or raises an
exception if none is available.
@ -186,10 +184,7 @@ def find_disk_dev_for_disk_bus(mapping, bus,
assigned_devices = []
max_dev = get_dev_count_for_disk_bus(bus)
if last_device:
devs = [max_dev - 1]
else:
devs = range(max_dev)
devs = range(max_dev)
for idx in devs:
disk_dev = dev_prefix + chr(ord('a') + idx)
@ -321,7 +316,6 @@ def get_disk_bus_for_disk_dev(virt_type, disk_dev):
def get_next_disk_info(mapping, disk_bus,
device_type='disk',
last_device=False,
boot_index=None,
assigned_devices=None):
"""Determine the disk info for the next device on disk_bus.
@ -335,7 +329,6 @@ def get_next_disk_info(mapping, disk_bus,
disk_dev = find_disk_dev_for_disk_bus(mapping,
disk_bus,
last_device,
assigned_devices)
info = {'bus': disk_bus,
'dev': disk_dev,
@ -530,8 +523,7 @@ def get_disk_mapping(virt_type, instance,
device_type)
config_info = get_next_disk_info(mapping,
disk_bus,
device_type,
last_device=True)
device_type)
mapping['disk.config.rescue'] = config_info
return mapping
@ -616,8 +608,7 @@ def get_disk_mapping(virt_type, instance,
device_type)
config_info = get_next_disk_info(mapping,
disk_bus,
device_type,
last_device=True)
device_type)
mapping['disk.config'] = config_info
return mapping