On 04/14/2014 02:15 AM, Xu Wang wrote:
于 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(a)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
--------------------------------------------------------------------
Took some time and I dug in a bit more on this today... the last
exception you see comes from the call to 'check_sblim()' which is used
to determine whether to go through the 'ret == PASS' or "else" clauses.
Digging into that finds another caller common_util.py/get_host_info()
which had commented out the call as part of commit id 'd669e64e' "as
libvirt-cim is not supporting sblim any more". Makes me wonder why this
particular code decides to still call it and why it did in the first place.
Regardless of whether we keep that check_sblim() call in going forward -
the enumerate instance of a "KVM_HostSystem" will return in the
"Name"
field the result of a "Virt_HostSystem.c"/get_fqdn() call. That name is
designed to be the fqdn; however, the code has a "prejudice" to not
using "localhost" and thus it seems possible to return something that's
not a fqdn.
That will be
1. gethostname() "if" it returns a name with a "." in it
2. Search gethostbyname() alias entries for an entry with "." in it
and that is not "localhost"
3. The value in hostentry->h_name field as long as it's not localhost
4. The gethostbyname() value as long as it's not localhost
Step 3 & 4 are after a "FIXME" comment about an ugly hack.
I have to assume that RH64wenchao perhaps fell into case 3 or 4.
I was able to reserve a test box and found that an "hent =
gethostbyname(hptr);" would return hent->aliases[0] == NULL. This would
cause the libvirt-cim code to fall into the code after "FIXME" returning
"h_name". In my test, that would be the hostname of the box. Why it
returned RH64wenchao for you I have no idea. On my Fedora box, I get a
list of localhost aliases returned. So my assumption is the issue has
more to do with proper network configuration.
After all that - I will re-post the code to adjust the full_hostname()
call. Additionally, I will post code to remove the check_sblim() usage.
I ran the full_hostname() on a RH65 box before/after and had no
difference in results.
John
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
_______________________________________________
Libvirt-cim mailing list
Libvirt-cim(a)redhat.com
https://www.redhat.com/mailman/listinfo/libvirt-cim