[Piuparts-commits] [piuparts] 07/17: p-s: use locking to avoid concurrent basetgz creation

Holger Levsen holger at alioth.debian.org
Wed Nov 6 09:45:53 UTC 2013


This is an automated email from the git hooks/post-receive script.

holger pushed a commit to branch develop
in repository piuparts.

commit d5d6fa300218ec1c75b09d3fae876ce773e6d910
Author: Andreas Beckmann <anbe at debian.org>
Date:   Tue Nov 5 20:24:12 2013 +0100

    p-s: use locking to avoid concurrent basetgz creation
    
    Signed-off-by: Andreas Beckmann <anbe at debian.org>
---
 debian/changelog  |    2 ++
 piuparts-slave.py |   43 +++++++++++++++++++++++++------------------
 2 files changed, 27 insertions(+), 18 deletions(-)

diff --git a/debian/changelog b/debian/changelog
index cc8383e..05c4e2a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,8 @@ piuparts (0.56) UNRELEASED; urgency=low
   * piupartslib/__init__.py:
     - open_packages_url(): Try Packages.gz if Packages.bz2 is not available.
       (Closes: #711157)
+  * piuparts-slave.py:
+    - Use locking to prevent concurrent basetgz creation.  (Closes: #708287)
   * piuparts-report.py:
     - Report URLs of all Packages files used for a section.
     - Avoid reporting duplicate dependencies after stripping versioning.
diff --git a/piuparts-slave.py b/piuparts-slave.py
index 47a05f4..39b5ed5 100644
--- a/piuparts-slave.py
+++ b/piuparts-slave.py
@@ -802,9 +802,6 @@ def run_test_with_timeout(cmd, maxwait, kill_all=True):
 
 
 def create_chroot(config, tarball, distro):
-    output_name = tarball + ".log"
-    logging.debug("Opening log file %s" % output_name)
-    logging.info("Creating new tarball %s" % tarball)
     command = config["piuparts-command"].split()
     if config["piuparts-flags"]:
         command.extend(config["piuparts-flags"].split())
@@ -818,21 +815,31 @@ def create_chroot(config, tarball, distro):
     command.extend(["-d", distro])
     command.extend(["-s", tarball + ".new"])
     command.extend(["--apt", "dpkg"])
-    output = file(output_name, "w")
-    output.write(time.strftime("Start: %Y-%m-%d %H:%M:%S %Z\n\n",
-                               time.gmtime()))
-    output.write("Executing: " + " ".join(command) + "\n\n")
-    logging.debug("Executing: " + " ".join(command))
-    p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
-    for line in p.stdout:
-        output.write(line)
-        logging.debug(">> " + line.rstrip())
-    p.wait()
-    output.write(time.strftime("\nEnd: %Y-%m-%d %H:%M:%S %Z\n",
-                               time.gmtime()))
-    output.close()
-    if os.path.exists(tarball + ".new"):
-        os.rename(tarball + ".new", tarball)
+
+    output_name = tarball + ".log"
+    with open(output_name, "we") as output:
+        try:
+            fcntl.flock(output, fcntl.LOCK_EX | fcntl.LOCK_NB)
+        except IOError:
+            logging.info("Creation of tarball %s already in progress." % tarball)
+        else:
+            logging.info("Creating new tarball %s" % tarball)
+            output.write(time.strftime("Start: %Y-%m-%d %H:%M:%S %Z\n\n",
+                                       time.gmtime()))
+            output.write("Executing: " + " ".join(command) + "\n\n")
+            logging.debug("Executing: " + " ".join(command))
+            p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
+            for line in p.stdout:
+                output.write(line)
+                logging.debug(">> " + line.rstrip())
+            p.wait()
+            output.write(time.strftime("\nEnd: %Y-%m-%d %H:%M:%S %Z\n",
+                                       time.gmtime()))
+            if os.path.exists(tarball + ".new"):
+                os.rename(tarball + ".new", tarball)
+            else:
+                logging.error("Tarball creation failed, see %s" % output_name)
+
 
 def create_or_replace_chroot_tgz(config, tgz, distro):
     max_tgz_age = int(config["max-tgz-age"])

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/piuparts/piuparts.git



More information about the Piuparts-commits mailing list