[virt-tools-list] [virt-manager PATCH] virtinst: fix an issue of disk bus caculation

Chen Hanxiao chenhanxiao at cn.fujitsu.com
Fri Feb 21 05:21:42 UTC 2014


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 at cn.fujitsu.com>
---
 tests/xmlconfig.py     | 18 +++++++++---------
 virtinst/devicedisk.py |  5 ++++-
 2 files changed, 13 insertions(+), 10 deletions(-)

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
 
 
-- 
1.8.5.3




More information about the virt-tools-list mailing list