Merge lp:~deeptik/linaro-license-protection/publish-to-snapshots into lp:~linaro-automation/linaro-license-protection/trunk
- publish-to-snapshots
- Merge into trunk
Status: | Merged |
---|---|
Merged at revision: | 49 |
Proposed branch: | lp:~deeptik/linaro-license-protection/publish-to-snapshots |
Merge into: | lp:~linaro-automation/linaro-license-protection/trunk |
Diff against target: |
261 lines (+157/-20) 2 files modified
scripts/publish_to_snapshots.py (+76/-16) testing/test_publish_to_snapshots.py (+81/-4) |
To merge this branch: | bzr merge lp:~deeptik/linaro-license-protection/publish-to-snapshots |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Paul Sokolovsky | Approve | ||
Review via email: mp+99221@code.launchpad.net |
Commit message
Description of the change
Adding changes to create manifest file and a symlink called lastSuccessful.
Adding tests to address the changes to create manifest file and a symlink called lastSuccessful
Deepti B. Kalakeri (deeptik) wrote : | # |
Ah! correct, I also had the same thing in mind. But not sure why I changed it to search for latest dir. Thanks I will submit the changes.
Regards,
Deepti.
- 51. By Deepti B. Kalakeri
-
Removed get_latest_dir, symlink now points to the build that was just copied
Paul Sokolovsky (pfalcon) wrote : | # |
Rev 51 looks good, thanks.
Deepti B. Kalakeri (deeptik) wrote : | # |
On Mon, Mar 26, 2012 at 4:36 PM, Paul Sokolovsky <<email address hidden>
> wrote:
> Review: Approve
>
> Rev 51 looks good, thanks.
>
Thanks a lot for the review
> --
>
> https:/
> You are the owner of
> lp:~deeptik/linaro-license-protection/publish-to-snapshots.
>
--
Thanks and Regards,
Deepti
Preview Diff
1 | === modified file 'scripts/publish_to_snapshots.py' |
2 | --- scripts/publish_to_snapshots.py 2012-03-16 10:55:32 +0000 |
3 | +++ scripts/publish_to_snapshots.py 2012-03-26 10:49:17 +0000 |
4 | @@ -16,6 +16,8 @@ |
5 | kernel-hwpack ${KERNEL_JOB_NAME}") |
6 | parser.add_argument("-n", "--build-num", dest="build_num", type=int, |
7 | help="Specify the job build number for android builds only") |
8 | +parser.add_argument("-m", "--manifest", dest="manifest", action='store_true', |
9 | + help="Optional parameter to generate MANIFEST file") |
10 | |
11 | uploads_path = '/srv3/snapshots.linaro.org/uploads/' |
12 | target_path = '/srv3/snapshots.linaro.org/www/' |
13 | @@ -83,29 +85,87 @@ |
14 | |
15 | return build_dir_path, target_dir_path |
16 | |
17 | + def create_symlink(self, target_dir_path): |
18 | + target_parent_dir = os.path.dirname(target_dir_path) |
19 | + symlink_path = os.path.join(target_parent_dir, "lastSuccessful") |
20 | + try: |
21 | + if os.path.islink(symlink_path): |
22 | + os.unlink(symlink_path) |
23 | + |
24 | + os.symlink(target_dir_path, symlink_path) |
25 | + print "The lastSuccessful build is now linked to ", target_dir_path |
26 | + return PASS |
27 | + except Exception, details: |
28 | + print "Failed to create symlink", symlink_path, ":", details |
29 | + return FAIL |
30 | + |
31 | + def create_manifest_file(self, target_dir): |
32 | + orig_dir=os.getcwd() |
33 | + os.chdir(target_dir) |
34 | + fn = os.path.join(target_dir, "MANIFEST") |
35 | + lines = [] |
36 | + |
37 | + try: |
38 | + for path, subdirs, files in os.walk("."): |
39 | + for name in files: |
40 | + lines.append(os.path.join(path, name).split("./")[1] + "\n") |
41 | + |
42 | + if len(lines) != 0: |
43 | + fd = open(fn, "w+") |
44 | + for line in lines: |
45 | + if not "MANIFEST" in line: |
46 | + fd.write(line) |
47 | + fd.close() |
48 | + else: |
49 | + raise Exception("Uploads directory was empty, nothing got moved to destination") |
50 | + |
51 | + os.chdir(orig_dir) |
52 | + |
53 | + if os.path.isfile(fn): |
54 | + print "Manifest file", fn, "generated" |
55 | + return PASS |
56 | + except Exception, details: |
57 | + print "Got Exception in create_manifest_file: ", details |
58 | + os.chdir(orig_dir) |
59 | + return FAIL |
60 | + |
61 | + |
62 | + def move_dir_content(self, src_dir, dest_dir): |
63 | + filelist = os.listdir(src_dir) |
64 | + try: |
65 | + for file in filelist: |
66 | + src = os.path.join(src_dir, file) |
67 | + dest = os.path.join(dest_dir, file) |
68 | + if os.path.exists(dest): |
69 | + if os.path.isdir(dest): |
70 | + self.move_dir_content(src, dest) |
71 | + continue |
72 | + else: |
73 | + os.remove(dest) |
74 | + shutil.move(src, dest) |
75 | + except shutil.Error: |
76 | + print "Error while moving the content" |
77 | |
78 | def move_artifacts(self, args, build_dir_path, target_dir_path): |
79 | try: |
80 | - # Make a note of the contents of src dir so that |
81 | - # it can be used to validate the move to destination |
82 | - uploads_dir_list = os.listdir(build_dir_path) |
83 | - |
84 | if not os.path.isdir(target_dir_path): |
85 | os.makedirs(target_dir_path) |
86 | if not os.path.isdir(target_dir_path): |
87 | raise OSError |
88 | |
89 | - for fname in uploads_dir_list: |
90 | - fname = os.path.join(build_dir_path, fname) |
91 | - shutil.copy2(fname, target_dir_path) |
92 | - |
93 | - target_dir_list = os.listdir(target_dir_path) |
94 | - for fname in uploads_dir_list: |
95 | - if not fname in target_dir_list: |
96 | - print "Destination missing file", fname |
97 | - return FAIL |
98 | - |
99 | - shutil.rmtree(build_dir_path) |
100 | + self.move_dir_content(build_dir_path, target_dir_path) |
101 | + |
102 | + if args.job_type != "kernel-hwpack": |
103 | + ret = self.create_symlink(target_dir_path) |
104 | + if ret != PASS: |
105 | + return ret |
106 | + |
107 | + if args.manifest: |
108 | + ret = self.create_manifest_file(target_dir_path) |
109 | + if ret != PASS: |
110 | + print "Failed to create manifest file" |
111 | + return ret |
112 | + |
113 | print "Moved the files from '",build_dir_path, "' to '",\ |
114 | target_dir_path, "'" |
115 | return PASS |
116 | @@ -113,9 +173,9 @@ |
117 | except OSError, details: |
118 | print "Failed to create the target path", target_dir_path, ":" , details |
119 | return FAIL |
120 | + |
121 | except shutil.Error: |
122 | print "Failed to move files destination path", target_dir_path |
123 | - print "Target already exists, move failed" |
124 | return FAIL |
125 | |
126 | def main(): |
127 | |
128 | === modified file 'testing/test_publish_to_snapshots.py' |
129 | --- testing/test_publish_to_snapshots.py 2012-03-16 10:55:32 +0000 |
130 | +++ testing/test_publish_to_snapshots.py 2012-03-26 10:49:17 +0000 |
131 | @@ -12,14 +12,16 @@ |
132 | class TestSnapshotsPublisher(TestCase): |
133 | '''Tests for publishing files to the snapshots.l.o www are.''' |
134 | |
135 | - uploads_path = "./uploads/" |
136 | - target_path = "./www/" |
137 | + uploads_path = "uploads/" |
138 | + target_path = "www/" |
139 | + orig_dir = os.getcwd() |
140 | |
141 | def setUp(self): |
142 | self.parser = argparse.ArgumentParser() |
143 | self.parser.add_argument("-t", "--job-type", dest="job_type") |
144 | self.parser.add_argument("-j", "--job-name", dest="job_name") |
145 | self.parser.add_argument("-n", "--build-num", dest="build_num", type=int) |
146 | + self.parser.add_argument("-m", "--manifest", dest="manifest", action='store_true') |
147 | if not os.path.isdir(self.uploads_path): |
148 | os.mkdir(self.uploads_path) |
149 | |
150 | @@ -28,6 +30,7 @@ |
151 | super(TestSnapshotsPublisher, self).setUp() |
152 | |
153 | def tearDown(self): |
154 | + os.chdir(self.orig_dir) |
155 | if os.path.isdir(self.uploads_path): |
156 | shutil.rmtree(self.uploads_path) |
157 | |
158 | @@ -112,9 +115,9 @@ |
159 | '-n', '1']) |
160 | |
161 | self.publisher.validate_args(param) |
162 | - self.uploads_path = "./dummy_uploads_path" |
163 | + uploads_path = "./dummy_uploads_path" |
164 | try: |
165 | - self.publisher.validate_paths(param, self.uploads_path, self.target_path) |
166 | + self.publisher.validate_paths(param, uploads_path, self.target_path) |
167 | finally: |
168 | sys.stdout = orig_stdout |
169 | stdout.seek(0) |
170 | @@ -150,6 +153,8 @@ |
171 | try: |
172 | uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, |
173 | self.uploads_path, self.target_path) |
174 | + uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) |
175 | + target_dir_path = os.path.join(self.orig_dir, target_dir_path) |
176 | self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) |
177 | finally: |
178 | sys.stdout = orig_stdout |
179 | @@ -172,6 +177,8 @@ |
180 | try: |
181 | uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, |
182 | self.uploads_path, self.target_path) |
183 | + uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) |
184 | + target_dir_path = os.path.join(self.orig_dir, target_dir_path) |
185 | self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) |
186 | finally: |
187 | sys.stdout = orig_stdout |
188 | @@ -179,3 +186,73 @@ |
189 | |
190 | stdout.seek(0) |
191 | self.assertIn("Moved the files from", stdout.read()) |
192 | + |
193 | + def test_create_symlink(self): |
194 | + orig_stdout = sys.stdout |
195 | + stdout = sys.stdout = StringIO() |
196 | + self.publisher = SnapshotsPublisher() |
197 | + param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', |
198 | + '-n', '1']) |
199 | + self.publisher.validate_args(param) |
200 | + build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) |
201 | + build_path = os.path.join(self.uploads_path, build_dir) |
202 | + os.makedirs(build_path) |
203 | + tempfiles = tempfile.mkstemp(dir=build_path) |
204 | + try: |
205 | + uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, |
206 | + self.uploads_path, self.target_path) |
207 | + uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) |
208 | + target_dir_path = os.path.join(self.orig_dir, target_dir_path) |
209 | + self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) |
210 | + finally: |
211 | + sys.stdout = orig_stdout |
212 | + pass |
213 | + |
214 | + stdout.seek(0) |
215 | + msg = "The lastSuccessful build is now linked to " + target_dir_path |
216 | + self.assertIn(msg, stdout.read()) |
217 | + |
218 | + def test_create_manifest_file_option(self): |
219 | + orig_stdout = sys.stdout |
220 | + stdout = sys.stdout = StringIO() |
221 | + self.publisher = SnapshotsPublisher() |
222 | + param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', |
223 | + '-n', '1', '-m']) |
224 | + self.publisher.validate_args(param) |
225 | + build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) |
226 | + build_path = os.path.join(self.uploads_path, build_dir) |
227 | + os.makedirs(build_path) |
228 | + tempfiles = tempfile.mkstemp(dir=build_path) |
229 | + lines = [] |
230 | + try: |
231 | + uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, |
232 | + self.uploads_path, self.target_path) |
233 | + uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) |
234 | + target_dir_path = os.path.join(self.orig_dir, target_dir_path) |
235 | + os.chdir(uploads_dir_path) |
236 | + for path, subdirs, files in os.walk("."): |
237 | + for name in files: |
238 | + lines.append(os.path.join(path, name).split("./")[1] + "\n") |
239 | + os.chdir(self.orig_dir) |
240 | + self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) |
241 | + |
242 | + manifest_file=os.path.join(target_dir_path, "MANIFEST") |
243 | + dest = open(manifest_file, "r").read() |
244 | + |
245 | + if len(lines) != 0: |
246 | + tempfiles = tempfile.mkstemp(dir=target_dir_path) |
247 | + fd = open(tempfiles[1], "w+") |
248 | + for line in lines: |
249 | + fd.write(line) |
250 | + fd.close() |
251 | + orig = open(tempfiles[1], "r").read() |
252 | + |
253 | + except Exception, details: |
254 | + pass |
255 | + |
256 | + finally: |
257 | + sys.stdout = orig_stdout |
258 | + |
259 | + stdout.seek(0) |
260 | + self.assertIn("Moved the files from", stdout.read()) |
261 | + self.assertTrue(orig == dest) |
symlink creation logic is not exactly correct. It should not scan for "latest" dir, it should use current build it was passed as such, it obviously the latest in time, and that's what we want to be linked.