Skip to content

Commit

Permalink
Speed up guest announcement on newer OSs.
Browse files Browse the repository at this point in the history
A newer OS that uses NetworkManager can significantly
speed up guest announcement by using dispatch scripts.
These are scripts that execute when a NetworkManager
event happens, like eth0 getting connected.  Note that
we still leave the cron job in place; in the worst
case, the Oz process running on the host may miss
this announcement, and the cron job will make sure that
it gets seen (on average, 30 seconds later).

Signed-off-by: Chris Lalancette <[email protected]>
  • Loading branch information
clalancette committed Nov 26, 2013
1 parent 21d80aa commit 3658319
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 32 deletions.
32 changes: 5 additions & 27 deletions TODO
Original file line number Diff line number Diff line change
Expand Up @@ -92,38 +92,16 @@
16. We should add additional commands section. In particular, we should have
"pre" package installation and "post" package installation command
sections.
17. On distributions that use NetworkManager, we can speed up the customization
and ICICLE generation step by using dbus-monitor to monitor when
NetworkManager has brought up the network. This should save us an average
of 30 seconds per customization. The script to do this would look
something like:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

while true; do
gdbus introspect --system --dest org.freedesktop.NetworkManager --object-path
/org/freedesktop/NetworkManager/Devices/0 | grep "State = 100" > /dev/null
if [ $? -eq 0 ]
then
break
fi
sleep 1
done

18. Support hashes for the root password support.
19. Add a mode where we use a reverse ssh tunnel with a SOCKS proxy to
17. Support hashes for the root password support.
18. Add a mode where we use a reverse ssh tunnel with a SOCKS proxy to
download the packages. This means that the packages need to be visible to
the imagefactory machine, but not necessarily to the instance.
20. During customization/icicle generation, we should check to make sure that
19. During customization/icicle generation, we should check to make sure that
the bridge listed in the libvirt XML matches up with what we detected (if
anything). This isn't really an issue when doing oz-install -g -u, but if
you use the short-circuit oz-customize or oz-generate-icicle, the user
could have fed us bad data.
21. Currently we use libguestfs to extract the installation ISO, make changes
20. Currently we use libguestfs to extract the installation ISO, make changes
to it, and then rebundle the ISO using mkisofs. This is time consuming,
partially because we are doing two copies of the ISO (once from the ISO to
the filesystem, and once from the filesystem to the new ISO), and partially
Expand All @@ -133,6 +111,6 @@ done
directory, and only modifying the small bits we need to. Then we can pack
the whole thing back up using mkisofs. This gets rid of the first copy, so
it should cut our initial time in half (plus or minus the page cache).
22. Change setup.py to make the directories /var/lib/oz/*. Since that is
21. Change setup.py to make the directories /var/lib/oz/*. Since that is
repeated in both of the RPM and deb building stuff, it would be better to
just do it on python setup.py install instead.
24 changes: 23 additions & 1 deletion oz/OpenSUSE.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def _image_ssh_teardown_step_3(self, g_handle):
self.log.debug("Teardown step 3")
# remove announce cronjob
self.log.debug("Resetting announcement to host")
self._guestfs_remove_if_exists(g_handle,
'/etc/NetworkManager/dispatcher.d/99-announce')
self._guestfs_remove_if_exists(g_handle, '/etc/cron.d/announce')

# remove reportip
Expand Down Expand Up @@ -255,10 +257,30 @@ def _image_ssh_setup_step_3(self, g_handle):
"""
# part 3; make sure the guest announces itself
self.log.debug("Step 3: Guest announcement")

scriptfile = os.path.join(self.icicle_tmp, "script")

if g_handle.exists("/etc/NetworkManager/dispatcher.d"):
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
if [ "$1" = "eth0" -a "$2" = "up" ]; then
echo -n "!$DHCP4_IP_ADDRESS,%s!" > /dev/ttyS1
fi
""" % (self.uuid))

try:
g_handle.upload(scriptfile,
'/etc/NetworkManager/dispatcher.d/99-reportip')
g_handle.chmod(0755,
'/etc/NetworkManager/dispatcher.d/99-reportip')
finally:
os.unlink(scriptfile)

if not g_handle.exists('/etc/init.d/cron') or not g_handle.exists('/usr/sbin/cron'):
raise oz.OzException.OzException("cron not installed on the image, cannot continue")

scriptfile = os.path.join(self.icicle_tmp, "script")
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
Expand Down
28 changes: 26 additions & 2 deletions oz/RedHat.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,10 @@ def _image_ssh_teardown_step_4(self, g_handle):
Fourth step to undo _image_ssh_setup (remove guest announcement).
"""
self.log.debug("Teardown step 4")
self.log.debug("Removing announcement to host")
self._guestfs_remove_if_exists(g_handle,
'/etc/NetworkManager/dispatcher.d/99-announce')

# remove announce cronjob
self.log.debug("Resetting announcement to host")
self._guestfs_remove_if_exists(g_handle, '/etc/cron.d/announce')
Expand Down Expand Up @@ -318,10 +322,30 @@ def _image_ssh_setup_step_4(self, g_handle):
"""
# part 4; make sure the guest announces itself
self.log.debug("Step 4: Guest announcement")

scriptfile = os.path.join(self.icicle_tmp, "script")

if g_handle.exists("/etc/NetworkManager/dispatcher.d"):
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
if [ "$1" = "eth0" -a "$2" = "up" ]; then
echo -n "!$DHCP4_IP_ADDRESS,%s!" > /dev/ttyS1
fi
""" % (self.uuid))

try:
g_handle.upload(scriptfile,
'/etc/NetworkManager/dispatcher.d/99-reportip')
g_handle.chmod(0755,
'/etc/NetworkManager/dispatcher.d/99-reportip')
finally:
os.unlink(scriptfile)

if not g_handle.exists('/usr/sbin/crond'):
raise oz.OzException.OzException("cron not installed on the image, cannot continue")

scriptfile = os.path.join(self.icicle_tmp, "script")
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
Expand All @@ -334,7 +358,7 @@ def _image_ssh_setup_step_4(self, g_handle):

try:
g_handle.upload(scriptfile, '/root/reportip')
g_handle.chmod(0o755, '/root/reportip')
g_handle.chmod(0755, '/root/reportip')
finally:
os.unlink(scriptfile)

Expand Down
27 changes: 25 additions & 2 deletions oz/Ubuntu.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ def _image_ssh_teardown_step_3(self, g_handle):
self.log.debug("Teardown step 3")
# remove announce cronjob
self.log.debug("Resetting announcement to host")
self._guestfs_remove_if_exists(g_handle,
'/etc/NetworkManager/dispatcher.d/99-announce')

self._guestfs_remove_if_exists(g_handle, '/etc/cron.d/announce')

# remove reportip
Expand Down Expand Up @@ -313,10 +316,30 @@ def _image_ssh_setup_step_3(self, g_handle):
"""
# part 3; make sure the guest announces itself
self.log.debug("Step 3: Guest announcement")

scriptfile = os.path.join(self.icicle_tmp, "script")

if g_handle.exists("/etc/NetworkManager/dispatcher.d"):
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
if [ "$1" = "eth0" -a "$2" = "up" ]; then
echo -n "!$DHCP4_IP_ADDRESS,%s!" > /dev/ttyS1
fi
""" % (self.uuid))

try:
g_handle.upload(scriptfile,
'/etc/NetworkManager/dispatcher.d/99-reportip')
g_handle.chmod(0755,
'/etc/NetworkManager/dispatcher.d/99-reportip')
finally:
os.unlink(scriptfile)

if not g_handle.exists('/usr/sbin/cron'):
raise oz.OzException.OzException("cron not installed on the image, cannot continue")

scriptfile = os.path.join(self.icicle_tmp, "script")
with open(scriptfile, 'w') as f:
f.write("""\
#!/bin/bash
Expand All @@ -330,7 +353,7 @@ def _image_ssh_setup_step_3(self, g_handle):

try:
g_handle.upload(scriptfile, '/root/reportip')
g_handle.chmod(0o755, '/root/reportip')
g_handle.chmod(0755, '/root/reportip')
finally:
os.unlink(scriptfile)

Expand Down

0 comments on commit 3658319

Please sign in to comment.