launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #01618
[Merge] lp:~abentley/launchpad/detect-xen into lp:launchpad/devel
LaMont Jones has proposed merging lp:~abentley/launchpad/detect-xen into lp:launchpad/devel.
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
Related bugs:
#662664 recipe builds should ensure they run only under xen
https://bugs.launchpad.net/bugs/662664
launchpad-buildd releases from launchpad/devel, not launchpad.
--
https://code.launchpad.net/~abentley/launchpad/detect-xen/+merge/38867
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~abentley/launchpad/detect-xen into lp:launchpad/devel.
=== modified file 'lib/canonical/buildd/buildrecipe'
--- lib/canonical/buildd/buildrecipe 2010-09-09 14:12:02 +0000
+++ lib/canonical/buildd/buildrecipe 2010-10-19 18:01:48 +0000
@@ -7,10 +7,12 @@
__metaclass__ = type
+import errno
import os
import pwd
+import re
import socket
-from subprocess import call
+from subprocess import call, Popen, PIPE
import sys
@@ -21,6 +23,26 @@
RETCODE_FAILURE_BUILD_SOURCE_PACKAGE = 203
+class NotVirtualized(Exception):
+ """Exception raised when not running in a virtualized environment."""
+
+
+class NoXenDetect(NotVirtualized):
+ """xen-detect not installed."""
+
+ def __init__(self):
+ NotVirtualized.__init__(self, 'xen-detect is not installed.')
+
+
+class BadXenDetect(NotVirtualized):
+ """xen-detect's output not not indicate that we are virtualized."""
+
+ def __init__(self, xen_detect_output):
+ NotVirtualized.__init__(
+ self, 'Bad xen-detect output: %s' % xen_detect_output)
+ self.xen_detect_output = xen_detect_output
+
+
class RecipeBuilder:
"""Builds a package from a recipe."""
@@ -64,6 +86,12 @@
As a side-effect, sets self.source_dir_relative.
:return: a retcode from `bzr dailydeb`.
"""
+ try:
+ ensure_virtualized()
+ except NotVirtualized, e:
+ sys.stderr.write('Aborting on failed virtualization check:\n')
+ sys.stderr.write(str(e))
+ return 1
assert not os.path.exists(self.tree_path)
recipe_path = os.path.join(self.work_dir, 'recipe')
manifest_path = os.path.join(self.tree_path, 'manifest')
@@ -159,6 +187,24 @@
return os.path.join(
os.environ["HOME"], "build-" + build_id, *extra)
+
+def ensure_virtualized():
+ """Raise an exception if not running in a virtualized environment.
+
+ Raises if unsure, or if not running under Xen.
+ """
+ try:
+ proc = Popen(['xen-detect'], stdout=PIPE)
+ except OSError, e:
+ if e.errno != errno.ENOENT:
+ raise
+ raise NoXenDetect()
+ status_code = proc.wait()
+ output = proc.stdout.read()
+ if not re.match('Running in .* context on Xen', output):
+ raise BadXenDetect(output)
+
+
if __name__ == '__main__':
builder = RecipeBuilder(*sys.argv[1:])
if builder.buildTree() != 0: