[PATCH V2 0/3] cimtest: Add default network device availability check

The default network device is a constant value. But if it doesn't exist in the system some failure would occur. Hence these patches add checking existence of them. If default network card name exists in the network info list, it will be kept. If not, the value of it will be changed into the 1st available one in the network info list. Xu Wang (3): cimtest: Add default network card name existence check to 27_definesystem_macvtap_dev.py cimtest: Add default network existence check to 28_definesystem_with_vsi_profile.py cimtest: Add default network existence check to 06_parent_net_pool.py .../libvirt-cim/cimtest/RASD/06_parent_net_pool.py | 25 +++++++++++++++++-- .../27_definesystem_macvtap_dev.py | 16 ++++++++++++ .../28_definesystem_with_vsi_profile.py | 17 +++++++++++++ 3 files changed, 55 insertions(+), 3 deletions(-)

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 <gesaint@linux.vnet.ibm.com> --- .../27_definesystem_macvtap_dev.py | 16 ++++++++++++++++ 1 files changed, 16 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..bc8c100 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py @@ -132,6 +132,22 @@ 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(source_dev) <> -1: + """ + source_dev exists in the network info list and keep it. + """ + else: + line = lines[2] + con = line.split(":") + source_dev = con[0].strip(" ") + guest_defined = False try: -- 1.7.1

On 08/07/2013 04:37 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.
I believe you neglected git pull --refresh before sending this patch as it doesn't apply to the top of the .git tree since DV pushed your previous patch...
Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- .../27_definesystem_macvtap_dev.py | 16 ++++++++++++++++ 1 files changed, 16 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..bc8c100 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/27_definesystem_macvtap_dev.py @@ -132,6 +132,22 @@ 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(source_dev) <> -1: + """ + source_dev exists in the network info list and keep it. + """ + else: + line = lines[2]
why pick 2? other than 1 being "lo"? what makes us sure that this is correct and usable?
+ con = line.split(":") + source_dev = con[0].strip(" ") +
There should be a more common way to do this rather than cut-n-paste into 3 modules... John
guest_defined = False
try:

The default network card name is 'eth0' or 'em1'. But if the network card name doesn't contain those values, error would occur. So this patch will check if the default network card name exists in the network card name list. If not, the network card name would changed into the first one in the network card name list. Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- .../28_definesystem_with_vsi_profile.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-) diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py index 2b108f9..b7f8a5e 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py @@ -188,6 +188,23 @@ def main(): if rc == 0: vsi_defaults['SourceDevice'] = "em1" + # 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(vsi_defaults['SourceDevice']) <> -1: + """ + Default net dev exists in the network info list and keep it. + """ + else: + line = lines[2] + con = line.split(":") + vsi_defaults['SourceDevice'] = con[0].strip(" ") + + nrasd_cn = get_typed_class(virt, 'NetResourceAllocationSettingData') status = FAIL cxml = None -- 1.7.1

On 08/07/2013 04:37 AM, Xu Wang wrote:
The default network card name is 'eth0' or 'em1'. But if the network card name doesn't contain those values, error would occur. So this patch will check if the default network card name exists in the network card name list. If not, the network card name would changed into the first one in the network card name list.
Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- .../28_definesystem_with_vsi_profile.py | 17 +++++++++++++++++ 1 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py index 2b108f9..b7f8a5e 100644 --- a/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py +++ b/suites/libvirt-cim/cimtest/VirtualSystemManagementService/28_definesystem_with_vsi_profile.py @@ -188,6 +188,23 @@ def main(): if rc == 0: vsi_defaults['SourceDevice'] = "em1"
+ # 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(vsi_defaults['SourceDevice']) <> -1: + """ + Default net dev exists in the network info list and keep it. + """ + else: + line = lines[2] + con = line.split(":") + vsi_defaults['SourceDevice'] = con[0].strip(" ") + +
Like 1/3 - needs to be common routine. Again you're getting different and unexpected results. John
nrasd_cn = get_typed_class(virt, 'NetResourceAllocationSettingData') status = FAIL cxml = None

The default network card name is 'eth0' or 'em1'. But if the network card name doesn't contain those values, error would occur. So this patch will check if the default network card name exists in the network card name list. If not, the network card name would changed into the first one in the network card name list. Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- .../libvirt-cim/cimtest/RASD/06_parent_net_pool.py | 25 +++++++++++++++++-- 1 files changed, 22 insertions(+), 3 deletions(-) diff --git a/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py b/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py index 2c1f285..d8b82ca 100644 --- a/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py +++ b/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py @@ -39,7 +39,8 @@ # -Netmask="255.255.255.0" # -IPRangeStart="192.168.122.2" # -IPRangeEnd="192.168.122.254" -# -ForwardDevice= [ verified for 'None' and "eth0" ] +# -ForwardDevice= [ verified for 'None' and forward device name \ +# (default is 'eth0' if available) ] # -ForwardMode=0 [ verified for 1,2 as well ] # # @@ -47,6 +48,7 @@ # Date : 18-05-2009 import sys +import os from sets import Set from CimTest.Globals import logger from XenKvmLib.const import do_main @@ -67,6 +69,23 @@ def main(): options = main.options virt = options.virt server = options.ip + net_dev = 'eth0' + + # The default device name may not named 'eth0', 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(net_dev) <> -1: + """ + net_dev exists in the network info list and keep it. + """ + else: + line = lines[2] + con = line.split(":") + net_dev = con[0].strip(" ") status, netpool_rasd = get_pool_rasds(server, virt, filter_default=False) if status != PASS: @@ -80,8 +99,8 @@ def main(): 'IPRangeStart' : "192.168.122.2", 'IPRangeEnd' : "192.168.122.254" } - exp_mode_device = [('None', 0L), ('None', 1L), ('eth0', 1L), - ('None', 2L), ('eth0', 2L)] + exp_mode_device = [('None', 0L), ('None', 1L), (net_dev, 1L), + ('None', 2L), (net_dev, 2L)] for inst_type in inst_list: logger.info("Verifying '%s' records", inst_type) -- 1.7.1

On 08/07/2013 04:37 AM, Xu Wang wrote:
The default network card name is 'eth0' or 'em1'. But if the network card name doesn't contain those values, error would occur. So this patch will check if the default network card name exists in the network card name list. If not, the network card name would changed into the first one in the network card name list.
Signed-off-by: Xu Wang <gesaint@linux.vnet.ibm.com> --- .../libvirt-cim/cimtest/RASD/06_parent_net_pool.py | 25 +++++++++++++++++-- 1 files changed, 22 insertions(+), 3 deletions(-)
diff --git a/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py b/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py index 2c1f285..d8b82ca 100644 --- a/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py +++ b/suites/libvirt-cim/cimtest/RASD/06_parent_net_pool.py @@ -39,7 +39,8 @@ # -Netmask="255.255.255.0" # -IPRangeStart="192.168.122.2" # -IPRangeEnd="192.168.122.254" -# -ForwardDevice= [ verified for 'None' and "eth0" ] +# -ForwardDevice= [ verified for 'None' and forward device name \ +# (default is 'eth0' if available) ] # -ForwardMode=0 [ verified for 1,2 as well ] # # @@ -47,6 +48,7 @@ # Date : 18-05-2009
import sys +import os from sets import Set from CimTest.Globals import logger from XenKvmLib.const import do_main @@ -67,6 +69,23 @@ def main(): options = main.options virt = options.virt server = options.ip + net_dev = 'eth0' + + # The default device name may not named 'eth0', 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. + f = open("/proc/net/dev") + lines = f.readlines() + f.close() + if str(lines).find(net_dev) <> -1: + """ + net_dev exists in the network info list and keep it. + """ + else: + line = lines[2] + con = line.split(":") + net_dev = con[0].strip(" ")
This is a very different algorithm than how you get the valid network interfaces in libvirt-cim - hence you get different results. Like 1/3 - there needs to be a common interface which this can reference
status, netpool_rasd = get_pool_rasds(server, virt, filter_default=False) if status != PASS: @@ -80,8 +99,8 @@ def main(): 'IPRangeStart' : "192.168.122.2", 'IPRangeEnd' : "192.168.122.254" } - exp_mode_device = [('None', 0L), ('None', 1L), ('eth0', 1L), - ('None', 2L), ('eth0', 2L)] + exp_mode_device = [('None', 0L), ('None', 1L), (net_dev, 1L),
^ Again, 'git am' reports trailing whitespace on the above line - there's an extra space at the end. John
+ ('None', 2L), (net_dev, 2L)] for inst_type in inst_list: logger.info("Verifying '%s' records", inst_type)
participants (2)
-
John Ferlan
-
Xu Wang