Subject: Fix generate_target once more From: Martin Kletzander mkletzan@redhat.com Mon Feb 17 16:41:02 2014 +0100 Date: Tue Feb 18 08:14:32 2014 +0100: Git: 55d5b35e504f1e6c21fbd24f5b351ed4ab4c603f Passing a zero to the generate_target() function's as pref_ctrl parameter makes the 'if pref_ctrl' conditions obviously false. Also the range created was starting from 0 and not from 1. Apart from fixing this, also fix tests so they actually test something this time. Signed-off-by: Martin Kletzander diff --git a/tests/xmlconfig.py b/tests/xmlconfig.py index 9db51cb..5d08ca0 100644 --- a/tests/xmlconfig.py +++ b/tests/xmlconfig.py @@ -1045,7 +1045,8 @@ class TestXMLConfig(unittest.TestCase): self.assertEquals("hdc", disk.generate_target(["hdb", "sda"])) self.assertEquals("hdb", disk.generate_target(["hda", "hdd"])) - disk.bus = "scsi" + disk.bus = "virtio-scsi" + self.assertEquals("sdb", disk.generate_target(["sda", "sdg", "sdi"], 0)) self.assertEquals("sdh", disk.generate_target(["sda", "sdg"], 1)) def testFedoraTreeinfo(self): diff --git a/virtinst/devicedisk.py b/virtinst/devicedisk.py index 28c55ba..6e7c6c8 100644 --- a/virtinst/devicedisk.py +++ b/virtinst/devicedisk.py @@ -925,14 +925,14 @@ class VirtualDisk(VirtualDevice): def get_target(): first_found = None - ran = range(1, maxnode + 1) - if pref_ctrl: + ran = range(maxnode) + if pref_ctrl is not None: # We assume narrow SCSI bus and libvirt assigning 7 - # (0-6, 7-13, etc.) devices per controller + # (1-7, 8-14, etc.) devices per controller ran = range(pref_ctrl * 7, (pref_ctrl + 1) * 7) for i in ran: - gen_t = prefix + self.num_to_target(i) + gen_t = prefix + self.num_to_target(i + 1) if gen_t in skip_targets: skip_targets.remove(gen_t) continue @@ -948,7 +948,7 @@ class VirtualDisk(VirtualDevice): self.target = ret return ret - if pref_ctrl: + if pref_ctrl is not None: # This basically means that we either chose full # controller or didn't add any raise ValueError(_("Controller number %d for disk of type %s has "