1 |
commit: 48856f7e10e04d1720b35d32a6151ff2e0d50b31 |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Thu Mar 9 05:04:47 2017 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Thu Mar 9 05:04:47 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/catalyst.git/commit/?id=48856f7e |
7 |
|
8 |
base/stagebase.py: Cleanup and fix the autoresume validation in the unpack() |
9 |
|
10 |
The previous logic was convoluted and had many errors, most notably, not checking |
11 |
the chroot is a directory, but instead was checking the seed source. |
12 |
I broke up and simplified the logic into two sections, one checks the chroot for a valid resume |
13 |
point, the other checks for seed tarball changes which would invalidate the existing chroot. |
14 |
|
15 |
Also the non-autoresume code block code was mostly not needed and was also simplified. |
16 |
|
17 |
catalyst/base/resume.py | 2 +- |
18 |
catalyst/base/stagebase.py | 92 ++++++++++++++++++++++------------------------ |
19 |
2 files changed, 45 insertions(+), 49 deletions(-) |
20 |
|
21 |
diff --git a/catalyst/base/resume.py b/catalyst/base/resume.py |
22 |
index 70d9a4f..b210073 100644 |
23 |
--- a/catalyst/base/resume.py |
24 |
+++ b/catalyst/base/resume.py |
25 |
@@ -75,7 +75,7 @@ class AutoResume(object): |
26 |
with open(self._points[point], 'r') as myf: |
27 |
data = myf.read() |
28 |
if data and no_lf: |
29 |
- data = data.replace('\n', '') |
30 |
+ data = data.replace('\n', ' ') |
31 |
except OSError as e: |
32 |
log.error('AutoResumeError: %s', e) |
33 |
return None |
34 |
|
35 |
diff --git a/catalyst/base/stagebase.py b/catalyst/base/stagebase.py |
36 |
index a6233b2..2557fe8 100644 |
37 |
--- a/catalyst/base/stagebase.py |
38 |
+++ b/catalyst/base/stagebase.py |
39 |
@@ -416,6 +416,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
40 |
self.settings["source_subpath"] + "/")): |
41 |
self.settings["source_path"] = normpath(self.settings["storedir"] + |
42 |
"/tmp/" + self.settings["source_subpath"] + "/") |
43 |
+ log.debug("source_subpath is: %s", self.settings["source_path"]) |
44 |
else: |
45 |
log.debug('Checking source path existence and ' |
46 |
'get the final filepath. subpath: %s', |
47 |
@@ -693,10 +694,10 @@ class StageBase(TargetBase, ClearBase, GenBase): |
48 |
raise CatalystError("Unable to auto-unbind " + target) |
49 |
|
50 |
def unpack(self): |
51 |
- _unpack = True |
52 |
|
53 |
clst_unpack_hash = self.resume.get("unpack") |
54 |
|
55 |
+ # Set up all unpack info settings |
56 |
unpack_info = self.decompressor.create_infodict( |
57 |
source = self.settings["source_path"], |
58 |
destination = self.settings["chroot_path"], |
59 |
@@ -721,56 +722,51 @@ class StageBase(TargetBase, ClearBase, GenBase): |
60 |
else: |
61 |
# No SEEDCACHE, use tar |
62 |
unpack_info['source'] = file_check(unpack_info['source']) |
63 |
- # endif "seedcache" |
64 |
+ # end of unpack_info settings |
65 |
|
66 |
+ # set defaults, |
67 |
+ # only change them if the resume point is proven to be good |
68 |
+ _unpack = True |
69 |
+ invalid_chroot = True |
70 |
+ # Begin autoresume validation |
71 |
if "autoresume" in self.settings["options"]: |
72 |
- if os.path.isdir(self.settings["source_path"]) \ |
73 |
- and self.resume.is_enabled("unpack"): |
74 |
- # Autoresume is valid, SEEDCACHE is valid |
75 |
- _unpack = False |
76 |
- invalid_snapshot = False |
77 |
- log.notice('Resume point "unpack" valid...') |
78 |
- |
79 |
- elif os.path.isfile(self.settings["source_path"]) \ |
80 |
- and self.settings["source_path_hash"] == clst_unpack_hash: |
81 |
- # Autoresume is valid, tarball is valid |
82 |
- _unpack = False |
83 |
- invalid_snapshot = False |
84 |
- log.notice('Resume point "source_path_hash" valid...') |
85 |
- |
86 |
- elif os.path.isdir(self.settings["source_path"]) \ |
87 |
- and self.resume.is_disabled("unpack"): |
88 |
- # Autoresume is invalid, SEEDCACHE |
89 |
- _unpack = True |
90 |
- invalid_snapshot = True |
91 |
- log.notice('Resume point "unpack is disabled" is True, invalidating snapshot... :(') |
92 |
- |
93 |
- elif os.path.isfile(self.settings["source_path"]) \ |
94 |
- and self.settings["source_path_hash"] != clst_unpack_hash: |
95 |
- # Autoresume is invalid, tarball |
96 |
- _unpack = True |
97 |
- invalid_snapshot = True |
98 |
- log.notice('Resume point "source_path_hash" is invalid... :(') |
99 |
- unpack_info['source'] = file_check(unpack_info['source']) |
100 |
+ # check chroot |
101 |
+ if os.path.isdir(self.settings["chroot_path"]): |
102 |
+ if self.resume.is_enabled("unpack"): |
103 |
+ # Autoresume is valid in the chroot |
104 |
+ _unpack = False |
105 |
+ invalid_chroot = False |
106 |
+ log.notice('Resume: "chroot" is valid...') |
107 |
+ else: |
108 |
+ # self.resume.is_disabled("unpack") |
109 |
+ # Autoresume is invalid in the chroot |
110 |
+ log.notice('Resume: "seed source" unpack resume point is disabled') |
111 |
+ |
112 |
+ # check seed source |
113 |
+ if os.path.isfile(self.settings["source_path"]) and not invalid_chroot: |
114 |
+ if self.settings["source_path_hash"] == clst_unpack_hash: |
115 |
+ # Seed tarball has not changed, chroot is valid |
116 |
+ _unpack = False |
117 |
+ invalid_chroot = False |
118 |
+ log.notice('Resume: "seed source" hash matches chroot...') |
119 |
+ else: |
120 |
+ # self.settings["source_path_hash"] != clst_unpack_hash |
121 |
+ # Seed tarball has changed, so invalidate the chroot |
122 |
+ _unpack = True |
123 |
+ invalid_chroot = True |
124 |
+ log.notice('Resume: "seed source" has changed, hashes do not match, invalidating resume...') |
125 |
+ log.notice(' source_path......: %s', self.settings["source_path"]) |
126 |
+ log.notice(' new source hash..: %s', self.settings["source_path_hash"].replace("\n", " ")) |
127 |
+ log.notice(' recorded hash....: %s', clst_unpack_hash) |
128 |
+ unpack_info['source'] = file_check(unpack_info['source']) |
129 |
|
130 |
else: |
131 |
- # No autoresume, SEEDCACHE |
132 |
+ # No autoresume, check SEEDCACHE |
133 |
if "seedcache" in self.settings["options"]: |
134 |
- # SEEDCACHE so let's run rsync and let it clean up |
135 |
+ # if the seedcache is a dir, rsync will clean up the chroot |
136 |
if os.path.isdir(self.settings["source_path"]): |
137 |
- _unpack = True |
138 |
- invalid_snapshot = False |
139 |
- elif os.path.isfile(self.settings["source_path"]): |
140 |
- # Tarball so unpack and remove anything already there |
141 |
- _unpack = True |
142 |
- invalid_snapshot = True |
143 |
- # No autoresume, no SEEDCACHE |
144 |
- else: |
145 |
- # Tarball so unpack and remove anything already there |
146 |
- if os.path.isfile(self.settings["source_path"]): |
147 |
- _unpack = True |
148 |
- invalid_snapshot = True |
149 |
- elif os.path.isdir(self.settings["source_path"]): |
150 |
+ pass |
151 |
+ elif os.path.isdir(self.settings["source_path"]): |
152 |
# We should never reach this, so something is very wrong |
153 |
raise CatalystError( |
154 |
"source path is a dir but seedcache is not enabled: %s" |
155 |
@@ -779,9 +775,9 @@ class StageBase(TargetBase, ClearBase, GenBase): |
156 |
if _unpack: |
157 |
self.mount_safety_check() |
158 |
|
159 |
- if invalid_snapshot: |
160 |
+ if invalid_chroot: |
161 |
if "autoresume" in self.settings["options"]: |
162 |
- log.notice('No Valid Resume point detected, cleaning up...') |
163 |
+ log.notice('Resume: Target chroot is invalid, cleaning up...') |
164 |
|
165 |
self.clear_autoresume() |
166 |
self.clear_chroot() |
167 |
@@ -808,7 +804,7 @@ class StageBase(TargetBase, ClearBase, GenBase): |
168 |
else: |
169 |
self.resume.enable("unpack") |
170 |
else: |
171 |
- log.notice('Resume point detected, skipping unpack operation...') |
172 |
+ log.notice('Resume: Valid resume point detected, skipping seed unpack operation...') |
173 |
|
174 |
def unpack_snapshot(self): |
175 |
unpack = True |