[PATCH 0/3] cimtest: Changes for live.full_hostname

Series of patches to close the loop on prior set of cimtest changes: http://www.redhat.com/archives/libvirt-cim/2014-April/msg00002.html Based primarily on feedback/investigation done as part of a prior cimtest commit: http://www.redhat.com/archives/libvirt-cim/2014-May/msg00012.html Patch 1 of 3 modifies the full_hostname() call to use getfqdn() only. A prior patch would attempt the gethostname() if something failed, but as seen through the documentation of the in the above link - thats also a fallback for getfqdn(). Patches 2&3 remove the check_sblim() usage. See the commit messages for details. John Ferlan (3): live.full_hostname: Adjust mechanism to get FQDN HostSystem: Remove call to check_sblim XenKvmLib: Remove check_sblim() lib/VirtLib/live.py | 6 +-- .../cimtest/ElementConforms/04_ectp_rev_errs.py | 2 +- suites/libvirt-cim/cimtest/HostSystem/01_enum.py | 56 +++++++--------------- .../cimtest/HostSystem/03_hs_to_settdefcap.py | 2 +- suites/libvirt-cim/lib/XenKvmLib/common_util.py | 28 ----------- suites/libvirt-cim/lib/XenKvmLib/vxml.py | 2 +- 6 files changed, 24 insertions(+), 72 deletions(-) -- 1.9.0

Use socket.getfqdn() rather than socket.gethostbyaddr(socket.gethostname())[0] to return the fully qualified domain name. Also, since the input parameter 'server' was never used - just remove it Signed-off-by: John Ferlan <jferlan@redhat.com> --- lib/VirtLib/live.py | 6 +++--- suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py | 2 +- suites/libvirt-cim/cimtest/HostSystem/01_enum.py | 4 ++-- suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py | 2 +- suites/libvirt-cim/lib/XenKvmLib/vxml.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py index c929e71..45a6713 100644 --- a/lib/VirtLib/live.py +++ b/lib/VirtLib/live.py @@ -99,7 +99,7 @@ def hostname(server): return out -def full_hostname(server): - """To return the fully qualifiec domain name(FQDN) of the system""" +def full_hostname(): + """To return the fully qualified domain name(FQDN) of the system""" - return socket.gethostbyaddr(socket.gethostname())[0] + return socket.getfqdn() diff --git a/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py b/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py index fa92176..b724815 100644 --- a/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py +++ b/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py @@ -155,7 +155,7 @@ def main(): hs = get_typed_class(options.virt, "HostSystem") cs = get_typed_class(options.virt, "ComputerSystem") - host_name = full_hostname(options.ip) + host_name = full_hostname() host_name_val = [ 'CreationClassName', hs, 'Name', host_name diff --git a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py index fd44b8b..75d6f5d 100644 --- a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py +++ b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py @@ -40,8 +40,8 @@ SUPPORTED_TYPES = ['Xen', 'KVM', 'XenFV', 'LXC'] @do_main(SUPPORTED_TYPES) def main(): options = main.options - host = full_hostname(options.ip) - + host = full_hostname() + status = FAIL keys = ['Name', 'CreationClassName'] name = get_typed_class(options.virt, 'HostSystem') diff --git a/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py b/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py index f960911..8bbe8c1 100644 --- a/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py +++ b/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py @@ -100,7 +100,7 @@ def get_inst_from_list(cn, qcn, list, filter, exp_val): def get_hostsys(server, virt="Xen"): status = PASS - host = full_hostname(server) + host = full_hostname() try: status, host_inst = get_host_info(server, virt) diff --git a/suites/libvirt-cim/lib/XenKvmLib/vxml.py b/suites/libvirt-cim/lib/XenKvmLib/vxml.py index 3bea13c..c38b4dd 100644 --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py @@ -1109,7 +1109,7 @@ def get_class(virt): def set_default(server): dict = {} - dict['default_sysname'] = live.full_hostname(server) + dict['default_sysname'] = live.full_hostname() dict['default_port'] = CIM_PORT dict['default_url'] = "%s:%s" % (dict['default_sysname'], dict['default_port']) -- 1.9.0

It works fine for me. hostname mismatch issue has been solved by this patch. Thanks, Xu Wang 于 2014年05月21日 02:26, John Ferlan 写道:
Use socket.getfqdn() rather than socket.gethostbyaddr(socket.gethostname())[0] to return the fully qualified domain name. Also, since the input parameter 'server' was never used - just remove it
Signed-off-by: John Ferlan <jferlan@redhat.com> --- lib/VirtLib/live.py | 6 +++--- suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py | 2 +- suites/libvirt-cim/cimtest/HostSystem/01_enum.py | 4 ++-- suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py | 2 +- suites/libvirt-cim/lib/XenKvmLib/vxml.py | 2 +- 5 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py index c929e71..45a6713 100644 --- a/lib/VirtLib/live.py +++ b/lib/VirtLib/live.py @@ -99,7 +99,7 @@ def hostname(server):
return out
-def full_hostname(server): - """To return the fully qualifiec domain name(FQDN) of the system""" +def full_hostname(): + """To return the fully qualified domain name(FQDN) of the system"""
- return socket.gethostbyaddr(socket.gethostname())[0] + return socket.getfqdn() diff --git a/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py b/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py index fa92176..b724815 100644 --- a/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py +++ b/suites/libvirt-cim/cimtest/ElementConforms/04_ectp_rev_errs.py @@ -155,7 +155,7 @@ def main():
hs = get_typed_class(options.virt, "HostSystem") cs = get_typed_class(options.virt, "ComputerSystem") - host_name = full_hostname(options.ip) + host_name = full_hostname() host_name_val = [ 'CreationClassName', hs, 'Name', host_name diff --git a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py index fd44b8b..75d6f5d 100644 --- a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py +++ b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py @@ -40,8 +40,8 @@ SUPPORTED_TYPES = ['Xen', 'KVM', 'XenFV', 'LXC'] @do_main(SUPPORTED_TYPES) def main(): options = main.options - host = full_hostname(options.ip) - + host = full_hostname() + status = FAIL keys = ['Name', 'CreationClassName'] name = get_typed_class(options.virt, 'HostSystem') diff --git a/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py b/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py index f960911..8bbe8c1 100644 --- a/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py +++ b/suites/libvirt-cim/cimtest/HostSystem/03_hs_to_settdefcap.py @@ -100,7 +100,7 @@ def get_inst_from_list(cn, qcn, list, filter, exp_val):
def get_hostsys(server, virt="Xen"): status = PASS - host = full_hostname(server) + host = full_hostname()
try: status, host_inst = get_host_info(server, virt) diff --git a/suites/libvirt-cim/lib/XenKvmLib/vxml.py b/suites/libvirt-cim/lib/XenKvmLib/vxml.py index 3bea13c..c38b4dd 100644 --- a/suites/libvirt-cim/lib/XenKvmLib/vxml.py +++ b/suites/libvirt-cim/lib/XenKvmLib/vxml.py @@ -1109,7 +1109,7 @@ def get_class(virt):
def set_default(server): dict = {} - dict['default_sysname'] = live.full_hostname(server) + dict['default_sysname'] = live.full_hostname() dict['default_port'] = CIM_PORT dict['default_url'] = "%s:%s" % (dict['default_sysname'], dict['default_port'])

Following the lead of commit id 'd669e64e', remove the check_sblim(). Then rework the remaining code to remove the "ret == PASS" section which was only done when check_sblim() was a valid function. Also removed spurious whitespace and reworked failure checks to check and message each condition separately - otherwise it was possible to get a message where expected and got values were the same if either failed. Signed-off-by: John Ferlan <jferlan@redhat.com> --- suites/libvirt-cim/cimtest/HostSystem/01_enum.py | 52 ++++++++---------------- 1 file changed, 16 insertions(+), 36 deletions(-) diff --git a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py index 75d6f5d..8ddc8b2 100644 --- a/suites/libvirt-cim/cimtest/HostSystem/01_enum.py +++ b/suites/libvirt-cim/cimtest/HostSystem/01_enum.py @@ -28,9 +28,8 @@ import sys from XenKvmLib import enumclass from XenKvmLib.classes import get_typed_class -from VirtLib.live import full_hostname +from VirtLib.live import full_hostname from VirtLib import utils -from XenKvmLib.common_util import check_sblim from CimTest.Globals import logger, CIM_ERROR_ENUMERATE from XenKvmLib.const import do_main from CimTest.ReturnCodes import PASS, FAIL @@ -42,48 +41,29 @@ def main(): options = main.options host = full_hostname() - status = FAIL keys = ['Name', 'CreationClassName'] name = get_typed_class(options.virt, 'HostSystem') - - ret, linux_cs = check_sblim(options.ip, options.virt) + try: hs = enumclass.EnumInstances(options.ip, name) except Exception, details: logger.error("%s %s: %s", CIM_ERROR_ENUMERATE, name, details) - status = FAIL + return FAIL + + if len(hs) != 1: + logger.error("Expected 1 %s instance returned got %d", name, len(hs)) + return FAIL - if ret == PASS: - if len(hs) != 0: - if hs[0].CreationClassName != name or hs[0].Name != host: - logger.error("Exp %s, got %s", name, hs[0].CreationClassName) - logger.error("Exp %s, got %s", host, hs[0].Name) - return FAIL - else: - return PASS - else: - if linux_cs.CreationClassName != 'Linux_ComputerSystem'\ - or linux_cs.Name != host: - logger.error("Exp Linux_ComputerSystem, got %s", - linux_cs.CreationClassName) - logger.error("Exp %s, got %s", host, system.Name) - return FAIL - else: - return PASS - else: - if len(hs) != 1: - logger.error("Expected 1 %s instance returned", name) - return FAIL - - system = hs[0] + system = hs[0] - if system.CreationClassName != name or system.Name != host: - logger.error("Exp %s, got %s", name, system.CreationClassName) - logger.error("Exp %s, got %s", host, system.Name) - status = FAIL - else: - logger.info("%s is %s", name, host) - status = PASS + status = PASS + logger.info("%s is %s", name, host) + if system.CreationClassName != name: + status = FAIL + logger.error("Exp %s, got %s", name, system.CreationClassName) + if system.Name != host: + logger.error("Exp %s, got %s", host, system.Name) + status = FAIL return status -- 1.9.0

Seeing as "some day" has never come - just remove the check_sblim() function so as to not have unused code lying around to wonder about. Signed-off-by: John Ferlan <jferlan@redhat.com> --- suites/libvirt-cim/lib/XenKvmLib/common_util.py | 28 ------------------------- 1 file changed, 28 deletions(-) diff --git a/suites/libvirt-cim/lib/XenKvmLib/common_util.py b/suites/libvirt-cim/lib/XenKvmLib/common_util.py index 0e3f1d6..3b35167 100644 --- a/suites/libvirt-cim/lib/XenKvmLib/common_util.py +++ b/suites/libvirt-cim/lib/XenKvmLib/common_util.py @@ -154,13 +154,6 @@ def poll_for_state_change(server, virt, dom, exp_state, timeout=30): def get_host_info(server, virt): try: - # Commenting out sblim check as libvirt-cim is not supporting it anymore. - # Leaving them commented, in case we add support for sblim at later time. - - # status, linux_cs = check_sblim(server) - # if status == PASS: - # return status, linux_cs - hs_class = get_typed_class(virt, 'HostSystem') host_info = enumclass.EnumInstances(server, hs_class) if len(host_info) == 1: @@ -458,27 +451,6 @@ def libvirt_cached_data_poll(ip, virt, dom_name): return cs -def check_sblim(server, virt='Xen'): - status = FAIL - prev_namespace = Globals.CIM_NS - Globals.CIM_NS = 'root/cimv2' - keys = ['Name', 'CreationClassName'] - linux_cs = None - cs = 'Linux_ComputerSystem' - try: - linux = enumclass.EnumInstances(server, cs) - if len(linux) == 1: - status = PASS - linux_cs = linux[0] - else: - logger.info("Enumerate of Linux_ComputerSystem return NULL") - except Exception, detail: - logger.error(CIM_ERROR_ENUMERATE, 'Linux_ComputerSystem') - logger.error("Exception: %s", detail) - - Globals.CIM_NS = prev_namespace - return status, linux_cs - def parse_instance_id(instid): str_arr = instid.split("/") if len(str_arr) < 2: -- 1.9.0

On 05/20/2014 02:26 PM, John Ferlan wrote:
Series of patches to close the loop on prior set of cimtest changes:
http://www.redhat.com/archives/libvirt-cim/2014-April/msg00002.html
Based primarily on feedback/investigation done as part of a prior cimtest commit:
http://www.redhat.com/archives/libvirt-cim/2014-May/msg00012.html
Patch 1 of 3 modifies the full_hostname() call to use getfqdn() only. A prior patch would attempt the gethostname() if something failed, but as seen through the documentation of the in the above link - thats also a fallback for getfqdn().
Patches 2&3 remove the check_sblim() usage. See the commit messages for details.
John Ferlan (3): live.full_hostname: Adjust mechanism to get FQDN HostSystem: Remove call to check_sblim XenKvmLib: Remove check_sblim()
lib/VirtLib/live.py | 6 +-- .../cimtest/ElementConforms/04_ectp_rev_errs.py | 2 +- suites/libvirt-cim/cimtest/HostSystem/01_enum.py | 56 +++++++--------------- .../cimtest/HostSystem/03_hs_to_settdefcap.py | 2 +- suites/libvirt-cim/lib/XenKvmLib/common_util.py | 28 ----------- suites/libvirt-cim/lib/XenKvmLib/vxml.py | 2 +- 6 files changed, 24 insertions(+), 72 deletions(-)
Any thoughts/comments on patches 2 & 3 to remove check_sblim()? Tks, John
participants (2)
-
John Ferlan
-
Xu Wang