Skip to contentSkip to conversation

Test 802.1Q vlan of nic

PATCH In review Amos Kong 3 participants 5 messages Sep 23, 2009 – Oct 21, 2009 KVM

lore
Share & tools
lore

Amos Kong

author
#0 lore raw

PATCH 1/1 Test 802.1Q vlan of nic

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

---
 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
client/tests/kvm/kvm_tests.cfg.sample +6 -0
index 285a38f..5a3f97d 100644
@@ -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:
client/tests/kvm/tests/vlan_tag.py new file +66 -0

66 lines not on this page · raw message

Signature · 1 line
1.5.5.6
#1 lore raw

Hi Amos, thanks for the patch, here are my comments (pretty much concerning only coding style):

Quoted 61 lines · Amos Kong

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

---
 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

client/tests/kvm/kvm_tests.cfg.sample +0 -0
index 285a38f..5a3f97d 100644
@@ -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:

client/tests/kvm/tests/vlan_tag.py new file +24 -0
new file mode 100644
index 0000000..2904276
@@ -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()
+

client/tests/kvm/tests/vlan_tag.py line 34

Quoted 10 lines
client/tests/kvm/tests/vlan_tag.py new file +10 -0
+    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"

In the above exception raise statement, the preferred form to do it is:

raise error.TestError("VM 1 create failed")

client/tests/kvm/tests/vlan_tag.py line 48

Quoted 13 lines
client/tests/kvm/tests/vlan_tag.py new file +13 -0
+    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:

In the above if statement, I'd assign the comparisons to variables to make the code more readable, like:

try:

    vconfig_cmd = "vconfig add eth0 %s;ifconfig eth0.%s %s.%s"
    # Attempt to configure IPs for the VMs and record the results in boolean
    # variables
    ip_config_vm1_ok = (session[0].get_command_status(
                        vconfig_cmd % (vlans[0], vlans[0], subnet2, "11")) == 0)

    ip_config_vm1_ok = (session[1].get_command_status(
                        vconfig_cmd % (vlans[1], vlans[1], subnet2, "12")) == 0)

    if not ip_config_vm1_ok or not ip_config_vm2_ok:

client/tests/kvm/tests/vlan_tag.py line 52

Quoted 4 lines
client/tests/kvm/tests/vlan_tag.py new file +4 -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")

A similar comment applies to the above block

client/tests/kvm/tests/vlan_tag.py line 59

Quoted 6 lines
client/tests/kvm/tests/vlan_tag.py new file +6 -0
+        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:

Idem

client/tests/kvm/tests/vlan_tag.py line 62

Quoted 3 lines
client/tests/kvm/tests/vlan_tag.py new file +3 -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"

See comment about the preferred form to write raise statements.

Quoted 6 lines
client/tests/kvm/tests/vlan_tag.py new file +4 -1
+    finally:
+        for i in range(2):
+            session[i].sendline("vconfig rem eth0.%s" % vlans[0])
+            session[i].close()
--

1.5.5.6

Please send me an updated version of the patch.

Lucas

author
#2 lore raw

PATCH 1/1 Test 802.1Q vlan of nic

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

---
 client/tests/kvm/kvm_tests.cfg.sample |    6 +++
 client/tests/kvm/tests/vlan_tag.py    |   73 +++++++++++++++++++++++++++++++++
 2 files changed, 79 insertions(+), 0 deletions(-)
 mode change 100644 => 100755 client/tests/kvm/scripts/qemu-ifup
 create mode 100644 client/tests/kvm/tests/vlan_tag.py
client/tests/kvm/kvm_tests.cfg.sample +6 -0
index 9ccc9b5..4e47767 100644
@@ -166,6 +166,12 @@ variants:
         used_cpus = 5
         used_mem = 2560
 
+    - vlan_tag:  install setup
+        type = vlan_tag
+        subnet2 = 192.168.123
+        vlans = "10 20"
+        nic_mode = tap
+        nic_model = e1000
 
     - autoit:       install setup
         type = autoit
client/tests/kvm/scripts/qemu-ifup +0 -0
old mode 100644
new mode 100755
client/tests/kvm/tests/vlan_tag.py new file +73 -0

73 lines not on this page · raw message

Signature · 1 line
1.5.5.6
#3 lore raw
Quoted 8 lines · Amos Kong

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

Quoted 6 lines
---
  client/tests/kvm/kvm_tests.cfg.sample |    6 +++
  client/tests/kvm/tests/vlan_tag.py    |   73 +++++++++++++++++++++++++++++++++
  2 files changed, 79 insertions(+), 0 deletions(-)

mode change 100644 => 100755 client/tests/kvm/scripts/qemu-ifup

In general the above should come as an independent patch.

Quoted 7 lines

create mode 100644 client/tests/kvm/tests/vlan_tag.py

client/tests/kvm/kvm_tests.cfg.sample +0 -0
index 9ccc9b5..4e47767 100644

client/tests/kvm/kvm_tests.cfg.sample variants: · line 172

Quoted 7 lines
client/tests/kvm/kvm_tests.cfg.sample +4 -0
@@ -166,6 +166,12 @@ variants:
          used_cpus = 5
          used_mem = 2560
 
+    - vlan_tag:  install setup
+        type = vlan_tag
+        subnet2 = 192.168.123
+        vlans = "10 20"

If we want to be fanatic and safe we should dynamically choose subnet and vlans numbers that are not used on the host instead of hard code it.

client/tests/kvm/kvm_tests.cfg.sample variants: · line 174

Quoted 2 lines
client/tests/kvm/kvm_tests.cfg.sample +2 -0
+        nic_mode = tap
+        nic_model = e1000

Why only e1000? Let's test virtio and rtl8139 as well. Can't you inherit the nic model from the config?

Quoted 36 lines
client/tests/kvm/kvm_tests.cfg.sample +0 -0
      - autoit:       install setup
          type = autoit
client/tests/kvm/scripts/qemu-ifup +0 -0
old mode 100644
new mode 100755
client/tests/kvm/tests/vlan_tag.py new file +24 -0
new file mode 100644
index 0000000..15e763f
@@ -0,0 +1,73 @@
+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()
+

client/tests/kvm/tests/vlan_tag.py line 34

Quoted 10 lines
client/tests/kvm/tests/vlan_tag.py new file +10 -0
+    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 1 create faild")

The whole 7-8 lines above should be grouped as a function to clone existing VM. It should be part of kvm autotest infrastructure.

Besides that, it looks good.

Quoted 39 lines
client/tests/kvm/tests/vlan_tag.py new file +39 -0
+
+    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"
+        # Attempt to configure IPs for the VMs and record the results in
+        # boolean variables
+        # Make vm1 and vm2 in the different vlan
+
+        ip_config_vm1_ok = (session[0].get_command_status(vconfig_cmd
+                                   % (vlans[0], vlans[0], subnet2, "11")) == 0)
+        ip_config_vm2_ok = (session[1].get_command_status(vconfig_cmd
+                                   % (vlans[1], vlans[1], subnet2, "12")) == 0)
+        if not ip_config_vm1_ok or not ip_config_vm2_ok:
+            raise error.TestError, "Fail to config VMs ip address"
+        ping_diff_vlan_ok = (session[0].get_command_status(
+                             "ping -c 2 %s.12" % subnet2) == 0)
+
+        if ping_diff_vlan_ok:
+            raise error.TestFail("VM 2 is unexpectedly pingable in different "
+                                 "vlan")
+        # Make vm2 in the same vlan with vm1
+        vlan_config_vm2_ok = (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)
+        if not vlan_config_vm2_ok:
+            raise error.TestError, "Fail to config ip address of VM 2"
+
+        ping_same_vlan_ok = (session[0].get_command_status(
+                             "ping -c 2 %s.12" % subnet2) == 0)
+        if not ping_same_vlan_ok:
+            raise error.TestFail("Fail to ping the guest in same vlan")
+    finally:
+        # Clean the vlan config
+        for i in range(2):
+            session[i].sendline("vconfig rem eth0.%s" % vlans[0])
+            session[i].close()
author
#4 lore raw
Quoted 9 lines · Dor Laor
Quoted 8 lines · Amos Kong

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

Quoted 8 lines
Quoted 6 lines
---
  client/tests/kvm/kvm_tests.cfg.sample |    6 +++
  client/tests/kvm/tests/vlan_tag.py    |   73 +++++++++++++++++++++++++++++++++
  2 files changed, 79 insertions(+), 0 deletions(-)

mode change 100644 => 100755 client/tests/kvm/scripts/qemu-ifup

In general the above should come as an independent patch.

yes.

Quoted 18 lines
Quoted 7 lines

create mode 100644 client/tests/kvm/tests/vlan_tag.py

client/tests/kvm/kvm_tests.cfg.sample +0 -0
index 9ccc9b5..4e47767 100644

client/tests/kvm/kvm_tests.cfg.sample variants: · line 172

Quoted 7 lines
client/tests/kvm/kvm_tests.cfg.sample +4 -0
@@ -166,6 +166,12 @@ variants:
          used_cpus = 5
          used_mem = 2560
 
+    - vlan_tag:  install setup
+        type = vlan_tag
+        subnet2 = 192.168.123
+        vlans = "10 20"

If we want to be fanatic and safe we should dynamically choose subnet and vlans numbers that are not used on the host instead of hard code it.

Quoted 5 lines

client/tests/kvm/kvm_tests.cfg.sample variants: · line 174

Quoted 2 lines
client/tests/kvm/kvm_tests.cfg.sample +2 -0
+        nic_mode = tap
+        nic_model = e1000

Why only e1000? Let's test virtio and rtl8139 as well. Can't you inherit the nic model from the config?

yes, we should remove 'nic_model = e1000' for testing all kind of nic.

It seems that there exists a kvm bug (https://bugzilla.redhat.com/show_bug.cgi?id=516587)
It was found by this testcase.

Quoted 91 lines
Quoted 35 lines
client/tests/kvm/kvm_tests.cfg.sample +0 -0
      - autoit:       install setup
          type = autoit
client/tests/kvm/scripts/qemu-ifup +0 -0
old mode 100644
new mode 100755
client/tests/kvm/tests/vlan_tag.py new file +24 -0
new file mode 100644
index 0000000..15e763f
@@ -0,0 +1,73 @@
+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()
+

client/tests/kvm/tests/vlan_tag.py line 34

Quoted 10 lines
client/tests/kvm/tests/vlan_tag.py new file +10 -0
+    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 1 create faild")

The whole 7-8 lines above should be grouped as a function to clone existing VM. It should be part of kvm autotest infrastructure.

Besides that, it looks good.

Quoted 39 lines
client/tests/kvm/tests/vlan_tag.py new file +39 -0
+
+    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"
+        # Attempt to configure IPs for the VMs and record the results in
+        # boolean variables
+        # Make vm1 and vm2 in the different vlan
+
+        ip_config_vm1_ok = (session[0].get_command_status(vconfig_cmd
+                                   % (vlans[0], vlans[0], subnet2, "11")) == 0)
+        ip_config_vm2_ok = (session[1].get_command_status(vconfig_cmd
+                                   % (vlans[1], vlans[1], subnet2, "12")) == 0)
+        if not ip_config_vm1_ok or not ip_config_vm2_ok:
+            raise error.TestError, "Fail to config VMs ip address"
+        ping_diff_vlan_ok = (session[0].get_command_status(
+                             "ping -c 2 %s.12" % subnet2) == 0)
+
+        if ping_diff_vlan_ok:
+            raise error.TestFail("VM 2 is unexpectedly pingable in different "
+                                 "vlan")
+        # Make vm2 in the same vlan with vm1
+        vlan_config_vm2_ok = (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)
+        if not vlan_config_vm2_ok:
+            raise error.TestError, "Fail to config ip address of VM 2"
+
+        ping_same_vlan_ok = (session[0].get_command_status(
+                             "ping -c 2 %s.12" % subnet2) == 0)
+        if not ping_same_vlan_ok:
+            raise error.TestFail("Fail to ping the guest in same vlan")
+    finally:
+        # Clean the vlan config
+        for i in range(2):
+            session[i].sendline("vconfig rem eth0.%s" % vlans[0])
+            session[i].close()
Signature · 4 lines
Amos Kong
Quality Engineer
Raycom Office(Beijing), Red Hat Inc.
Phone: +86-10-62608183