The fixes/ directory will be recursively copied to /usr/lib/ganeti/fixes
on the bootstrap OS. It contains a few executable scripts which will be
run with run-parts. If these are to be python scripts, most of their
code should be contained in modules in fixes/fixlib/, so that they can
be unit tested.

This patch:
- Updates p2v-target.conf.in so that python will be available on the
  bootstap os
- Changes things so that scripts is no longer a package. This is a
  result of changing PYTHONPATH in Makefile.am.
- Adds the hook script to install the fixes directory on the boostrap OS
- Creates the fixes/fixlib directory where python modules for the
  scripts will live

Signed-off-by: Ben Lipton <[email protected]>
---
 instance-p2v-target/fixes/fixlib/__init__.py       |   12 +++++++++++
 instance-p2v-target/hooks/install-fixes.in         |   21 ++++++++++++++++++++
 instance-p2v-target/p2v-target.conf.in             |    2 +-
 .../test/make_ramboot_initrd_test.py               |    4 +-
 4 files changed, 36 insertions(+), 3 deletions(-)
 create mode 100644 instance-p2v-target/fixes/fixlib/__init__.py
 create mode 100644 instance-p2v-target/hooks/install-fixes.in
 delete mode 100644 instance-p2v-target/scripts/__init__.py

diff --git a/instance-p2v-target/fixes/fixlib/__init__.py 
b/instance-p2v-target/fixes/fixlib/__init__.py
new file mode 100644
index 0000000..2b122cf
--- /dev/null
+++ b/instance-p2v-target/fixes/fixlib/__init__.py
@@ -0,0 +1,12 @@
+#!/usr/bin/python2.4
+#
+# Copyright 2011 Google Inc. All Rights Reserved.
+
+"""Code for python fix scripts.
+
+Fixlib is a package for the actual code of the python fix scripts, so that they
+can be unit tested but also run with run-parts.
+"""
+
+class FixError(Exception):
+  pass
diff --git a/instance-p2v-target/hooks/install-fixes.in 
b/instance-p2v-target/hooks/install-fixes.in
new file mode 100644
index 0000000..961de1d
--- /dev/null
+++ b/instance-p2v-target/hooks/install-fixes.in
@@ -0,0 +1,21 @@
+#!/bin/sh
+
+set -e
+
+# Make sure we're not working on the root directory
+if [ -z "$TARGET" -o "$TARGET" = "/" ]; then
+    echo "Invalid target directory '$TARGET', aborting." 1>&2
+    exit 1
+fi
+
+if [ "$(mountpoint -d /)" = "$(mountpoint -d "$TARGET")" ]; then
+    echo "The target directory seems to be the root dir, aborting."  1>&2
+    exit 1
+fi
+
+# Copy the fixes from @configdir@/fixes to the instance:
+mkdir -p "$TARGET/usr/lib/ganeti"
+cp -r "@configdir@/fixes" "$TARGET/usr/lib/ganeti"
+
+exit 0
+
diff --git a/instance-p2v-target/p2v-target.conf.in 
b/instance-p2v-target/p2v-target.conf.in
index 615777f..3decbbb 100644
--- a/instance-p2v-target/p2v-target.conf.in
+++ b/instance-p2v-target/p2v-target.conf.in
@@ -37,7 +37,7 @@
 # EXTRA_PKGS="acpi-support-base,console-tools,udev,linux-image-amd64"
 
 # Additional packages required for p2v-target image
-EXTRA_PKGS+=",rsync,openssh-server"
+EXTRA_PKGS+=",rsync,openssh-server,python"
 
 # CUSTOMIZE_DIR: a directory containing scripts to customize the installation.
 # The scripts are executed using run-parts
diff --git a/instance-p2v-target/scripts/__init__.py 
b/instance-p2v-target/scripts/__init__.py
deleted file mode 100644
index e69de29..0000000
diff --git a/instance-p2v-target/test/make_ramboot_initrd_test.py 
b/instance-p2v-target/test/make_ramboot_initrd_test.py
index c6c3b93..36e534c 100755
--- a/instance-p2v-target/test/make_ramboot_initrd_test.py
+++ b/instance-p2v-target/test/make_ramboot_initrd_test.py
@@ -17,7 +17,7 @@
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 # 02110-1301, USA.
 
-"""Tests for scripts.make_ramboot_initrd."""
+"""Tests for make_ramboot_initrd."""
 
 import os
 import platform
@@ -26,7 +26,7 @@ import tempfile
 import unittest
 import mox
 
-import scripts.make_ramboot_initrd as mkinitrd
+import make_ramboot_initrd as mkinitrd
 
 class MakeRambootInitrdTest(unittest.TestCase):
   SRCDIR = os.environ.get("SRCDIR", ".")
-- 
1.7.3.1

Reply via email to