virtinst: fix an issue of disk bus caculation
commit 466c2bcf9c
will generate the same index for
'hda' and 'hdaa'.
Also break test cases.
This patch will fix this.
Signed-off-by: Chen Hanxiao <chenhanxiao@cn.fujitsu.com>
This commit is contained in:
parent
2ace5317e0
commit
0dceb24b3b
|
@ -1027,15 +1027,15 @@ class TestXMLConfig(unittest.TestCase):
|
|||
self.assertEquals("zz", VirtualDisk.num_to_target(27 * 26))
|
||||
self.assertEquals("aaa", VirtualDisk.num_to_target(27 * 26 + 1))
|
||||
|
||||
self.assertEquals(VirtualDisk.target_to_num("hda"), 1)
|
||||
self.assertEquals(VirtualDisk.target_to_num("hdb"), 2)
|
||||
self.assertEquals(VirtualDisk.target_to_num("sdz"), 26)
|
||||
self.assertEquals(VirtualDisk.target_to_num("sdaa"), 27)
|
||||
self.assertEquals(VirtualDisk.target_to_num("vdab"), 28)
|
||||
self.assertEquals(VirtualDisk.target_to_num("vdaz"), 52)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdba"), 53)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdzz"), 27 * 26)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdaaa"), 27 * 26 + 1)
|
||||
self.assertEquals(VirtualDisk.target_to_num("hda"), 0)
|
||||
self.assertEquals(VirtualDisk.target_to_num("hdb"), 1)
|
||||
self.assertEquals(VirtualDisk.target_to_num("sdz"), 25)
|
||||
self.assertEquals(VirtualDisk.target_to_num("sdaa"), 26)
|
||||
self.assertEquals(VirtualDisk.target_to_num("vdab"), 27)
|
||||
self.assertEquals(VirtualDisk.target_to_num("vdaz"), 51)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdba"), 52)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdzz"), 26 * (25 + 1) + 25)
|
||||
self.assertEquals(VirtualDisk.target_to_num("xvdaaa"), 26 * 26 * 1 + 26 * 1 + 0)
|
||||
|
||||
disk = virtinst.VirtualDisk(utils.get_conn())
|
||||
disk.bus = "ide"
|
||||
|
|
|
@ -480,11 +480,14 @@ class VirtualDisk(VirtualDevice):
|
|||
Convert disk /dev number (like hda, hdb, hdaa, etc.) to an index
|
||||
"""
|
||||
num = 0
|
||||
k = 0
|
||||
if tgt[0] == 'x':
|
||||
# This case is here for 'xvda'
|
||||
tgt = tgt[1:]
|
||||
for i, c in enumerate(reversed(tgt[2:])):
|
||||
num += (ord(c) - ord('a')) * (26 ** i)
|
||||
if i != 0:
|
||||
k = 1
|
||||
num += (ord(c) - ord('a') + k) * (26 ** i)
|
||||
return num
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue