'started libvirt-bin' event occurs before libvirt networks available

Bug #1056927 reported by Scott Moser
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
libvirt (Ubuntu)
Triaged
Medium
Unassigned

Bug Description

I was trying to create an event that occurred on libvirt coming up:
$ cat /etc/init/libvirt-isc-dhcpd-restart.conf
description "restart dhcpd"
start on started libvirt-bin
task
script
sleep 5 # hack, let the interfaces comeup
start maas-dhcp-server
end script

Specifically I was looking for the availability of a given network in libvirt (see bug 1056921), but 'started' would have been fine. The problem was that libvirt daemonizes (and goes to 'started') before all of its 'auto' created networks are up.

Basically, given:
BRIDGE="smbr0"
cat > libvirt-$BRIDGE.xml <<EOF
<network>
  <name>$BRIDGE</name>
  <forward mode='nat'/>
  <bridge name='$BRIDGE' stp='off' delay='0' />
  <ip address='192.168.77.1' netmask='255.255.255.0'>
  </ip>
</network>
EOF

sg libvirtd -c "virsh -c qemu:///system net-define libvirt-$BRIDGE.xml"
sg libvirtd -c "virsh -c qemu:///system net-autostart $BRIDGE"
sg libvirtd -c "virsh -c qemu:///system net-start $BRIDGE"

I'm suggesting that 'started libvirt-bin' should mean that $BRIDGE is up.

ProblemType: Bug
DistroRelease: Ubuntu 12.10
Package: libvirt-bin 0.9.13-0ubuntu10
ProcVersionSignature: User Name 3.5.0-15.23-generic 3.5.4
Uname: Linux 3.5.0-15-generic x86_64
ApportVersion: 2.5.2-0ubuntu4
Architecture: amd64
Date: Wed Sep 26 14:57:54 2012
Ec2AMI: ami-00000153
Ec2AMIManifest: FIXME
Ec2AvailabilityZone: nova
Ec2InstanceType: m1.small
Ec2Kernel: unavailable
Ec2Ramdisk: unavailable
ProcEnviron:
 TERM=screen
 PATH=(custom, no user)
 LANG=en_US.UTF-8
 SHELL=/bin/bash
SourcePackage: libvirt
UpgradeStatus: No upgrade log present (probably fresh install)

Revision history for this message
Scott Moser (smoser) wrote :
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks for this bug report.

There was a session at the last UDS about how upstart could detect service readiness. I'm going to temporarily assign this bug to jodh to ask for his feedback on how this would best be done, since AIUI upstart simply says "libvirt has started running', and I can't recall what was the answer to whether or how it could detect 'libvirt is ready'. I do recall that the idea of upstart statements saying "it is ready when port xyz is up' was in the end rejected.

Changed in libvirt (Ubuntu):
importance: Undecided → Medium
assignee: nobody → James Hunt (jamesodhunt)
Revision history for this message
James Hunt (jamesodhunt) wrote :

The simplest idiom here is to use a 'post-start' to allow you to perform some libvirt check on its bridges: only once the post-start has completed is the 'started JOB=libvirt-bin' event emitted.

Changed in libvirt (Ubuntu):
assignee: James Hunt (jamesodhunt) → nobody
Changed in libvirt (Ubuntu):
status: New → Triaged
Revision history for this message
Serge Hallyn (serge-hallyn) wrote :

Thanks, James.

So perhaps adding (a cleaned-up version of) the following would work?

post-start script
 checkifs() {
  count=0;
  virsh net-list | while read line; do
   count=$((count+1))
   if [ $count -lt 3 ]; then continue; fi
   if echo $line | awk '{ print $3 }' | grep yes > /dev/null 2>&1; then
    if [ `echo $line | awk '{ print $2 }'` = "inactive" ]; then
     echo notready
     return
    fi
   fi
  done
  echo ready
  return
 }

 while [ `checkifs` = "notready" ]; do
  sleep 1
 done
end script

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.