From: Thierry Parmentelat Date: Sat, 11 Apr 2015 11:38:25 +0000 (+0200) Subject: figuring out guest's ipv4 now relies on domiflist and arp - much more robust, and... X-Git-Tag: 5.3.9~52 X-Git-Url: http://git.onelab.eu/?p=build.git;a=commitdiff_plain;h=8a656cc4218a687de61bc4543203a5c56f6dd093 figuring out guest's ipv4 now relies on domiflist and arp - much more robust, and no need to cache anything --- diff --git a/build.common b/build.common index 7a09d86f..fe74e127 100644 --- a/build.common +++ b/build.common @@ -750,3 +750,16 @@ function yumconf_exclude () { sed -i -e "/#baseurl=.*$/i\\ $yumexclude_line" $repo } + +######################################## +# workaround for broken lxc-enter-namespace +# 1st version was relying on virsh net-dhcp-leases +# however this was too fragile, would not work for fedora14 containers +function guest_ipv4() { + lxc=$1; shift + + mac=$(virsh -c lxc:/// domiflist $lxc | egrep 'network|bridge' | awk '{print $5;}') + # sanity check + [ -z "$mac" ] && return 0 + arp -en | grep "$mac" | awk '{print $1;}' +} diff --git a/lbuild-initvm.sh b/lbuild-initvm.sh index cd071eae..4f6a9642 100755 --- a/lbuild-initvm.sh +++ b/lbuild-initvm.sh @@ -710,25 +710,6 @@ PROFILE EOF } -# workaround for broken lxc-enter-namespace -# relies on virsh net-dhcp-leases -# when successful we store result in /vservers//ipv4 -# because the lease expires afer a while -function guest_ipv4_cached_or_from_virsh_leases() { - lxc=$1; shift - network=default - - # place to cache result - cache=/vservers/$lxc/ipv4 - ipv4=$(cat $cache 2> /dev/null) - [ -z "$ipv4" ] && ipv4=$(virsh net-dhcp-leases $network | sed -e 's, *, ,g' | grep " $lxc " | grep ipv4 | cut -d' ' -f6 | cut -d/ -f1) - echo $ipv4 - # cache if needed - [ -n "$ipv4" -a ! -f $cache ] && echo $ipv4 > $cache - # always return 0 - return 0 -} - function wait_for_ssh () { set -x set -e @@ -746,7 +727,7 @@ function wait_for_ssh () { counter=1 while [ "$current_time" -lt "$stop_time" ] ; do echo "$counter-th attempt to reach sshd in container $lxc ..." - [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4_cached_or_from_virsh_leases $lxc) + [ -z "$guest_ip" ] && guest_ip=$(guest_ipv4 $lxc) [ -n "$guest_ip" ] && ssh -o "StrictHostKeyChecking no" $guest_ip 'uname -i' && { success=true; echo "SSHD in container $lxc is UP on IP $guest_ip"; break ; } || : counter=$(($counter+1)) diff --git a/lbuild-nightly.sh b/lbuild-nightly.sh index 6ffeb66e..1eb39c8b 100755 --- a/lbuild-nightly.sh +++ b/lbuild-nightly.sh @@ -231,13 +231,6 @@ function in_root_context () { rpm -q libvirt > /dev/null } -### lxc-enter-namespace being broken, let us try to work around this issue -# lbuild-initvm.sh stores the guest ipv4 address in /vservers//ipv4 -function guest_ipv4 () { - buildname=$1; shift - cat /vservers/$buildname/ipv4 -} - # convenient for simple commands function run_in_build_guest () { buildname=$1; shift