kvm.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amos Kong <akong@redhat.com>
To: autotest@test.kernel.org, kvm@vger.kernel.org
Cc: lmr@redhat.com, Amos Kong <akong@redhat.com>
Subject: [PATCH] Test 802.1Q vlan of nic
Date: Wed, 23 Sep 2009 19:19:00 +0800	[thread overview]
Message-ID: <1253704740-26370-1-git-send-email-akong@redhat.com> (raw)

Test 802.1Q vlan of nic, config it by vconfig command.
1) Create two VMs
2) Setup guests in different vlan by vconfig and test communication by ping
   using hard-coded ip address
3) Setup guests in same vlan and test communication by ping
4) Recover the vlan config

Signed-off-by: Amos Kong <akong@redhat.com>
---
 client/tests/kvm/kvm_tests.cfg.sample |    6 +++
 client/tests/kvm/tests/vlan_tag.py    |   66 +++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+), 0 deletions(-)
 create mode 100644 client/tests/kvm/tests/vlan_tag.py

diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample
index 285a38f..5a3f97d 100644
--- a/client/tests/kvm/kvm_tests.cfg.sample
+++ b/client/tests/kvm/kvm_tests.cfg.sample
@@ -145,6 +145,12 @@ variants:
         kill_vm = yes
         kill_vm_gracefully = no
 
+    - vlan_tag:  install setup
+        type = vlan_tag
+        subnet2 = 192.168.123
+        vlans = "10 20"
+        nic_mode = tap
+        nic_model = e1000
 
 # NICs
 variants:
diff --git a/client/tests/kvm/tests/vlan_tag.py b/client/tests/kvm/tests/vlan_tag.py
new file mode 100644
index 0000000..2904276
--- /dev/null
+++ b/client/tests/kvm/tests/vlan_tag.py
@@ -0,0 +1,66 @@
+import logging, time
+from autotest_lib.client.common_lib import error
+import kvm_subprocess, kvm_test_utils, kvm_utils
+
+def run_vlan_tag(test, params, env):
+    """
+    Test 802.1Q vlan of nic, config it by vconfig command.
+
+    1) Create two VMs
+    2) Setup guests in different vlan by vconfig and test communication by ping 
+       using hard-coded ip address
+    3) Setup guests in same vlan and test communication by ping
+    4) Recover the vlan config
+
+    @param test: Kvm test object
+    @param params: Dictionary with the test parameters.
+    @param env: Dictionary with test environment.
+    """
+
+    vm = []
+    session = []
+    subnet2 = params.get("subnet2")
+    vlans = params.get("vlans").split()
+
+    vm.append(kvm_test_utils.get_living_vm(env, "%s" % params.get("main_vm")))
+
+    params_vm2 = params.copy()
+    params_vm2['image_snapshot'] = "yes"
+    params_vm2['kill_vm_gracefully'] = "no"
+    params_vm2["address_index"] = int(params.get("address_index", 0))+1
+    vm.append(vm[0].clone("vm2", params_vm2))
+    kvm_utils.env_register_vm(env, "vm2", vm[1])
+    if not vm[1].create():
+        raise error.TestError, "VM 'vm[1]' create faild"
+
+    for i in range(2):
+        session.append(kvm_test_utils.wait_for_login(vm[i]))
+
+    try:
+        vconfig_cmd = "vconfig add eth0 %s;ifconfig eth0.%s %s.%s"
+        if session[0].get_command_status(vconfig_cmd % (vlans[0],
+                                                        vlans[0],
+                                                        subnet2,
+                                                        "11")) != 0 or \
+           session[1].get_command_status(vconfig_cmd % (vlans[1],
+                                                        vlans[1],
+                                                        subnet2,
+                                                        "12")) != 0:
+            raise error.TestError, "Fail to config VMs ip address"
+        if session[0].get_command_status("ping -c 2 %s.12" % subnet2) == 0:
+            raise error.TestFail("Guest is unexpectedly pingable in different "
+                                 "vlan")
+
+        if session[1].get_command_status("vconfig rem eth0.%s;vconfig add eth0 "
+                                         "%s;ifconfig eth0.%s %s.12" %
+                                          (vlans[1],
+                                           vlans[0],
+                                           vlans[0],
+                                           subnet2)) != 0:
+            raise error.TestError, "Fail to config ip address of VM 'vm[1]'"
+        if session[0].get_command_status("ping -c 2 %s.12" % subnet2) != 0:
+            raise error.TestFail, "Fail to ping the guest in same vlan"
+    finally:
+        for i in range(2):
+            session[i].sendline("vconfig rem eth0.%s" % vlans[0])
+            session[i].close()
-- 
1.5.5.6


             reply	other threads:[~2009-09-23 11:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-09-23 11:19 Amos Kong [this message]
2009-10-14 10:51 ` [Autotest] [PATCH] Test 802.1Q vlan of nic Lucas Meneghel Rodrigues
2009-10-15  9:48   ` Amos Kong
2009-10-19  8:22     ` Dor Laor
2009-10-21 10:04       ` Amos Kong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1253704740-26370-1-git-send-email-akong@redhat.com \
    --to=akong@redhat.com \
    --cc=autotest@test.kernel.org \
    --cc=kvm@vger.kernel.org \
    --cc=lmr@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).