Merge lp:~deeptik/linaro-license-protection/publish-to-snapshot into lp:~linaro-automation/linaro-license-protection/trunk

Proposed by Deepti B. Kalakeri
Status: Merged
Merged at revision: 47
Proposed branch: lp:~deeptik/linaro-license-protection/publish-to-snapshot
Merge into: lp:~linaro-automation/linaro-license-protection/trunk
Diff against target: 354 lines (+330/-1)
3 files modified
scripts/publish_to_snapshots.py (+142/-0)
testing/__init__.py (+5/-1)
testing/test_publish_to_snapshots.py (+183/-0)
To merge this branch: bzr merge lp:~deeptik/linaro-license-protection/publish-to-snapshot
Reviewer Review Type Date Requested Status
Paul Sokolovsky Approve
Review via email: mp+96735@code.launchpad.net

Description of the change

Script to move the artifacts from tmp location to permanent location on s.l.o.
I have retained the example uploads and target dir in the script so that it would be easy for you to test the code.
Here is the ex: inputs you can use to verify the script

 1) For Android
 $mkdir -p /tmp/uploads/android/android_user/android_job/1 && cd /tmp/uploads/android/android_user/android_job/1 && touch one two three && cd -
 $scripts/publish_to_snapshots.py -j "android" -u "android_user" -i 1 -n "android_job"
 Moved the files from /tmp/uploads/android/android_user/android_job/1 to /tmp/www/android/android_user/android_job/1
 Move succeeded

 2) For kernel-hwpack
 $ mkdir -p /tmp/uploads/kernel-hwpack/kernel_tree/kernel_tree_job && cd /tmp/uploads/kernel-hwpack/kernel_tree/kernel_tree_job && touch one two three && cd -
 $ scripts/publish_to_snapshots.py -j "kernel-hwpack" -u "android" -i 1 -n "kernel_tree_job" -t "kernel_tree"
 Moved the files from /tmp/uploads/kernel-hwpack/kernel_tree/kernel_tree_job to /tmp/www/kernel-hwpack/kernel_tree/kernel_tree_job
 Move succeeded

To post a comment you must log in.
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

One immediate comment is inconsistent format of the long options, like "--job_type". It's GNU (originators of long options) convention that long options use dashes as separators. It's of course also looks better and easier to remember. We had/have the same issue with l-m-c: there was non-compliant options, then there was a patch to fix it, then it turned out it breaks existing scripts which pass those options, then the fix had to be reverted or something, etc. So, we should do it rightly from the start.

review: Needs Fixing
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

" help="Specifiy the job type (Ex: android/kernel-hwpack)"

Typo in "specify". Also, would suggest to rewrite to avoid possible confusion, e.g.:
"Specify the job type (Values: android, kernel-hwpack)"

review: Needs Fixing
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

9
parser.add_argument("-a", "--archive_info", dest="archive_info",
10
                    help="Specify the job which resulted the archive to be stored.\
11
                         Ex: ${JOB_NAME}/${BUILD_NUMBER} should be specified for \
12
                             andriod and for \
13
                             kernel-hwpack ${KERNEL_NAME}/${KERNEL_JOB_NAME}")

This seems like confusing option. Reading the help, I don't have an idea why it is called "archive_info". Nor reading help I have clear picture what and how it should be used/works - that's too much specifics, out of context. This script is supposed to be called from Jenkins, and Jenkins cab basically pass to it it job name (in its native format) and build number. That's what script should accept, and help for options should describe just that, any specifics like the fact that job name have internal structure based on --job-type should be left to manual IMHO.

review: Needs Fixing
46. By Georgy Redkozubov

[merge] New STE license text

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Also, short option assignment is not ideal IMHO. For "job type", main word is (t)ype. For "kernel tree" it's (k)ernel (or (r)epository if should be generalized), "build number" is apparently (n)umber, which leaves "job name" to (j)ob.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

60 + if args.job_type == "android":
61 + build_path = '/'.join([args.job_type, args.user_name, args.job_name])

Well, nope, that's not correct. There's no "user name" on Jenkins level, only job name. That's what this script accepts. It then can reformat native Jenkins name into "external" name which we want to see.

review: Needs Fixing
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

71 + if not (os.path.isdir(uploads_path) or os.path.isdir(build_dir_path)):
72 + print "Missing build path", build_dir_path
73 + return FAIL

The error message is incorrect - it checks 2 dirs, but reports problem as if applies to only one. Such cases are always great source of confusion and suffering (the latest one, (c) by Google: https://bugs.launchpad.net/bugs/949100)

review: Needs Fixing
Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

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_dirList = os.listdir(build_dir_path)

That sounds complicated and overinsuring. Can't we make requirement that upload dir and destination dir were on the same FS, so we can just use mv? Even if we can't, why wouldn't we trust shutil.copy2()? It either does the copy, or throws an exception, so we can't miss failed move.

Minor note - would be nice to use consistent var naming convention, like uploads_dir_list.

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

111 +def main():
112 + uploads_path = '/srv3/snapshots.linaro.org/uploads/'
113 + target_path = '/srv3/snapshots.linaro.org/www/'
114 + uploads_path = '/tmp/uploads/'
115 + target_path = '/tmp/www/'

IMHO, it would be better to treat these as the constants, not as the variables, to be defined in the beginning of the script (like they were before r50).

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

Thanks paul for comments. I will reply back on tuesday when am back to office.

Thanks!!!
Deepti

On 3/9/12, Paul Sokolovsky <email address hidden> wrote:
> 111 +def main():
> 112 + uploads_path = '/srv3/snapshots.linaro.org/uploads/'
> 113 + target_path = '/srv3/snapshots.linaro.org/www/'
> 114 + uploads_path = '/tmp/uploads/'
> 115 + target_path = '/tmp/www/'
>
> IMHO, it would be better to treat these as the constants, not as the
> variables, to be defined in the beginning of the script (like they were
> before r50).
>
> --
> https://code.launchpad.net/~deeptik/linaro-license-protection/publish-to-snapshot/+merge/96735
> You are the owner of
> lp:~deeptik/linaro-license-protection/publish-to-snapshot.
>

--
Sent from my mobile device

Thanks and Regards,
Deepti
Infrastructure Team Member, Linaro Platform Teams
Linaro.org | Open source software for ARM SoCs
Follow Linaro: http://www.facebook.com/pages/Linaro
http://twitter.com/#!/linaroorg - http://www.linaro.org/linaro-blog

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

> " help="Specifiy the job type (Ex: android/kernel-hwpack)"
>
> Typo in "specify". Also, would suggest to rewrite to avoid possible confusion,
> e.g.:
> "Specify the job type (Values: android, kernel-hwpack)"

oops! copy paste effect.. done.

Thanks!!!
Deepti.

Revision history for this message
Deepti B. Kalakeri (deeptik) wrote :
Download full text (4.1 KiB)

>
> 9
> parser.add_argument("-a", "--archive_info", dest="archive_info",
> 10
> help="Specify the job which resulted the archive to be
> stored.\
> 11
> Ex: ${JOB_NAME}/${BUILD_NUMBER} should be specified
> for \
> 12
> andriod and for \
> 13
> kernel-hwpack ${KERNEL_NAME}/${KERNEL_JOB_NAME}")
>
> This seems like confusing option. Reading the help, I don't have an idea why
> it is called "archive_info". Nor reading help I have clear picture what and
> how it should be used/works - that's too much specifics, out of context. This
> script is supposed to be called from Jenkins, and Jenkins cab basically pass
> to it it job name (in its native format) and build number. That's what script
> should accept, and help for options should describe just that, any specifics
> like the fact that job name have internal structure based on --job-type should
> be left to manual IMHO.

There is not archive_info anymore. This was an old change.

> Also, short option assignment is not ideal IMHO. For "job type", main word is
> (t)ype. For "kernel tree" it's (k)ernel (or (r)epository if should be
> generalized), "build number" is apparently (n)umber, which leaves "job name"
> to (j)ob.

Good suggestions. done.

> 60 + if args.job_type == "android":
> 61 + build_path = '/'.join([args.job_type, args.user_name,
> args.job_name])
>
> Well, nope, that's not correct. There's no "user name" on Jenkins level, only
> job name. That's what this script accepts. It then can reformat native Jenkins
> name into "external" name which we want to see.

Yes I agree that there is no username at jenkins level. But for android, I believe the jenkins-post-www.sh script line 38 refer to $TARGET_PATH/~$username/$jobname.
So I just tried to retain the extra work of separating the jobname into username + jobname.
Let me know if this is not required and what exactly did the username in the script meant to be.
I will make the changes accordingly.

> 71 + if not (os.path.isdir(uploads_path) or
> os.path.isdir(build_dir_path)):
> 72 + print "Missing build path", build_dir_path
> 73 + return FAIL
>
> The error message is incorrect - it checks 2 dirs, but reports problem as if
> applies to only one. Such cases are always great source of confusion and
> suffering (the latest one, (c) by Google:
> https://bugs.launchpad.net/bugs/949100)

I agree. Modified this to correct the error message.

> 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_dirList = os.listdir(build_dir_path)
>
> That sounds complicated and overinsuring. Can't we make requirement that
> upload dir and destination dir were on the same FS, so we can just use mv?
> Even if we can't, why wouldn't we trust shutil.copy2()? It either does the
> copy, or throws an exception, so we can't miss failed move.
>

I did consider using the mv action for this. shutil.move has the following issue:
1) The destination dir should be non-existent. so in case of kernel hwpacks we intend to store all the hwpack...

Read more...

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :
Download full text (6.1 KiB)

On Tue, 13 Mar 2012 09:55:27 -0000
"Deepti B. Kalakeri" <email address hidden> wrote:

> >
> > 9
> > parser.add_argument("-a", "--archive_info", dest="archive_info",
> > 10
> > help="Specify the job which resulted the
> > archive to be stored.\
> > 11
> > Ex: ${JOB_NAME}/${BUILD_NUMBER} should be
> > specified for \
> > 12
> > andriod and for \
> > 13
> > kernel-hwpack
> > ${KERNEL_NAME}/${KERNEL_JOB_NAME}")
> >
> > This seems like confusing option. Reading the help, I don't have an
> > idea why it is called "archive_info". Nor reading help I have clear
> > picture what and how it should be used/works - that's too much
> > specifics, out of context. This script is supposed to be called
> > from Jenkins, and Jenkins cab basically pass to it it job name (in
> > its native format) and build number. That's what script should
> > accept, and help for options should describe just that, any
> > specifics like the fact that job name have internal structure based
> > on --job-type should be left to manual IMHO.
>
> There is not archive_info anymore. This was an old change.
>
> > Also, short option assignment is not ideal IMHO. For "job type",
> > main word is (t)ype. For "kernel tree" it's (k)ernel (or
> > (r)epository if should be generalized), "build number" is
> > apparently (n)umber, which leaves "job name" to (j)ob.
>
> Good suggestions. done.
>
> > 60 + if args.job_type == "android":
> > 61 + build_path = '/'.join([args.job_type, args.user_name,
> > args.job_name])
> >
> > Well, nope, that's not correct. There's no "user name" on Jenkins
> > level, only job name. That's what this script accepts. It then can
> > reformat native Jenkins name into "external" name which we want to
> > see.
>
> Yes I agree that there is no username at jenkins level. But for
> android, I believe the jenkins-post-www.sh script line 38 refer to
> $TARGET_PATH/~$username/$jobname.

Yes, and those are parsed from Jenkin job name in line 32 and on:
http://bazaar.launchpad.net/~linaro-infrastructure/linaro-license-protection/trunk/view/head:/scripts/jenkins-post-www.sh#L32

> So I just tried to retain the extra
> work of separating the jobname into username + jobname. Let me know
> if this is not required and what exactly did the username in the
> script meant to be. I will make the changes accordingly.

So, the script should accept ${JOB_NAME} from Jenkins (we simply
don't have anything more specific on its level), but then it should be
ready to parse/convert that into job-type-specific target path (i.e.
this conversion will be different for different job-type). So, I would
suggest to add job_to_target_subdir(job_name, build_no) method to
encapsulate this conversion. For android case, it will be equivalent of
lines 32-38 in jenkins-post-www.sh .

>
> > 71 + if not (os.path.isdir(uploads_path) or
> > os.path.isdir(build_dir_path)):
> > 72 + print "Missing build path", build_dir_path
> > 73 + return FAIL
> >
> > The error message is incorrect - it checks 2 dirs, but reports
> > problem as if applies to only one. Such cases are alway...

Read more...

Revision history for this message
Paul Sokolovsky (pfalcon) wrote :

Ok, based on the further discussion on IRC, this should be good enough to proceed, further elaboration can be done separately.

review: Approve
47. By Deepti B. Kalakeri

Script to move the artifacts from tmp location to permanent location on s.l.o.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added file 'scripts/__init__.py'
=== added file 'scripts/publish_to_snapshots.py'
--- scripts/publish_to_snapshots.py 1970-01-01 00:00:00 +0000
+++ scripts/publish_to_snapshots.py 2012-03-14 08:03:18 +0000
@@ -0,0 +1,142 @@
1#!/usr/bin/env python
2# This script moves the artifacts from tmp location to a
3# to a permanent location on s.l.o
4
5import os
6import sys
7import shutil
8import argparse
9
10parser = argparse.ArgumentParser()
11parser.add_argument("-t", "--job-type", dest="job_type",
12 help="Specify the job type (Ex: android/kernel-hwpack)")
13parser.add_argument("-r", "--ktree", dest="kernel_tree",
14 help="Specify the kernel tree built by the job")
15parser.add_argument("-j", "--job-name", dest="job_name",
16 help="Specify the job name which resulted the archive to be stored.\
17 Ex: ${JOB_NAME} should be specified for andriod and for \
18 kernel-hwpack ${KERNEL_JOB_NAME}")
19parser.add_argument("-n", "--build-num", dest="build_num", type=int,
20 help="Specify the job build number for android builds only")
21
22uploads_path = '/srv3/snapshots.linaro.org/uploads/'
23target_path = '/srv3/snapshots.linaro.org/www/'
24PASS = 0
25FAIL = 1
26acceptable_job_types = [
27 'android',
28 'kernel-hwpack',
29 ]
30
31class SnapshotsPublisher(object):
32
33 def validate_args(self, args):
34 # Validate that all the required information
35 # is passed on the command line
36 if (args.job_type == None or args.job_name == None):
37 parser.error("\nYou must specify job-type and job-name")
38 return FAIL
39
40 if (args.job_type == "android" and args.build_num == None):
41 parser.error("You must specify build number")
42 return FAIL
43
44 if (args.job_type == "kernel-hwpack" and args.kernel_tree == None):
45 parser.error("You must specify kernel tree name built by the job")
46 return FAIL
47
48 if (args.job_type not in acceptable_job_types):
49 parser.error("Invalid job type")
50 return FAIL
51
52 def jobname_to_target_subdir(self, args, jobname):
53 ret_val = None
54 if args.job_type == "android":
55 ret_val = jobname.split("_")
56 return ret_val
57
58 def validate_paths(self, args, uploads_path, target_path):
59 build_dir_path = target_dir_path = None
60 if args.job_type == "android":
61 build_path = '/'.join([args.job_type, args.job_name,
62 str(args.build_num)])
63 build_dir_path = os.path.join(uploads_path, build_path)
64 ret_val = self.jobname_to_target_subdir(args, args.job_name)
65 if ret_val != None:
66 user_name = ret_val[0]
67 job_name = '_'.join(ret_val[1:])
68 target_dir = '/'.join([args.job_type, user_name, job_name,
69 str(args.build_num)])
70 target_dir_path = os.path.join(target_path, target_dir)
71 else:
72 return None, None
73 else:
74 build_path = '/'.join([args.job_type, args.kernel_tree, args.job_name])
75 build_dir_path = os.path.join(uploads_path, build_path)
76 target_dir_path = os.path.join(target_path, build_path)
77
78 if not (os.path.isdir(uploads_path) or os.path.isdir(build_dir_path)):
79 build_paths = "'%s' or '%s'" % (uploads_path, build_dir_path)
80 print "Missing build paths: ", build_paths
81 return None, None
82
83 if not os.path.isdir(target_path):
84 print "Missing target path", target_path
85 return None, None
86
87 return build_dir_path, target_dir_path
88
89
90 def move_artifacts(self, args, build_dir_path, target_dir_path):
91 try:
92 # Make a note of the contents of src dir so that
93 # it can be used to validate the move to destination
94 uploads_dir_list = os.listdir(build_dir_path)
95
96 if not os.path.isdir(target_dir_path):
97 os.makedirs(target_dir_path)
98 if not os.path.isdir(target_dir_path):
99 raise OSError
100
101 for fname in uploads_dir_list:
102 fname = os.path.join(build_dir_path, fname)
103 shutil.copy2(fname, target_dir_path)
104
105 target_dir_list = os.listdir(target_dir_path)
106 for fname in uploads_dir_list:
107 if not fname in target_dir_list:
108 print "Destination missing file", fname
109 return FAIL
110
111 shutil.rmtree(build_dir_path)
112 print "Moved the files from '",build_dir_path, "' to '",\
113 target_dir_path, "'"
114 return PASS
115
116 except OSError, details:
117 print "Failed to create the target path", target_dir_path, ":" , details
118 return FAIL
119 except shutil.Error:
120 print "Failed to move files destination path", target_dir_path
121 print "Target already exists, move failed"
122 return FAIL
123
124def main():
125 publisher = SnapshotsPublisher()
126 args = parser.parse_args()
127 publisher.validate_args(args)
128 build_dir_path, target_dir_path = publisher.validate_paths(args, uploads_path,
129 target_path)
130 if build_dir_path == None or target_dir_path == None:
131 print "Problem with build/target path, move failed"
132 return FAIL
133
134 ret = publisher.move_artifacts(args, build_dir_path, target_dir_path)
135 if ret != PASS:
136 print "Move Failed"
137 return FAIL
138 else:
139 print "Move succeeded"
140 return PASS
141if __name__ == '__main__':
142 sys.exit(main())
0143
=== modified file 'testing/__init__.py'
--- testing/__init__.py 2012-01-12 14:07:05 +0000
+++ testing/__init__.py 2012-03-14 08:03:18 +0000
@@ -1,9 +1,13 @@
1import os1import os
2import unittest2import unittest
33
4from testing.test_click_through_license import *
5from testing.test_publish_to_snapshots import *
6
4def test_suite():7def test_suite():
5 module_names = [8 module_names = [
6 'testing.test_click_through_license',9 'testing.test_click_through_license.TestLicense',
10 'testing.test_publish_to_snapshots.TestSnapshotsPublisher',
7 ]11 ]
8 loader = unittest.TestLoader()12 loader = unittest.TestLoader()
9 suite = loader.loadTestsFromNames(module_names)13 suite = loader.loadTestsFromNames(module_names)
1014
=== added file 'testing/test_publish_to_snapshots.py'
--- testing/test_publish_to_snapshots.py 1970-01-01 00:00:00 +0000
+++ testing/test_publish_to_snapshots.py 2012-03-14 08:03:18 +0000
@@ -0,0 +1,183 @@
1#!/usr/bin/env python
2
3import os
4import sys
5import shutil
6import tempfile
7import argparse
8from StringIO import StringIO
9from testtools import TestCase
10from scripts.publish_to_snapshots import SnapshotsPublisher
11
12class TestSnapshotsPublisher(TestCase):
13 '''Tests for publishing files to the snapshots.l.o www are.'''
14
15 uploads_path = "./uploads/"
16 target_path = "./www/"
17
18 def setUp(self):
19 self.parser = argparse.ArgumentParser()
20 self.parser.add_argument("-t", "--job-type", dest="job_type")
21 self.parser.add_argument("-r", "--ktree", dest="kernel_tree")
22 self.parser.add_argument("-j", "--job-name", dest="job_name")
23 self.parser.add_argument("-n", "--build-num", dest="build_num", type=int)
24 if not os.path.isdir(self.uploads_path):
25 os.mkdir(self.uploads_path)
26
27 if not os.path.isdir(self.target_path):
28 os.mkdir(self.target_path)
29 super(TestSnapshotsPublisher, self).setUp()
30
31 def tearDown(self):
32 if os.path.isdir(self.uploads_path):
33 shutil.rmtree(self.uploads_path)
34
35 if os.path.isdir(self.target_path):
36 shutil.rmtree(self.target_path)
37 super(TestSnapshotsPublisher, self).tearDown()
38
39 def test_validate_args_valid_job_values(self):
40 self.publisher = SnapshotsPublisher()
41 param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', '-n', '1'])
42 self.publisher.validate_args(param)
43 param = self.parser.parse_args(['-t', 'kernel-hwpack', '-r', 'dummy_tree',
44 '-j', 'dummy_job_name'])
45 self.publisher.validate_args(param)
46
47 def test_validate_args_invalid_job_type(self):
48 orig_stderr = sys.stderr
49 stderr = sys.stderr = StringIO()
50 self.publisher = SnapshotsPublisher()
51 param = self.parser.parse_args(['-t', 'invalid_job_type', '-j', 'dummy_job_name',
52 '-n', '1'])
53 try:
54 self.publisher.validate_args(param)
55 except SystemExit, err:
56 self.assertEqual(err.code, 2, "Expected result")
57 finally:
58 sys.stderr = orig_stderr
59 stderr.seek(0)
60 self.assertIn("Invalid job type", stderr.read())
61
62
63 def test_validate_args_run_invalid_argument(self):
64 orig_stderr = sys.stderr
65 stderr = sys.stderr = StringIO()
66 self.publisher = SnapshotsPublisher()
67 try:
68 param = self.parser.parse_args(['-a'])
69 self.publisher.validate_args(param)
70 except SystemExit, err:
71 self.assertEqual(err.code, 2, "Invalid argument passed")
72 finally:
73 sys.stderr = orig_stderr
74 stderr.seek(0)
75 self.assertIn("unrecognized arguments: -a\n", stderr.read())
76
77 def test_validate_args_run_invalid_value(self):
78 orig_stderr = sys.stderr
79 stderr = sys.stderr = StringIO()
80 self.publisher = SnapshotsPublisher()
81 try:
82 param = self.parser.parse_args(['-n', "N"])
83 self.publisher.validate_args(param)
84 except SystemExit, err:
85 self.assertEqual(err.code, 2, "Invalid value passed")
86 finally:
87 sys.stderr = orig_stderr
88 stderr.seek(0)
89 self.assertIn("argument -n/--build-num: invalid int value: 'N'",
90 stderr.read())
91
92 def test_validate_args_run_none_values(self):
93 orig_stderr = sys.stderr
94 stderr = sys.stderr = StringIO()
95 self.publisher = SnapshotsPublisher()
96 try:
97 param = self.parser.parse_args(['-t', None , '-r', None,
98 '-j', None , '-n' , 0])
99 self.publisher.validate_args(param)
100 except SystemExit, err:
101 self.assertEqual(err.code, 2, "None values are not acceptable")
102 finally:
103 sys.stderr = orig_stderr
104 stderr.seek(0)
105 self.assertIn("You must specify job-type and job-name",
106 stderr.read())
107
108 def test_validate_paths_invalid_uploads_path(self):
109 orig_stdout = sys.stdout
110 stdout = sys.stdout = StringIO()
111 self.publisher = SnapshotsPublisher()
112 param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name',
113 '-n', '1'])
114
115 self.publisher.validate_args(param)
116 self.uploads_path = "./dummy_uploads_path"
117 try:
118 self.publisher.validate_paths(param, self.uploads_path, self.target_path)
119 finally:
120 sys.stdout = orig_stdout
121 stdout.seek(0)
122 self.assertIn("Missing build path", stdout.read())
123
124 def test_validate_paths_invalid_target_path(self):
125 orig_stdout = sys.stdout
126 stdout = sys.stdout = StringIO()
127 self.publisher = SnapshotsPublisher()
128 param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name',
129 '-n', '1'])
130
131 self.publisher.validate_args(param)
132 self.target_path = "./dummy_target_path"
133 try:
134 self.publisher.validate_paths(param, self.uploads_path,
135 self.target_path)
136 finally:
137 sys.stdout = orig_stdout
138 stdout.seek(0)
139 self.assertIn("Missing target path", stdout.read())
140
141 def test_move_artifacts_kernel_successful_move(self):
142 orig_stdout = sys.stdout
143 stdout = sys.stdout = StringIO()
144 self.publisher = SnapshotsPublisher()
145 param = self.parser.parse_args(['-t', 'kernel-hwpack', '-j', 'dummy_job_name',
146 '-r', 'dummy_kernel_tree'])
147 self.publisher.validate_args(param)
148 build_path = os.path.join(self.uploads_path, param.job_type, param.kernel_tree,
149 param.job_name)
150 os.makedirs(build_path)
151 tempfiles = tempfile.mkstemp(dir=build_path)
152 try:
153 uploads_dir_path, target_dir_path = self.publisher.validate_paths(param,
154 self.uploads_path, self.target_path)
155 self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path)
156 finally:
157 sys.stdout = orig_stdout
158 pass
159
160 stdout.seek(0)
161 self.assertIn("Moved the files from", stdout.read())
162
163 def test_move_artifacts_android_successful_move(self):
164 orig_stdout = sys.stdout
165 stdout = sys.stdout = StringIO()
166 self.publisher = SnapshotsPublisher()
167 param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name',
168 '-n', '1'])
169 self.publisher.validate_args(param)
170 build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)])
171 build_path = os.path.join(self.uploads_path, build_dir)
172 os.makedirs(build_path)
173 tempfiles = tempfile.mkstemp(dir=build_path)
174 try:
175 uploads_dir_path, target_dir_path = self.publisher.validate_paths(param,
176 self.uploads_path, self.target_path)
177 self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path)
178 finally:
179 sys.stdout = orig_stdout
180 pass
181
182 stdout.seek(0)
183 self.assertIn("Moved the files from", stdout.read())

Subscribers

People subscribed via source and target branches