[PATCH] KVM test: Test 802.1Q vlan of nic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

The subnet of vlan can be setup in configure file.

3rd try:
 * Instead of using lists of vms and sessions, just use vm1 and vm2 and
   session1 and session2 as it's clearer and we just need 2 vms.

Signed-off-by: Amos Kong <akong@xxxxxxxxxx>
---
 client/tests/kvm/kvm_tests.cfg.sample |   13 ++++++-
 client/tests/kvm/tests/vlan_tag.py    |   67 +++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 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 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()
-- 
1.6.5.2

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [KVM ARM]     [KVM ia64]     [KVM ppc]     [Virtualization Tools]     [Spice Development]     [Libvirt]     [Libvirt Users]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite Questions]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux