Base_VM.add_nic() doesn't add mac to address_cache,
so when we delete call BaseVM.del_nic(), it is like this:
    del self.address_cache[nic_mac]
This may lead to KeyError. But BaseVM.del_nic() only catch IndexError.
So we should catch KeyError too.

And also, we should do delete the nic in virtnet before we delete it
from address_cache, in case we occur the KeyError.

Signed-off-by: Tang Chen <[email protected]>
---
 client/virt/virt_vm.py |    4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/client/virt/virt_vm.py b/client/virt/virt_vm.py
index 534f8e3..b5d0c4c 100644
--- a/client/virt/virt_vm.py
+++ b/client/virt/virt_vm.py
@@ -537,10 +537,12 @@ class BaseVM(object):
         nic_mac = nic.mac.lower()
         self.free_mac_address(nic_index_or_name)
         try:
-            del self.address_cache[nic_mac]
             del self.virtnet[nic_index_or_name]
+            del self.address_cache[nic_mac]
         except IndexError:
             pass # continue to not exist
+        except KeyError:
+            pass # continue to not exist


     def verify_kernel_crash(self):
-- 
1.7.10.2

_______________________________________________
Autotest mailing list
[email protected]
http://test.kernel.org/cgi-bin/mailman/listinfo/autotest

Reply via email to