Anonymous avatar Anonymous committed 62a67ab

initial push of chroot python tool

Comments (0)

Files changed (3)

+# coding: utf8
+
+
+"""Small subprocess wrapper
+
+
+"""
+
+# Borrowed from vabs/vinstall
+
+import subprocess
+import functools
+
+
+__all__ = ["call", "check_call", "check_output"]
+
+
+_LOGFILE = "subprocess.log"
+
+
+def make_sp_wrapper(func):
+    def wrapper(*args, **kwargs):
+        with open(_LOGFILE, 'a') as stdio:
+            if 'stdout' not in kwargs:
+                kwargs['stdout'] = stdio
+            if 'stderr' not in kwargs:
+                kwargs['stderr'] = stdio
+            return func(*args, **kwargs)
+    return wrapper
+
+
+call = make_sp_wrapper(subprocess.call)
+check_call = make_sp_wrapper(subprocess.check_call)
+try:
+    check_output = subprocess.check_output
+except:
+    pass

pytools/vlmkchroot.py

+#!/bin/env python
+
+#    This file is part of vlbuildbot.
+#
+#    vlbuildbot is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License v3 as published by
+#    the Free Software Foundation.
+#
+#    vlbuildbot is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    See http://www.gnu.org/licenses/ for complete licensing terms.
+
+__author__ = "M0E-lnx"
+__author_email__ = "moc.liamg@xnl.e0m"[::-1]
+
+import os
+import unittest
+import sp
+import shutil
+
+class Jail(object):
+        def __init__(self, uri="", jail_location = "/tmp",
+                     jail_vector = "7.1", jail_arch = "i586"):
+                self.path = jail_location
+                self.vector = jail_vector
+                self.arch = jail_arch
+                self.uri = uri
+                self.slaptgetrc = "/tmp/slapt-getrc.vlmkchroot"
+                self.workingdir = "/tmp/vlmkchroot-cache"
+                self.blacklist = ['grub2','kernel','kernel-firmware',
+                                  'kernel-modules','vim','lilo','vlconfig2',]
+                self.append = ['nano']
+        
+        @property
+        def bburi(self):
+                uri = "http://bitbucket.org/VLCore/vabs/raw/veclinux-%s/var/vabs/VL-ISO-BB/src/pkgs"% self.vector
+                return uri
+        @property
+        def pkgsdef(self):
+                if self.uri.startswith("/"):
+                        return self.uri
+                else:
+                        # need to download the definition file
+                        self.uri = "/tmp/pkgs"
+                        sp.check_call(['wget','-c','--no-check-certificate',
+                                       self.bburi, '-O', self.uri])
+                        
+                        return self.uri
+
+        @classmethod
+        def packages(cls):
+                pklist = cls().pkgsdef
+                with open(pklist) as data:
+                        # Check if we need to append any packages here
+#                        data.append([x for x in self.append if x not in data])
+
+                        for line in data:
+                                pname = line.strip().split("/")[1]
+                                if pname not in cls().blacklist:
+                                        yield pname
+
+	@property
+	def base_repo(self):
+		"""Return the base URL for the repo"""
+		if self.vector == "7.0":
+			if self.arch == "x86_64":
+				url = os.path.join(
+						"http://vectorlinux.osuosl.org",
+						"VL64-" + self.vector)
+			else:
+				url = os.path.join(
+						"http://vectorlinux.osuosl.org",
+						"veclinux-" + self.vector)
+			return url
+		elif self.vector == "7.1":
+			if self.arch == "x86_64":
+				uarch = "x86_64"
+			elif self.arch in ["i586","i686"]:
+				uarch = "x86"
+			url = os.path.join(
+					"http://vlcore.vectorlinux.com",
+					"pkg","untested","veclinux-" + self.vector, uarch)
+			return url	
+	
+	@property
+        def software_sources(self):
+                """Return a list of software sources for the slapt-getrc for
+                this jail"""
+                res = []
+                if self.vector == "7.0":
+                        for area in ('packages','patches','extra'):
+                                res.append('SOURCE=%s' % os.path.join(
+                                        self.base_repo, area))
+                elif self.vector == '7.1':
+                        res.append('SOURCE=%s'% self.base_repo)
+                return res
+
+        @property
+	def slapt_config(self):
+		"""Generate the slapt-getrc file to be used"""
+		fbuffer = ["WORKINGDIR=%s" % self.workingdir,]
+                for line in self.software_sources:
+                        fbuffer.append(line)
+		return fbuffer
+        
+        @property
+        def jail_slapt_config(self):
+                fbuffer = ["WORKINGDIR=%s"% "/home/ftp/pub/veclinux/packages",
+                           "EXCLUDE=%s"% "kernel,kernel-ide,kernel-src,kernel-headers,kernel-modules"]
+                for line in self.software_sources:
+                        fbuffer.append(line)
+                return fbuffer
+
+	def build(self):
+		"""Create the chroot jail"""
+		pass
+	def write_config(self, path="", data = []):
+		"""write slapt_config to a text file"""
+                with open(path, 'w') as target:
+                        for line in data:
+                                target.write(line)
+                                target.write("\n")
+
+	def sync_sources(self):
+		"""Run slapt-get -u"""
+		self.write_config(self.slaptgetrc, self.slapt_config)
+		update = sp.check_call(['slapt-get','-c',self.slaptgetrc,'-u'])
+
+	def clear_package_cache(self):
+		"""Clear the package cache"""
+		clear = sp.check_call(['slapt-get','-c',self.slaptgetrc, 
+			'--clean'])
+	
+	def download_packages(self):
+		self.sync_sources()
+		self.clear_package_cache()
+                pklist = sorted(self.packages())
+                for item in self.append:
+                        if item not in pklist:
+                                pklist.append(item)
+#                pklist.append([x for x in self.append if x not in pklist])
+                for pkg in pklist:
+                        dload = sp.check_call(['slapt-get',
+                                               '-c', self.slaptgetrc,
+                                               '-i','-d','--reinstall',
+                                               '--no-dep',pkg])
+                return
+                
+
+        def install_packages(self):
+                """Packages should be downloaded already.  Just run installpkg"""
+                jaildir = os.path.join(self.path,'CHROOT-RO')
+                if not os.path.exists(jaildir):
+                        os.makedirs(jaildir)
+                for (path,dirs,files) in os.walk(self.workingdir):
+                        for pkg in files:
+                                if os.path.splitext(pkg)[1] in ('.txz','.tgz'):
+                                        pkgpath = os.path.join(path, pkg)
+                                        install = sp.check_call([
+                                                'installpkg', '--root',
+                                                jaildir, pkgpath])
+        def post_install(self):
+                """ Post installation tricks """
+                jaildir = os.path.join(self.path, 'CHROOT-RO')
+                toolsdir = os.path.split(os.getcwd())[0]
+                # copy resolv.conf
+                shutil.copy('/etc/resolv.conf',os.path.join(jaildir, 'etc'))
+                # copy the timezone info from the host
+                for f in ('localtime','localtime-copied-from'):
+                        shutil.copy(os.path.join('/etc',f),
+                                    os.path.join(jaildir, 'etc'))
+                # fix the uname vs uname.bin hack
+                if self.arch in ('i386','i486','i586','i686'):
+                        vlbbraw = 'http://bitbucket.org/VLCore/vlbuildbot/raw/master'
+                        # move the existing uname to uname.bin
+                        shutil.move(os.path.join(jaildir,'bin','uname'),
+                                    os.path.join(jaildir,'bin','uname.bin'))
+                        # the modded uname to usr/bin in the chroot
+                        shutil.copy(os.path.join(toolsdir, 'chroot', 'x86','bin','uname'),
+                                    os.path.join(jaildir, 'bin','uname'))
+                        # chmod +x the modded script
+                        sp.call(['chmod','+x',os.path.join(jaildir,'bin','uname')])
+                # the requiredbuilder hack
+                shutil.move(os.path.join(jaildir,'usr','bin','requiredbuilder'),
+                            os.path.join(jaildir,'usr','bin','requiredbuilder.real'))
+                shutil.copy(os.path.join(toolsdir, 'chroot','usr','bin','requiredbuilder'),
+                            os.path.join(jaildir,'usr','bin','requiredbuilder'))
+                sp.call(['chmod','+x',os.path.join(jaildir,'usr','bin','requiredbuilder')])
+                # fix slapt-getrc in the chroot using self.base_repo
+                self.write_config(os.path.join(jaildir,'etc','slapt-get','slapt-getrc'),
+                                  self.jail_slapt_config)
+                
+
+
+class JailTests(unittest.TestCase):
+	def setUp(self):
+		self.jail = Jail()
+	
+
+
+if __name__ == '__main__':
+	unittest.main()
+

slave/usr/local/bin/jailedbuild

 CONF=/etc/vlbuildslave/slavehost.conf
 source $CONF
 
-cpus=$(count_cpus)
+cpus=$(count_cpus) # from slavehost.conf
 
 if [ $cpus -lt 2 ]; then
 	export NUMJOBS=" "
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.