On 09/14/2012 12:17 AM, Yiqiao Pu wrote:
On 09/14/2012 03:44 AM, Chris Evich wrote:
On 09/13/2012 01:51 PM, Lucas Meneghel Rodrigues wrote:
From: Yiqiao Pu<[email protected]>

Make kvm_vm create vm following the parameters, not the env,
otherwise the cases runs in a queue will create vm always
follow the first case's nic configuration.

Signed-off-by: Yiqiao Pu<[email protected]>
---
client/tests/virt/virttest/kvm_vm.py | 26 +++++++++++++++++++++++---
1 file changed, 23 insertions(+), 3 deletions(-)

diff --git a/client/tests/virt/virttest/kvm_vm.py
b/client/tests/virt/virttest/kvm_vm.py
index 98dad8e..18f107c 100644
--- a/client/tests/virt/virttest/kvm_vm.py
+++ b/client/tests/virt/virttest/kvm_vm.py
@@ -904,6 +904,11 @@ class VM(virt_vm.BaseVM):
# Clone this VM using the new params
vm = self.clone(name, params, root_dir, copy_state=True)

+ # Update the virtnet with params
+ params_virtnet = utils_misc.VirtNet(params, name, self.instance)
+ if vm.virtnet != params_virtnet:
+ vm.virtnet = params_virtnet
+
qemu_binary = utils_misc.get_path(os.path.join(root_dir,
params.get("vm_type")),
params.get("qemu_binary", "qemu"))
@@ -1435,6 +1440,10 @@ class VM(virt_vm.BaseVM):
name = self.name
params = self.params
root_dir = self.root_dir
+ # Update the virtnet with params
+ params_virtnet = utils_misc.VirtNet(params, name, self.instance)
+ if self.virtnet != params_virtnet:
+ self.virtnet = params_virtnet

# Verify the md5sum of the ISO images
for cdrom in params.objects("cdroms"):
@@ -2619,11 +2628,22 @@ class VM(virt_vm.BaseVM):
"""
if (self.__make_qemu_command() !=
self.__make_qemu_command(name, params, basedir)):
- logging.debug("VM params in env don't match requested, restarting.")
- return True
+ restart = True
+ else:
+ for i, nic in enumerate(params.objects('nics')):
+ if (self.virtnet[i]['netdst'] !=
+ params.object_params('nic').get('netdst')):
+ restart = True
+ else:
+ restart = False
+
+ if restart:
+ logging.debug("VM params in env don't match requested, "
+ "restarting.")
else:
logging.debug("VM params in env do match requested, continuing.")
- return False
+
+ return restart

def pause(self):
"""

Talked with lucas on this. We believe this fix will solve the
root-problem:
https://github.com/kongove/autotest/commit/35bcae3e589a6e5fa6a48e39ea9b58e95ffd32f1#commitcomment-1851180


You're patch may work, but in my experience vm.needs_restart() is VERY
sensitive to messing with __init__ behavior. Amos's patch fixes the
core of the problem by forcing virtnet to always initialize from params.


Tried Amos's patch but find some problem as the netdst change will not
be catched by that fix. That fix only update the KVMIface related
parameters but not include ParamsNet. So It can not find the bridge
changed.

And another problem I try to fix is after we using tap fd in our command
line the command line will shows no different when only netdst changed.
This may caused problem when there is a set of cases running without
kill vm after test. So any idea about this problem?


Thanks a lot for your review.

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Here, this should help make comparing these in vm.needs_restart() much easier...

(see attached)

Now you can do "if virtnet1 == virtnet2: ..."

N.B. I didn't commit this to next since I'm not sure if it's still frozen or not.

--
Chris Evich, RHCA, RHCE, RHCDS, RHCSS
Quality Assurance Engineer
e-mail: cevich + `@' + redhat.com o: 1-888-RED-HAT1 x44214
>From f90d74d3ed4d3efc6fb130a0177b79094afaa333 Mon Sep 17 00:00:00 2001
From: Chris Evich <[email protected]>
Date: Mon, 17 Sep 2012 12:21:45 -0400
Subject: [PATCH] virt: Add comparison operator support for VirtNet
Cc: Chris Evich <[email protected]>

Signed-off-by: Chris Evich <[email protected]>
---
 client/tests/virt/virttest/utils_misc.py          |   28 +++++++++++++-
 client/tests/virt/virttest/utils_misc_unittest.py |   42 ++++++++++++++++++++-
 2 files changed, 68 insertions(+), 2 deletions(-)

diff --git a/client/tests/virt/virttest/utils_misc.py 
b/client/tests/virt/virttest/utils_misc.py
index 094a6cc..c2f81dc 100644
--- a/client/tests/virt/virttest/utils_misc.py
+++ b/client/tests/virt/virttest/utils_misc.py
@@ -424,6 +424,18 @@ class PropCan(object):
             return True
 
 
+    def __eq__(self, other):
+        for key in self.__class__.__slots__:
+            if self.has_key(key) and other.has_key(key):
+                if self[key] != other[key]:
+                    return False
+        return True
+
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+
     def keys(self):
         keylist = []
         for propertea in self.__slots__:
@@ -528,7 +540,7 @@ class VirtIface(PropCan):
 
     def __getstate__(self):
         state = {}
-        for key in VirtIface.__slots__:
+        for key in self.__class__.__slots__:
             if self.has_key(key):
                 state[key] = self[key]
         return state
@@ -1161,6 +1173,20 @@ class VirtNet(DbNet, ParamsNet):
         self._INITIALIZED = True
 
 
+    def __eq__(self, other):
+        if len(self) != len(other):
+            return False
+        # Order doesn't matter for most OS's as long as MAC & netdst match
+        for nic_name in self.nic_name_list():
+            if self[nic_name] != other[nic_name]:
+                return False
+        return True
+
+
+    def __ne__(self, other):
+        return not self.__eq__(other)
+
+
     def mac_index(self):
         """
         Generator for all allocated mac addresses (requires db lock)
diff --git a/client/tests/virt/virttest/utils_misc_unittest.py 
b/client/tests/virt/virttest/utils_misc_unittest.py
index be95f8b..bb9757f 100755
--- a/client/tests/virt/virttest/utils_misc_unittest.py
+++ b/client/tests/virt/virttest/utils_misc_unittest.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 
-import unittest, time, sys, os, shelve
+import unittest, time, sys, os, shelve, random
 import common
 from autotest.client import utils
 from autotest.client.shared.test_utils import mock
@@ -507,6 +507,46 @@ class test_VMNet_Subclasses(unittest.TestCase):
             sys.stdout.write(".")
             sys.stdout.flush()
 
+
+    def test_cmp_Virtnet(self):
+        self.zero_counter()
+        to_test = 600 # Random generator slows this test way down
+        for fakevm1 in self.fakevm_generator():
+            to_test -= 1
+            if to_test < 1:
+                break
+            fvm1p = fakevm1.get_params()
+            fakevm1.virtnet = utils_misc.VirtNet(fvm1p, fakevm1.name,
+                                                 fakevm1.instance,
+                                                 self.db_filename)
+            if len(fakevm1.virtnet) < 2:
+                continue
+            fakevm2 = self.FakeVm(fakevm1.name + "_2", fvm1p)
+            fakevm2.virtnet = utils_misc.VirtNet(fvm1p, fakevm2.name,
+                                                 fakevm2.instance,
+                                                 self.db_filename)
+            # Verify nic order doesn't matter
+            fvm3p = utils_misc.Params(fvm1p.items()) # work on copy
+            nic_list = fvm1p.object_params(fakevm1.name).get(
+                         "nics", fvm1p.get('nics', "") ).split()
+            random.shuffle(nic_list)
+            fvm3p['nics'] = " ".join(nic_list)
+            fakevm3 = self.FakeVm(fakevm1.name + "_3", fvm3p)
+            fakevm3.virtnet = utils_misc.VirtNet(fvm3p, fakevm3.name,
+                                                 fakevm3.instance,
+                                                 self.db_filename)
+            self.assertTrue(fakevm1.virtnet == fakevm1.virtnet)
+            self.assertTrue(fakevm1.virtnet == fakevm2.virtnet)
+            self.assertTrue(fakevm1.virtnet == fakevm3.virtnet)
+            self.assertTrue(fakevm2.virtnet == fakevm3.virtnet)
+            if len(fakevm1.virtnet) > 1:
+                del fakevm1.virtnet[0]
+                self.assertFalse(fakevm1.virtnet == fakevm2.virtnet)
+                self.assertFalse(fakevm1.virtnet == fakevm3.virtnet)
+                self.assertTrue(fakevm1.virtnet != fakevm2.virtnet)
+                self.assertTrue(fakevm1.virtnet != fakevm3.virtnet)
+            self.print_and_inc()
+
     def test_01_Params(self):
         """
         Load Cartesian combinatorial result verifies against all styles of VM.
-- 
1.7.1

_______________________________________________
Autotest-kernel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/autotest-kernel

Reply via email to