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
=== modified file 'scripts/publish_to_snapshots.py'
--- scripts/publish_to_snapshots.py 2012-08-28 20:29:05 +0000
+++ scripts/publish_to_snapshots.py 2012-09-04 06:15:22 +0000
@@ -87,15 +87,16 @@
87 def sanitize_file(cls, file_path):87 def sanitize_file(cls, file_path):
88 """This truncates the file and fills it with its own filename."""88 """This truncates the file and fills it with its own filename."""
89 assert not cls.is_accepted_for_staging(file_path)89 assert not cls.is_accepted_for_staging(file_path)
90 base_file_name = os.path.basename(file_path)90 if not os.path.isdir(file_path):
91 protected_file = open(file_path, "w")91 base_file_name = os.path.basename(file_path)
92 # Nice property of this is that we are also saving on disk space92 protected_file = open(file_path, "w")
93 # needed.93 # Nice property of this is that we are also saving on disk space
94 protected_file.truncate()94 # needed.
95 # To help distinguish files more easily when they are downloaded,95 protected_file.truncate()
96 # we write out the base file name as the contents.96 # To help distinguish files more easily when they are downloaded,
97 protected_file.write(base_file_name)97 # we write out the base file name as the contents.
98 protected_file.close()98 protected_file.write(base_file_name)
99 protected_file.close()
99100
100 def validate_args(self, args):101 def validate_args(self, args):
101 # Validate that all the required information102 # Validate that all the required information
@@ -263,21 +264,22 @@
263 for file in filelist:264 for file in filelist:
264 src = os.path.join(src_dir, file)265 src = os.path.join(src_dir, file)
265 dest = os.path.join(dest_dir, file)266 dest = os.path.join(dest_dir, file)
267 if os.path.isdir(src):
268 if not os.path.exists(dest):
269 os.makedirs(dest)
270 self.move_dir_content(src, dest, sanitize)
271 continue
266 if os.path.exists(dest):272 if os.path.exists(dest):
267 if os.path.isdir(dest):273 if os.path.isdir(dest):
268 continue274 continue
269 else:275 else:
270 os.remove(dest)276 os.remove(dest)
271 if os.path.isdir(src):277 if sanitize and not self.is_accepted_for_staging(src):
272 os.mkdir(dest)278 # Perform the sanitization before moving the file
273 self.move_dir_content(src, dest, sanitize)279 # into place.
274 else:280 print "Sanitizing contents of '%s'." % src
275 if sanitize and not self.is_accepted_for_staging(src):281 self.sanitize_file(src)
276 # Perform the sanitization before moving the file282 shutil.move(src, dest)
277 # into place.
278 print "Sanitizing contents of '%s'." % src
279 self.sanitize_file(src)
280 shutil.move(src, dest)
281 except shutil.Error:283 except shutil.Error:
282 print "Error while moving the content"284 print "Error while moving the content"
283285
284286
=== modified file 'tests/test_publish_to_snapshots.py'
--- tests/test_publish_to_snapshots.py 2012-08-22 19:42:28 +0000
+++ tests/test_publish_to_snapshots.py 2012-09-04 06:15:22 +0000
@@ -620,3 +620,78 @@
620 msg = "Manifest file " + manifest_file + " generated"620 msg = "Manifest file " + manifest_file + " generated"
621 self.assertIn(msg, res_output)621 self.assertIn(msg, res_output)
622 self.assertTrue(orig == dest)622 self.assertTrue(orig == dest)
623
624 def test_move_artifacts_with_subdirs_successful_move(self):
625 job_dir = 'precise/pre-built/lt-panda/2'
626 orig_stdout = sys.stdout
627 stdout = sys.stdout = StringIO()
628 self.publisher = SnapshotsPublisher()
629 param = self.parser.parse_args(
630 ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
631 '-n', '1'])
632 self.publisher.validate_args(param)
633 build_dir = '/'.join([param.job_name, str(param.build_num)])
634 build_path = os.path.join(self.uploads_path, build_dir)
635 os.makedirs(build_path)
636 new_subdirs = os.path.join(build_dir, job_dir)
637 new_subdirs_path = os.path.join(self.uploads_path, new_subdirs)
638 os.makedirs(new_subdirs_path)
639 artifact = self.make_temporary_file("Content", root=new_subdirs_path)
640 try:
641 uploads_dir_path, target_dir_path = self.publisher.validate_paths(
642 param, self.uploads_path, self.target_path)
643 uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path)
644 target_dir_path = os.path.join(self.orig_dir, target_dir_path)
645 subdirs = 'precise/pre-built/lt-panda/1'
646 subdirs_path = os.path.join(target_dir_path, subdirs)
647 os.makedirs(subdirs_path)
648 self.publisher.move_artifacts(param, uploads_dir_path,
649 target_dir_path)
650
651 moved_artifact = os.path.join(target_dir_path, job_dir,
652 os.path.basename(artifact))
653 print moved_artifact
654 self.assertEqual("Content", open(moved_artifact).read())
655 finally:
656 sys.stdout = orig_stdout
657 pass
658
659 stdout.seek(0)
660 self.assertIn("Moved the files from", stdout.read())
661
662 def test_move_artifacts_with_subdirs_sanitizing_successful_move(self):
663 job_dir = 'precise/pre-built/lt-panda/2'
664 orig_stdout = sys.stdout
665 stdout = sys.stdout = StringIO()
666 self.publisher = SnapshotsPublisher()
667 param = self.parser.parse_args(
668 ['-t', 'prebuilt', '-j', 'precise-armhf-ubuntu-desktop',
669 '-n', '1', '-s'])
670 self.publisher.validate_args(param)
671 build_dir = '/'.join([param.job_name, str(param.build_num)])
672 build_path = os.path.join(self.uploads_path, build_dir)
673 os.makedirs(build_path)
674 new_subdirs = os.path.join(build_dir, job_dir)
675 new_subdirs_path = os.path.join(self.uploads_path, new_subdirs)
676 os.makedirs(new_subdirs_path)
677 artifact = self.make_temporary_file("Content", root=new_subdirs_path)
678 try:
679 uploads_dir_path, target_dir_path = self.publisher.validate_paths(
680 param, self.uploads_path, self.target_path)
681 uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path)
682 target_dir_path = os.path.join(self.orig_dir, target_dir_path)
683 subdirs = 'precise/pre-built/lt-panda/1'
684 subdirs_path = os.path.join(target_dir_path, subdirs)
685 os.makedirs(subdirs_path)
686 self.publisher.move_artifacts(param, uploads_dir_path,
687 target_dir_path)
688
689 moved_artifact = os.path.join(target_dir_path, job_dir,
690 os.path.basename(artifact))
691 finally:
692 sys.stdout = orig_stdout
693 pass
694
695 stdout.seek(0)
696 self.assertEqual(os.path.basename(artifact), open(moved_artifact).read())
697 self.assertIn("Moved the files from", stdout.read())

Subscribers

People subscribed via source and target branches