Browse code

PackageBuilder: add Sandbox class

Sandbox is a low-level abstraction of isolating mechanisms.
It currently supports Chroot and Container implementations.
Use Sandbox abstract in the PackageBuilder and PackageUtils instead of
specific lowlevel calls.

Extras: constants.py: Remove perPackageToolchain.

Change-Id: I0e5345414218a71296fc75ea2d00b9e96e0b8d80
Reviewed-on: http://photon-jenkins.eng.vmware.com:8082/6110
Tested-by: gerrit-photon <photon-checkins@vmware.com>
Reviewed-by: Anish Swaminathan <anishs@vmware.com>

Alexey Makhalov authored on 2018/10/26 04:20:39
Showing 33 changed files
... ...
@@ -493,7 +493,7 @@ check-docker-service:
493 493
 	@docker ps >/dev/null 2>&1 || { echo "Docker service is not running. Aborting." >&2; exit 1; }
494 494
 
495 495
 check-docker-py:
496
-	@python3 -c "import docker; assert docker.__version__ == '$(PHOTON_DOCKER_PY_VER)'" >/dev/null 2>&1 || { echo "Error: Python3 package docker-py3 2.3.0 not installed.\nPlease use: pip3 install docker==2.3.0" >&2; exit 1; }
496
+	@python3 -c "import docker; assert docker.__version__ >= '$(PHOTON_DOCKER_PY_VER)'" >/dev/null 2>&1 || { echo "Error: Python3 package docker-py3 $(PHOTON_DOCKER_PY_VER) not installed.\nPlease use: pip3 install docker==$(PHOTON_DOCKER_PY_VER)" >&2; exit 1; }
497 497
 
498 498
 check-bison:
499 499
 	@command -v bison >/dev/null 2>&1 || { echo "Package bison not installed. Aborting." >&2; exit 1; }
... ...
@@ -1,7 +1,7 @@
1 1
 Summary:	Apache Maven
2 2
 Name:		apache-maven
3 3
 Version:	3.5.4
4
-Release:	1%{?dist}
4
+Release:	2%{?dist}
5 5
 License:	Apache License 2.0
6 6
 URL:		http://maven.apache.org
7 7
 Group:		Applications/System
... ...
@@ -15,6 +15,7 @@ BuildRequires: apache-ant
15 15
 BuildRequires: wget >= 1.15
16 16
 Requires: openjre8
17 17
 Requires: /usr/bin/which
18
+%define ExtraBuildRequires apache-maven
18 19
 
19 20
 %define _prefix /var/opt/%{name}
20 21
 %define _bindir %{_prefix}/bin
... ...
@@ -76,6 +77,8 @@ done
76 76
 %exclude %{_libdir}/jansi-native
77 77
 
78 78
 %changelog
79
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 3.5.4-2
80
+-   Use ExtraBuildRequires
79 81
 *   Tue Sep 18 2018 Ankit Jain <ankitja@vmware.com> 3.5.4-1
80 82
 -   Updated apache-maven to version 3.5.4
81 83
 *   Fri Oct 13 2017 Alexey Makhalov <amakhalov@vmware.com> 3.5.0-5
... ...
@@ -103,18 +106,18 @@ done
103 103
 *   Fri May 20 2016 Divya Thaluru <dthaluru@vmware.com> 3.3.9-3
104 104
 -   Updated JAVA_HOME path to point to latest JDK.
105 105
 *   Tue Mar 01 2016 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 3.3.9-2
106
--   Updated the apache-ant version to 1.9.6 
106
+-   Updated the apache-ant version to 1.9.6
107 107
 *   Fri Feb 26 2016 Kumar Kaushik <kaushikk@vmware.com> 3.3.9-2
108 108
 -   Updated JAVA_HOME path to point to latest JDK.
109 109
 *   Thu Jan 21 2016 Xiaolin Li <xiaolinl@vmware.com> 3.3.9-1
110 110
 -   Updated to version 3.3.9
111 111
 *   Tue Jan 5 2016 Xiaolin Li <xiaolinl@vmware.com> 3.3.3-4
112
--   Increase build timeout from 600000 to 1200000 
112
+-   Increase build timeout from 600000 to 1200000
113 113
 *   Mon Nov 16 2015 Sharath George <sharathg@vmware.com> 3.3.3-3
114 114
 -   Change path to /var/opt.
115 115
 *   Wed Sep 16 2015 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 3.3.3-2
116 116
 -   Updated dependencies after repackaging openjdk.
117 117
 *   Thu Jul 9 2015 	Sarah Choi<sarahc@vmware.com> 3.3.3-1
118
--   Add a script to set environment variables for MAVEN 
118
+-   Add a script to set environment variables for MAVEN
119 119
 *   Fri May 22 2015 Sriram Nambakam <snambakam@vmware.com> 1.9.4
120 120
 -   Initial build.	First version
... ...
@@ -13,7 +13,7 @@
13 13
 Summary:        Go
14 14
 Name:           go
15 15
 Version:        1.10.4
16
-Release:        1%{?dist}
16
+Release:        2%{?dist}
17 17
 License:        BSD
18 18
 URL:            https://golang.org
19 19
 Group:          System Environment/Security
... ...
@@ -22,6 +22,7 @@ Distribution:   Photon
22 22
 Source0:        https://dl.google.com/go/%{name}%{version}.src.tar.gz
23 23
 %define sha1    go=adcd9d0bbbc764fa4ff20c08eb4a5a527fa95d96
24 24
 Requires:       glibc
25
+%define ExtraBuildRequires go
25 26
 
26 27
 %description
27 28
 Go is an open source programming language that makes it easy to build simple, reliable, and efficient software.
... ...
@@ -109,5 +110,7 @@ rm -rf %{buildroot}/*
109 109
 %{_bindir}/*
110 110
 
111 111
 %changelog
112
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 1.10.4-2
113
+-   Use ExtraBuildRequires
112 114
 *   Mon Sep 24 2018 Tapas Kundu <tkundu@vmware.com> 1.10.4-1
113 115
 -   Initial build for 1.10.4
... ...
@@ -14,7 +14,7 @@
14 14
 Summary:        Go
15 15
 Name:           go
16 16
 Version:        1.9.4
17
-Release:        2%{?dist}
17
+Release:        3%{?dist}
18 18
 License:        BSD
19 19
 URL:            https://golang.org
20 20
 Group:          System Environment/Security
... ...
@@ -25,6 +25,8 @@ Source0:        https://dl.google.com/go/%{name}%{version}.src.tar.gz
25 25
 Patch0:         go_imports_fix.patch
26 26
 Patch1:         CVE-2018-7187.patch
27 27
 Requires:       glibc
28
+# to avoid cyclic dependency use prebuilt publish go rpm
29
+%define ExtraBuildRequires go
28 30
 
29 31
 %description
30 32
 Go is an open source programming language that makes it easy to build simple, reliable, and efficient software
... ...
@@ -114,6 +116,8 @@ rm -rf %{buildroot}/*
114 114
 %{_bindir}/*
115 115
 
116 116
 %changelog
117
+*   Wed Oct 24 2018 Alexey Makhalov <amakhalov@vmware.com> 1.9.4-3
118
+-   Use extra build requires
117 119
 *   Mon Apr 02 2018 Dheeraj Shetty <dheerajs@vmware.com> 1.9.4-2
118 120
 -   Fix for CVE-2018-7187
119 121
 *   Thu Mar 15 2018 Xiaolin Li <xiaolinl@vmware.com> 1.9.4-1
... ...
@@ -3,7 +3,7 @@
3 3
 Summary:	OpenJDK
4 4
 Name:		openjdk10
5 5
 Version:	1.10.0.23
6
-Release:	1%{?dist}
6
+Release:	2%{?dist}
7 7
 License:	GNU GPL
8 8
 URL:		https://openjdk.java.net
9 9
 Group:		Development/Tools
... ...
@@ -23,8 +23,10 @@ Requires:       openjre10 = %{version}-%{release}
23 23
 Requires:       chkconfig
24 24
 Obsoletes:      openjdk <= %{version}
25 25
 AutoReqProv: 	no
26
+%define ExtraBuildRequires icu-devel, cups, cups-devel, xorg-proto-devel, libXtst, libXtst-devel, libXfixes, libXfixes-devel, libXi, libXi-devel, openjdk, openjre, icu, alsa-lib, alsa-lib-devel, xcb-proto, libXdmcp-devel, libXau-devel, util-macros, xtrans, libxcb-devel, proto, libXdmcp, libxcb, libXau, xtrans-devel, libX11, libX11-devel, libXext, libXext-devel, libICE-devel, libSM, libICE, libSM-devel, libXt, libXmu, libXt-devel, libXmu-devel, libXrender, libXrender-devel
26 27
 %define bootstrapjdkversion 1.8.0.112
27 28
 %define jdk_major_version 1.10.0
29
+
28 30
 %description
29 31
 The OpenJDK package installs java class library and javac java compiler.
30 32
 
... ...
@@ -57,10 +59,9 @@ This package provides the runtime library class sources.
57 57
 %setup -qn openjdk-%{version}
58 58
 
59 59
 %build
60
-chmod a+x ./configure
61 60
 unset JAVA_HOME &&
62 61
 ENABLE_HEADLESS_ONLY="true" &&
63
-./configure \
62
+sh configure \
64 63
 	--with-target-bits=64 \
65 64
 	--with-boot-jdk=/var/opt/OpenJDK-%bootstrapjdkversion-bin \
66 65
 	--enable-headless-only \
... ...
@@ -83,7 +84,7 @@ make \
83 83
 
84 84
 %install
85 85
 unset JAVA_HOME &&
86
-make install 
86
+make install
87 87
 
88 88
 install -vdm755 %{buildroot}%{_libdir}/jvm/OpenJDK-%{version}
89 89
 chown -R root:root %{buildroot}%{_libdir}/jvm/OpenJDK-%{version}
... ...
@@ -219,5 +220,7 @@ rm -rf %{buildroot}/*
219 219
 %{_libdir}/jvm/OpenJDK-%{version}/lib/src.zip
220 220
 
221 221
 %changelog
222
-*   Thu Apr 23 2018 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.10.0.23-1
222
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 1.10.0.23-2
223
+-   Use ExtraBuildRequires
224
+*   Mon Apr 23 2018 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.10.0.23-1
223 225
 -   Initial build. First version
... ...
@@ -3,7 +3,7 @@
3 3
 Summary:	OpenJDK
4 4
 Name:		openjdk8
5 5
 Version:	1.8.0.192
6
-Release:	1%{?dist}
6
+Release:	2%{?dist}
7 7
 License:	GNU GPL
8 8
 URL:		https://openjdk.java.net
9 9
 Group:		Development/Tools
... ...
@@ -25,7 +25,9 @@ Requires:       openjre8 = %{version}-%{release}
25 25
 Requires:       chkconfig
26 26
 Obsoletes:      openjdk <= %{version}
27 27
 AutoReqProv: 	no
28
+%define ExtraBuildRequires icu-devel, cups, cups-devel, xorg-proto-devel, libXtst, libXtst-devel, libXfixes, libXfixes-devel, libXi, libXi-devel, openjdk, openjre, icu, alsa-lib, alsa-lib-devel, xcb-proto, libXdmcp-devel, libXau-devel, util-macros, xtrans, libxcb-devel, proto, libXdmcp, libxcb, libXau, xtrans-devel, libX11, libX11-devel, libXext, libXext-devel, libICE-devel, libSM, libICE, libSM-devel, libXt, libXmu, libXt-devel, libXmu-devel, libXrender, libXrender-devel
28 29
 %define bootstrapjdkversion 1.8.0.112
30
+
29 31
 %description
30 32
 The OpenJDK package installs java class library and javac java compiler.
31 33
 
... ...
@@ -239,6 +241,8 @@ rm -rf %{buildroot}/*
239 239
 %{_libdir}/jvm/OpenJDK-%{version}/src.zip
240 240
 
241 241
 %changelog
242
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 1.8.0.192-2
243
+-   Use ExtraBuildRequires
242 244
 *   Thu Oct 18 2018 Tapas Kundu <tkundu@vmware.com> 1.8.0.192-1
243 245
 -   Upgraded to version 1.8.0.192
244 246
 *   Fri Sep 21 2018 Srinidhi Rao <srinidhir@vmware.com> 1.8.0.181-1
... ...
@@ -8,7 +8,7 @@
8 8
 Summary:	OpenJDK
9 9
 Name:		openjdk8
10 10
 Version:	1.8.0.151
11
-Release:	1%{?dist}
11
+Release:	2%{?dist}
12 12
 License:	GNU GPL
13 13
 URL:		http://hg.openjdk.java.net/aarch64-port/jdk8u/
14 14
 Group:		Development/Tools
... ...
@@ -44,7 +44,9 @@ Requires:       openjre8 = %{version}-%{release}
44 44
 Requires:       chkconfig
45 45
 Obsoletes:      openjdk <= %{version}
46 46
 AutoReqProv: 	no
47
+%define ExtraBuildRequires icu-devel, openjdk8, openjre8, icu, alsa-lib, alsa-lib-devel, xcb-proto, libXdmcp-devel, libXau-devel, util-macros, xtrans, libxcb-devel, proto, libXdmcp, libxcb, libXau, xtrans-devel, libX11, libX11-devel, libXext, libXext-devel, libICE-devel, libSM, libICE, libSM-devel, libXt, libXmu, libXt-devel, libXmu-devel, libXrender, libXrender-devel
47 48
 %define bootstrapjdk /usr/lib/jvm/OpenJDK-1.8.0.151
49
+
48 50
 %description
49 51
 The OpenJDK package installs java class library and javac java compiler.
50 52
 
... ...
@@ -95,9 +97,8 @@ sed -i "s#\"ft2build.h\"#<ft2build.h>#g" jdk/src/share/native/sun/font/freetypeS
95 95
 sed -i '0,/BUILD_LIBMLIB_SRC/s/BUILD_LIBMLIB_SRC/BUILD_HEADLESS_ONLY := 1\nOPENJDK_TARGET_OS := linux\n&/' jdk/make/lib/Awt2dLibraries.gmk
96 96
 
97 97
 %build
98
-chmod a+x ./configure
99 98
 unset JAVA_HOME &&
100
-./configure \
99
+sh configure \
101 100
 	CUPS_NOT_NEEDED=yes \
102 101
 	--with-target-bits=64 \
103 102
 	--with-boot-jdk=%{bootstrapjdk} \
... ...
@@ -260,6 +261,8 @@ rm -rf %{buildroot}/*
260 260
 %{_libdir}/jvm/OpenJDK-%{version}/src.zip
261 261
 
262 262
 %changelog
263
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 1.8.0.151-2
264
+-   Use ExtraBuildRequires
263 265
 *   Thu Dec 21 2017 Alexey Makhalov <amakhalov@vmware.com> 1.8.0.151-1
264 266
 -   Initial version of OpenJDK for aarch64. SPEC file was forked from
265 267
     openjdk8-1.8.0.152-1 of x86_64
... ...
@@ -3,7 +3,7 @@
3 3
 Summary:	OpenJDK
4 4
 Name:		openjdk9
5 5
 Version:	1.9.0.181
6
-Release:	1%{?dist}
6
+Release:	2%{?dist}
7 7
 License:	GNU GPL
8 8
 URL:		https://openjdk.java.net
9 9
 Group:		Development/Tools
... ...
@@ -23,8 +23,10 @@ Requires:       openjre9 = %{version}-%{release}
23 23
 Requires:       chkconfig
24 24
 Obsoletes:      openjdk <= %{version}
25 25
 AutoReqProv: 	no
26
+%define ExtraBuildRequires icu-devel, cups, cups-devel, xorg-proto-devel, libXtst, libXtst-devel, libXfixes, libXfixes-devel, libXi, libXi-devel, openjdk, openjre, icu, alsa-lib, alsa-lib-devel, xcb-proto, libXdmcp-devel, libXau-devel, util-macros, xtrans, libxcb-devel, proto, libXdmcp, libxcb, libXau, xtrans-devel, libX11, libX11-devel, libXext, libXext-devel, libICE-devel, libSM, libICE, libSM-devel, libXt, libXmu, libXt-devel, libXmu-devel, libXrender, libXrender-devel
26 27
 %define bootstrapjdkversion 1.8.0.112
27 28
 %define jdk_major_version 1.9.0
29
+
28 30
 %description
29 31
 The OpenJDK package installs java class library and javac java compiler.
30 32
 
... ...
@@ -57,10 +59,9 @@ This package provides the runtime library class sources.
57 57
 %setup -qn openjdk-%{version}
58 58
 
59 59
 %build
60
-chmod a+x ./configure
61 60
 unset JAVA_HOME &&
62 61
 ENABLE_HEADLESS_ONLY="true" &&
63
-./configure \
62
+sh configure \
64 63
 	--with-target-bits=64 \
65 64
 	--with-boot-jdk=/var/opt/OpenJDK-%bootstrapjdkversion-bin \
66 65
 	--enable-headless-only \
... ...
@@ -223,5 +224,7 @@ rm -rf %{buildroot}/*
223 223
 %{_libdir}/jvm/OpenJDK-%{version}/lib/src.zip
224 224
 
225 225
 %changelog
226
+*   Mon Oct 29 2018 Alexey Makhalov <amakhalov@vmware.com> 1.9.0.181-2
227
+-   Use ExtraBuildRequires
226 228
 *   Thu Apr 19 2018 Harish Udaiya Kumar <hudaiyakumar@vmware.com> 1.9.0.181-1
227 229
 -   Initial build. First version
228 230
deleted file mode 100644
... ...
@@ -1,47 +0,0 @@
1
-# pylint: disable=invalid-name,missing-docstring
2
-import os.path
3
-from Logger import Logger
4
-from CommandUtils import CommandUtils
5
-from constants import constants
6
-
7
-class ChrootUtils(object):
8
-
9
-    def __init__(self, logName=None, logPath=None):
10
-        if logName is None:
11
-            logName = "ChrootUtils"
12
-        if logPath is None:
13
-            logPath = constants.logPath
14
-        self.logName = logName
15
-        self.logPath = logPath
16
-        self.logger = Logger.getLogger(logName, logPath, constants.logLevel)
17
-
18
-    def createChroot(self, chrootName):
19
-        chrootID = constants.buildRootPath + "/" + chrootName
20
-        if os.path.isdir(chrootID):
21
-            if not self.destroyChroot(chrootID):
22
-                self.logger.error("Given chroot " + chrootID +
23
-                                  " is already exists. unable to destroy it ")
24
-                return False, None
25
-        # need to add timeout for this step
26
-        # http://stackoverflow.com/questions/1191374/subprocess-with-timeout
27
-        cmdUtils = CommandUtils()
28
-        returnVal = cmdUtils.runCommandInShell("mkdir -p " + chrootID)
29
-        if not returnVal:
30
-            self.logger.error("Unable to create chroot:" + chrootID + ".Unknown error.")
31
-            return False, None
32
-        return True, chrootID
33
-
34
-    def destroyChroot(self, chrootID):
35
-        # need to add timeout for this step
36
-        # http://stackoverflow.com/questions/1191374/subprocess-with-timeout
37
-        cmdUtils = CommandUtils()
38
-        returnVal = cmdUtils.runCommandInShell("./clean-up-chroot.py " + chrootID)
39
-        if not returnVal:
40
-            self.logger.error("Unable to destroy chroot:" + chrootID + ".Unknown error.")
41
-            return False
42
-
43
-        returnVal = cmdUtils.runCommandInShell("rm -rf " + chrootID)
44
-        if not returnVal:
45
-            self.logger.error("Unable to destroy chroot:" + chrootID + ".Unknown error.")
46
-            return False
47
-        return True
... ...
@@ -2,12 +2,11 @@
2 2
 import subprocess
3 3
 import os
4 4
 
5
-class CommandUtils(object):
6
-    def __init__(self):
7
-        self.findBinary = "find"
5
+class CommandUtils:
8 6
 
9
-    def findFile(self, filename, sourcePath):
10
-        process = subprocess.Popen([self.findBinary, "-L", sourcePath, "-name", filename,
7
+    @staticmethod
8
+    def findFile(filename, sourcePath):
9
+        process = subprocess.Popen(["find", "-L", sourcePath, "-name", filename,
11 10
                                     "-not", "-type", "d"], stdout=subprocess.PIPE)
12 11
         # We don't check the return val here because find could return 1 but still be
13 12
         # able to find
... ...
@@ -26,23 +25,17 @@ class CommandUtils(object):
26 26
         return result.decode().split()
27 27
 
28 28
     @staticmethod
29
-    def runCommandInShell(cmd, logfilePath=None, chrootCmd=None):
30
-        if chrootCmd is not None:
31
-            cmd = chrootCmd + " " + cmd
32
-        if logfilePath is None:
33
-            logfilePath = os.devnull
34
-        with open(logfilePath, "w") as logfile:
35
-            process = subprocess.Popen("%s" %cmd, shell=True, stdout=logfile, stderr=logfile)
29
+    def runCommandInShell(cmd, logfile=None, logfn=None):
30
+        retval = 0
31
+        if logfn:
32
+            process = subprocess.Popen("%s" %cmd, shell=True, stdout=subprocess.PIPE)
36 33
             retval = process.wait()
37
-            if retval == 0:
38
-                return True
39
-        return False
40
-    @staticmethod
41
-    def runCommandInShell2(cmd, chrootCmd=None):
42
-        if chrootCmd is not None:
43
-            cmd = chrootCmd + " " + cmd
44
-        process = subprocess.Popen("%s" %cmd, shell=True, stdout=subprocess.PIPE)
45
-        retval = process.wait()
46
-        if retval != 0:
47
-            return None
48
-        return process.communicate()[0]
34
+            logfn(process.communicate()[0].decode())
35
+        else:
36
+            if logfile is None:
37
+                logfile = os.devnull
38
+            with open(logfile, "w") as f:
39
+                process = subprocess.Popen("%s" %cmd, shell=True, stdout=f, stderr=f)
40
+            retval = process.wait()
41
+        return retval
42
+
... ...
@@ -216,7 +216,7 @@ def buildSRPMList(srpmPath, yamlDir, blackListPkgs, dist_tag, logger, singleFile
216 216
                 srpmName = os.path.basename(srpmFullPath)
217 217
                 cpcmd = "cp " + srpmFullPath + " " + yamlSrpmDir + "/"
218 218
                 returnVal = cmdUtils.runCommandInShell(cpcmd)
219
-                if not returnVal:
219
+                if returnVal != 0:
220 220
                     logger.error("Copy SRPM File is failed for package:" + ossname)
221 221
             else:
222 222
                 logger.error("SRPM file is not found:" + ossname)
223 223
deleted file mode 100644
... ...
@@ -1,36 +0,0 @@
1
-import os.path
2
-
3
-class MiscUtils(object):
4
-
5
-    @staticmethod
6
-    def isOutdated(listInputFiles, listOutputFiles):
7
-        thresholdTimeStamp = None
8
-        if not listInputFiles:
9
-            return False
10
-        if not listOutputFiles:
11
-            return True
12
-        for f in listOutputFiles:
13
-            t = os.path.getmtime(f)
14
-            if thresholdTimeStamp is None:
15
-                thresholdTimeStamp = t
16
-            if t < thresholdTimeStamp:
17
-                thresholdTimeStamp = t
18
-        for f in listInputFiles:
19
-            t = os.path.getmtime(f)
20
-            if t > thresholdTimeStamp:
21
-                return True
22
-        return False
23
-
24
-    @staticmethod
25
-    def getListSpecFiles(listSpecFiles, path):
26
-        for dirEntry in os.listdir(path):
27
-            dirEntryPath = os.path.join(path, dirEntry)
28
-            if os.path.isfile(dirEntryPath) and dirEntryPath.endswith(".spec"):
29
-                listSpecFiles.append(dirEntryPath)
30
-            elif os.path.isdir(dirEntryPath):
31
-                MiscUtils.getListSpecFiles(listSpecFiles, dirEntryPath)
32
-
33
-if __name__ == "__main__":
34
-    inputFiles = ["SpecParser.py", "Logger.py"]
35
-    outputFiles = ["builder.py"]
36
-    print(MiscUtils.isOutdated(inputFiles, outputFiles))
... ...
@@ -2,14 +2,12 @@ import sys
2 2
 import os.path
3 3
 from PackageUtils import PackageUtils
4 4
 from Logger import Logger
5
-from ChrootUtils import ChrootUtils
6 5
 from ToolChainUtils import ToolChainUtils
7 6
 from CommandUtils import CommandUtils
8 7
 from constants import constants
9 8
 from SpecData import SPECS
10
-import docker
11
-from distutils.version import LooseVersion
12 9
 from StringUtils import StringUtils
10
+from Sandbox import Chroot, Container
13 11
 
14 12
 class PackageBuilderBase(object):
15 13
     def __init__(self, mapPackageToCycles, pkgBuildType):
... ...
@@ -63,12 +61,9 @@ class PackageBuilderBase(object):
63 63
         pkg = rpmfile[0:releaseindex]
64 64
         return pkg
65 65
 
66
-    def _findInstalledPackages(self, instanceID):
66
+    def _findInstalledPackages(self, sandbox):
67 67
         pkgUtils = PackageUtils(self.logName, self.logPath)
68
-        if self.pkgBuildType == "chroot":
69
-            listInstalledRPMs = pkgUtils.findInstalledRPMPackages(instanceID)
70
-        elif self.pkgBuildType == "container":
71
-            listInstalledRPMs = pkgUtils.findInstalledRPMPackagesInContainer(instanceID)
68
+        listInstalledRPMs = pkgUtils.findInstalledRPMPackages(sandbox)
72 69
         listInstalledPackages = []
73 70
         for installedRPM in listInstalledRPMs:
74 71
             pkg = self._findPackageNameAndVersionFromRPMFile(installedRPM)
... ...
@@ -96,7 +91,7 @@ class PackageBuilderBase(object):
96 96
     def _findBuildTimeCheckRequiredPackages(self):
97 97
         return SPECS.getData().getCheckBuildRequiresForPackage(self.package, self.version)
98 98
 
99
-    def _installPackage(self, pkgUtils, package,packageVersion, instanceID, destLogPath,
99
+    def _installPackage(self, pkgUtils, package, packageVersion, sandbox, destLogPath,
100 100
                         listInstalledPackages, listInstalledRPMs):
101 101
         rpmfile = pkgUtils.findRPMFileForGivenPackage(package,packageVersion);
102 102
         if rpmfile is None:
... ...
@@ -109,19 +104,16 @@ class PackageBuilderBase(object):
109 109
         # mark it as installed -  to avoid cyclic recursion
110 110
         listInstalledPackages.append(pkg)
111 111
         listInstalledRPMs.append(specificRPM)
112
-        self._installDependentRunTimePackages(pkgUtils, package, packageVersion, instanceID, destLogPath,
112
+        self._installDependentRunTimePackages(pkgUtils, package, packageVersion, sandbox, destLogPath,
113 113
                                               listInstalledPackages, listInstalledRPMs)
114 114
         noDeps = False
115 115
         if (package in self.mapPackageToCycles or
116 116
                 package in self.listNodepsPackages or
117 117
                 package in constants.noDepsPackageList):
118 118
             noDeps = True
119
-        if self.pkgBuildType == "chroot":
120
-            pkgUtils.installRPM(package, packageVersion,instanceID, noDeps, destLogPath)
121
-        elif self.pkgBuildType == "container":
122
-            pkgUtils.prepRPMforInstallInContainer(package,packageVersion, instanceID, noDeps, destLogPath)
119
+        pkgUtils.prepRPMforInstall(package,packageVersion, noDeps, destLogPath)
123 120
 
124
-    def _installDependentRunTimePackages(self, pkgUtils, package, packageVersion, instanceID, destLogPath,
121
+    def _installDependentRunTimePackages(self, pkgUtils, package, packageVersion, sandbox, destLogPath,
125 122
                                          listInstalledPackages, listInstalledRPMs):
126 123
         listRunTimeDependentPackages = self._findRunTimeRequiredRPMPackages(package, packageVersion)
127 124
         if listRunTimeDependentPackages:
... ...
@@ -133,10 +125,10 @@ class PackageBuilderBase(object):
133 133
                     pkgUtils.findRPMFileForGivenPackage(packageName, packageVersion)).replace(".rpm", "")
134 134
                 if pkg in listInstalledPackages and latestPkgRPM in listInstalledRPMs:
135 135
                     continue
136
-                self._installPackage(pkgUtils, packageName,packageVersion, instanceID, destLogPath,listInstalledPackages, listInstalledRPMs)
136
+                self._installPackage(pkgUtils, packageName,packageVersion, sandbox, destLogPath,listInstalledPackages, listInstalledRPMs)
137 137
 
138
-    def _findDependentPackagesAndInstalledRPM(self, instanceID):
139
-        listInstalledPackages, listInstalledRPMs = self._findInstalledPackages(instanceID)
138
+    def _findDependentPackagesAndInstalledRPM(self, sandbox):
139
+        listInstalledPackages, listInstalledRPMs = self._findInstalledPackages(sandbox)
140 140
         self.logger.debug(listInstalledPackages)
141 141
         listDependentPackages = self._findBuildTimeRequiredPackages()
142 142
         listTestPackages=[]
... ...
@@ -158,181 +150,77 @@ class PackageBuilderBase(object):
158 158
 
159 159
 class PackageBuilderContainer(PackageBuilderBase):
160 160
     def __init__(self, mapPackageToCycles, pkgBuildType):
161
-        self.buildContainerImage = "photon_build_container:latest"
162
-        self.dockerClient = docker.from_env(version="auto")
163
-
164 161
         PackageBuilderBase.__init__(self, mapPackageToCycles, pkgBuildType)
165 162
 
166
-    def _prepareBuildContainer(self, containerTaskName, packageName, packageVersion,
167
-                               isToolChainPackage=False):
168
-        # Prepare an empty chroot environment to let docker use the BUILD folder.
169
-        # This avoids docker using overlayFS which will cause make check failure.
170
-        chrootName = packageName + "-" + packageVersion
171
-        chrUtils = ChrootUtils(self.logName, self.logPath)
172
-        returnVal, chrootID = chrUtils.createChroot(chrootName)
173
-        if not returnVal:
174
-            raise Exception("Unable to prepare build root")
175
-        cmdUtils = CommandUtils()
176
-        cmdUtils.runCommandInShell("mkdir -p " + chrootID + constants.topDirPath)
177
-        cmdUtils.runCommandInShell("mkdir -p " + chrootID + constants.topDirPath + "/BUILD")
178
-
179
-        containerID = None
180
-        mountVols = {
181
-            constants.prevPublishRPMRepo: {'bind': '/publishrpms', 'mode': 'ro'},
182
-            constants.prevPublishXRPMRepo: {'bind': '/publishxrpms', 'mode': 'ro'},
183
-            constants.tmpDirPath: {'bind': '/tmp', 'mode': 'rw'},
184
-            constants.rpmPath: {'bind': constants.topDirPath + "/RPMS", 'mode': 'rw'},
185
-            constants.sourceRpmPath: {'bind': constants.topDirPath + "/SRPMS", 'mode': 'rw'},
186
-            constants.logPath + "/" + self.logName: {'bind': constants.topDirPath + "/LOGS",
187
-                                                     'mode': 'rw'},
188
-            chrootID + constants.topDirPath + "/BUILD": {'bind': constants.topDirPath + "/BUILD",
189
-                                                         'mode': 'rw'},
190
-            constants.dockerUnixSocket: {'bind': constants.dockerUnixSocket, 'mode': 'rw'}
191
-            }
192
-
193
-        containerName = containerTaskName
194
-        containerName = containerName.replace("+", "p")
195
-        try:
196
-            oldContainerID = self.dockerClient.containers.get(containerName)
197
-            if oldContainerID is not None:
198
-                oldContainerID.remove(force=True)
199
-        except docker.errors.NotFound:
200
-            try:
201
-                sys.exc_clear()
202
-            except:
203
-                pass
204
-
205
-        try:
206
-            self.logger.debug("BuildContainer-prepareBuildContainer: " +
207
-                             "Starting build container: " + containerName)
208
-            #TODO: Is init=True equivalent of --sig-proxy?
209
-            privilegedDocker = False
210
-            cap_list = ['SYS_PTRACE']
211
-            if packageName in constants.listReqPrivilegedDockerForTest:
212
-                privilegedDocker = True
213
-
214
-            containerID = self.dockerClient.containers.run(self.buildContainerImage,
215
-                                                           detach=True,
216
-                                                           cap_add=cap_list,
217
-                                                           privileged=privilegedDocker,
218
-                                                           name=containerName,
219
-                                                           network_mode="host",
220
-                                                           volumes=mountVols,
221
-                                                           command="/bin/bash -l -c /wait.sh")
222
-
223
-            self.logger.debug("Started Photon build container for task " + containerTaskName +
224
-                              " ID: " + containerID.short_id)
225
-            if not containerID:
226
-                raise Exception("Unable to start Photon build container for task " +
227
-                                containerTaskName)
228
-        except Exception as e:
229
-            self.logger.debug("Unable to start Photon build container for task " +
230
-                              containerTaskName)
231
-            raise e
232
-        return containerID, chrootID
233
-
234 163
     def _buildPackage(self):
235 164
         #should initialize a logger based on package name
236
-        containerTaskName = "build-" + self.package
237
-        containerID = None
238
-        chrootID = None
239
-        isToolChainPackage = False
240
-        if self.package in constants.listToolChainPackages:
241
-            isToolChainPackage = True
242
-        destLogPath = constants.logPath + "/build-" + self.package
165
+        containerTaskName = "build-" + self.package + "-" + self.version
166
+        container = None
243 167
         try:
244
-            containerID, chrootID = self._prepareBuildContainer(
245
-                containerTaskName, self.package, self.version, isToolChainPackage)
168
+            container = Container(self.logger)
169
+            container.create(containerTaskName)
246 170
 
247 171
             tcUtils = ToolChainUtils(self.logName, self.logPath)
248
-            if self.package in constants.perPackageToolChain:
249
-                self.logger.debug(constants.perPackageToolChain[self.package])
250
-                tcUtils.installCustomToolChainRPMSinContainer(
251
-                    containerID,
252
-                    constants.perPackageToolChain[self.package].get(platform.machine(), []),
253
-                    self.package)
172
+            tcUtils.installCustomToolChainRPMS(container, self.package, self.version)
254 173
 
255 174
             listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = (
256
-                self._findDependentPackagesAndInstalledRPM(containerID))
175
+                self._findDependentPackagesAndInstalledRPM(container))
257 176
 
258 177
             pkgUtils = PackageUtils(self.logName, self.logPath)
178
+
259 179
             if listDependentPackages:
260
-                self.logger.debug("BuildContainer-buildPackage: " +
261
-                                 "Installing dependent packages..")
262
-                self.logger.debug(listDependentPackages)
180
+                self.logger.debug("Installing the build time dependent packages......")
263 181
                 for pkg in listDependentPackages:
264 182
                     packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg)
265
-                    self._installPackage(pkgUtils, packageName, packageVersion, containerID, destLogPath,listInstalledPackages, listInstalledRPMs)
183
+                    self._installPackage(pkgUtils, packageName, packageVersion, container, self.logPath,listInstalledPackages, listInstalledRPMs)
266 184
                 for pkg in listTestPackages:
267
-                    packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg)
268 185
                     flag = False
186
+                    packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg)
269 187
                     for depPkg in listDependentPackages:
270 188
                         depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion(depPkg)
271 189
                         if depPackageName == packageName:
272 190
                             flag = True
273 191
                             break;
274 192
                     if flag == False:
275
-                        self._installPackage(pkgUtils, packageName,packageVersion, containerID, destLogPath,listInstalledPackages, listInstalledRPMs)
276
-                pkgUtils.installRPMSInAOneShotInContainer(containerID, destLogPath)
193
+                        self._installPackage(pkgUtils, packageName,packageVersion, container, self.logPath,listInstalledPackages, listInstalledRPMs)
194
+                pkgUtils.installRPMSInOneShot(container)
277 195
                 self.logger.debug("Finished installing the build time dependent packages....")
278 196
 
279 197
             self.logger.debug("BuildContainer-buildPackage: Start building the package: " +
280 198
                              self.package)
281
-            pkgUtils.adjustGCCSpecsInContainer(self.package, self.version, containerID, destLogPath)
282
-            pkgUtils.buildRPMSForGivenPackageInContainer(
283
-                self.package,
284
-                self.version,
285
-                containerID,
286
-                destLogPath)
199
+            pkgUtils.adjustGCCSpecs(container, self.package, self.version)
200
+            pkgUtils.buildRPMSForGivenPackage(container, self.package, self.version, self.logPath)
287 201
             self.logger.debug("BuildContainer-buildPackage: Successfully built the package: " +
288 202
                              self.package)
289 203
         except Exception as e:
290 204
             self.logger.error("Failed while building package:" + self.package)
291
-            if containerID is not None:
292
-                self.logger.debug("Container " + containerID.short_id +
205
+            if container is not None:
206
+                self.logger.debug("Container " + container.getID() +
293 207
                                   " retained for debugging.")
294
-            logFileName = os.path.join(destLogPath, self.package + ".log")
208
+            logFileName = os.path.join(self.logPath, self.package + ".log")
295 209
             fileLog = os.popen('tail -n 20 ' + logFileName).read()
296 210
             self.logger.debug(fileLog)
297 211
             raise e
298 212
 
299 213
         # Remove the container
300
-        if containerID is not None:
301
-            containerID.remove(force=True)
302
-        # Remove the dummy chroot
303
-        if chrootID is not None:
304
-            chrUtils = ChrootUtils(self.logName, self.logPath)
305
-            chrUtils.destroyChroot(chrootID)
214
+        if container:
215
+            container.destroy()
306 216
 
307 217
 class PackageBuilderChroot(PackageBuilderBase):
308 218
     def __init__(self, mapPackageToCycles, pkgBuildType):
309 219
         PackageBuilderBase.__init__(self, mapPackageToCycles, pkgBuildType)
310 220
 
311
-    def _prepareBuildRoot(self):
312
-        chrootID = None
313
-        chrootName = self.package + "-" + self.version
221
+    def _buildPackage(self):
222
+        chroot = None
314 223
         try:
315
-            chrUtils = ChrootUtils(self.logName, self.logPath)
316
-            returnVal, chrootID = chrUtils.createChroot(chrootName)
317
-            self.logger.debug("Created new chroot: " + chrootID)
318
-            if not returnVal:
319
-                raise Exception("Unable to prepare build root")
224
+            chroot = Chroot(self.logger)
225
+            chroot.create(self.package + "-" + self.version)
226
+
320 227
             tUtils = ToolChainUtils(self.logName, self.logPath)
321
-            tUtils.installToolChainRPMS(self.package, self.version, chrootID, self.logPath)
322
-        except Exception as e:
323
-            if chrootID is not None:
324
-                self.logger.debug("Deleting chroot: " + chrootID)
325
-                chrUtils.destroyChroot(chrootID)
326
-            raise e
327
-        return chrootID
228
+            tUtils.installToolChainRPMS(chroot, self.package, self.version, self.logPath)
328 229
 
329
-    def _buildPackage(self):
330
-        chrUtils = ChrootUtils(self.logName, self.logPath)
331
-        chrootID = None
332
-        try:
333
-            chrootID = self._prepareBuildRoot()
334 230
             listDependentPackages, listTestPackages, listInstalledPackages, listInstalledRPMs = (
335
-                self._findDependentPackagesAndInstalledRPM(chrootID))
231
+                self._findDependentPackagesAndInstalledRPM(chroot))
336 232
 
337 233
             pkgUtils = PackageUtils(self.logName, self.logPath)
338 234
 
... ...
@@ -340,31 +228,31 @@ class PackageBuilderChroot(PackageBuilderBase):
340 340
                 self.logger.debug("Installing the build time dependent packages......")
341 341
                 for pkg in listDependentPackages:
342 342
                     packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg)
343
-                    self._installPackage(pkgUtils, packageName, packageVersion, chrootID, self.logPath,listInstalledPackages, listInstalledRPMs)
343
+                    self._installPackage(pkgUtils, packageName, packageVersion, chroot, self.logPath,listInstalledPackages, listInstalledRPMs)
344 344
                 for pkg in listTestPackages:
345 345
                     flag = False
346 346
                     packageName, packageVersion = StringUtils.splitPackageNameAndVersion(pkg)
347 347
                     for depPkg in listDependentPackages:
348 348
                         depPackageName, depPackageVersion = StringUtils.splitPackageNameAndVersion(depPkg)
349 349
                         if depPackageName == packageName:
350
-                                flag = True
351
-                                break;
350
+                            flag = True
351
+                            break;
352 352
                     if flag == False:
353
-                        self._installPackage(pkgUtils, packageName,packageVersion, chrootID, self.logPath,listInstalledPackages, listInstalledRPMs)
354
-                pkgUtils.installRPMSInAOneShot(chrootID, self.logPath)
353
+                        self._installPackage(pkgUtils, packageName,packageVersion, chroot, self.logPath,listInstalledPackages, listInstalledRPMs)
354
+                pkgUtils.installRPMSInOneShot(chroot)
355 355
                 self.logger.debug("Finished installing the build time dependent packages....")
356 356
 
357
-            pkgUtils.adjustGCCSpecs(self.package, self.version, chrootID, self.logPath)
358
-            pkgUtils.buildRPMSForGivenPackage(self.package, self.version, chrootID,
357
+            pkgUtils.adjustGCCSpecs(chroot, self.package, self.version)
358
+            pkgUtils.buildRPMSForGivenPackage(chroot, self.package, self.version,
359 359
                                               self.logPath)
360 360
             self.logger.debug("Successfully built the package:" + self.package)
361 361
         except Exception as e:
362 362
             self.logger.error("Failed while building package:" + self.package)
363
-            self.logger.debug("Chroot with ID: " + chrootID +
363
+            self.logger.debug("Chroot: " + chroot.getPath() +
364 364
                               " not deleted for debugging.")
365 365
             logFileName = os.path.join(self.logPath, self.package + ".log")
366 366
             fileLog = os.popen('tail -n 100 ' + logFileName).read()
367 367
             self.logger.info(fileLog)
368 368
             raise e
369
-        if chrootID is not None:
370
-            chrUtils.destroyChroot(chrootID)
369
+        if chroot:
370
+            chroot.destroy()
... ...
@@ -5,7 +5,6 @@ from PackageBuildDataGenerator import PackageBuildDataGenerator
5 5
 from Logger import Logger
6 6
 from constants import constants
7 7
 import docker
8
-from ChrootUtils import ChrootUtils
9 8
 from CommandUtils import CommandUtils
10 9
 from PackageUtils import PackageUtils
11 10
 from ToolChainUtils import ToolChainUtils
... ...
@@ -13,6 +12,7 @@ from Scheduler import Scheduler
13 13
 from ThreadPool import ThreadPool
14 14
 from SpecData import SPECS
15 15
 from StringUtils import StringUtils
16
+from Sandbox import Chroot, Container
16 17
 
17 18
 class PackageManager(object):
18 19
 
... ...
@@ -49,7 +49,7 @@ class PackageManager(object):
49 49
         if self.pkgBuildType == "container":
50 50
             # Stage 1 build container
51 51
             #TODO image name constants.buildContainerImageName
52
-            if pkgCount > 0 or not self.dockerClient.images.list("photon_build_container:latest"):
52
+            if pkgCount > 0 or not self.dockerClient.images.list(constants.buildContainerImage):
53 53
                 self._createBuildContainer()
54 54
         self.logger.info("Step 2 : Building stage 2 of the toolchain...")
55 55
         self.logger.info(constants.listToolChainPackages)
... ...
@@ -229,46 +229,41 @@ class PackageManager(object):
229 229
         self.logger.debug("Generating photon build container..")
230 230
         try:
231 231
             #TODO image name constants.buildContainerImageName
232
-            self.dockerClient.images.remove("photon_build_container:latest", force=True)
232
+            self.dockerClient.images.remove(constants.buildContainerImage, force=True)
233 233
         except Exception as e:
234 234
             #TODO - better handling
235 235
             self.logger.debug("Photon build container image not found.")
236 236
 
237 237
         # Create toolchain chroot and install toolchain RPMs
238
-        chrootID = None
238
+        chroot = None
239 239
         try:
240 240
             #TODO: constants.tcrootname
241
-            chrUtils = ChrootUtils("toolchain-chroot", self.logPath)
242
-            returnVal, chrootID = chrUtils.createChroot("toolchain-chroot")
243
-            self.logger.debug("Created tool-chain chroot: " + chrootID)
244
-            if not returnVal:
245
-                raise Exception("Unable to prepare tool-chain chroot")
241
+            chroot = Chroot(self.logger)
242
+            chroot.create("toolchain-chroot")
246 243
             tcUtils = ToolChainUtils("toolchain-chroot", self.logPath)
247
-            tcUtils.installToolChainRPMS(chrootID, "dummy")
244
+            tcUtils.installToolChainRPMS(chroot)
248 245
         except Exception as e:
249
-            if chrootID is not None:
250
-                self.logger.debug("Deleting chroot: " + chrootID)
251
-                chrUtils.destroyChroot(chrootID)
246
+            if chroot:
247
+                chroot.destroy()
252 248
             raise e
253
-        self.logger.debug("createBuildContainer: chrootID: " + chrootID)
249
+        self.logger.debug("createBuildContainer: " + chroot.getPath())
254 250
 
255 251
         # Create photon build container using toolchain chroot
252
+        chroot.unmountAll()
256 253
         #TODO: Coalesce logging
257 254
         cmdUtils = CommandUtils()
258
-        cmd = "./umount-build-root.sh " + chrootID
259
-        cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot1.log")
260
-        cmd = "cd " + chrootID + " && tar -czvf ../tcroot.tar.gz ."
261
-        cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot2.log")
262
-        cmd = "mv " + chrootID + "/../tcroot.tar.gz ."
263
-        cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot3.log")
255
+        cmd = "cd " + chroot.getPath() + " && tar -czf ../tcroot.tar.gz ."
256
+        cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug)
257
+        cmd = "mv " + chroot.getPath() + "/../tcroot.tar.gz ."
258
+        cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug)
264 259
         #TODO: Container name, docker file name from constants.
265
-        self.dockerClient.images.build(tag="photon_build_container:latest",
260
+        self.dockerClient.images.build(tag=constants.buildContainerImage,
266 261
                                        path=".",
267 262
                                        rm=True,
268 263
                                        dockerfile="Dockerfile.photon_build_container")
269 264
 
270 265
         # Cleanup
271 266
         cmd = "rm -f ./tcroot.tar.gz"
272
-        cmdUtils.runCommandInShell(cmd, self.logPath + "/toolchain-chroot4.log")
273
-        chrUtils.destroyChroot(chrootID)
267
+        cmdUtils.runCommandInShell(cmd, logfn=self.logger.debug)
268
+        chroot.destroy()
274 269
         self.logger.debug("Photon build container successfully created.")
... ...
@@ -21,8 +21,6 @@ class PackageUtils(object):
21 21
         self.logName = logName
22 22
         self.logPath = logPath
23 23
         self.logger = Logger.getLogger(logName, logPath, constants.logLevel)
24
-        self.runInChrootCommand = ("./run-in-chroot.sh " + constants.sourcePath +
25
-                                   " " + constants.rpmPath)
26 24
         self.rpmBinary = "rpm"
27 25
         self.installRPMPackageOptions = "-Uvh"
28 26
         self.nodepsRPMPackageOptions = "--nodeps"
... ...
@@ -39,73 +37,81 @@ class PackageUtils(object):
39 39
         self.packagesToInstallInAOneShot = ""
40 40
         self.noDepsRPMFilesToInstallInAOneShot = ""
41 41
         self.noDepsPackagesToInstallInAOneShot = ""
42
-        self.rpmFilesToReInstallInAOneShot = ""
43
-        self.noDepsRPMFilesToReInstallInAOneShot = ""
42
+        self.logfnvalue = None
44 43
 
45
-    def installRPM(self, package,version, chrootID, noDeps=False, destLogPath=None):
46
-
47
-        rpmfile = self.findRPMFileForGivenPackage(package,version)
44
+    def prepRPMforInstall(self, package, version, noDeps=False, destLogPath=None):
45
+        rpmfile = self.findRPMFileForGivenPackage(package, version)
48 46
         if rpmfile is None:
49
-            self.logger.error("No rpm file found for package:" + package)
50
-            raise Exception("Missing rpm file: " + package)
47
+            self.logger.error("No rpm file found for package: " + package)
48
+            raise Exception("Missing rpm file")
49
+
50
+        rpmName = os.path.basename(rpmfile)
51
+        #TODO: path from constants
52
+        if "PUBLISHRPMS" in rpmfile:
53
+            rpmDestFile = "/publishrpms/"
54
+        elif "PUBLISHXRPMS" in rpmfile:
55
+            rpmDestFile = "/publishxrpms/"
56
+        else:
57
+            rpmDestFile = constants.topDirPath + "/RPMS/"
58
+        if "noarch" in rpmfile:
59
+            rpmDestFile += "noarch/"
60
+        else:
61
+            rpmDestFile += platform.machine()+"/"
62
+        rpmDestFile += rpmName
51 63
 
52
-        rpmDestFile = self._copyRPM(rpmfile, chrootID + constants.topDirPath + "/RPMS")
53
-        rpmFile = rpmDestFile.replace(chrootID, "")
54 64
         if noDeps:
55
-            self.noDepsRPMFilesToInstallInAOneShot += " " + rpmFile
65
+            self.noDepsRPMFilesToInstallInAOneShot += " " + rpmDestFile
56 66
             self.noDepsPackagesToInstallInAOneShot += " " + package
57 67
         else:
58
-            self.rpmFilesToInstallInAOneShot += " " + rpmFile
68
+            self.rpmFilesToInstallInAOneShot += " " + rpmDestFile
59 69
             self.packagesToInstallInAOneShot += " " + package
60 70
 
61
-    def installRPMSInAOneShot(self, chrootID, destLogPath):
62
-        chrootCmd = self.runInChrootCommand + " " + chrootID
71
+    def installRPMSInOneShot(self, sandbox):
63 72
         rpmInstallcmd = self.rpmBinary + " " + self.installRPMPackageOptions
64
-        cmdUtils = CommandUtils()
73
+        # TODO: Container sandbox might need  + self.forceRpmPackageOptions
65 74
         if self.noDepsRPMFilesToInstallInAOneShot != "":
66 75
             self.logger.debug("Installing nodeps rpms: " +
67 76
                              self.noDepsPackagesToInstallInAOneShot)
68
-            logFile = destLogPath + "/install_rpms_nodeps.log"
69 77
             cmd = (rpmInstallcmd+" "+self.nodepsRPMPackageOptions + " " +
70 78
                    self.noDepsRPMFilesToInstallInAOneShot)
71
-            returnVal = cmdUtils.runCommandInShell(cmd, logFile, chrootCmd)
72
-            if not returnVal:
79
+            returnVal = sandbox.run(cmd, logfn=self.logger.debug)
80
+            if returnVal != 0:
73 81
                 self.logger.debug("Command Executed:" + cmd)
74
-                self.logger.error("Unable to install rpms")
82
+                self.logger.error("Unable to install rpms. Error {}".format(returnVal))
75 83
                 raise Exception("RPM installation failed")
76 84
         if self.rpmFilesToInstallInAOneShot != "":
77 85
             self.logger.debug("Installing rpms: " + self.packagesToInstallInAOneShot)
78
-            logFile = destLogPath+"/install_rpms.log"
79 86
             cmd = rpmInstallcmd+" "+self.rpmFilesToInstallInAOneShot
80
-            returnVal = cmdUtils.runCommandInShell(cmd, logFile, chrootCmd)
81
-            if not returnVal:
87
+            returnVal = sandbox.run(cmd, logfn=self.logger.debug)
88
+            if returnVal != 0:
82 89
                 self.logger.debug("Command Executed:" + cmd)
83 90
                 self.logger.error("Unable to install rpms")
84 91
                 raise Exception("RPM installation failed")
85 92
 
86
-    def buildRPMSForGivenPackage(self, package, version, chrootID, destLogPath=None):
93
+    def buildRPMSForGivenPackage(self, sandbox, package, version, destLogPath):
87 94
         self.logger.info("Building package : " + package)
88 95
 
89 96
         listSourcesFiles = SPECS.getData().getSources(package, version)
90 97
         listPatchFiles = SPECS.getData().getPatches(package, version)
91 98
         specFile = SPECS.getData().getSpecFile(package, version)
92 99
         specName = SPECS.getData().getSpecName(package) + ".spec"
93
-
94
-        chrootSourcePath = chrootID + constants.topDirPath + "/SOURCES/"
95
-        chrootSpecPath = constants.topDirPath + "/SPECS/"
96
-        chrootLogsFilePath = chrootID + constants.topDirPath + "/LOGS/" + package + ".log"
97
-        chrootCmd = self.runInChrootCommand + " " + chrootID
98
-        shutil.copyfile(specFile, chrootID + chrootSpecPath + specName)
100
+        sourcePath = constants.topDirPath + "/SOURCES/"
101
+        specPath = constants.topDirPath + "/SPECS/"
102
+        if (constants.rpmCheck and
103
+                package in constants.testForceRPMS and
104
+                SPECS.getData().isCheckAvailable(package)):
105
+            logFilePath = destLogPath + "/" + package + "-test.log"
106
+        else:
107
+            logFilePath = destLogPath + "/" + package + ".log"
108
+        sandbox.put(specFile, specPath + specName)
99 109
 
100 110
         sources_urls, macros = self._getAdditionalBuildOptions(package)
101 111
         self.logger.debug("Extra macros for " + package + ": " + str(macros))
102 112
         self.logger.debug("Extra source URLs for " + package + ": " + str(sources_urls))
103 113
         constants.setExtraSourcesURLs(package, sources_urls)
104 114
 
105
-        # FIXME: some sources are located in SPECS/.. how to mount?
106
-        #        if os.geteuid()==0:
107
-        self._copySourcesTobuildroot(listSourcesFiles, package, version, chrootSourcePath)
108
-        self._copySourcesTobuildroot(listPatchFiles, package, version, chrootSourcePath)
115
+        self._copySources(sandbox, listSourcesFiles, package, version, sourcePath)
116
+        self._copySources(sandbox, listPatchFiles, package, version, sourcePath)
109 117
 
110 118
         #Adding rpm macros
111 119
         listRPMMacros = constants.userDefinedMacros
... ...
@@ -115,9 +121,8 @@ class PackageUtils(object):
115 115
         listRPMFiles = []
116 116
         listSRPMFiles = []
117 117
         try:
118
-            listRPMFiles, listSRPMFiles = self._buildRPM(chrootSpecPath + specName,
119
-                                                         chrootLogsFilePath, chrootCmd,
120
-                                                         package, macros)
118
+            listRPMFiles, listSRPMFiles = self._buildRPM(sandbox, specPath + specName,
119
+                                                         logFilePath, package, macros)
121 120
             logmsg = package + " build done - RPMs : [ "
122 121
             for f in listRPMFiles:
123 122
                 logmsg += (os.path.basename(f) + " ")
... ...
@@ -127,26 +132,13 @@ class PackageUtils(object):
127 127
             self.logger.error("Failed while building rpm:" + package)
128 128
             raise e
129 129
         finally:
130
-            if destLogPath is not None:
131
-                if (constants.rpmCheck and
132
-                        package in constants.testForceRPMS and
133
-                        SPECS.getData().isCheckAvailable(package)):
134
-                    cmd = ("sed -i '/^Executing(%check):/,/^Processing files:/{//!b};d' " +
135
-                           chrootLogsFilePath)
136
-                    logFile = destLogPath + "/adjustTestFile.log"
137
-                    returnVal = CommandUtils().runCommandInShell(cmd, logFile)
138
-                    testLogFile = destLogPath + "/" + package + "-test.log"
139
-                    shutil.copyfile(chrootLogsFilePath, testLogFile)
140
-                else:
141
-                    shutil.copy2(chrootLogsFilePath, destLogPath)
130
+            if (constants.rpmCheck and
131
+                    package in constants.testForceRPMS and
132
+                    SPECS.getData().isCheckAvailable(package)):
133
+                cmd = ("sed -i '/^Executing(%check):/,/^Processing files:/{//!b};d' " + logFilePath)
134
+                CommandUtils().runCommandInShell(cmd, logfn=self.logger.debug)
142 135
         self.logger.debug("RPM build is successful")
143 136
 
144
-        for rpmFile in listRPMFiles:
145
-            self._copyRPM(chrootID + "/" + rpmFile, constants.rpmPath)
146
-
147
-        for srpmFile in listSRPMFiles:
148
-            srpmDestFile = self._copyRPM(chrootID + "/" + srpmFile, constants.sourceRpmPath)
149
-
150 137
     def findRPMFileForGivenPackage(self, package,version="*"):
151 138
         cmdUtils = CommandUtils()
152 139
         if version == "*":
... ...
@@ -171,268 +163,33 @@ class PackageUtils(object):
171 171
                               " : " + str(listFoundRPMFiles))
172 172
             raise Exception("Multiple rpm files found")
173 173
 
174
-    def findInstalledRPMPackages(self, chrootID):
174
+    def findInstalledRPMPackages(self, sandbox):
175
+        rpms = None
176
+        def setOutValue(data):
177
+            nonlocal rpms
178
+            rpms = data
175 179
         cmd = self.rpmBinary + " " + self.queryRpmPackageOptions
176
-        chrootCmd = self.runInChrootCommand + " " + chrootID
177
-        cmdUtils = CommandUtils()
178
-        result = cmdUtils.runCommandInShell2(cmd, chrootCmd)
179
-        if result is not None:
180
-            return result.decode().split()
181
-        return result
180
+        sandbox.run(cmd, logfn=setOutValue)
181
+        return rpms.split()
182 182
 
183
-    def adjustGCCSpecs(self, package, version, chrootID, logPath):
183
+    def adjustGCCSpecs(self, sandbox, package, version):
184 184
         opt = " " + SPECS.getData().getSecurityHardeningOption(package, version)
185
-        cmdUtils = CommandUtils()
186
-        cpcmd = ("cp " + self.adjustGCCSpecScript + " " + chrootID +
187
-                 "/tmp/" + self.adjustGCCSpecScript)
185
+        sandbox.put(self.adjustGCCSpecScript, "/tmp")
188 186
         cmd = "/tmp/" + self.adjustGCCSpecScript + opt
189
-        logFile = logPath + "/adjustGCCSpecScript.log"
190
-        chrootCmd = self.runInChrootCommand + " " + chrootID
191
-        returnVal = cmdUtils.runCommandInShell(cpcmd, logFile)
192
-        if not returnVal:
193
-            self.logger.error("Error during copying the file adjust gcc spec")
194
-            raise Exception("Failed while copying adjust gcc spec file")
195
-        returnVal = cmdUtils.runCommandInShell(cmd, logFile, chrootCmd)
196
-        if returnVal:
187
+        returnVal = sandbox.run(cmd, logfn=self.logger.debug)
188
+        if returnVal == 0:
197 189
             return
198 190
 
199
-        self.logger.debug(cmdUtils.runCommandInShell2("ls -la " + chrootID +
200
-                                                      "/tmp/" + self.adjustGCCSpecScript))
201
-        self.logger.debug(cmdUtils.runCommandInShell2("lsof " + chrootID + "/tmp/" +
202
-                                                      self.adjustGCCSpecScript))
203
-        self.logger.debug(cmdUtils.runCommandInShell2("ps ax"))
204
-
205
-        self.logger.error("Failed while adjusting gcc specs")
206
-        raise Exception("Failed while adjusting gcc specs")
207
-
208
-    def prepRPMforInstallInContainer(self, package,version, containerID, noDeps=False, destLogPath=None):
209
-        rpmfile = self.findRPMFileForGivenPackage(package,version)
210
-        if rpmfile is None:
211
-            self.logger.error("No rpm file found for package: " + package)
212
-            raise Exception("Missing rpm file")
213
-
214
-        rpmDestFile = self._getRPMPathInContainer(rpmfile, containerID)
215
-        if noDeps:
216
-            self.noDepsRPMFilesToInstallInAOneShot += " " + rpmDestFile
217
-            self.noDepsPackagesToInstallInAOneShot += " " + package
218
-            if package in constants.listReInstallPackages:
219
-                self.noDepsRPMFilesToReInstallInAOneShot += " " + rpmDestFile
220
-        else:
221
-            self.rpmFilesToInstallInAOneShot += " " + rpmDestFile
222
-            self.packagesToInstallInAOneShot += " " + package
223
-            if package in constants.listReInstallPackages:
224
-                self.rmpFilesToReInstallInAOneShot += " " + rpmDestFile
225
-
226
-    def installRPMSInAOneShotInContainer(self, containerID, destLogPath):
227
-        rpmInstallcmd = (self.rpmBinary + " " + self.installRPMPackageOptions + " " +
228
-                         self.forceRpmPackageOptions)
229
-
230
-        if self.noDepsRPMFilesToInstallInAOneShot != "":
231
-            self.logger.debug("PackageUtils-installRPMSInAOneShotInContainer: " +
232
-                             "Installing nodeps rpms: " +
233
-                             self.noDepsPackagesToInstallInAOneShot)
234
-            logFile = destLogPath + "/install_rpms_nodeps.log"
235
-            cmd = (rpmInstallcmd + " " + self.nodepsRPMPackageOptions + " " +
236
-                   self.noDepsRPMFilesToInstallInAOneShot)
237
-            cmd = "/bin/bash -l -c '" + cmd + "'"
238
-            #self.logger.debug("VDBG-PU-installRPMSInAOneShotInContainer: " +
239
-            #                  "Install nodeps cmd: " + cmd)
240
-            #TODO: Error code from exec_run
241
-            installLog = containerID.exec_run(cmd)
242
-            if not installLog:
243
-                self.logger.error("Unable to install nodeps rpms")
244
-                raise Exception("nodeps RPM installation failed")
245
-            with open(logFile, 'w') as logfile:
246
-                logfile.write(installLog.decode())
247
-
248
-            if self.noDepsRPMFilesToReInstallInAOneShot != "":
249
-                cmd = (rpmInstallcmd + " " + self.nodepsRPMPackageOptions + " " +
250
-                       self.forceRpmPackageOptions + " " +
251
-                       self.noDepsRPMFilesToReInstallInAOneShot)
252
-                cmd = "/bin/bash -l -c '" + cmd + "'"
253
-                #self.logger.debug("VDBG-PU-installRPMSInAOneShotInContainer: " +
254
-                #                  "ReInstall nodeps cmd: " + cmd)
255
-                #TODO: Error code from exec_run
256
-                installLog = containerID.exec_run(cmd)
257
-                if not installLog:
258
-                    self.logger.error("Unable to re-install nodeps rpms")
259
-                    raise Exception("nodeps RPM re-installation failed")
260
-                with open(logFile, 'a') as logfile:
261
-                    logfile.write(installLog.decode())
262
-
263
-        if self.rpmFilesToInstallInAOneShot != "":
264
-            self.logger.debug("PackageUtils-installRPMSInAOneShotInContainer: Installing rpms: " +
265
-                             self.packagesToInstallInAOneShot)
266
-            logFile = destLogPath + "/install_rpms.log"
267
-            cmd = rpmInstallcmd + " " + self.rpmFilesToInstallInAOneShot
268
-            cmd = "/bin/bash -l -c '" + cmd + "'"
269
-            #self.logger.debug("VDBG-PU-installRPMSInAOneShotInContainer: Install cmd: " + cmd)
270
-            #TODO: Error code from exec_run
271
-            installLog = containerID.exec_run(cmd)
272
-            if not installLog:
273
-                self.logger.error("Unable to install rpms")
274
-                raise Exception("RPM installation failed")
275
-            with open(logFile, 'w') as logfile:
276
-                logfile.write(installLog.decode())
277
-
278
-            if self.rpmFilesToReInstallInAOneShot != "":
279
-                cmd = (rpmInstallcmd + " " + self.forceRpmPackageOptions + " " +
280
-                       self.rpmFilesToReInstallInAOneShot)
281
-                cmd = "/bin/bash -l -c '" + cmd + "'"
282
-                #self.logger.debug("VDBG-PU-installRPMSInAOneShotInContainer: " +
283
-                #                  "ReInstall cmd: " + cmd)
284
-                #TODO: Error code from exec_run
285
-                installLog = containerID.exec_run(cmd)
286
-                if not installLog:
287
-                    self.logger.error("Unable to re-install rpms")
288
-                    raise Exception("RPM re-installation failed")
289
-                with open(logFile, 'a') as logfile:
290
-                    logfile.write(installLog.decode())
291
-
292
-    def findInstalledRPMPackagesInContainer(self, containerID):
293
-        cmd = self.rpmBinary + " " + self.queryRpmPackageOptions
294
-        cmd = "/bin/bash -l -c '" + cmd + "'"
295
-        #TODO: Error code from exec_run
296
-        result = containerID.exec_run(cmd)
297
-        if result is not None:
298
-            return result.decode().split()
299
-        return result
300
-
301
-    def adjustGCCSpecsInContainer(self, package, version, containerID, logPath):
302
-        opt = " " + SPECS.getData().getSecurityHardeningOption(package, version)
303
-        adjustCmd = "/" + self.adjustGCCSpecScript + opt
304
-        adjustCmd = "/bin/bash -l -c '" + adjustCmd + "'"
305
-        logFile = logPath + "/adjustGCCSpecScript.log"
306
-
307
-        #TODO: Error code from exec_run
308
-        scriptLog = containerID.exec_run(adjustCmd)
309
-        if scriptLog:
310
-            with open(logFile, 'w') as logfile:
311
-                logfile.write(scriptLog.decode())
312
-            return
191
+        # in debugging ...
192
+        sandbox.run("ls -la /tmp/" + self.adjustGCCSpecScript,
193
+                    logfn=self.logger.debug)
194
+        sandbox.run("lsof /tmp/" + self.adjustGCCSpecScript,
195
+                    logfn=self.logger.debug)
196
+        sandbox.run("ps ax", logfn=self.logger.debug)
313 197
 
314
-        self.logger.debug(containerID.exec_run("ls -la /tmp/" + self.adjustGCCSpecScript))
315
-        self.logger.debug(containerID.exec_run("lsof /tmp/" + self.adjustGCCSpecScript))
316
-        self.logger.debug(containerID.exec_run("ps ax"))
317 198
         self.logger.error("Failed while adjusting gcc specs")
318 199
         raise Exception("Failed while adjusting gcc specs")
319 200
 
320
-    def buildRPMSForGivenPackageInContainer(self, package, version, containerID, destLogPath=None):
321
-        self.logger.debug("Building rpms for package " + package + " in container " +
322
-                         containerID.short_id)
323
-
324
-        listSourcesFiles = SPECS.getData().getSources(package, version)
325
-        listPatchFiles = SPECS.getData().getPatches(package, version)
326
-        specFile = SPECS.getData().getSpecFile(package, version)
327
-        specName = SPECS.getData().getSpecName(package) + ".spec"
328
-        sourcePath = constants.topDirPath + "/SOURCES/"
329
-        specPath = constants.topDirPath + "/SPECS/"
330
-        rpmLogFile = constants.topDirPath + "/LOGS/" + package + ".log"
331
-        destLogFile = destLogPath + "/" + package + ".log"
332
-        cmdUtils = CommandUtils()
333
-
334
-        #TODO: mount it in, don't copy
335
-        cpSpecCmd = "docker cp " + specFile + " " + containerID.short_id \
336
-                        + ":" + specPath + specName
337
-        returnVal = cmdUtils.runCommandInShell(cpSpecCmd)
338
-        if not returnVal:
339
-            self.logger.error("Error copying source SPEC file to container")
340
-            raise Exception("Failed copying source SPEC to container")
341
-
342
-        macros = []
343
-        sources_urls, macros = self._getAdditionalBuildOptions(package)
344
-        constants.setExtraSourcesURLs(package, sources_urls)
345
-
346
-        #FIXME: some sources are located in SPECS/.. how to mount?
347
-        #        if os.geteuid()==0:
348
-        #TODO: mount it in, don't copy
349
-        self._copySourcesToContainer(listSourcesFiles, package, version, containerID, sourcePath)
350
-        #TODO: mount it in, don't copy
351
-        self._copySourcesToContainer(listPatchFiles, package, version, containerID, sourcePath)
352
-
353
-        # Add rpm macros
354
-        listRPMMacros = constants.userDefinedMacros
355
-        for macroName, value in listRPMMacros.items():
356
-            macros.append(macroName + " " + value)
357
-
358
-        # Build RPMs
359
-        listRPMFiles = []
360
-        listSRPMFiles = []
361
-        try:
362
-            listRPMFiles, listSRPMFiles = self._buildRPMinContainer(
363
-                specPath + specName,
364
-                rpmLogFile,
365
-                destLogFile,
366
-                containerID,
367
-                package,
368
-                version,
369
-                macros)
370
-            logmsg = "Successfully built " + package + " - RPMs : [" + "".join(os.path.basename(listRPMFiles)) + "]"
371
-            self.logger.info(logmsg)
372
-        except Exception as e:
373
-            self.logger.error("Failed while building rpm: " + package)
374
-            raise e
375
-        finally:
376
-            if destLogPath is not None:
377
-                rpmLog = destLogPath + "/" + package + ".log"
378
-                if (constants.rpmCheck and
379
-                        package in constants.testForceRPMS and
380
-                        SPECS.getData().isCheckAvailable(package, version)):
381
-                    cmd = "sed -i '/^Executing(%check):/,/^Processing files:/{//!b};d' " + rpmLog
382
-                    logFile = destLogPath + "/adjustTestFile.log"
383
-                    returnVal = CommandUtils().runCommandInShell(cmd, logFile)
384
-                    testLogFile = destLogPath + "/" + package + "-test.log"
385
-                    shutil.copyfile(rpmLog, testLogFile)
386
-        self.logger.debug("RPM build is successful")
387
-
388
-        # Verify RPM and SRPM files exist as success criteria
389
-        for rpmFile in listRPMFiles:
390
-            rpmName = os.path.basename(rpmFile)
391
-            rpmDestDir = self._getRPMDestDir(rpmName, constants.rpmPath)
392
-            rpmDestFile = rpmDestDir + "/" + rpmName
393
-            if not os.path.isfile(rpmDestFile):
394
-                self.logger.error("Could not find RPM file: " + rpmDestFile)
395
-                raise Exception("Built RPM file not found.")
396
-
397
-        for srpmFile in listSRPMFiles:
398
-            srpmName = os.path.basename(srpmFile)
399
-            srpmDestDir = self._getRPMDestDir(os.path.basename(srpmFile), constants.sourceRpmPath)
400
-            srpmDestFile = srpmDestDir + "/" + srpmName
401
-            if not os.path.isfile(srpmDestFile):
402
-                self.logger.error("Could not find RPM file: " + srpmDestFile)
403
-                raise Exception("Built SRPM file not found.")
404
-
405
-    def _getRPMArch(self, rpmName):
406
-        arch = ""
407
-        if "x86_64" in rpmName:
408
-            arch = "x86_64"
409
-        elif "aarch64" in rpmName:
410
-            arch = "aarch64"
411
-        elif "noarch" in rpmName:
412
-            arch = "noarch"
413
-        return arch
414
-
415
-    def _getRPMDestDir(self, rpmName, rpmDir):
416
-        arch = self._getRPMArch(rpmName)
417
-        rpmDestDir = rpmDir + "/" + arch
418
-        return rpmDestDir
419
-
420
-    def _copyRPM(self, rpmFile, destDir):
421
-        cmdUtils = CommandUtils()
422
-        rpmName = os.path.basename(rpmFile)
423
-        rpmDestDir = self._getRPMDestDir(rpmName, destDir)
424
-        # shutil is not atomic. copy & move to ensure atomicity.
425
-        rpmDestPath = rpmDestDir + "/" + rpmName
426
-        rpmDestPathTemp = (rpmDestDir + "/." +
427
-                           ''.join([random.choice(string.ascii_letters +
428
-                                                  string.digits) for n in range(10)]))
429
-        if os.geteuid() == 0:
430
-            if not os.path.isdir(rpmDestDir):
431
-                cmdUtils.runCommandInShell("mkdir -p " + rpmDestDir)
432
-            shutil.copyfile(rpmFile, rpmDestPathTemp)
433
-            shutil.move(rpmDestPathTemp, rpmDestPath)
434
-        return rpmDestPath
435
-
436 201
     def _verifyShaAndGetSourcePath(self, source, package, version):
437 202
         cmdUtils = CommandUtils()
438 203
         # Fetch/verify sources if sha1 not None.
... ...
@@ -462,12 +219,13 @@ class PackageUtils(object):
462 462
             raise Exception("Multiple sources found")
463 463
         return sourcePath
464 464
 
465
-    def _copySourcesTobuildroot(self, listSourceFiles, package, version, destDir):
465
+    def _copySources(self, sandbox, listSourceFiles, package, version, destDir):
466
+        # Fetch and verify sha1 if missing
466 467
         for source in listSourceFiles:
467 468
             sourcePath = self._verifyShaAndGetSourcePath(source, package, version)
468 469
             self.logger.debug("Copying... Source path :" + source +
469 470
                              " Source filename: " + sourcePath[0])
470
-            shutil.copy2(sourcePath[0], destDir)
471
+            sandbox.put(sourcePath[0], destDir)
471 472
 
472 473
     def _getAdditionalBuildOptions(self, package):
473 474
         pullsources_urls = []
... ...
@@ -479,8 +237,7 @@ class PackageUtils(object):
479 479
         return pullsources_urls, macros
480 480
 
481 481
 
482
-    def _buildRPM(self, specFile, logFile, chrootCmd, package, macros):
483
-
482
+    def _buildRPM(self, sandbox, specFile, logFile, package, macros):
484 483
         rpmBuildcmd = self.rpmbuildBinary + " " + self.rpmbuildBuildallOption
485 484
 
486 485
         if constants.rpmCheck and package in constants.testForceRPMS:
... ...
@@ -500,34 +257,36 @@ class PackageUtils(object):
500 500
             rpmBuildcmd += " " + self.rpmbuildNocheckOption
501 501
 
502 502
         for macro in macros:
503
-            rpmBuildcmd += ' --define \\\"%s\\\"' % macro
503
+            rpmBuildcmd += ' --define \"%s\"' % macro
504 504
         rpmBuildcmd += " " + specFile
505 505
 
506
-        cmdUtils = CommandUtils()
507 506
         self.logger.debug("Building rpm....")
508 507
         self.logger.debug(rpmBuildcmd)
509
-        returnVal = cmdUtils.runCommandInShell(rpmBuildcmd, logFile, chrootCmd)
508
+
509
+        returnVal = sandbox.run(rpmBuildcmd, logfile = logFile)
510
+
510 511
         if constants.rpmCheck and package in constants.testForceRPMS:
511 512
             if not SPECS.getData().isCheckAvailable(package):
512 513
                 constants.testLogger.debug(package + " : N/A")
513
-            elif returnVal:
514
+            elif returnVal == 0:
514 515
                 constants.testLogger.debug(package + " : PASS")
515 516
             else:
516 517
                 constants.testLogger.debug(package + " : FAIL")
517 518
 
518 519
         if constants.rpmCheck:
519
-            if not returnVal and constants.rpmCheckStopOnError:
520
+            if returnVal != 0 and constants.rpmCheckStopOnError:
520 521
                 self.logger.error("Checking rpm is failed " + specFile)
521 522
                 raise Exception("RPM check failed")
522 523
         else:
523
-            if not returnVal:
524
+            if returnVal != 0:
524 525
                 self.logger.error("Building rpm is failed " + specFile)
525 526
                 raise Exception("RPM build failed")
526 527
 
527 528
         #Extracting rpms created from log file
528 529
         listRPMFiles = []
529 530
         listSRPMFiles = []
530
-        with open(logFile, 'r') as logfile:
531
+        stageLogFile = logFile.replace(constants.topDirPath + "/LOGS", constants.logPath )
532
+        with open(stageLogFile, 'r') as logfile:
531 533
             fileContents = logfile.readlines()
532 534
             for i in range(0, len(fileContents)):
533 535
                 if re.search("^Wrote:", fileContents[i]):
... ...
@@ -542,103 +301,3 @@ class PackageUtils(object):
542 542
                         listSRPMFiles.append(listcontents[1])
543 543
         return listRPMFiles, listSRPMFiles
544 544
 
545
-
546
-    def _copySourcesToContainer(self, listSourceFiles, package, version, containerID, destDir):
547
-        cmdUtils = CommandUtils()
548
-        for source in listSourceFiles:
549
-            sourcePath = self._verifyShaAndGetSourcePath(source, package, version)
550
-            self.logger.debug("Copying source file: " + sourcePath[0])
551
-            copyCmd = "docker cp " + sourcePath[0] + " " + containerID.short_id + ":" + destDir
552
-            cmdUtils.runCommandInShell(copyCmd)
553
-
554
-    def _getRPMPathInContainer(self, rpmFile, containerID):
555
-        rpmName = os.path.basename(rpmFile)
556
-        #TODO: Container path from constants
557
-        if "PUBLISHRPMS" in rpmFile:
558
-            rpmPath = "/publishrpms/"
559
-        elif "PUBLISHXRPMS" in rpmFile:
560
-            rpmPath = "/publishxrpms/"
561
-        else:
562
-            rpmPath = constants.topDirPath + "/RPMS/"
563
-        if "noarch" in rpmFile:
564
-            rpmPath += "noarch/"
565
-        else:
566
-            rpmPath += platform.machine()+"/"
567
-        rpmPath += rpmName
568
-        return rpmPath