64 lines
2.7 KiB
Diff
64 lines
2.7 KiB
Diff
|
Subject: virtinst: fix an issue of disk bus caculation
|
||
|
From: Chen Hanxiao chenhanxiao@cn.fujitsu.com Sun Feb 23 13:31:48 2014 +0800
|
||
|
Date: Sun Feb 23 13:31:48 2014 +0800:
|
||
|
Git: 0dceb24b3ba567aad3976fe3c6af524db9e1ac6d
|
||
|
|
||
|
commit 466c2bcf9cb07f16690cb41684d67d0265d2d47e
|
||
|
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>
|
||
|
|
||
|
diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py
|
||
|
index 5d08ca0..022d278 100644
|
||
|
--- a/tests/xmlconfig.py
|
||
|
+++ b/tests/xmlconfig.py
|
||
|
@@ -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"
|
||
|
diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py
|
||
|
index 9ebcc11..2d692f1 100644
|
||
|
--- a/virtinst/devicedisk.py
|
||
|
+++ b/virtinst/devicedisk.py
|
||
|
@@ -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
|
||
|
|
||
|
|