Merge lp:~gesha/linaro-license-protection/fix-prebuilt-publishing into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Georgy Redkozubov
Status: Merged
Merged at revision: 127
Proposed branch: lp:~gesha/linaro-license-protection/fix-prebuilt-publishing
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 145 lines (+96/-19)
2 files modified
scripts/publish_to_snapshots.py (+21/-19)
tests/test_publish_to_snapshots.py (+75/-0)
To merge this branch: bzr merge lp:~gesha/linaro-license-protection/fix-prebuilt-publishing
Reviewer Review Type Date Requested Status
Deepti B. Kalakeri (community) Approve
Linaro Infrastructure Pending
Review via email: mp+122497@code.launchpad.net

Description of the change

This branch fixes handling of already existed dirs in dest.
Checking if source being sanitized is not a directory.

To post a comment you must log in.
Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Looks good. I would like you to please add some more tests with --staging for android/kernel-hwpack/prebuilt/images/hwpacks. I see there is only one test for 'binaries' type only.

review: Needs Fixing
128. By Georgy Redkozubov

Added tests for moving artifacts where destination subdirs exist.

Revision history for this message
Georgy Redkozubov (gesha) wrote :

> Looks good. I would like you to please add some more tests with --staging for
> android/kernel-hwpack/prebuilt/images/hwpacks. I see there is only one test
> for 'binaries' type only.

Actually we don't need tests for each type of job with --staging. We have params validation, single artifact moving test with and w/o --staging.
I've added tests for moving artifacts with subdirs in the path.

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :

Thanks for adding the test. Actually kernel-hwpack/android/prebuilt/images/hwpacks all of them have different way of storing the data. Hence it would have be good to test regressions in future.
Anyways for now this looks good.
+1.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'scripts/publish_to_snapshots.py'
2--- scripts/publish_to_snapshots.py 2012-08-28 20:29:05 +0000
3+++ scripts/publish_to_snapshots.py 2012-09-04 06:15:22 +0000
4@@ -87,15 +87,16 @@
5 def sanitize_file(cls, file_path):
6 """This truncates the file and fills it with its own filename."""
7 assert not cls.is_accepted_for_staging(file_path)
8- base_file_name = os.path.basename(file_path)
9- protected_file = open(file_path, "w")
10- # Nice property of this is that we are also saving on disk space
11- # needed.
12- protected_file.truncate()
13- # To help distinguish files more easily when they are downloaded,
14- # we write out the base file name as the contents.
15- protected_file.write(base_file_name)
16- protected_file.close()
17+ if not os.path.isdir(file_path):
18+ base_file_name = os.path.basename(file_path)
19+ protected_file = open(file_path, "w")
20+ # Nice property of this is that we are also saving on disk space
21+ # needed.
22+ protected_file.truncate()
23+ # To help distinguish files more easily when they are downloaded,
24+ # we write out the base file name as the contents.
25+ protected_file.write(base_file_name)
26+ protected_file.close()
27
28 def validate_args(self, args):
29 # Validate that all the required information
30@@ -263,21 +264,22 @@
31 for file in filelist:
32 src = os.path.join(src_dir, file)
33 dest = os.path.join(dest_dir, file)
34+ if os.path.isdir(src):
35+ if not os.path.exists(dest):
36+ os.makedirs(dest)
37+ self.move_dir_content(src, dest, sanitize)
38+ continue
39 if os.path.exists(dest):
40 if os.path.isdir(dest):
41 continue
42 else:
43 os.remove(dest)
44- if os.path.isdir(src):
45- os.mkdir(dest)
46- self.move_dir_content(src, dest, sanitize)
47- else:
48- if sanitize and not self.is_accepted_for_staging(src):
49- # Perform the sanitization before moving the file
50- # into place.
51- print "Sanitizing contents of '%s'." % src
52- self.sanitize_file(src)
53- shutil.move(src, dest)
54+ if sanitize and not self.is_accepted_for_staging(src):
55+ # Perform the sanitization before moving the file
56+ # into place.
57+ print "Sanitizing contents of '%s'." % src
58+ self.sanitize_file(src)
59+ shutil.move(src, dest)
60 except shutil.Error:
61 print "Error while moving the content"
62
63
64=== modified file 'tests/test_publish_to_snapshots.py'
65--- tests/test_publish_to_snapshots.py 2012-08-22 19:42:28 +0000
66+++ tests/test_publish_to_snapshots.py 2012-09-04 06:15:22 +0000
67@@ -620,3 +620,78 @@
68 msg = "Manifest file " + manifest_file + " generated"
69 self.assertIn(msg, res_output)
70 self.assertTrue(orig == dest)
71+
72+ def test_move_artifacts_with_subdirs_successful_move(self):
73+ job_dir = 'precise/pre-built/lt-panda/2'
74+ orig_stdout = sys.stdout
75+ stdout = sys.stdout = StringIO()
76+ self.publisher = SnapshotsPublisher()
77+ param = self.parser.parse_args(
78+ ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
79+ '-n', '1'])
80+ self.publisher.validate_args(param)
81+ build_dir = '/'.join([param.job_name, str(param.build_num)])
82+ build_path = os.path.join(self.uploads_path, build_dir)
83+ os.makedirs(build_path)
84+ new_subdirs = os.path.join(build_dir, job_dir)
85+ new_subdirs_path = os.path.join(self.uploads_path, new_subdirs)
86+ os.makedirs(new_subdirs_path)
87+ artifact = self.make_temporary_file("Content", root=new_subdirs_path)
88+ try:
89+ uploads_dir_path, target_dir_path = self.publisher.validate_paths(
90+ param, self.uploads_path, self.target_path)
91+ uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path)
92+ target_dir_path = os.path.join(self.orig_dir, target_dir_path)
93+ subdirs = 'precise/pre-built/lt-panda/1'
94+ subdirs_path = os.path.join(target_dir_path, subdirs)
95+ os.makedirs(subdirs_path)
96+ self.publisher.move_artifacts(param, uploads_dir_path,
97+ target_dir_path)
98+
99+ moved_artifact = os.path.join(target_dir_path, job_dir,
100+ os.path.basename(artifact))
101+ print moved_artifact
102+ self.assertEqual("Content", open(moved_artifact).read())
103+ finally:
104+ sys.stdout = orig_stdout
105+ pass
106+
107+ stdout.seek(0)
108+ self.assertIn("Moved the files from", stdout.read())
109+
110+ def test_move_artifacts_with_subdirs_sanitizing_successful_move(self):
111+ job_dir = 'precise/pre-built/lt-panda/2'
112+ orig_stdout = sys.stdout
113+ stdout = sys.stdout = StringIO()
114+ self.publisher = SnapshotsPublisher()
115+ param = self.parser.parse_args(
116+ ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
117+ '-n', '1', '-s'])
118+ self.publisher.validate_args(param)
119+ build_dir = '/'.join([param.job_name, str(param.build_num)])
120+ build_path = os.path.join(self.uploads_path, build_dir)
121+ os.makedirs(build_path)
122+ new_subdirs = os.path.join(build_dir, job_dir)
123+ new_subdirs_path = os.path.join(self.uploads_path, new_subdirs)
124+ os.makedirs(new_subdirs_path)
125+ artifact = self.make_temporary_file("Content", root=new_subdirs_path)
126+ try:
127+ uploads_dir_path, target_dir_path = self.publisher.validate_paths(
128+ param, self.uploads_path, self.target_path)
129+ uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path)
130+ target_dir_path = os.path.join(self.orig_dir, target_dir_path)
131+ subdirs = 'precise/pre-built/lt-panda/1'
132+ subdirs_path = os.path.join(target_dir_path, subdirs)
133+ os.makedirs(subdirs_path)
134+ self.publisher.move_artifacts(param, uploads_dir_path,
135+ target_dir_path)
136+
137+ moved_artifact = os.path.join(target_dir_path, job_dir,
138+ os.path.basename(artifact))
139+ finally:
140+ sys.stdout = orig_stdout
141+ pass
142+
143+ stdout.seek(0)
144+ self.assertEqual(os.path.basename(artifact), open(moved_artifact).read())
145+ self.assertIn("Moved the files from", stdout.read())

Subscribers

People subscribed via source and target branches