[PATCH] Add default network card name existence check

Default network card name was set as 'eth1' or 'em1'. But when os has no network card named like that, FAIL would occured. This patch added check if default name exists in the network card list and if not, change the default value into the 1st one in the list. Signed-off-by: Xu Wang <cngesaint@gmail.com> --- .../27_definesystem_macvtap_dev.py | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py index 36bf52f..7832e90 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py @@ -30,6 +30,7 @@ # import sys +import os from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS, SKIP from VirtLib import utils @@ -132,6 +133,14 @@ def main(): else: source_dev = "eth1" + # The default device name may not named 'eth1' or 'em1' so this case would + # return FAIL. The following code will check if default device exists in + # the network card list and if not, source_dev will be changed into the 1st + # network card in the list. + net_info = os.popen('ifconfig').read() + if net_info.find(source_dev) == -1: + source_dev = net_info.split(' ')[0] + guest_defined = False try: -- 1.7.1

Xu, please see below. On 07/09/2013 07:58 AM, Xu Wang wrote:
Default network card name was set as 'eth1' or 'em1'. But when os has no network card named like that, FAIL would occured. This patch added check if default name exists in the network card list and if not, change the default value into the 1st one in the list.
Signed-off-by: Xu Wang <cngesaint@gmail.com> --- .../27_definesystem_macvtap_dev.py | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py index 36bf52f..7832e90 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py @@ -30,6 +30,7 @@ #
import sys +import os from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS, SKIP from VirtLib import utils @@ -132,6 +133,14 @@ def main(): else: source_dev = "eth1"
+ # The default device name may not named 'eth1' or 'em1' so this case would + # return FAIL. The following code will check if default device exists in + # the network card list and if not, source_dev will be changed into the 1st + # network card in the list. + net_info = os.popen('ifconfig').read() + if net_info.find(source_dev) == -1: + source_dev = net_info.split(' ')[0] My guess is this would end up with trailing colon e.g. eth0: Wouldn't it better to do the splits on the colon?
+ guest_defined = False
try:
-- Mit freundlichen Grüßen/Kind Regards Boris Fiuczynski IBM Deutschland Research & Development GmbH Vorsitzender des Aufsichtsrats: Martina Köderitz Geschäftsführung: Dirk Wittkopp Sitz der Gesellschaft: Böblingen Registergericht: Amtsgericht Stuttgart, HRB 243294

于 2013-07-10 19:43, Boris Fiuczynski 写道:
Xu, please see below.
On 07/09/2013 07:58 AM, Xu Wang wrote:
Default network card name was set as 'eth1' or 'em1'. But when os has no network card named like that, FAIL would occured. This patch added check if default name exists in the network card list and if not, change the default value into the 1st one in the list.
Signed-off-by: Xu Wang <cngesaint@gmail.com> --- .../27_definesystem_macvtap_dev.py | 9 +++++++++ 1 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py
index 36bf52f..7832e90 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py
+++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py
@@ -30,6 +30,7 @@ #
import sys +import os from CimTest.Globals import logger from CimTest.ReturnCodes import FAIL, PASS, SKIP from VirtLib import utils @@ -132,6 +133,14 @@ def main(): else: source_dev = "eth1"
+ # The default device name may not named 'eth1' or 'em1' so this case would + # return FAIL. The following code will check if default device exists in + # the network card list and if not, source_dev will be changed into the 1st + # network card in the list. + net_info = os.popen('ifconfig').read() + if net_info.find(source_dev) == -1: + source_dev = net_info.split(' ')[0] My guess is this would end up with trailing colon e.g. eth0: Wouldn't it better to do the splits on the colon? So it is, on some os like Fedora 18. I find that output format of 'ip addr' is same between Fedora, Ubuntu, RHEL and CentOS. Hence in my new version patch I'll use it to recognize network card:-)
Xu Wang
+ guest_defined = False
try:
participants (2)
-
Boris Fiuczynski
-
Xu Wang