diff options
author | Danilo Šegan <danilo@segan.org> | 2012-05-18 12:31:47 +0200 |
---|---|---|
committer | Danilo Šegan <danilo@segan.org> | 2012-05-18 12:31:47 +0200 |
commit | 55904b51e3a968b53974c1ed3a8b7bdaf11db433 (patch) | |
tree | f20262d9aa97051141cd2a00c6e004d3bcb7d08c | |
parent | 730b0526529e46dbffa4ae53232a37dc44ee2e61 (diff) | |
parent | f77636f3d7bfdc8d15d35fd99332ca007a49c9f4 (diff) |
Clean up the Python code to adhere to PEP-8, do a few changes to the code structure.
-rw-r--r-- | .bzrignore | 1 | ||||
-rw-r--r-- | .testr.conf | 2 | ||||
-rw-r--r-- | README | 65 | ||||
-rwxr-xr-x | scripts/do_if_old.py | 2 | ||||
-rwxr-xr-x | scripts/publish_to_snapshots.py | 108 | ||||
-rw-r--r-- | testing/__init__.py | 16 | ||||
-rw-r--r-- | testplans/releases.txt | 2 | ||||
-rw-r--r-- | testplans/snapshots.txt | 2 | ||||
-rw-r--r-- | tests/LicenseHelperTest.php (renamed from testing/LicenseHelperTest.php) | 0 | ||||
-rw-r--r-- | tests/__init__.py | 12 | ||||
-rw-r--r-- | tests/apache2.conf.tmpl (renamed from testing/apache2.conf.tmpl) | 0 | ||||
-rw-r--r-- | tests/doctest_production_browser.py (renamed from testing/doctest_production_browser.py) | 0 | ||||
-rw-r--r-- | tests/license_protected_file_downloader.py (renamed from testing/license_protected_file_downloader.py) | 0 | ||||
-rw-r--r-- | tests/mime.types (renamed from testing/mime.types) | 0 | ||||
-rw-r--r-- | tests/test_click_through_license.py (renamed from testing/test_click_through_license.py) | 17 | ||||
-rw-r--r-- | tests/test_php_unit.py (renamed from testing/test_php_unit.py) | 5 | ||||
-rw-r--r-- | tests/test_publish_to_snapshots.py (renamed from testing/test_publish_to_snapshots.py) | 228 |
17 files changed, 262 insertions, 198 deletions
diff --git a/.bzrignore b/.bzrignore new file mode 100644 index 0000000..a9b310f --- /dev/null +++ b/.bzrignore @@ -0,0 +1 @@ +.testrepository diff --git a/.testr.conf b/.testr.conf index 34a6148..6e60b1c 100644 --- a/.testr.conf +++ b/.testr.conf @@ -1,3 +1,3 @@ [DEFAULT] test_command=python -m subunit.run $IDLIST -test_id_list_default=testing.test_suite +test_id_list_default=tests.test_suite @@ -1,26 +1,47 @@ Linaro downloads license protection =================================== -Linaro builds sometimes contain "binary blobs"—pieces of binary-only code which enable extra features like accelerated graphics or multimedia. These pieces are distributed under a separate license, and downloading images or collections containing them requires some sort of license protection. +Linaro builds sometimes contain "binary blobs"—pieces of binary-only code +which enable extra features like accelerated graphics or multimedia. +These pieces are distributed under a separate license, and downloading +images or collections containing them requires some sort of license +protection. -This code provides such license protection on the hosting web server: other parts of infrastructure need to properly integrate with it (see eg. android-build.linaro.org section). At the moment, it's implemented as a click-through license acceptance on the Apache side. +This code provides such license protection on the hosting web server: +other parts of infrastructure need to properly integrate with it (see +eg. android-build.linaro.org section). At the moment, it's implemented as +a click-through license acceptance on the Apache side. -To ensure and prove this keeps working, we are also using automated tests with this code. +To ensure and prove this keeps working, we are also using automated tests +with this code. Setup ----- -This tree is the base for snapshots.linaro.org and releases.linaro.org www roots as served by Apache. It makes heavy use of mod_rewrite from within the .htaccess file. +This tree is the base for snapshots.linaro.org and releases.linaro.org www +roots as served by Apache. It makes heavy use of mod_rewrite from within +the .htaccess file. -Currently, all directories/files containing either 'origen' or 'snowball' in the URL path are protected with appropriate license (Samsung or ST-E) click-through. +Currently, all directories/files containing either 'origen' or 'snowball' +in the URL path are protected with appropriate license (Samsung or ST-E) +click-through. Dependencies ............ libapache2-mod-php5 -Testing: phpunit, testrepository, python-html2text +Testing: + phpunit, python 2.7, testrepository (>=0.0.6), python-html2text, + python-subunit, python-beautifulsoup + +Recent (as of 2012-05-08) Ubuntu/Debian releases have a broken phpunit +package and thus require installation of phpunit through PEAR: + + $ sudo apt-get install php-pear + $ sudo pear config-set auto_discover 1 + $ sudo pear install pear.phpunit.de/PHPUnit Technical details @@ -32,7 +53,9 @@ releases.linaro.org Root directory for releases.linaro.org includes .htaccess and licenses/*. It has mod_rewrite enabled. -It allows a few hard-coded hosts to bypass the click-through protection, by their IPs: +It allows a few hard-coded hosts to bypass the click-through protection, +by their IPs: + * android-build.linaro.org (50.17.250.69) * validation.linaro.org (213.123.120.124) @@ -57,7 +80,8 @@ www area directly, we set-up two different users on the system with SSH keys: limited to executing only a single command through /etc/ssh/user-authorized-keys/android-build-linaro-trigger - command="/home/android-build-linaro-trigger/scripts/trigger-android-build-linaro.sh ${SSH_ORIGINAL_COMMAND#* }" + command="/home/android-build-linaro-trigger/scripts + /trigger-android-build-linaro.sh ${SSH_ORIGINAL_COMMAND#* }" (this passes the arguments received from the remote end as well) @@ -72,7 +96,8 @@ www area directly, we set-up two different users on the system with SSH keys: android-build.linaro.org ........................ -Runs Jenkins and uses SFTP plugin to access the above two users. Private keys live in +Runs Jenkins and uses SFTP plugin to access the above two users. Private +keys live in /home/ubuntu/snapshots-sync/snapshots-sync — android-build-linaro /home/ubuntu/snapshots-sync/snapshots-filemove — android-build-linaro-trigger @@ -90,24 +115,24 @@ Python and Apache2: $ testr init $ testr run -To run the production test plans (NOTE: They will take a bit more time to run) -execute the following: +Test plans +.......... + +To run the test plans from testplans/ subdirectory against +snapshots.linaro.org and releases.linaro.org, execute the following: $ testr init $ testr run testplans.test_suite +These tests require an internet connection. Tests for PHP license-matching logic .................................... -There's currently only one unit test file, LicenseHelperTest.php under testing directory. You first need to install the phpunit package from ubuntu repos: - $ sudo apt-get install php-unit - +Unit tests for the license-matching logic written in PHP are automatically +ran as part of the full test suite (testr run). However, for a more +detailed output, you may need to run phpunit directly. -Recent (as of 2012-05-08) Ubuntu/Debian releases have a broken phpunit package and thus require installation in a different manner: - $ sudo apt-get install php-pear - $ sudo pear config-set auto_discover 1 - $ sudo pear install pear.phpunit.de/PHPUnit +To run the tests separately, do the following: -PHPUnit tests execution is already included in the python integration tests, but if you wish to run unit tests separately, do the following: - $ phpunit testing/LicenseHelperTest + $ phpunit tests/LicenseHelperTest diff --git a/scripts/do_if_old.py b/scripts/do_if_old.py index 4cdb012..b8952f7 100755 --- a/scripts/do_if_old.py +++ b/scripts/do_if_old.py @@ -5,6 +5,7 @@ import re import time import sys + def search_and_run(root_dir, command, trigger_age_string): """Run command on old directories @@ -44,6 +45,7 @@ def search_and_run(root_dir, command, trigger_age_string): if (time.time() - mod_time) > trigger_age_seconds: os.system(command + " " + path) + if __name__ == '__main__': """Run command on directories that are older than trigger-age.""" diff --git a/scripts/publish_to_snapshots.py b/scripts/publish_to_snapshots.py index 8522988..404fd9b 100755 --- a/scripts/publish_to_snapshots.py +++ b/scripts/publish_to_snapshots.py @@ -9,20 +9,22 @@ import argparse parser = argparse.ArgumentParser() parser.add_argument("-t", "--job-type", dest="job_type", help="Specify the job type (Ex: android/kernel-hwpack)") -parser.add_argument("-j", "--job-name", dest="job_name", - help="Specify the job name which resulted the archive to "\ - "be stored. Ex: ${JOB_NAME} should be specified for "\ - "android/ubuntu-{hwpacks,images,sysroots}/binaries and for"\ - "kernel-hwpack ${KERNEL_JOB_NAME}") -parser.add_argument("-n", "--build-num", dest="build_num", type=int, - help="Specify the job build number for android/"\ - "ubuntu-{hwpacks,images,sysroots}/binaries") +parser.add_argument( + "-j", "--job-name", dest="job_name", + help=("Specify the job name which resulted the archive to " + "be stored. Ex: ${JOB_NAME} should be specified for " + "android/ubuntu-{hwpacks,images,sysroots}/binaries and for" + "kernel-hwpack ${KERNEL_JOB_NAME}")) +parser.add_argument( + "-n", "--build-num", dest="build_num", type=int, + help=("Specify the job build number for android/" + "ubuntu-{hwpacks,images,sysroots}/binaries")) parser.add_argument("-m", "--manifest", dest="manifest", action='store_true', help="Optional parameter to generate MANIFEST file") uploads_path = '/srv/snapshots.linaro.org/uploads/' target_path = '/srv/snapshots.linaro.org/www/' -PASS = 0 +PASS = 0 FAIL = 1 acceptable_job_types = [ 'android', @@ -35,14 +37,16 @@ acceptable_job_types = [ 'binaries' ] + class SnapshotsPublisher(object): def validate_args(self, args): - # Validate that all the required information + # Validate that all the required information # is passed on the command line - if (args.job_type == None or args.job_name == None or \ - args.build_num == None): - parser.error("\nYou must specify job-type, job-name and build-num") + if (args.job_type == None or args.job_name == None or + args.build_num == None): + parser.error( + "\nYou must specify job-type, job-name and build-num") return FAIL if (args.job_type not in acceptable_job_types): @@ -52,16 +56,17 @@ class SnapshotsPublisher(object): def jobname_to_target_subdir(self, args, jobname): ret_val = None if args.job_type == "android": - ret_val = jobname.split("_") + ret_val = jobname.split("_") elif args.job_type == "kernel-hwpack": ret_val = jobname.split('_')[0].replace(".", "_") - elif args.job_type == "ubuntu-hwpacks" or \ - args.job_type == "ubuntu-images" or\ - args.job_type == "ubuntu-restricted" or\ - args.job_type == "ubuntu-sysroots": + elif (args.job_type == "ubuntu-hwpacks" or + args.job_type == "ubuntu-images" or + args.job_type == "ubuntu-restricted" or + args.job_type == "ubuntu-sysroots"): ret_val = jobname.split('-', 2) elif args.job_type == "prebuilt": - ret_val = '' #just need non-null since its isn't needed + # Return value must not be None when we want to ignore it. + ret_val = '' elif args.job_type == "binaries": ret_val = jobname.split('-', 2) return ret_val @@ -73,31 +78,32 @@ class SnapshotsPublisher(object): if args.job_type == "android": build_path = '/'.join([args.job_type, args.job_name, str(args.build_num)]) - build_dir_path = os.path.join(uploads_path, build_path) + build_dir_path = os.path.join(uploads_path, build_path) user_name = ret_val[0] job_name = '_'.join(ret_val[1:]) - target_dir = '/'.join([args.job_type, "~%s" % user_name, + target_dir = '/'.join([args.job_type, "~%s" % user_name, job_name, str(args.build_num)]) target_dir_path = os.path.join(target_path, target_dir) elif args.job_type == "kernel-hwpack": kernel_tree = ret_val - build_path = '/'.join([args.job_type, args.job_name, + build_path = '/'.join([args.job_type, args.job_name, str(args.build_num)]) build_dir_path = os.path.join(uploads_path, build_path) - target_dir = '/'.join([args.job_type, kernel_tree, + target_dir = '/'.join([args.job_type, kernel_tree, args.job_name]) target_dir_path = os.path.join(target_path, target_dir) - elif args.job_type == "ubuntu-hwpacks" or \ - args.job_type == "ubuntu-images" or\ - args.job_type == "ubuntu-restricted" or\ - args.job_type == "ubuntu-sysroots": + elif (args.job_type == "ubuntu-hwpacks" or + args.job_type == "ubuntu-images" or + args.job_type == "ubuntu-restricted" or + args.job_type == "ubuntu-sysroots"): dist_name = ret_val[0] hwpack_image = args.job_type.split("-")[1] board_rootfs_name = ret_val[2] - build_dir_path = os.path.join(uploads_path, args.job_name, + build_dir_path = os.path.join(uploads_path, args.job_name, str(args.build_num)) - target_dir = '/'.join([dist_name, hwpack_image, - board_rootfs_name, str(args.build_num)]) + target_dir = '/'.join( + [dist_name, hwpack_image, board_rootfs_name, + str(args.build_num)]) target_dir_path = os.path.join(target_path, target_dir) elif args.job_type == "prebuilt": build_path = '%s/%d' % (args.job_name, args.build_num) @@ -113,11 +119,9 @@ class SnapshotsPublisher(object): timestamp = f.read().strip() f.close() os.remove(ts_file) - target_dir_path = os.path.join(target_path, - 'android', - args.job_type, - ret_val[0], - timestamp) + target_dir_path = os.path.join( + target_path, 'android', args.job_type, ret_val[0], + timestamp) else: return None, None @@ -157,7 +161,7 @@ class SnapshotsPublisher(object): return FAIL def create_manifest_file(self, target_dir): - orig_dir=os.getcwd() + orig_dir = os.getcwd() os.chdir(target_dir) fn = os.path.join(target_dir, "MANIFEST") lines = [] @@ -165,7 +169,8 @@ class SnapshotsPublisher(object): try: for path, subdirs, files in os.walk("."): for name in files: - lines.append(os.path.join(path, name).split("./")[1] + "\n") + lines.append( + os.path.join(path, name).split("./")[1] + "\n") if len(lines) != 0: fd = open(fn, "w+") @@ -174,7 +179,7 @@ class SnapshotsPublisher(object): fd.write(line) fd.close() else: - raise Exception("Uploads directory was empty, "\ + raise Exception("Uploads directory was empty, " "nothing got moved to destination") os.chdir(orig_dir) @@ -218,11 +223,11 @@ class SnapshotsPublisher(object): self.move_dir_content(build_dir_path, target_dir_path) - if args.job_type == "android" or\ - args.job_type == "ubuntu-hwpacks" or\ - args.job_type == "ubuntu-images" or\ - args.job_type == "ubuntu-restricted" or\ - args.job_type == "ubuntu-sysroots": + if (args.job_type == "android" or + args.job_type == "ubuntu-hwpacks" or + args.job_type == "ubuntu-images" or + args.job_type == "ubuntu-restricted" or + args.job_type == "ubuntu-sysroots"): ret = self.create_symlink(args, target_dir_path) if ret != PASS: return ret @@ -233,30 +238,33 @@ class SnapshotsPublisher(object): print "Failed to create manifest file" return ret - print "Moved the files from '",build_dir_path, "' to '",\ - target_dir_path, "'" + print ( + "Moved the files from '%s' to '%s'" % ( + build_dir_path, target_dir_path)) return PASS except OSError, details: - print "Failed to create the target path", target_dir_path, \ - ":", details + print ( + "Failed to create the target path %s: %s" % ( + target_dir_path, details)) return FAIL except shutil.Error: print "Failed to move files destination path", target_dir_path return FAIL + def main(): publisher = SnapshotsPublisher() args = parser.parse_args() publisher.validate_args(args) try: - build_dir_path, target_dir_path = publisher.validate_paths(args, uploads_path, - target_path) + build_dir_path, target_dir_path = publisher.validate_paths( + args, uploads_path, target_path) if build_dir_path == None or target_dir_path == None: print "Problem with build/target path, move failed" return FAIL - ret = publisher.move_artifacts(args, build_dir_path, target_dir_path) + ret = publisher.move_artifacts(args, build_dir_path, target_dir_path) if ret != PASS: print "Move Failed" return FAIL diff --git a/testing/__init__.py b/testing/__init__.py deleted file mode 100644 index ff8b7ce..0000000 --- a/testing/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -import os -import unittest - -from testing.test_click_through_license import * -from testing.test_publish_to_snapshots import * - - -def test_suite(): - module_names = [ - 'testing.test_click_through_license.TestLicense', - 'testing.test_publish_to_snapshots.TestSnapshotsPublisher', - 'testing.test_php_unit.PhpUnitTest', - ] - loader = unittest.TestLoader() - suite = loader.loadTestsFromNames(module_names) - return suite diff --git a/testplans/releases.txt b/testplans/releases.txt index c1db01f..5ca3de9 100644 --- a/testplans/releases.txt +++ b/testplans/releases.txt @@ -6,7 +6,7 @@ Navigate to the regular ST-E license-protected file and initiate download Import class we will use for this test and init browser object. - >>> from testing.doctest_production_browser import DoctestProductionBrowser + >>> from tests.doctest_production_browser import DoctestProductionBrowser >>> browser = DoctestProductionBrowser("http://releases.linaro.org/") Visiting homepage and check for title. diff --git a/testplans/snapshots.txt b/testplans/snapshots.txt index 12495f3..719790b 100644 --- a/testplans/snapshots.txt +++ b/testplans/snapshots.txt @@ -6,7 +6,7 @@ Navigate to the regular ST-E license-protected file and initiate download Import class we will use for this test and init browser object. - >>> from testing.doctest_production_browser import DoctestProductionBrowser + >>> from tests.doctest_production_browser import DoctestProductionBrowser >>> browser = DoctestProductionBrowser("http://snapshots.linaro.org/") Visiting homepage and check for title. diff --git a/testing/LicenseHelperTest.php b/tests/LicenseHelperTest.php index b7bc855..b7bc855 100644 --- a/testing/LicenseHelperTest.php +++ b/tests/LicenseHelperTest.php diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 0000000..56f6d60 --- /dev/null +++ b/tests/__init__.py @@ -0,0 +1,12 @@ +import unittest + + +def test_suite(): + module_names = [ + 'tests.test_click_through_license.TestLicense', + 'tests.test_publish_to_snapshots.TestSnapshotsPublisher', + 'tests.test_php_unit.PhpUnitTest', + ] + loader = unittest.TestLoader() + suite = loader.loadTestsFromNames(module_names) + return suite diff --git a/testing/apache2.conf.tmpl b/tests/apache2.conf.tmpl index 4cfd851..4cfd851 100644 --- a/testing/apache2.conf.tmpl +++ b/tests/apache2.conf.tmpl diff --git a/testing/doctest_production_browser.py b/tests/doctest_production_browser.py index 0b5a157..0b5a157 100644 --- a/testing/doctest_production_browser.py +++ b/tests/doctest_production_browser.py diff --git a/testing/license_protected_file_downloader.py b/tests/license_protected_file_downloader.py index 5726a56..5726a56 100644 --- a/testing/license_protected_file_downloader.py +++ b/tests/license_protected_file_downloader.py diff --git a/testing/mime.types b/tests/mime.types index c4a3984..c4a3984 100644 --- a/testing/mime.types +++ b/tests/mime.types diff --git a/testing/test_click_through_license.py b/tests/test_click_through_license.py index f1e7e07..1620001 100644 --- a/testing/test_click_through_license.py +++ b/tests/test_click_through_license.py @@ -14,7 +14,7 @@ from license_protected_file_downloader import LicenseProtectedFileFetcher fetcher = LicenseProtectedFileFetcher() cwd = os.getcwd() docroot = cwd -srvroot = os.path.abspath(os.path.join(*([cwd] + ['testing']))) +srvroot = os.path.abspath(os.path.join(*([cwd] + ['tests']))) local_rewrite = 'RewriteCond %{REMOTE_ADDR} 127.0.0.1 [OR]' host = 'http://127.0.0.1' @@ -23,12 +23,15 @@ samsung_license_path = '/licenses/samsung.html' ste_license_path = '/licenses/ste.html' linaro_license_path = '/licenses/linaro.html' samsung_test_file = '/android/~linaro-android/staging-origen/test.txt' -ste_test_file = '/android/~linaro-android/staging-snowball/173/target/product/snowball/test.txt' +ste_test_file = ('/android/~linaro-android/staging-snowball' + '/173/target/product/snowball/test.txt') ste_open_test_file = '/android/~linaro-android/staging-snowball/173/test.txt' never_available = '/android/~linaro-android/staging-imx53/test.txt' linaro_test_file = '/android/~linaro-android/staging-panda/test.txt' -not_protected_test_file = '/android/~linaro-android/staging-vexpress-a9/test.txt' -not_found_test_file = '/android/~linaro-android/staging-vexpress-a9/notfound.txt' +not_protected_test_file = ('/android/~linaro-android/staging-vexpress-a9' + '/test.txt') +not_found_test_file = ('/android/~linaro-android/staging-vexpress-a9' + '/notfound.txt') per_file_samsung_test_file = '/android/images/origen-blob.txt' per_file_ste_test_file = '/android/images/snowball-blob.txt' per_file_not_protected_test_file = '/android/images/MANIFEST' @@ -267,13 +270,15 @@ class TestLicense(TestCase): def test_per_file_license_accepted_samsung(self): search = "This is protected with click-through Samsung license." os.rename("%s/cookies.samsung" % docroot, "%s/cookies.txt" % docroot) - testfile = fetcher.get(host + per_file_samsung_test_file, ignore_license=True) + testfile = fetcher.get(host + per_file_samsung_test_file, + ignore_license=True) self.assertThat(testfile, Contains(search)) def test_per_file_license_accepted_ste(self): search = "This is protected with click-through ST-E license." os.rename("%s/cookies.ste" % docroot, "%s/cookies.txt" % docroot) - testfile = fetcher.get(host + per_file_ste_test_file, ignore_license=True) + testfile = fetcher.get(host + per_file_ste_test_file, + ignore_license=True) self.assertThat(testfile, Contains(search)) def test_per_file_non_protected_dirs(self): diff --git a/testing/test_php_unit.py b/tests/test_php_unit.py index f226f33..1d19d70 100644 --- a/testing/test_php_unit.py +++ b/tests/test_php_unit.py @@ -7,6 +7,9 @@ from testtools import TestCase from testtools.matchers import Equals from testtools.matchers import AllMatch +from tests.test_click_through_license import CommandNotFoundException + + class PhpUnitTest(TestCase): '''Tests for executing the PHP Unit tests''' @@ -14,7 +17,7 @@ class PhpUnitTest(TestCase): super(PhpUnitTest, self).setUp() self.xml_path = tempfile.mkstemp()[1] if subprocess.Popen(['phpunit', '--log-junit', - self.xml_path, 'testing/LicenseHelperTest'], + self.xml_path, 'tests/LicenseHelperTest'], stdout=open('/dev/null', 'w'), stderr=subprocess.STDOUT).wait(): raise CommandNotFoundException("phpunit command not found. Please " diff --git a/testing/test_publish_to_snapshots.py b/tests/test_publish_to_snapshots.py index 870d404..5ce7aed 100644 --- a/testing/test_publish_to_snapshots.py +++ b/tests/test_publish_to_snapshots.py @@ -9,22 +9,25 @@ from StringIO import StringIO from testtools import TestCase from scripts.publish_to_snapshots import SnapshotsPublisher + class TestSnapshotsPublisher(TestCase): - '''Tests for publishing files to the snapshots.l.o www are.''' + '''Tests for publishing files to the snapshots.l.o www area.''' uploads_path = "uploads/" target_path = "www/" orig_dir = os.getcwd() def setUp(self): - self.parser = argparse.ArgumentParser() + self.parser = argparse.ArgumentParser() self.parser.add_argument("-t", "--job-type", dest="job_type") self.parser.add_argument("-j", "--job-name", dest="job_name") - self.parser.add_argument("-n", "--build-num", dest="build_num", type=int) - self.parser.add_argument("-m", "--manifest", dest="manifest", action='store_true') + self.parser.add_argument("-n", "--build-num", dest="build_num", + type=int) + self.parser.add_argument("-m", "--manifest", dest="manifest", + action='store_true') if not os.path.isdir(self.uploads_path): os.mkdir(self.uploads_path) - + if not os.path.isdir(self.target_path): os.mkdir(self.target_path) super(TestSnapshotsPublisher, self).setUp() @@ -40,38 +43,38 @@ class TestSnapshotsPublisher(TestCase): def test_validate_args_valid_job_values(self): self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'kernel-hwpack', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'kernel-hwpack', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'prebuilt', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'prebuilt', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'ubuntu-hwpacks', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-hwpacks', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'ubuntu-images', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-images', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'ubuntu-restricted', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-restricted', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'ubuntu-sysroots', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-sysroots', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - param = self.parser.parse_args(['-t', 'binaries', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'binaries', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) def test_validate_args_invalid_job_type(self): orig_stderr = sys.stderr stderr = sys.stderr = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'invalid_job_type', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'invalid_job_type', '-j', 'dummy_job_name', '-n', '1']) try: self.publisher.validate_args(param) except SystemExit, err: @@ -82,7 +85,6 @@ class TestSnapshotsPublisher(TestCase): stderr.seek(0) self.assertIn("Invalid job type", stderr.read()) - def test_validate_args_run_invalid_argument(self): orig_stderr = sys.stderr stderr = sys.stderr = StringIO() @@ -111,7 +113,7 @@ class TestSnapshotsPublisher(TestCase): sys.stderr = orig_stderr stderr.seek(0) - self.assertIn("argument -n/--build-num: invalid int value: 'N'", + self.assertIn("argument -n/--build-num: invalid int value: 'N'", stderr.read()) def test_validate_args_run_none_values(self): @@ -119,7 +121,8 @@ class TestSnapshotsPublisher(TestCase): stderr = sys.stderr = StringIO() self.publisher = SnapshotsPublisher() try: - param = self.parser.parse_args(['-t', None , '-j', None , '-n' , 0]) + param = self.parser.parse_args( + ['-t', None, '-j', None, '-n', 0]) self.publisher.validate_args(param) except SystemExit, err: self.assertEqual(err.code, 2, "None values are not acceptable") @@ -127,20 +130,21 @@ class TestSnapshotsPublisher(TestCase): sys.stderr = orig_stderr stderr.seek(0) - self.assertIn("You must specify job-type, job-name and build-num", + self.assertIn("You must specify job-type, job-name and build-num", stderr.read()) def test_validate_paths_invalid_uploads_path(self): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) uploads_path = "./dummy_uploads_path" try: - self.publisher.validate_paths(param, uploads_path, self.target_path) + self.publisher.validate_paths(param, uploads_path, + self.target_path) finally: sys.stdout = orig_stdout @@ -151,16 +155,18 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - build_path = os.path.join(self.uploads_path, param.job_type, param.job_name, - str(param.build_num)) + build_path = os.path.join( + self.uploads_path, param.job_type, param.job_name, + str(param.build_num)) os.makedirs(build_path) self.target_path = "./dummy_target_path" try: - self.publisher.validate_paths(param, self.uploads_path, self.target_path) + self.publisher.validate_paths(param, self.uploads_path, + self.target_path) finally: sys.stdout = orig_stdout @@ -171,19 +177,21 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'kernel-hwpack', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'kernel-hwpack', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - build_path = os.path.join(self.uploads_path, param.job_type, param.job_name, - str(param.build_num)) + build_path = os.path.join( + self.uploads_path, param.job_type, param.job_name, + str(param.build_num)) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -195,19 +203,21 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) + build_dir = '/'.join( + [param.job_type, param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -219,19 +229,20 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'prebuilt', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'prebuilt', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) build_dir = '/'.join([param.job_name, str(param.build_num)]) - build_path = os.path.join(self.uploads_path, build_dir,'oneiric') + build_path = os.path.join(self.uploads_path, build_dir, 'oneiric') os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -243,7 +254,7 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'ubuntu-hwpacks', '-j', + param = self.parser.parse_args(['-t', 'ubuntu-hwpacks', '-j', 'precise-armhf-lt-panda', '-n', '1']) self.publisher.validate_args(param) build_dir = '/'.join([param.job_name, str(param.build_num)]) @@ -251,11 +262,12 @@ class TestSnapshotsPublisher(TestCase): os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -267,19 +279,21 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'ubuntu-images', '-j', - 'precise-armhf-ubuntu-desktop', '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-images', '-j', 'precise-armhf-ubuntu-desktop', + '-n', '1']) self.publisher.validate_args(param) build_dir = '/'.join([param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -291,20 +305,21 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'ubuntu-restricted', '-j', - 'precise-armhf-integrated-big.little-fastmodels', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-restricted', '-j', + 'precise-armhf-integrated-big.little-fastmodels', '-n', '1']) self.publisher.validate_args(param) build_dir = '/'.join([param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -316,19 +331,21 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'ubuntu-sysroots', '-j', - 'precise-armhf-ubuntu-desktop-dev', '-n', '1']) + param = self.parser.parse_args( + ['-t', 'ubuntu-sysroots', '-j', + 'precise-armhf-ubuntu-desktop-dev', '-n', '1']) self.publisher.validate_args(param) build_dir = '/'.join([param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -353,12 +370,12 @@ class TestSnapshotsPublisher(TestCase): f.write('20120416') f.close() try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, - self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -366,23 +383,25 @@ class TestSnapshotsPublisher(TestCase): stdout.seek(0) self.assertIn("Moved the files from", stdout.read()) - def test_move_artifacts_android_successful_move(self): + def test_move_artifacts_android_successful_move2(self): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) + build_dir = '/'.join( + [param.job_type, param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass @@ -394,52 +413,57 @@ class TestSnapshotsPublisher(TestCase): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1']) self.publisher.validate_args(param) - build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) + build_dir = '/'.join( + [param.job_type, param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) finally: sys.stdout = orig_stdout pass stdout.seek(0) - msg = "The latest build is now linked to " + target_dir_path + msg = "The latest build is now linked to " + target_dir_path self.assertIn(msg, stdout.read()) def test_create_manifest_file_option(self): orig_stdout = sys.stdout stdout = sys.stdout = StringIO() self.publisher = SnapshotsPublisher() - param = self.parser.parse_args(['-t', 'android', '-j', 'dummy_job_name', - '-n', '1', '-m']) + param = self.parser.parse_args( + ['-t', 'android', '-j', 'dummy_job_name', '-n', '1', '-m']) self.publisher.validate_args(param) - build_dir = '/'.join([param.job_type, param.job_name, str(param.build_num)]) + build_dir = '/'.join( + [param.job_type, param.job_name, str(param.build_num)]) build_path = os.path.join(self.uploads_path, build_dir) os.makedirs(build_path) tempfile.mkstemp(dir=build_path) lines = [] try: - uploads_dir_path, target_dir_path = self.publisher.validate_paths(param, - self.uploads_path, self.target_path) + uploads_dir_path, target_dir_path = self.publisher.validate_paths( + param, self.uploads_path, self.target_path) uploads_dir_path = os.path.join(self.orig_dir, uploads_dir_path) target_dir_path = os.path.join(self.orig_dir, target_dir_path) os.chdir(uploads_dir_path) for path, subdirs, files in os.walk("."): for name in files: - lines.append(os.path.join(path, name).split("./")[1] + "\n") + lines.append( + os.path.join(path, name).split("./")[1] + "\n") os.chdir(self.orig_dir) - self.publisher.move_artifacts(param, uploads_dir_path, target_dir_path) + self.publisher.move_artifacts(param, uploads_dir_path, + target_dir_path) - manifest_file=os.path.join(target_dir_path, "MANIFEST") + manifest_file = os.path.join(target_dir_path, "MANIFEST") dest = open(manifest_file, "r").read() if len(lines) != 0: @@ -449,8 +473,8 @@ class TestSnapshotsPublisher(TestCase): fd.write(line) fd.close() orig = open(tempfiles[1], "r").read() - - except Exception, details: + + except: pass finally: |