Skip to contentSkip to conversation

KVM test: make_qemu_command(): catch IndexError when accessing self.netdev_id

PATCH New Michael Goldish 1 participant 1 message Dec 28, 2010 KVM

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 KVM test: make_qemu_command(): catch IndexError when accessing self.netdev_id

make_qemu_command() is sometimes called to see if a VM needs to be restarted using a different qemu command line. When it's called with more NICs than the VM currently has, accessing self.netdev_id can raise an IndexError.

Changes from v1:
- Fix rebase error (omitted netdev_extra_params).

---
 client/tests/kvm/kvm_vm.py |   10 ++++++----
 1 files changed, 6 insertions(+), 4 deletions(-)
client/tests/kvm/kvm_vm.py +6 -4
index 6aa8eb4..ebab981 100755
@@ -402,11 +402,14 @@ class VM:
         vlan = 0
         for nic_name in kvm_utils.get_sub_dict_names(params, "nics"):
             nic_params = kvm_utils.get_sub_dict(params, nic_name)
+            try:
+                netdev_id = self.netdev_id[vlan]
+            except IndexError:
+                netdev_id = None
             # Handle the '-net nic' part
             mac = self.get_mac_address(vlan)
             qemu_cmd += add_nic(help, vlan, nic_params.get("nic_model"), mac,
-                                self.netdev_id[vlan],
-                                nic_params.get("nic_extra_params"))
+                                netdev_id, nic_params.get("nic_extra_params"))
             # Handle the '-net tap' or '-net user' part
             script = nic_params.get("nic_script")
             downscript = nic_params.get("nic_downscript")
@@ -420,8 +423,7 @@ class VM:
             qemu_cmd += add_net(help, vlan, nic_params.get("nic_mode", "user"),
                                 self.get_ifname(vlan),
                                 script, downscript, tftp,
-                                nic_params.get("bootp"), redirs,
-                                self.netdev_id[vlan],
+                                nic_params.get("bootp"), redirs, netdev_id,
                                 nic_params.get("netdev_extra_params"))
             # Proceed to next NIC
             vlan += 1
Signature · 1 line
1.7.3.4