[PATCH] [TEST] Adding new tc to verify Libvirt-CIM profile advertisement via slp

# HG changeset patch # User Deepti B. Kalakeri<deeptik@linux.vnet.ibm.com> # Date 1258744084 28800 # Node ID b4b4e5f9b7efad90d37e06a2583d2a426b291d8e # Parent c7561bf6112633f00d6bfb2ba1871ef63855d529 [TEST] Adding new tc to verify Libvirt-CIM profile advertisement via slp. Tested with KVM and current sources on rhel5.4. Signed-off-by: Deepti B. Kalakeri <deeptik@linux.vnet.ibm.com> diff -r c7561bf61126 -r b4b4e5f9b7ef suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/suites/libvirt-cim/cimtest/Profile/04_verify_libvirt_cim_slp_profiles.py Fri Nov 20 11:08:04 2009 -0800 @@ -0,0 +1,188 @@ +#! /usr/bin/python +# +# Copyright 2009 IBM Corp. +# +# Authors: +# Deepti B. Kalakeri <dkalaker@in.ibm.com> +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public +# License along with this library; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# The following test case is used to verify the profiles registered by +# Libvirt-CIM are advertised via slp tool. +# +# Date : 20-10-2009 + +import sys +import os +import string +from sets import Set +from socket import gethostbyaddr +from VirtLib.utils import run_remote +from XenKvmLib import enumclass +from XenKvmLib.classes import get_typed_class +from CimTest import Globals +from CimTest.Globals import logger +from XenKvmLib.const import do_main +from CimTest.ReturnCodes import PASS, FAIL, SKIP + +sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +slp_path="/usr/bin/slptool" + +def get_slp_info(server): + + if not os.path.exists(slp_path): + logger.error("Slp tool does not exist on the machine ") + return SKIP + + logger.info("Slp tool found on the machine ....") + + # The test is written to work with Pegasus for now. + # In future we can include sfcb support as well + # When sfcb support will be planned then replace the following check + # with check_cimom() fn of common_util.py lib + cmd = "ps -ef | grep -v grep | grep cimserver" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("cimserver not found on '%s'", server) + return FAIL + + cmd = "cimconfig -l -p | grep slp" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("slp is not enabled in the cimserver on '%s'", server) + return FAIL + + return PASS + +def get_slp_attrs(server): + slp_attrs = None + status = FAIL + + cmd = "%s findsrvs service:wbem | grep -w http | "\ + "grep -e '%s'" % (slp_path, server) + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("Failed to find slp service on '%s'", server) + return status, slp_attrs + + attrs_in = out.rsplit(",") + slp_query = attrs_in[0] + cmd = "%s findattrs %s" % (slp_path, slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) == 0: + # Getting the query and the port details + slp_query_info = slp_query.rsplit(":", 1) + slp_service_query = slp_query_info[0] + port_used = slp_query_info[1] + logger.info("Did not get the profile information for '%s'", slp_query) + logger.info("Trying with ports other than '%s'....", port_used) + + # Remove the already used port information + ports = attrs_in.remove(slp_query) + for port in attrs_in: + new_slp_query = slp_service_query + ":" + port + cmd = "%s findattrs %s" % (slp_path, new_slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) != 0: + break + + if len(slp_attrs) != 0: + status = PASS + + return status, slp_attrs + +def filter_reg_name_from_slp(slp_attrs): + slp_profile_list = [] + + for line in slp_attrs.split('\n'): + lines=line.split("RegisteredProfilesSupported") + dmtf_profiles=lines[1].split("DMTF") + for profile in dmtf_profiles: + temp_reg_ele = profile.rsplit(":", 1)[1].rstrip(",") + reg_prof_name = temp_reg_ele.rstrip(")") + slp_profile_list.append(reg_prof_name) + + slp_profile_list = Set(slp_profile_list) + + return slp_profile_list + +def get_libvirt_cim_profile_info(server, virt): + libvirt_cim_reg_list = None + status = FAIL + prev_namespace = Globals.CIM_NS + Globals.CIM_NS = 'root/interop' + cn = get_typed_class(virt, 'RegisteredProfile') + + try: + proflist = enumclass.EnumInstances(server, cn) + except Exception, detail: + logger.error(CIM_ERROR_ENUMERATE, get_typed_class(virt, cn)) + logger.error("Exception: %s", detail) + Globals.CIM_NS = prev_namespace + return status, libvirt_cim_reg_list + + Globals.CIM_NS = prev_namespace + + libvirt_cim_reg_list = Set([str(x.RegisteredName) for x in proflist]) + if len(libvirt_cim_reg_list) != 0: + status = PASS + + return status, libvirt_cim_reg_list + + +@do_main(sup_types) +def main(): + options = main.options + server = options.ip + virt = options.virt + status = FAIL + + # Making sure that the server information passed is + # hostname or ip address + if server == "localhost": + logger.error("Please specify hostname or ip address, than '%s'", + server) + return SKIP + + status = get_slp_info(server) + if status != PASS: + return status + + ip_addr = gethostbyaddr(server)[2][0] + status, slp_attrs = get_slp_attrs(ip_addr) + if status != PASS: + logger.error("Failed to get slp attributes on %s", server) + return status + + slp_profile_list = filter_reg_name_from_slp(slp_attrs) + + status, libvirt_cim_reg_list = get_libvirt_cim_profile_info(server, virt) + if status != PASS: + logger.error("Failed to enumerate profile information on %s", server) + return status + + # Make sure all the Libvirt-CIM profiles are advertised via slp + if (libvirt_cim_reg_list) <= (slp_profile_list): + logger.info("Successfully verified the Libvirt-CIM profiles") + return PASS + else: + logger.error("Mismatch in the profiles registered") + logger.error("Slp returned profile --> %s,\n Libvirt-CIM expected " + "profiles %s", slp_profile_list, libvirt_cim_reg_list) + return FAIL + +if __name__=="__main__": + sys.exit(main()) +

+sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +slp_path="/usr/bin/slptool"
It's possible that slptool might be installed in a different location. You don't have to do this, but instead of checking the path, you could use run_remote() to check whether "slptool help" returns an error. If it does, slptool isn't installed (or the path is non-standard).
+ +def get_slp_info(server): + + if not os.path.exists(slp_path): + logger.error("Slp tool does not exist on the machine ") + return SKIP + + logger.info("Slp tool found on the machine ....") + + # The test is written to work with Pegasus for now. + # In future we can include sfcb support as well + # When sfcb support will be planned then replace the following check + # with check_cimom() fn of common_util.py lib + cmd = "ps -ef | grep -v grep | grep cimserver" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("cimserver not found on '%s'", server) + return FAIL
I would SKIP here. Also, can you add something like "test only supported for sfcb at this time" - so the user knows why the test is skipped.
+ + cmd = "cimconfig -l -p | grep slp" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("slp is not enabled in the cimserver on '%s'", server) + return FAIL
I would skip here as well.
+ + return PASS + +def get_slp_attrs(server): + slp_attrs = None + status = FAIL + + cmd = "%s findsrvs service:wbem | grep -w http | "\ + "grep -e '%s'" % (slp_path, server) + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("Failed to find slp service on '%s'", server) + return status, slp_attrs
Instead of calling findsrvs, why not call findattrs directly?
+ + attrs_in = out.rsplit(",") + slp_query = attrs_in[0] + cmd = "%s findattrs %s" % (slp_path, slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) == 0: + # Getting the query and the port details + slp_query_info = slp_query.rsplit(":", 1) + slp_service_query = slp_query_info[0] + port_used = slp_query_info[1] + logger.info("Did not get the profile information for '%s'", slp_query) + logger.info("Trying with ports other than '%s'....", port_used) + + # Remove the already used port information + ports = attrs_in.remove(slp_query) + for port in attrs_in: + new_slp_query = slp_service_query + ":" + port + cmd = "%s findattrs %s" % (slp_path, new_slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) != 0: + break
If I force the test to execute this block of code, I get the following error: ERROR - ValueError : list.remove(x): x not in list Traceback (most recent call last): File "./lib/XenKvmLib/const.py", line 140, in do_try File "04_verify_libvirt_cim_slp_profiles.py", line 167, in main status, slp_attrs = get_slp_attrs(ip_addr) File "04_verify_libvirt_cim_slp_profiles.py", line 96, in get_slp_attrs ports = attrs_in.remove(slp_query) ValueError: list.remove(x): x not in list I think it's okay to remove this bit of code. We have to enable http connections with the CIMOM in order to run cimtest. If we want cimtest to work with just https, we'd need to do a lot of cleanup. That means if the CIMOM is advertising via slp correctly, then the advertisement will occur with the http port (otherwise its an error with the advertisement). You can put a comment here indicating the test only works when the CIMOM is enabled for http. That's fine for now.
+ + if len(slp_attrs) != 0: + status = PASS + + return status, slp_attrs + +def filter_reg_name_from_slp(slp_attrs): + slp_profile_list = [] + + for line in slp_attrs.split('\n'): + lines=line.split("RegisteredProfilesSupported")
Spaces around the = needed here.
+ dmtf_profiles=lines[1].split("DMTF")
And here.
+ +@do_main(sup_types) +def main(): + options = main.options + server = options.ip + virt = options.virt + status = FAIL + + # Making sure that the server information passed is + # hostname or ip address + if server == "localhost": + logger.error("Please specify hostname or ip address, than '%s'", + server) + return SKIP
Why not use gethostname() to get the hostname?
+ + status = get_slp_info(server) + if status != PASS: + return status + + ip_addr = gethostbyaddr(server)[2][0]
You can use gethostbyname(), which is a little cleaner. You can pass it the output from gethostname().
+ status, slp_attrs = get_slp_attrs(ip_addr) + if status != PASS: + logger.error("Failed to get slp attributes on %s", server) + return status + + slp_profile_list = filter_reg_name_from_slp(slp_attrs) + + status, libvirt_cim_reg_list = get_libvirt_cim_profile_info(server, virt) + if status != PASS: + logger.error("Failed to enumerate profile information on %s", server) + return status + + # Make sure all the Libvirt-CIM profiles are advertised via slp + if (libvirt_cim_reg_list) <= (slp_profile_list): + logger.info("Successfully verified the Libvirt-CIM profiles") + return PASS + else:
No need for the else here.
+ logger.error("Mismatch in the profiles registered") + logger.error("Slp returned profile --> %s,\n Libvirt-CIM expected " + "profiles %s", slp_profile_list, libvirt_cim_reg_list) + return FAIL + +if __name__=="__main__": + sys.exit(main()) +
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
+sup_types = ['Xen', 'KVM', 'XenFV', 'LXC'] +slp_path="/usr/bin/slptool"
It's possible that slptool might be installed in a different location. You don't have to do this, but instead of checking the path, you could use run_remote() to check whether "slptool help" returns an error. If it does, slptool isn't installed (or the path is non-standard).
+ +def get_slp_info(server): + + if not os.path.exists(slp_path): + logger.error("Slp tool does not exist on the machine ") + return SKIP + + logger.info("Slp tool found on the machine ....") + + # The test is written to work with Pegasus for now. + # In future we can include sfcb support as well + # When sfcb support will be planned then replace the following check + # with check_cimom() fn of common_util.py lib + cmd = "ps -ef | grep -v grep | grep cimserver" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("cimserver not found on '%s'", server) + return FAIL
I would SKIP here. Also, can you add something like "test only supported for sfcb at this time" - so the user knows why the test is skipped.
+ + cmd = "cimconfig -l -p | grep slp" + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("slp is not enabled in the cimserver on '%s'", server) + return FAIL
I would skip here as well.
+ + return PASS + +def get_slp_attrs(server): + slp_attrs = None + status = FAIL + + cmd = "%s findsrvs service:wbem | grep -w http | "\ + "grep -e '%s'" % (slp_path, server) + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("Failed to find slp service on '%s'", server) + return status, slp_attrs
Instead of calling findsrvs, why not call findattrs directly?
I call findsrvs to get all the ports which could be used to find the attrs.
+ + attrs_in = out.rsplit(",") + slp_query = attrs_in[0] + cmd = "%s findattrs %s" % (slp_path, slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) == 0: + # Getting the query and the port details + slp_query_info = slp_query.rsplit(":", 1) + slp_service_query = slp_query_info[0] + port_used = slp_query_info[1] + logger.info("Did not get the profile information for '%s'", slp_query) + logger.info("Trying with ports other than '%s'....", port_used) + + # Remove the already used port information + ports = attrs_in.remove(slp_query) + for port in attrs_in: + new_slp_query = slp_service_query + ":" + port + cmd = "%s findattrs %s" % (slp_path, new_slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) != 0: + break
If I force the test to execute this block of code, I get the following error:
ERROR - ValueError : list.remove(x): x not in list Traceback (most recent call last): File "./lib/XenKvmLib/const.py", line 140, in do_try File "04_verify_libvirt_cim_slp_profiles.py", line 167, in main status, slp_attrs = get_slp_attrs(ip_addr) File "04_verify_libvirt_cim_slp_profiles.py", line 96, in get_slp_attrs ports = attrs_in.remove(slp_query) ValueError: list.remove(x): x not in list
I think it's okay to remove this bit of code. We have to enable http connections with the CIMOM in order to run cimtest. If we want cimtest to work with just https, we'd need to do a lot of cleanup. That means if the CIMOM is advertising via slp correctly, then the advertisement will occur with the http port (otherwise its an error with the advertisement).
You can put a comment here indicating the test only works when the CIMOM is enabled for http. That's fine for now.
I am not using https at all. I am parsing the port associated with the http record returned by the slptool findsrvs.. Let me know if I am wrong in understanding what you mean here.
+ + if len(slp_attrs) != 0: + status = PASS + + return status, slp_attrs + +def filter_reg_name_from_slp(slp_attrs): + slp_profile_list = [] + + for line in slp_attrs.split('\n'): + lines=line.split("RegisteredProfilesSupported")
Spaces around the = needed here.
+ dmtf_profiles=lines[1].split("DMTF")
And here.
+ +@do_main(sup_types) +def main(): + options = main.options + server = options.ip + virt = options.virt + status = FAIL + + # Making sure that the server information passed is + # hostname or ip address + if server == "localhost": + logger.error("Please specify hostname or ip address, than '%s'", + server) + return SKIP
Why not use gethostname() to get the hostname?
+ + status = get_slp_info(server) + if status != PASS: + return status + + ip_addr = gethostbyaddr(server)[2][0]
You can use gethostbyname(), which is a little cleaner. You can pass it the output from gethostname().
I tried supplying the hostname to the slp command, but it does not seem to work. Hence I choose gethostbyaddr() to get the ip from the hostname. Let me know if we can access the attrs while passing the hostname.
+ status, slp_attrs = get_slp_attrs(ip_addr) + if status != PASS: + logger.error("Failed to get slp attributes on %s", server) + return status + + slp_profile_list = filter_reg_name_from_slp(slp_attrs) + + status, libvirt_cim_reg_list = get_libvirt_cim_profile_info(server, virt) + if status != PASS: + logger.error("Failed to enumerate profile information on %s", server) + return status + + # Make sure all the Libvirt-CIM profiles are advertised via slp + if (libvirt_cim_reg_list) <= (slp_profile_list): + logger.info("Successfully verified the Libvirt-CIM profiles") + return PASS + else:
No need for the else here. Don't we want to print an error message if we dont get the expected Libvirt-CIM profiles ?
+ logger.error("Mismatch in the profiles registered") + logger.error("Slp returned profile --> %s,\n Libvirt-CIM expected " + "profiles %s", slp_profile_list, libvirt_cim_reg_list) + return FAIL + +if __name__=="__main__": + sys.exit(main()) +
-- Thanks and Regards, Deepti B. Kalakeri IBM Linux Technology Center deeptik@linux.vnet.ibm.com

+ cmd = "%s findsrvs service:wbem | grep -w http | "\ + "grep -e '%s'" % (slp_path, server) + rc, out = run_remote(server, cmd) + if rc != 0: + logger.error("Failed to find slp service on '%s'", server) + return status, slp_attrs
Instead of calling findsrvs, why not call findattrs directly? I call findsrvs to get all the ports which could be used to find the attrs.
The different ports are http (5988) versus https (5989). I think you only need to check for 5988, since cimtest requires that the CIMOM have http enabled.
+ + attrs_in = out.rsplit(",") + slp_query = attrs_in[0] + cmd = "%s findattrs %s" % (slp_path, slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) == 0: + # Getting the query and the port details + slp_query_info = slp_query.rsplit(":", 1) + slp_service_query = slp_query_info[0] + port_used = slp_query_info[1] + logger.info("Did not get the profile information for '%s'", slp_query) + logger.info("Trying with ports other than '%s'....", port_used) + + # Remove the already used port information + ports = attrs_in.remove(slp_query) + for port in attrs_in: + new_slp_query = slp_service_query + ":" + port + cmd = "%s findattrs %s" % (slp_path, new_slp_query) + rc, slp_attrs = run_remote(server, cmd) + if len(slp_attrs) != 0: + break
If I force the test to execute this block of code, I get the following error:
ERROR - ValueError : list.remove(x): x not in list Traceback (most recent call last): File "./lib/XenKvmLib/const.py", line 140, in do_try File "04_verify_libvirt_cim_slp_profiles.py", line 167, in main status, slp_attrs = get_slp_attrs(ip_addr) File "04_verify_libvirt_cim_slp_profiles.py", line 96, in get_slp_attrs ports = attrs_in.remove(slp_query) ValueError: list.remove(x): x not in list
I think it's okay to remove this bit of code. We have to enable http connections with the CIMOM in order to run cimtest. If we want cimtest to work with just https, we'd need to do a lot of cleanup. That means if the CIMOM is advertising via slp correctly, then the advertisement will occur with the http port (otherwise its an error with the advertisement).
You can put a comment here indicating the test only works when the CIMOM is enabled for http. That's fine for now.
I am not using https at all. I am parsing the port associated with the http record returned by the slptool findsrvs.. Let me know if I am wrong in understanding what you mean here.
Pegasus does the SLP advertisement with two ports 5988 (wbem-http) and 5989 (wbem-https). # cat /etc/services | grep 5988 wbem-http 5988/tcp # WBEM HTTP wbem-http 5988/udp # WBEM HTTP # cat /etc/services | grep 5989 wbem-https 5989/tcp # WBEM HTTPS wbem-https 5989/udp # WBEM HTTPS I think you only need to check the output of wbem-http - no need to verify both. If the advertisement doesn't show up on 5988, then either: 1) the CIMOM isn't enabled with HTTP (which it should be for cimtest to run) 2) there's something wrong with Pegasus' advertisement
+ + if len(slp_attrs) != 0: + status = PASS + + return status, slp_attrs + +def filter_reg_name_from_slp(slp_attrs): + slp_profile_list = [] + + for line in slp_attrs.split('\n'): + lines=line.split("RegisteredProfilesSupported")
Spaces around the = needed here.
+ dmtf_profiles=lines[1].split("DMTF")
And here.
+ +@do_main(sup_types) +def main(): + options = main.options + server = options.ip + virt = options.virt + status = FAIL + + # Making sure that the server information passed is + # hostname or ip address + if server == "localhost": + logger.error("Please specify hostname or ip address, than '%s'", + server) + return SKIP
Why not use gethostname() to get the hostname?
+ + status = get_slp_info(server) + if status != PASS: + return status + + ip_addr = gethostbyaddr(server)[2][0]
You can use gethostbyname(), which is a little cleaner. You can pass it the output from gethostname().
I tried supplying the hostname to the slp command, but it does not seem to work. Hence I choose gethostbyaddr() to get the ip from the hostname. Let me know if we can access the attrs while passing the hostname.
Using the IP address is correct. What I meant here was that instead of doing: ip_addr = gethostbyaddr(server)[2][0] You can do: host = gethostbyname() ip_addr = gethostbyname(host) This will allow people to run the test using "localhost".
+ status, slp_attrs = get_slp_attrs(ip_addr) + if status != PASS: + logger.error("Failed to get slp attributes on %s", server) + return status + + slp_profile_list = filter_reg_name_from_slp(slp_attrs) + + status, libvirt_cim_reg_list = get_libvirt_cim_profile_info(server, virt) + if status != PASS: + logger.error("Failed to enumerate profile information on %s", server) + return status + + # Make sure all the Libvirt-CIM profiles are advertised via slp + if (libvirt_cim_reg_list) <= (slp_profile_list): + logger.info("Successfully verified the Libvirt-CIM profiles") + return PASS + else:
No need for the else here. Don't we want to print an error message if we dont get the expected Libvirt-CIM profiles ?
Sure - but you don't need the else. If the test passed, it has already returned at this point. So the else is unnecessary indentation. But it's fine to leave it as is if you want.
+ logger.error("Mismatch in the profiles registered") + logger.error("Slp returned profile --> %s,\n Libvirt-CIM expected " + "profiles %s", slp_profile_list, libvirt_cim_reg_list) + return FAIL + +if __name__=="__main__": + sys.exit(main()) +
-- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (3)
-
Deepti B Kalakeri
-
Deepti B. Kalakeri
-
Kaitlin Rupert