← Back to team overview

yellow team mailing list archive

[Merge] lp:~frankban/launchpad/setuplxc-dns-management into lp:launchpad

 

Francesco Banconi has proposed merging lp:~frankban/launchpad/setuplxc-dns-management into lp:launchpad.

Requested reviews:
  Launchpad Yellow Squad (yellow)

For more details, see:
https://code.launchpad.net/~frankban/launchpad/setuplxc-dns-management/+merge/97421

== Changes ==

The build script generated by setuplxc now fetches the container ip address and uses it (rather than the lxc name) to connect via ssh.

The ip address is retrieved parsing dhcp leases: the script uses the correct leases path for current system.

-- 
https://code.launchpad.net/~frankban/launchpad/setuplxc-dns-management/+merge/97421
Your team Launchpad Yellow Squad is requested to review the proposed merge of lp:~frankban/launchpad/setuplxc-dns-management into lp:launchpad.
=== modified file 'utilities/setuplxc.py'
--- utilities/setuplxc.py	2012-03-13 09:57:26 +0000
+++ utilities/setuplxc.py	2012-03-14 15:20:29 +0000
@@ -763,8 +763,15 @@
 
 def create_scripts(user, lxcname, ssh_key_path):
     """Create scripts to update the Launchpad environment and run tests."""
+    # Leases path in lucid differs from the one in oneiric/precise.
     mapping = {
+        'leases1': get_container_path(
+            lxcname, '/var/lib/dhcp3/dhclient.eth0.leases'),
+        'leases2': get_container_path(
+            lxcname, '/var/lib/dhcp/dhclient.eth0.leases'),
         'lxcname': lxcname,
+        'pattern':
+            r's/.* ([0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}).*/\1/',
         'ssh_key_path': ssh_key_path,
         'user': user,
         }
@@ -775,21 +782,43 @@
         script.write(textwrap.dedent("""\
             #!/bin/sh
             set -ux
+            truncate -c -s0 {leases1}
+            truncate -c -s0 {leases2}
+
             lxc-start -n {lxcname} -d
             lxc-wait -n {lxcname} -s RUNNING
-            for i in $(seq 1 30); do
-                su {user} -c "/usr/bin/ssh -o StrictHostKeyChecking=no \\
-                    -i '{ssh_key_path}' {lxcname} make -C $PWD schema"
-                if [ ! 255 -eq $? ]; then
-                    # If ssh returns 255 then its connection failed.
-                    # Anything else is either success (status 0) or a
-                    # failure from whatever we ran over the SSH connection.
-                    # In those cases we want to stop looping, so we break
-                    # here.
-                    break;
-                fi
+
+            delay=30
+            while [ $delay -gt 0 -a ! -s {leases1} -a ! -s {leases2} ]
+            do
+                delay=$(( $delay - 1 ))
                 sleep 1
             done
+
+            [ -s {leases1} ] && LEASES={leases1} || LEASES={leases2}
+            IP_ADDRESS=`grep fixed-address $LEASES | \\
+                tail -n 1 | sed -r '{pattern}'`
+
+            if [ 0 -eq $? -a -n "$IP_ADDRESS" ]; then
+                for i in $(seq 1 30); do
+                    su {user} -c "/usr/bin/ssh -o StrictHostKeyChecking=no \\
+                        -i '{ssh_key_path}' $IP_ADDRESS make -C $PWD schema"
+                    if [ ! 255 -eq $? ]; then
+                        # If ssh returns 255 then its connection failed.
+                        # Anything else is either success (status 0) or a
+                        # failure from whatever we ran over the SSH connection.
+                        # In those cases we want to stop looping, so we break
+                        # here.
+                        break;
+                    fi
+                    sleep 1
+                done
+            else
+                echo "could not get IP address - aborting." >&2
+                echo "content of $LEASES:" >&2
+                cat $LEASES >&2
+            fi
+
             lxc-stop -n {lxcname}
             lxc-wait -n {lxcname} -s STOPPED
             """.format(**mapping)))