[Libvirt-cim] [PATCH 01/10] live.full_hostname: Adjust mechanism to get FQDN

Xu Wang cngesaint at gmail.com
Mon Apr 14 06:15:54 UTC 2014


于 2014年04月05日 00:12, John Ferlan 写道:
> Rather than default to socket.gethostbyaddr(socket.gethostname())[0] to
> get full_hostname(), go through a sequence of steps to get a more
> correct result
>
> NOTE:
> See http://www.redhat.com/archives/libvirt-cim/2013-November/msg00082.html
> for more details and history.
>
> Signed-off-by: John Ferlan <jferlan at redhat.com>
> ---
>   lib/VirtLib/live.py | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/lib/VirtLib/live.py b/lib/VirtLib/live.py
> index c929e71..e9cafc1 100644
> --- a/lib/VirtLib/live.py
> +++ b/lib/VirtLib/live.py
> @@ -100,6 +100,11 @@ def hostname(server):
>       return out
>   
>   def full_hostname(server):
> -    """To return the fully qualifiec domain name(FQDN) of the system"""
> -
> -    return socket.gethostbyaddr(socket.gethostname())[0]
> +    """To return the fully qualified domain name(FQDN) of the system"""
> +
> +    if socket.getfqdn().find('.') >= 0:
> +        return socket.getfqdn()
> +    elif socket.gethostname().find('.') >= 0:
> +        return socket.gethostname()
> +    else:
> +        return socket.gethostbyaddr(server)[1][0]
I got an error here. The content of my /etc/hosts is,

# cat /etc/hosts
127.0.0.1 RH64wenchao localhost localhost.localdomain localhost4 
localhost4.localdomain4 #RH64wenchao

And I got an failed result,

# CIM_NS=root/virt CIM_USER=root CIM_PASS=****** ./runtests libvirt-cim 
-i localhost -c -d -v KVM -g HostSystem -t 01_enum.py
Starting test suite: libvirt-cim
Cleaned log files.

Testing KVM hypervisor
--------------------------------------------------------------------
HostSystem - 01_enum.py: FAIL
ERROR - Exp KVM_HostSystem, got KVM_HostSystem
ERROR - Exp localhost.localdomain, got RH64wenchao
CIM_ERR_INVALID_CLASS: Linux_ComputerSystem
--------------------------------------------------------------------

It means that @host and @hs[0].Name get the different value. I think it 
may happened when a computer
has more than one hostname. My suggestion is @host make a string match 
with content of every element
of @hs[] to check if @host is contained in it.

Thanks,
Xu Wang





More information about the Libvirt-cim mailing list