From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id A2C4F139694 for ; Thu, 9 Mar 2017 05:05:20 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id C6246E0C2F; Thu, 9 Mar 2017 05:05:19 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 903B2E0C2F for ; Thu, 9 Mar 2017 05:05:19 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 5310434165B for ; Thu, 9 Mar 2017 05:05:18 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 135E561D3 for ; Thu, 9 Mar 2017 05:05:17 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1489035887.48856f7e10e04d1720b35d32a6151ff2e0d50b31.dolsen@gentoo> Subject: [gentoo-commits] proj/catalyst:master commit in: catalyst/base/ X-VCS-Repository: proj/catalyst X-VCS-Files: catalyst/base/resume.py catalyst/base/stagebase.py X-VCS-Directories: catalyst/base/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: 48856f7e10e04d1720b35d32a6151ff2e0d50b31 X-VCS-Branch: master Date: Thu, 9 Mar 2017 05:05:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 244f2d10-763c-4b6b-bb51-2cd63a5f136a X-Archives-Hash: ee718f42a8a7b56887c7533b4df81665 commit: 48856f7e10e04d1720b35d32a6151ff2e0d50b31 Author: Brian Dolbec gentoo org> AuthorDate: Thu Mar 9 05:04:47 2017 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Thu Mar 9 05:04:47 2017 +0000 URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=48856f7e base/stagebase.py: Cleanup and fix the autoresume validation in the unpack() The previous logic was convoluted and had many errors, most notably, not checking the chroot is a directory, but instead was checking the seed source. I broke up and simplified the logic into two sections, one checks the chroot for a valid resume point, the other checks for seed tarball changes which would invalidate the existing chroot. Also the non-autoresume code block code was mostly not needed and was also simplified. catalyst/base/resume.py | 2 +- catalyst/base/stagebase.py | 92 ++++++++++++++++++++++------------------------ 2 files changed, 45 insertions(+), 49 deletions(-) diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py index 70d9a4f..b210073 100644 --- a/catalyst/base/resume.py +++ b/catalyst/base/resume.py @@ -75,7 +75,7 @@ class AutoResume(object): with open(self._points[point], 'r') as myf: data = myf.read() if data and no_lf: - data = data.replace('\n', '') + data = data.replace('\n', ' ') except OSError as e: log.error('AutoResumeError: %s', e) return None diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py index a6233b2..2557fe8 100644 --- a/catalyst/base/stagebase.py +++ b/catalyst/base/stagebase.py @@ -416,6 +416,7 @@ class StageBase(TargetBase, ClearBase, GenBase): self.settings["source_subpath"] + "/")): self.settings["source_path"] = normpath(self.settings["storedir"] + "/tmp/" + self.settings["source_subpath"] + "/") + log.debug("source_subpath is: %s", self.settings["source_path"]) else: log.debug('Checking source path existence and ' 'get the final filepath. subpath: %s', @@ -693,10 +694,10 @@ class StageBase(TargetBase, ClearBase, GenBase): raise CatalystError("Unable to auto-unbind " + target) def unpack(self): - _unpack = True clst_unpack_hash = self.resume.get("unpack") + # Set up all unpack info settings unpack_info = self.decompressor.create_infodict( source = self.settings["source_path"], destination = self.settings["chroot_path"], @@ -721,56 +722,51 @@ class StageBase(TargetBase, ClearBase, GenBase): else: # No SEEDCACHE, use tar unpack_info['source'] = file_check(unpack_info['source']) - # endif "seedcache" + # end of unpack_info settings + # set defaults, + # only change them if the resume point is proven to be good + _unpack = True + invalid_chroot = True + # Begin autoresume validation if "autoresume" in self.settings["options"]: - if os.path.isdir(self.settings["source_path"]) \ - and self.resume.is_enabled("unpack"): - # Autoresume is valid, SEEDCACHE is valid - _unpack = False - invalid_snapshot = False - log.notice('Resume point "unpack" valid...') - - elif os.path.isfile(self.settings["source_path"]) \ - and self.settings["source_path_hash"] == clst_unpack_hash: - # Autoresume is valid, tarball is valid - _unpack = False - invalid_snapshot = False - log.notice('Resume point "source_path_hash" valid...') - - elif os.path.isdir(self.settings["source_path"]) \ - and self.resume.is_disabled("unpack"): - # Autoresume is invalid, SEEDCACHE - _unpack = True - invalid_snapshot = True - log.notice('Resume point "unpack is disabled" is True, invalidating snapshot... :(') - - elif os.path.isfile(self.settings["source_path"]) \ - and self.settings["source_path_hash"] != clst_unpack_hash: - # Autoresume is invalid, tarball - _unpack = True - invalid_snapshot = True - log.notice('Resume point "source_path_hash" is invalid... :(') - unpack_info['source'] = file_check(unpack_info['source']) + # check chroot + if os.path.isdir(self.settings["chroot_path"]): + if self.resume.is_enabled("unpack"): + # Autoresume is valid in the chroot + _unpack = False + invalid_chroot = False + log.notice('Resume: "chroot" is valid...') + else: + # self.resume.is_disabled("unpack") + # Autoresume is invalid in the chroot + log.notice('Resume: "seed source" unpack resume point is disabled') + + # check seed source + if os.path.isfile(self.settings["source_path"]) and not invalid_chroot: + if self.settings["source_path_hash"] == clst_unpack_hash: + # Seed tarball has not changed, chroot is valid + _unpack = False + invalid_chroot = False + log.notice('Resume: "seed source" hash matches chroot...') + else: + # self.settings["source_path_hash"] != clst_unpack_hash + # Seed tarball has changed, so invalidate the chroot + _unpack = True + invalid_chroot = True + log.notice('Resume: "seed source" has changed, hashes do not match, invalidating resume...') + log.notice(' source_path......: %s', self.settings["source_path"]) + log.notice(' new source hash..: %s', self.settings["source_path_hash"].replace("\n", " ")) + log.notice(' recorded hash....: %s', clst_unpack_hash) + unpack_info['source'] = file_check(unpack_info['source']) else: - # No autoresume, SEEDCACHE + # No autoresume, check SEEDCACHE if "seedcache" in self.settings["options"]: - # SEEDCACHE so let's run rsync and let it clean up + # if the seedcache is a dir, rsync will clean up the chroot if os.path.isdir(self.settings["source_path"]): - _unpack = True - invalid_snapshot = False - elif os.path.isfile(self.settings["source_path"]): - # Tarball so unpack and remove anything already there - _unpack = True - invalid_snapshot = True - # No autoresume, no SEEDCACHE - else: - # Tarball so unpack and remove anything already there - if os.path.isfile(self.settings["source_path"]): - _unpack = True - invalid_snapshot = True - elif os.path.isdir(self.settings["source_path"]): + pass + elif os.path.isdir(self.settings["source_path"]): # We should never reach this, so something is very wrong raise CatalystError( "source path is a dir but seedcache is not enabled: %s" @@ -779,9 +775,9 @@ class StageBase(TargetBase, ClearBase, GenBase): if _unpack: self.mount_safety_check() - if invalid_snapshot: + if invalid_chroot: if "autoresume" in self.settings["options"]: - log.notice('No Valid Resume point detected, cleaning up...') + log.notice('Resume: Target chroot is invalid, cleaning up...') self.clear_autoresume() self.clear_chroot() @@ -808,7 +804,7 @@ class StageBase(TargetBase, ClearBase, GenBase): else: self.resume.enable("unpack") else: - log.notice('Resume point detected, skipping unpack operation...') + log.notice('Resume: Valid resume point detected, skipping seed unpack operation...') def unpack_snapshot(self): unpack = True