Hello good friends,
I've installed Fedora 22 on a new work laptop today and started to do
my usual setup to get things going.
I've realized that virt-test is not working on Fedora, because the good
ol' trick of using
socket.gethostbyname(socket.gethostname())
Is not working for F22, as it returns some bogus value, such as
92.242.140.67.
I've been thinking of solutions, but the only one I could find that
would possibly work in other hosts does require a connection to a
network resource of some sort, such as 'redhat.com' (see below).
Now, this is not quite ideal, so I'm writing this e-mail to see if any
of you has a good idea that we could use.
Or maybe this is some bug in Fedora 22 that is yet to be fixed. Anyway,
some food for thought.
Cheers,
Lucas
From 0e04529d57ece9dedfe9e428deb95eb6d6b687da Mon Sep 17 00:00:00 2001
From: Lucas Meneghel Rodrigues <[email protected]>
Date: Wed, 1 Apr 2015 21:35:58 -0300
Subject: [PATCH] virttest.virt_vm: Alternate method for locating local
machine
IP
Sometimes, socket.gethostbyname(socket.gethostname()) just doesn't
cut it, as I found it to be the case in my fresh Fedora 22 install.
One proposal of fixing this would be this fairly unorthodox procedure,
which is to establish a socket, connect to an internet address and
check the socket address afterwards. This only works if we have
an internet connection, though.
n
Signed-off-by: Lucas Meneghel Rodrigues <[email protected]>
---
virttest/virt_vm.py | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/virttest/virt_vm.py b/virttest/virt_vm.py
index 5ebf6be..1933940 100644
--- a/virttest/virt_vm.py
+++ b/virttest/virt_vm.py
@@ -642,8 +642,9 @@ class BaseVM(object):
self.ip_version = self.params.get("ip_version", "ipv4").lower()
# TODO: Determine port redirection in use w/o checking nettype
if nic.nettype not in ['bridge', 'macvtap']:
- hostname = socket.gethostname()
- return socket.gethostbyname(hostname)
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.connect(('redhat.com', 0))
+ return socket.gethostbyname(s.getsockname()[0])
if not nic.has_key('mac') and self.params.get('vm_type') ==
'libvirt':
# Look it up from xml
nic.mac = self.get_virsh_mac_address(index)
--
2.3.4
_______________________________________________
Virt-test-devel mailing list
[email protected]
https://www.redhat.com/mailman/listinfo/virt-test-devel