From patchwork Tue Dec 1 03:58:49 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lucas Meneghel Rodrigues X-Patchwork-Id: 63846 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB13x0K7013719 for ; Tue, 1 Dec 2009 03:59:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752624AbZLAD6v (ORCPT ); Mon, 30 Nov 2009 22:58:51 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1752107AbZLAD6v (ORCPT ); Mon, 30 Nov 2009 22:58:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:17538 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751503AbZLAD6u (ORCPT ); Mon, 30 Nov 2009 22:58:50 -0500 Received: from int-mx03.intmail.prod.int.phx2.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id nB13wuQq000929 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 30 Nov 2009 22:58:56 -0500 Received: from localhost.localdomain (vpn-11-225.rdu.redhat.com [10.11.11.225]) by int-mx03.intmail.prod.int.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id nB13wsPg012409; Mon, 30 Nov 2009 22:58:55 -0500 From: Lucas Meneghel Rodrigues To: autotest@test.kernel.org Cc: kvm@vger.kernel.org, Lucas Meneghel Rodrigues , Amos Kong Subject: [PATCH] KVM test: Test 802.1Q vlan of nic Date: Tue, 1 Dec 2009 01:58:49 -0200 Message-Id: <1259639929-26250-1-git-send-email-lmr@redhat.com> X-Scanned-By: MIMEDefang 2.67 on 10.5.11.16 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org diff --git a/client/tests/kvm/kvm_tests.cfg.sample b/client/tests/kvm/kvm_tests.cfg.sample index feffb8d..5e15b30 100644 --- a/client/tests/kvm/kvm_tests.cfg.sample +++ b/client/tests/kvm/kvm_tests.cfg.sample @@ -243,6 +243,17 @@ variants: kill_vm = yes kill_vm_gracefully = no + - vlan_tag: install setup unattended_install + type = vlan_tag + # subnet should not be used by host + subnet = 192.168.123 + vlans = "10 20" + nic_mode = tap + vms += " vm2" + extra_params_vm1 += " -snapshot" + extra_params_vm2 += " -snapshot" + kill_vm_gracefully_vm2 = no + address_index_vm2 = 1 # NICs variants: @@ -525,7 +536,7 @@ variants: unattended_file = unattended/RHEL-3-series.ks # Windows section - @Windows: - no autotest linux_s3 + no autotest linux_s3 vlan_tag shutdown_command = shutdown /s /t 0 reboot_command = shutdown /r /t 0 status_test_command = echo %errorlevel% diff --git a/client/tests/kvm/tests/vlan_tag.py b/client/tests/kvm/tests/vlan_tag.py new file mode 100644 index 0000000..88baf23 --- /dev/null +++ b/client/tests/kvm/tests/vlan_tag.py @@ -0,0 +1,67 @@ +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 VLANs by vconfig and test communication by + ping using hard-coded ip addresses. + 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. + """ + subnet = params.get("subnet") + vlans = params.get("vlans").split() + + vm1 = kvm_test_utils.get_living_vm(env, params.get("main_vm")) + vm2 = kvm_test_utils.get_living_vm(env, "vm2") + + session1 = kvm_test_utils.wait_for_login(vm1) + session2 = kvm_test_utils.wait_for_login(vm2) + + try: + ip_cfg_base = "vconfig add eth0 %s && ifconfig eth0.%s %s.%s" + ip_cfg_cmd1 = ip_cfg_base % (vlans[0], vlans[0], subnet, "11") + ip_cfg_cmd2 = ip_cfg_base % (vlans[1], vlans[1], subnet, "12") + + # Configure VM1 and VM2 in different VLANs + ip_cfg_vm1 = session1.get_command_status(ip_cfg_cmd1) + if ip_cfg_vm1 != 0: + raise error.TestError("Failed to config VM 1 IP address") + ip_cfg_vm2 = session2.get_command_status(ip_cfg_cmd2) + if ip_cfg_vm2 != 0: + raise error.TestError("Failed to config VM 2 IP address") + + # Trying to ping VM 2 from VM 1, this shouldn't work + ping_cmd = "ping -c 2 -I eth0.%s %s.%s" % (vlans[0], subnet, "12") + ping_diff_vlan = session1.get_command_status(ping_cmd) + if ping_diff_vlan == 0: + raise error.TestFail("VM 2 can be reached even though it was " + "configured on a different VLAN") + + # Now let's put VM 2 in the same VLAN as VM 1 + ip_cfg_reconfig= ("vconfig rem eth0.%s && vconfig add eth0 %s && " + "ifconfig eth0.%s %s.%s" % (vlans[1], vlans[0], + vlans[0], subnet, "12")) + ip_cfg_vm2 = session2.get_command_status(ip_cfg_reconfig) + if ip_cfg_vm2 != 0: + raise error.TestError("Failed to re-config IP address of VM 2") + + # Try to ping VM 2 from VM 1, this should work + ping_same_vlan = session1.get_command_status(ping_cmd) + if ping_same_vlan != 0: + raise error.TestFail("Failed to ping VM 2 even though it was " + "configured on the same VLAN") + + finally: + session1.get_command_status("vconfig rem eth0.%s" % vlans[0]) + session1.close() + session2.get_command_status("vconfig rem eth0.%s" % vlans[0]) + session2.close()