提交 83b2f5e9 编写于 作者: Y Yang Feng

Merge pull request #658 from humanux/mac_change_v1

tests.mac_change : change mac when the interface is active
...@@ -2,3 +2,13 @@ ...@@ -2,3 +2,13 @@
virt_test_type = qemu libvirt virt_test_type = qemu libvirt
type = mac_change type = mac_change
kill_vm = yes kill_vm = yes
variants:
- down_change:
only Linux
shutdown_int = yes
int_shutdown_cmd = ifconfig %s down
int_activate_cmd = ifconfig %s up
- @up_change:
virtio_net:
no RHEL.5, RHEL.6.0, RHEL.6.1, RHEL.6.2, RHEL.6.3
shutdown_int = no
...@@ -15,18 +15,6 @@ def run_mac_change(test, params, env): ...@@ -15,18 +15,6 @@ def run_mac_change(test, params, env):
@param params: Dictionary with the test parameters. @param params: Dictionary with the test parameters.
@param env: Dictionary with test environment. @param env: Dictionary with test environment.
""" """
def get_drive_num(session, path):
"""
return file path drive
"""
cmd = "wmic datafile where \"path='%s'\" get drive" % path
info = session.cmd_output(cmd, timeout=360).strip()
drive_num = re.search(r'(\w):', info, re.M)
if not drive_num:
raise error.TestError("No path %s in your guest" % path)
return drive_num.group()
vm = env.get_vm(params["main_vm"]) vm = env.get_vm(params["main_vm"])
vm.verify_alive() vm.verify_alive()
timeout = int(params.get("login_timeout", 360)) timeout = int(params.get("login_timeout", 360))
...@@ -47,6 +35,10 @@ def run_mac_change(test, params, env): ...@@ -47,6 +35,10 @@ def run_mac_change(test, params, env):
logging.info("The initial MAC address is %s", old_mac) logging.info("The initial MAC address is %s", old_mac)
if os_type == "linux": if os_type == "linux":
interface = utils_net.get_linux_ifname(session_serial, old_mac) interface = utils_net.get_linux_ifname(session_serial, old_mac)
if params.get("shutdown_int", "yes") == "yes":
int_shutdown_cmd = params.get("int_shutdown_cmd",
"ifconfig %s down")
session_serial.cmd(int_shutdown_cmd % interface)
else: else:
connection_id = utils_net.get_windows_nic_attribute(session, connection_id = utils_net.get_windows_nic_attribute(session,
...@@ -62,17 +54,14 @@ def run_mac_change(test, params, env): ...@@ -62,17 +54,14 @@ def run_mac_change(test, params, env):
"netconnectionid", "netconnectionid",
connection_id, connection_id,
"pnpdeviceid") "pnpdeviceid")
devcon_path = r"\\devcon\\wxp_x86\\" cd_drive = utils_misc.get_winutils_vol(session)
cd_drive = get_drive_num(session, devcon_path) copy_cmd = r"xcopy %s:\devcon\wxp_x86\devcon.exe c:\ " % cd_drive
copy_cmd = r"xcopy %s\devcon\wxp_x86\devcon.exe c:\ " % cd_drive
session.cmd(copy_cmd) session.cmd(copy_cmd)
# Start change MAC address # Start change MAC address
error.context("Changing MAC address to %s" % new_mac, logging.info) error.context("Changing MAC address to %s" % new_mac, logging.info)
if os_type == "linux": if os_type == "linux":
change_cmd = change_cmd_pattern % (interface, change_cmd = change_cmd_pattern % (interface, new_mac)
interface, new_mac, interface)
else: else:
change_cmd = change_cmd_pattern % (int(nic_index), change_cmd = change_cmd_pattern % (int(nic_index),
"".join(new_mac.split(":"))) "".join(new_mac.split(":")))
...@@ -83,6 +72,10 @@ def run_mac_change(test, params, env): ...@@ -83,6 +72,10 @@ def run_mac_change(test, params, env):
error.context("Verify the new mac address, and restart the network", error.context("Verify the new mac address, and restart the network",
logging.info) logging.info)
if os_type == "linux": if os_type == "linux":
if params.get("shutdown_int", "yes") == "yes":
int_activate_cmd = params.get("int_activate_cmd",
"ifconfig %s up")
session_serial.cmd(int_activate_cmd % interface)
session_serial.cmd("ifconfig | grep -i %s" % new_mac) session_serial.cmd("ifconfig | grep -i %s" % new_mac)
logging.info("Mac address change successfully, net restart...") logging.info("Mac address change successfully, net restart...")
dhclient_cmd = "dhclient -r && dhclient %s" % interface dhclient_cmd = "dhclient -r && dhclient %s" % interface
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册