KVM test: make_qemu_command(): properly deal with get_mac_address() failure
PATCH 1/2 KVM test: make_qemu_command(): properly deal with get_mac_address() failure
If VM params define a new NIC that didn't previously exist, then when make_qemu_command() is called in order to see if the VM should be restarted, it attempts to get the MAC address of the new (nonexistent) NIC, and an exception is raised. This exception is expected and should be caught.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_vm.py | 5 ++++- 1 files changed, 4 insertions(+), 1 deletions(-)
client/tests/kvm/kvm_vm.py +4 -1
@@ -638,7 +638,10 @@ class VM: except IndexError: netdev_id = None # Handle the '-net nic' part - mac = vm.get_mac_address(vlan) + try: + mac = vm.get_mac_address(vlan) + except VMAddressError: + mac = None qemu_cmd += add_nic(help, vlan, nic_params.get("nic_model"), mac, netdev_id, nic_params.get("nic_extra_params")) # Handle the '-net tap' or '-net user' part
Signature · 1 line
1.7.3.4
PATCH 2/2 KVM test: kvm_vm.py: make 'nic_mac' trigger a VM restart when changed
get_mac_address() should first check if 'nic_mac' is defined and then check the address pool. This way, if 'nic_mac' is changed between tests, make_qemu_command(), which calls get_mac_address(), will reveal the change and trigger a VM restart.
Signed-off-by Michael Goldish <[email protected]>
--- client/tests/kvm/kvm_vm.py | 16 ++++++++-------- 1 files changed, 8 insertions(+), 8 deletions(-)
client/tests/kvm/kvm_vm.py +8 -8
@@ -850,15 +850,12 @@ class VM: for vlan in range(num_nics): nic_name = params.objects("nics")[vlan] nic_params = params.object_params(nic_name) - if nic_params.get("nic_mac", None): - mac = nic_params.get("nic_mac") + mac = (nic_params.get("nic_mac") or + mac_source and mac_source.get_mac_address(vlan)) + if mac: kvm_utils.set_mac_address(self.instance, vlan, mac) else: - mac = mac_source and mac_source.get_mac_address(vlan) - if mac: - kvm_utils.set_mac_address(self.instance, vlan, mac) - else: - kvm_utils.generate_mac_address(self.instance, vlan) + kvm_utils.generate_mac_address(self.instance, vlan) # Assign a PCI assignable device self.pci_assignable = None
@@ -1233,7 +1230,10 @@ class VM: @raise VMMACAddressMissingError: If no MAC address is defined for the requested NIC """ - mac = kvm_utils.get_mac_address(self.instance, nic_index) + nic_name = self.params.objects("nics")[nic_index] + nic_params = self.params.object_params(nic_name) + mac = (nic_params.get("nic_mac") or + kvm_utils.get_mac_address(self.instance, nic_index)) if not mac: raise VMMACAddressMissingError(nic_index) return mac
Signature · 1 line
1.7.3.4