diff --git a/setup.py b/setup.py index 4175561b..bbbc3c85 100755 --- a/setup.py +++ b/setup.py @@ -76,7 +76,8 @@ 'tuf.pushtools', 'tuf.pushtools.transfer', 'tuf.repo', - 'tuf.tests' + 'tuf.tests', + 'tuf.tests.system_tests' ], scripts=[ 'tuf/repo/quickstart.py', diff --git a/tuf/client/basic_client.py b/tuf/client/basic_client.py index b690955c..1ba36dbc 100755 --- a/tuf/client/basic_client.py +++ b/tuf/client/basic_client.py @@ -55,6 +55,8 @@ import optparse import logging +import tuf +import tuf.formats import tuf.client.updater import tuf.log diff --git a/tuf/client/updater.py b/tuf/client/updater.py index 54796c28..2f9ca1a1 100755 --- a/tuf/client/updater.py +++ b/tuf/client/updater.py @@ -106,6 +106,7 @@ import shutil import time +import tuf import tuf.conf import tuf.download import tuf.formats @@ -118,7 +119,7 @@ import tuf.sig import tuf.util -logger = logging.getLogger('tuf') +logger = logging.getLogger('tuf.client.updater') class Updater(object): diff --git a/tuf/examples/example_client.py b/tuf/examples/example_client.py index 78b1103f..a1735412 100755 --- a/tuf/examples/example_client.py +++ b/tuf/examples/example_client.py @@ -27,10 +27,12 @@ import logging +import tuf +import tuf.log import tuf.client.updater -# Uncomment the line below to enable printing of debugging information. -#tuf.log.set_log_level(logging.DEBUG) +logger = logging.getLogger('tuf.cient.basic_client') + # Set the local repository directory containing the metadata files. tuf.conf.repository_directory = '.' diff --git a/tuf/hash.py b/tuf/hash.py index 9421ce35..161a181c 100755 --- a/tuf/hash.py +++ b/tuf/hash.py @@ -24,12 +24,13 @@ """ +import logging + # Import tuf Exceptions. import tuf import tuf.log # Import tuf logger to log warning messages. -import logging logger = logging.getLogger('tuf.hash') # The list of hash libraries imported successfully. diff --git a/tuf/keydb.py b/tuf/keydb.py index e2ee142d..601993b3 100755 --- a/tuf/keydb.py +++ b/tuf/keydb.py @@ -31,6 +31,7 @@ import logging +import tuf import tuf.formats import tuf.rsa_key diff --git a/tuf/log.py b/tuf/log.py index 716cf379..51397d1f 100755 --- a/tuf/log.py +++ b/tuf/log.py @@ -89,7 +89,7 @@ # may be modified with 'set_filehandler_log_level()'. '_DEFAULT_LOG_FILENAME' # will be opened in append mode. file_handler = logging.FileHandler(_DEFAULT_LOG_FILENAME) -file_handler.setLevel(_DEFAULT_LOG_LEVEL) +file_handler.setLevel(_DEFAULT_FILE_LOG_LEVEL) file_handler.setFormatter(formatter) # Set the logger and its settings. diff --git a/tuf/mirrors.py b/tuf/mirrors.py index 5d159021..6a375467 100755 --- a/tuf/mirrors.py +++ b/tuf/mirrors.py @@ -21,6 +21,7 @@ import os import urllib +import tuf import tuf.util import tuf.formats diff --git a/tuf/pushtools/push.py b/tuf/pushtools/push.py index dc100659..17a3b19c 100755 --- a/tuf/pushtools/push.py +++ b/tuf/pushtools/push.py @@ -59,6 +59,7 @@ import sys import optparse +import tuf import tuf.formats import tuf.pushtools.pushtoolslib import tuf.pushtools.transfer.scp diff --git a/tuf/pushtools/pushtoolslib.py b/tuf/pushtools/pushtoolslib.py index ce6ae292..995a2ab2 100755 --- a/tuf/pushtools/pushtoolslib.py +++ b/tuf/pushtools/pushtoolslib.py @@ -151,4 +151,4 @@ def read_config_file(filename, config_type): message = 'Invalid "config_type" argument. Supported: '+repr(CONFIG_TYPES) raise tuf.Error(message) - return config_dict \ No newline at end of file + return config_dict diff --git a/tuf/pushtools/receivetools/receive.py b/tuf/pushtools/receivetools/receive.py index 7734a456..9fe81121 100755 --- a/tuf/pushtools/receivetools/receive.py +++ b/tuf/pushtools/receivetools/receive.py @@ -155,6 +155,7 @@ import logging import optparse +import tuf import tuf.formats import tuf.keydb import tuf.roledb @@ -165,7 +166,7 @@ import tuf.pushtools.pushtoolslib # See 'log.py' to learn how logging is handled in TUF. -logger = logging.getLogger('tuf.receive') +logger = logging.getLogger('tuf.pushtools.receivetools.receive') def receive(config_filepath): @@ -257,7 +258,7 @@ def receive(config_filepath): for directory_name, path in directories_to_check.items(): if not os.path.exists(path): - message = directory_name+' directory does not exist: '+str(path) + message = directory_name+' directory does not exist: '+repr(path) logger.error(message) raise tuf.Error(message) @@ -270,13 +271,13 @@ def receive(config_filepath): # Process all the pushes for each of the pushroots. for pushroot in pushroots: if not os.path.exists(pushroot): - logger.error('The pushroot '+str(pushroot)+' does not exist. Skipping.') + logger.error('The pushroot '+repr(pushroot)+' does not exist. Skipping.') continue # Add the 'processed' and 'processing' directories if not present. # These directories must exist so that we can properly process # a push. - logger.debug('Looking for pushes in pushroot '+str(pushroot)) + logger.debug('Looking for pushes in pushroot '+repr(pushroot)) if not os.path.exists(os.path.join(pushroot, 'processed')): os.mkdir(os.path.join(pushroot, 'processed')) if not os.path.exists(os.path.join(pushroot, 'processing')): @@ -297,7 +298,7 @@ def receive(config_filepath): # Ensure the 'info' file exists. A successful push operation creates # and saves this 'info' file to the push directory. if not os.path.exists(os.path.join(pushpath, 'info')): - message = 'Skipping incomplete push '+str(pushpath)+' (no info file).' + message = 'Skipping incomplete push '+repr(pushpath)+' (no info file).' logger.warn(message) continue @@ -313,7 +314,7 @@ def receive(config_filepath): # Done. Log the result of processing the pushes for 'pushroot'. message = 'Completed processing of all pushes. Push successes = '+\ - str(success_count)+', failures = '+str(failure_count)+'.' + repr(success_count)+', failures = '+repr(failure_count)+'.' logger.info(message) @@ -364,11 +365,11 @@ def _process_new_push(pushroot, pushname, metadata_directory, """ - logger.info('Processing '+str(pushroot)+'/'+str(pushname)) + logger.info('Processing '+repr(pushroot)+'/'+repr(pushname)) # Move the pushed directory to the 'processing' directory. pushpath = os.path.join(pushroot, 'processing', pushname) - logger.debug('Moving push directory to '+str(pushpath)) + logger.debug('Moving push directory to '+repr(pushpath)) if os.path.isdir(pushpath) or os.path.isfile(pushpath): os.remove(pushpath) os.rename(os.path.join(pushroot, pushname), pushpath) @@ -418,14 +419,14 @@ def _process_new_push(pushroot, pushname, metadata_directory, finally: file_object.close() - message = 'Could not process: '+str(pushroot)+'/'+str(pushname) + message = 'Could not process: '+repr(pushroot)+'/'+repr(pushname) logger.exception(message) return False # On success or failure, move 'pushpath' to the processed directory. finally: processedpath = os.path.join(pushroot, 'processed', pushname) - logger.debug('Moving push directory to '+str(processedpath)) + logger.debug('Moving push directory to '+repr(processedpath)) if os.path.isdir(processedpath) or os.path.isfile(processedpath): os.remove(processedpath) os.rename(pushpath, processedpath) @@ -575,17 +576,17 @@ def _process_copied_push(pushpath, metadata_directory, # Allowing equality makes testing/development easier. if formatted_timestamp > new_formatted_timestamp: - message = 'Existing metadata timestamp '+str(timestamp)+' is newer '+\ - 'than the new metadata\'s timestamp '+str(new_timestamp) + message = 'Existing metadata timestamp '+repr(timestamp)+' is newer '+\ + 'than the new metadata\'s timestamp '+repr(new_timestamp) raise tuf.Error(message) else: - message = 'New metadata timestamp is '+str(new_timestamp)+'. '+\ - ' Replacing old metadata with timestamp '+str(timestamp) + message = 'New metadata timestamp is '+repr(new_timestamp)+'. '+\ + ' Replacing old metadata with timestamp '+repr(timestamp) logger.debug(message) # There appears to be no 'targets.txt' metadata file on the repository. else: - message = 'The old targets metadata file '+str(targets_metadatapath)+'. '+\ + message = 'The old targets metadata file '+repr(targets_metadatapath)+'. '+\ 'doesn\'t exist in the repo. Skipping the timestamp check.' logger.warn(message) @@ -594,10 +595,10 @@ def _process_copied_push(pushpath, metadata_directory, formatted_expiration = tuf.formats.parse_time(expiration) if formatted_expiration <= time.time(): - message = 'Pushed metadata expired at '+str(expiration) + message = 'Pushed metadata expired at '+repr(expiration) raise tuf.Error(message) else: - message = 'Metadata will expire at '+str(expiration) + message = 'Metadata will expire at '+repr(expiration) logger.debug(message) # Verify the signatures of the new targets metadata. @@ -608,11 +609,11 @@ def _process_copied_push(pushpath, metadata_directory, # Log the status of the signatures. For example, the number of good, # bad, untrusted, unknown, signatures. status = tuf.sig.get_signature_status(new_targets_signable, 'targets') - logger.debug(str(status)) + logger.debug(repr(status)) # Log the number of targets specified in the new targets metadata file. targets_count = len(new_targets_signable['signed']['targets'].keys()) - message = 'Number of targets specified: '+str(targets_count) + message = 'Number of targets specified: '+repr(targets_count) logger.info(message) # Verify the files of the new targets metadata file. @@ -625,39 +626,39 @@ def _process_copied_push(pushpath, metadata_directory, # Check that the target was provided. if not os.path.exists(targetpath): message = 'The specified target file was not provided: '+\ - str(target_relativepath) + repr(target_relativepath) raise tuf.Error(message) # Check the target's size. A valid size is required of target files. target_size = os.path.getsize(targetpath) if target_size != target_info['length']: - message = 'The size of target file '+str(target_relativepath)+\ - ' is incorrect: was '+str(target_size)+', expected '+\ - str(target_info['length']) + message = 'The size of target file '+repr(target_relativepath)+\ + ' is incorrect: was '+repr(target_size)+', expected '+\ + repr(target_info['length']) raise tuf.Error(message) else: - message = 'Size of target '+str(targetpath)+' is correct '+\ - '('+str(target_size)+' bytes).' + message = 'Size of target '+repr(targetpath)+' is correct '+\ + '('+repr(target_size)+' bytes).' logger.debug(message) # Check hashes. Valid target files is required. hash_count = len(target_info['hashes'].items()) if hash_count == 0: - message = str(targetpath)+' contains an empty hashes dictionary.' + message = repr(targetpath)+' contains an empty hashes dictionary.' raise tuf.Error(message) else: - logger.debug(str(hash_count)+' hash(es) to check.') + logger.debug(repr(hash_count)+' hash(es) to check.') for algorithm, digest in target_info['hashes'].items(): digest_object = tuf.hash.digest_filename(targetpath, algorithm=algorithm) if digest_object.hexdigest() != digest: - message = str(algorithm)+' hash does not match: '+\ - ' was '+str(digest_object.hexdigest())+', expected '+\ - str(digest) + message = repr(algorithm)+' hash does not match: '+\ + ' was '+repr(digest_object.hexdigest())+', expected '+\ + repr(digest) raise tuf.Error(message) else: - message = str(algorithm)+' hash of target '+str(targetpath)+\ - ' is correct ('+str(digest)+').' + message = repr(algorithm)+' hash of target '+repr(targetpath)+\ + ' is correct ('+repr(digest)+').' logger.debug(message) # At this point, the targets metadata and all specified files have been @@ -673,14 +674,14 @@ def _process_copied_push(pushpath, metadata_directory, source_path = os.path.join(push_temporary_directory, targets_basename, target_relativepath) destination_path = os.path.join(targets_directory, target_relativepath) - logger.info('Adding target to repository: '+str(destination_path)) + logger.info('Adding target to repository: '+repr(destination_path)) destination_directory = os.path.dirname(destination_path) if not os.path.exists(destination_directory): os.mkdir(destination_directory) shutil.copy(source_path, destination_path) # Copy the new targets metadata file into place on the repository. - message = 'Adding new targets metadata to repository: '+str(targets_metadatapath) + message = 'Adding new targets metadata to repository: '+repr(targets_metadatapath) logger.info(message) shutil.copy(new_targets_metadatapath, targets_metadatapath) @@ -745,7 +746,7 @@ def _remove_old_files(targets_metadatapath, pushname, for target_relativepath in targets_signable['signed']['targets'].keys(): targetpath = os.path.join(targets_directory, target_relativepath) backup_targetpath = os.path.join(backup_targetsdirectory, target_relativepath) - message = 'Backing up target '+str(targetpath)+' to '+str(backup_targetpath) + message = 'Backing up target '+repr(targetpath)+' to '+repr(backup_targetpath) logger.info(message) # Move the old target file to the backup directory. Create any @@ -760,13 +761,13 @@ def _remove_old_files(targets_metadatapath, pushname, raise tuf.Error(str(e)) os.rename(targetpath, backup_targetpath) else: - message = 'The old target '+str(targetpath)+' doesn\'t exist in the repo.' + message = 'The old target '+repr(targetpath)+' doesn\'t exist in the repo.' logger.warn(message) # Backup the old 'targets.txt' metadata file. backup_targets_metadatafile = os.path.join(backup_destdirectory, 'targets.txt') - message = 'Backing up old metadata '+str(targets_metadatapath)+\ - ' to '+str(backup_targets_metadatafile) + message = 'Backing up old metadata '+repr(targets_metadatapath)+\ + ' to '+repr(backup_targets_metadatafile) logger.info(message) if os.path.isfile(backup_targets_metadatafile): os.remove(backup_targets_metadatafile) diff --git a/tuf/pushtools/transfer/scp.py b/tuf/pushtools/transfer/scp.py index c844f4e9..d4aa7b0d 100755 --- a/tuf/pushtools/transfer/scp.py +++ b/tuf/pushtools/transfer/scp.py @@ -54,6 +54,7 @@ import tempfile import time +import tuf import tuf.formats diff --git a/tuf/repo/quickstart.py b/tuf/repo/quickstart.py index ff67890d..e51373da 100755 --- a/tuf/repo/quickstart.py +++ b/tuf/repo/quickstart.py @@ -102,7 +102,7 @@ import tuf.log # See 'log.py' to learn how logging is handled in TUF. -logger = logging.getLogger('tuf') +logger = logging.getLogger('tuf.quickstart') # Set the default file names for the top-level roles. # For instance: in 'signerlib.py', ROOT_FILENAME = 'root.txt'. diff --git a/tuf/repo/signercli.py b/tuf/repo/signercli.py index a2971351..8536a405 100755 --- a/tuf/repo/signercli.py +++ b/tuf/repo/signercli.py @@ -58,16 +58,17 @@ import errno import tuf +import tuf.formats import tuf.repo.signerlib import tuf.repo.keystore import tuf.util import tuf.log -json = tuf.util.import_json() - # See 'log.py' to learn how logging is handled in TUF. logger = logging.getLogger('tuf.signercli') +json = tuf.util.import_json() + # The maximum number of attempts the user has to enter # valid input. MAX_INPUT_ATTEMPTS = 3 diff --git a/tuf/repo/signerlib.py b/tuf/repo/signerlib.py index ab30c84f..2698518f 100755 --- a/tuf/repo/signerlib.py +++ b/tuf/repo/signerlib.py @@ -24,6 +24,7 @@ import ConfigParser import logging +import tuf import tuf.formats import tuf.hash import tuf.rsa_key diff --git a/tuf/roledb.py b/tuf/roledb.py index f6446731..4f114dfc 100755 --- a/tuf/roledb.py +++ b/tuf/roledb.py @@ -29,9 +29,10 @@ """ -import tuf.formats import logging +import tuf +import tuf.formats import tuf.log # See 'tuf.log' to learn how logging is handled in TUF. diff --git a/tuf/rsa_key.py b/tuf/rsa_key.py index bc1767a0..a86a6138 100755 --- a/tuf/rsa_key.py +++ b/tuf/rsa_key.py @@ -42,6 +42,8 @@ import evpy.signature import evpy.envelope +import tuf + # Digest objects needed to generate hashes. import tuf.hash diff --git a/tuf/sig.py b/tuf/sig.py index 32faae89..ce5b9f56 100755 --- a/tuf/sig.py +++ b/tuf/sig.py @@ -36,6 +36,7 @@ """ +import tuf import tuf.formats import tuf.keydb import tuf.roledb diff --git a/tuf/tests/system_tests/slow_retrieval_server.py b/tuf/tests/system_tests/slow_retrieval_server.py index 0887d119..161277b6 100755 --- a/tuf/tests/system_tests/slow_retrieval_server.py +++ b/tuf/tests/system_tests/slow_retrieval_server.py @@ -24,11 +24,9 @@ import random from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer - DELAY = 1 - # HTTP request handler. class Handler(BaseHTTPRequestHandler): @@ -76,4 +74,4 @@ def run(port): else: port = get_random_port() - run(port) \ No newline at end of file + run(port) diff --git a/tuf/tests/system_tests/test_arbitrary_package_attack.py b/tuf/tests/system_tests/test_arbitrary_package_attack.py index 1ddcb053..b5f207ce 100755 --- a/tuf/tests/system_tests/test_arbitrary_package_attack.py +++ b/tuf/tests/system_tests/test_arbitrary_package_attack.py @@ -40,11 +40,6 @@ -# Disable logging. -util_test_tools.disable_logging() - - - class ArbitraryPackageAlert(Exception): pass @@ -149,4 +144,4 @@ def test_arbitrary_package_attack(TUF=False): test_arbitrary_package_attack(TUF=True) except ArbitraryPackageAlert, error: - print error \ No newline at end of file + print error diff --git a/tuf/tests/system_tests/test_endless_data_attack.py b/tuf/tests/system_tests/test_endless_data_attack.py index 9366accf..4cac5531 100755 --- a/tuf/tests/system_tests/test_endless_data_attack.py +++ b/tuf/tests/system_tests/test_endless_data_attack.py @@ -43,12 +43,6 @@ from tuf.interposition import urllib_tuf - -# Disable logging. -util_test_tools.disable_logging() - - - class EndlessDataAttack(Exception): pass diff --git a/tuf/tests/system_tests/test_extraneous_dependencies_attack.py b/tuf/tests/system_tests/test_extraneous_dependencies_attack.py index 72937d65..de327ea7 100755 --- a/tuf/tests/system_tests/test_extraneous_dependencies_attack.py +++ b/tuf/tests/system_tests/test_extraneous_dependencies_attack.py @@ -27,18 +27,17 @@ import tempfile import time -import util_test_tools +import tuf +import tuf.formats +import tuf.tests.system_tests.util_test_tools import tuf.repo.keystore import tuf.repo.signerlib as signerlib import tuf.repo.signercli as signercli from tuf.interposition import urllib_tuf - -# Disable logging. -util_test_tools.disable_logging() - version = 1 + class ExtraneousDependenciesAttackAlert(Exception): pass diff --git a/tuf/tests/system_tests/test_indefinite_freeze_attack.py b/tuf/tests/system_tests/test_indefinite_freeze_attack.py index 9a5bb1a0..85f457d2 100755 --- a/tuf/tests/system_tests/test_indefinite_freeze_attack.py +++ b/tuf/tests/system_tests/test_indefinite_freeze_attack.py @@ -27,21 +27,16 @@ import tempfile import util_test_tools +import tuf import tuf.formats import tuf.repo.signerlib as signerlib from tuf.interposition import urllib_tuf -# Disable logging. -util_test_tools.disable_logging() - - - class IndefiniteFreezeAttackAlert(Exception): pass - EXPIRATION = 1 # second(s) version = 1 diff --git a/tuf/tests/system_tests/test_mix_and_match_attack.py b/tuf/tests/system_tests/test_mix_and_match_attack.py index 94c40057..29ee9fcf 100755 --- a/tuf/tests/system_tests/test_mix_and_match_attack.py +++ b/tuf/tests/system_tests/test_mix_and_match_attack.py @@ -44,11 +44,6 @@ from tuf.interposition import urllib_tuf -# Disable logging. -util_test_tools.disable_logging() - - - class MixAndMatchAttackAlert(Exception): pass @@ -195,4 +190,4 @@ def test_mix_and_match_attack(TUF=False): try: test_mix_and_match_attack(TUF=True) except MixAndMatchAttackAlert, error: - print error \ No newline at end of file + print error diff --git a/tuf/tests/system_tests/test_replay_attack.py b/tuf/tests/system_tests/test_replay_attack.py index 4250a854..1c190dfa 100755 --- a/tuf/tests/system_tests/test_replay_attack.py +++ b/tuf/tests/system_tests/test_replay_attack.py @@ -38,16 +38,10 @@ import urllib import tempfile -import util_test_tools +import tuf.tests.system_tests.util_test_tools as util_test_tools from tuf.interposition import urllib_tuf - -# Disable logging. -util_test_tools.disable_logging() - - - class TestSetupError(Exception): pass @@ -189,4 +183,4 @@ def test_replay_attack(TUF=False): try: test_replay_attack(TUF=True) except ReplayAttackAlert, error: - print error \ No newline at end of file + print error diff --git a/tuf/tests/system_tests/test_slow_retrieval_attack.py b/tuf/tests/system_tests/test_slow_retrieval_attack.py index d2f9f4d9..7d25a7d2 100755 --- a/tuf/tests/system_tests/test_slow_retrieval_attack.py +++ b/tuf/tests/system_tests/test_slow_retrieval_attack.py @@ -42,15 +42,10 @@ import subprocess from multiprocessing import Process -import util_test_tools +import tuf.tests.system_tests.util_test_tools as util_test_tools from tuf.interposition import urllib_tuf -# Disable logging. -util_test_tools.disable_logging() - - - class SlowRetrievalAttackAlert(Exception): pass @@ -72,7 +67,8 @@ def test_slow_retrieval_attack(TUF=False): # Launch the server. port = random.randint(30000, 45000) command = ['python', 'slow_retrieval_server.py', str(port)] - server_process = subprocess.Popen(command, stderr=subprocess.PIPE) + server_process = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) time.sleep(.1) try: @@ -134,4 +130,4 @@ def test_slow_retrieval_attack(TUF=False): try: test_slow_retrieval_attack(TUF=True) except SlowRetrievalAttackAlert, error: - print error \ No newline at end of file + print error diff --git a/tuf/tests/system_tests/util_test_tools.py b/tuf/tests/system_tests/util_test_tools.py index 1e5714c0..25f710c0 100755 --- a/tuf/tests/system_tests/util_test_tools.py +++ b/tuf/tests/system_tests/util_test_tools.py @@ -137,6 +137,7 @@ import subprocess import tuf +import tuf.formats import tuf.interposition import tuf.util import tuf.client.updater @@ -144,13 +145,7 @@ import tuf.repo.signerlib as signerlib import tuf.repo.keystore as keystore -logger = logging.getLogger('tuf') - -# Disable logging for cleaner output. -def disable_logging(): - logging.getLogger('tuf') - logging.disable(logging.CRITICAL) - +logger = logging.getLogger('tuf.tests.system_tests.util_test_tools') PASSWD = 'test' version = 1 @@ -174,7 +169,8 @@ def init_repo(tuf=False, port=None): # Start a simple server pointing to the repository directory. port = random.randint(30000, 45000) command = ['python', '-m', 'SimpleHTTPServer', str(port)] - server_proc = subprocess.Popen(command, stderr=subprocess.PIPE) + server_proc = subprocess.Popen(command, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) # Tailor url for the repository. In order to download a 'file.txt' # from 'reg_repo' do: url+'reg_repo/file.txt' diff --git a/tuf/tests/test_download.py b/tuf/tests/test_download.py index 96716875..d2e0e38d 100755 --- a/tuf/tests/test_download.py +++ b/tuf/tests/test_download.py @@ -19,12 +19,9 @@ NOTE: Make sure test_download.py is ran in 'tuf/tests/' directory. Otherwise, module that launches simple server would not be found. + """ -import tuf -import tuf.log -import tuf.download as download -import tuf.tests.unittest_toolbox as unittest_toolbox import os import sys @@ -37,11 +34,12 @@ import SocketServer import SimpleHTTPServer -logger = logging.getLogger('tuf') +import tuf +import tuf.log +import tuf.download as download +import tuf.tests.unittest_toolbox as unittest_toolbox -# Disable/Enable logging. Comment-out to Enable logging. -logging.getLogger('tuf') -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_download') class TestDownload(unittest_toolbox.Modified_TestCase): diff --git a/tuf/tests/test_formats.py b/tuf/tests/test_formats.py index ecc5338b..1e375ca3 100755 --- a/tuf/tests/test_formats.py +++ b/tuf/tests/test_formats.py @@ -20,6 +20,7 @@ import unittest +import tuf import tuf.formats import tuf.schema diff --git a/tuf/tests/test_hash.py b/tuf/tests/test_hash.py index 0a56c175..8e634a81 100755 --- a/tuf/tests/test_hash.py +++ b/tuf/tests/test_hash.py @@ -23,9 +23,12 @@ import tempfile import unittest +import tuf +import tuf.log import tuf.hash -logger = logging.getLogger('tuf') +logger = logging.getLogger('tuf.test_hash') + if not 'hashlib' in tuf.hash._supported_libraries: logger.warn('Not testing hashlib: could not be imported.') diff --git a/tuf/tests/test_keydb.py b/tuf/tests/test_keydb.py index 7e61f223..c7330875 100755 --- a/tuf/tests/test_keydb.py +++ b/tuf/tests/test_keydb.py @@ -19,15 +19,13 @@ import unittest import logging +import tuf +import tuf.formats import tuf.rsa_key import tuf.keydb import tuf.log -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_keydb') # Generate the three keys to use in our test cases. diff --git a/tuf/tests/test_keystore.py b/tuf/tests/test_keystore.py index 816f400a..5302d5f2 100755 --- a/tuf/tests/test_keystore.py +++ b/tuf/tests/test_keystore.py @@ -21,16 +21,14 @@ import os import logging +import tuf import tuf.repo.keystore import tuf.rsa_key import tuf.formats import tuf.util +import tuf.log -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_keystore') # We'll need json module for testing '_encrypt()' and '_decrypt()' # internal function. diff --git a/tuf/tests/test_push.py b/tuf/tests/test_push.py index 699881c0..c491b22f 100755 --- a/tuf/tests/test_push.py +++ b/tuf/tests/test_push.py @@ -24,20 +24,17 @@ import ConfigParser import tuf +import tuf.log import tuf.pushtools.push as push import tuf.pushtools.transfer.scp as scp import tuf.pushtools.pushtoolslib as pushtoolslib -import system_tests.util_test_tools as util_test_tools +import tuf.tests.system_tests.util_test_tools as util_test_tools -logger = logging.getLogger('tuf') +logger = logging.getLogger('tuf.test_push') -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) class TestPush(unittest.TestCase): src_push_dict = {} - logger.info(scp.transfer) ORIGINAL_PUSH_CONFIG = pushtoolslib.PUSH_CONFIG diff --git a/tuf/tests/test_pushtoolslib.py b/tuf/tests/test_pushtoolslib.py index 60c4975f..e0cf6694 100755 --- a/tuf/tests/test_pushtoolslib.py +++ b/tuf/tests/test_pushtoolslib.py @@ -20,10 +20,14 @@ import tempfile import unittest import ConfigParser +import logging +import tuf +import tuf.log import tuf.formats import tuf.pushtools.pushtoolslib as pushtoolslib +logger = logging.getLogger('tuf.test_pushtoolslib') class TestPushtoolslib(unittest.TestCase): diff --git a/tuf/tests/test_quickstart.py b/tuf/tests/test_quickstart.py index f0ec3544..a211f905 100755 --- a/tuf/tests/test_quickstart.py +++ b/tuf/tests/test_quickstart.py @@ -25,19 +25,19 @@ import shutil import unittest import logging -import tuf.repo.quickstart as quickstart +import tuf +import tuf.log +import tuf.repo.quickstart as quickstart import tuf.util import tuf.tests.unittest_toolbox - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) - +logger = logging.getLogger('tuf.test_quickstart') unit_tbox = tuf.tests.unittest_toolbox.Modified_TestCase +logger.info('from test_quickstart') + class TestQuickstart(unit_tbox): def test_1_get_password(self): diff --git a/tuf/tests/test_roledb.py b/tuf/tests/test_roledb.py index 7badf680..6d068054 100755 --- a/tuf/tests/test_roledb.py +++ b/tuf/tests/test_roledb.py @@ -16,20 +16,18 @@ """ + import unittest import logging +import tuf import tuf.formats import tuf.rsa_key import tuf.roledb import tuf.log +logger = logging.getLogger('tuf.test_roledb') -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) # Generate the three keys to use in our test cases. KEYS = [] diff --git a/tuf/tests/test_rsa_key.py b/tuf/tests/test_rsa_key.py index d6543378..a7b8708d 100755 --- a/tuf/tests/test_rsa_key.py +++ b/tuf/tests/test_rsa_key.py @@ -23,10 +23,14 @@ """ import unittest +import logging +import tuf +import tuf.log import tuf.formats import tuf.rsa_key +logger = logging.getLogger('tuf.test_rsa_key') RSA_KEY = tuf.rsa_key FORMAT_ERROR_MSG = 'tuf.FormatError was raised! Check object\'s format.' diff --git a/tuf/tests/test_schema.py b/tuf/tests/test_schema.py index f72ae02b..66320a01 100755 --- a/tuf/tests/test_schema.py +++ b/tuf/tests/test_schema.py @@ -17,9 +17,14 @@ """ import unittest +import logging +import tuf +import tuf.log import tuf.schema +logger = logging.getLogger('tuf.test_schema') + class TestSchema(unittest.TestCase): def setUp(self): diff --git a/tuf/tests/test_sig.py b/tuf/tests/test_sig.py index dd302748..efdbe516 100755 --- a/tuf/tests/test_sig.py +++ b/tuf/tests/test_sig.py @@ -17,13 +17,19 @@ """ -import unittest +import unittest +import logging + +import tuf +import tuf.log +import tuf.formats import tuf.keydb import tuf.roledb import tuf.rsa_key import tuf.sig +logger = logging.getLogger('tuf.test_sig') # Setup the keys to use in our test cases. KEYS = [] diff --git a/tuf/tests/test_signercli.py b/tuf/tests/test_signercli.py index aa91d862..61ba1ef4 100755 --- a/tuf/tests/test_signercli.py +++ b/tuf/tests/test_signercli.py @@ -42,28 +42,25 @@ class guarantees the order of unit tests. So that, 'test_something_A' import unittest import tuf +import tuf.log import tuf.formats import tuf.util import tuf.repo.keystore as keystore import tuf.repo.signerlib as signerlib + # Module to test: signercli.py import tuf.repo.signercli as signercli + # Helper module unittest_toolbox.py import tuf.tests.unittest_toolbox as unittest_toolbox - -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_signercli') # Populating 'rsa_keystore' and 'rsa_passwords' dictionaries. # We will need them when creating keystore directories. unittest_toolbox.Modified_TestCase.bind_keys_to_roles() - class TestSignercli(unittest_toolbox.Modified_TestCase): # SETUP original_prompt = signercli._prompt diff --git a/tuf/tests/test_signerlib.py b/tuf/tests/test_signerlib.py index dcb47993..9008350e 100755 --- a/tuf/tests/test_signerlib.py +++ b/tuf/tests/test_signerlib.py @@ -54,6 +54,8 @@ import logging import unittest +import tuf +import tuf.log import tuf.util import tuf.formats as formats import tuf.repo.signerlib as signerlib @@ -61,12 +63,7 @@ import tuf.tests.unittest_toolbox - -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_signerlib') # 'unittest_toolbox.Modified_TestCase' is too long, I'll set it to 'unit_tbox'. unit_tbox = tuf.tests.unittest_toolbox.Modified_TestCase diff --git a/tuf/tests/test_updater.py b/tuf/tests/test_updater.py index d32664e7..dc708d62 100755 --- a/tuf/tests/test_updater.py +++ b/tuf/tests/test_updater.py @@ -43,6 +43,9 @@ class guarantees the order of unit tests. So that, 'test_something_A' import logging import unittest + +import tuf +import tuf.log import tuf.util import tuf.formats import tuf.repo.keystore as keystore @@ -51,11 +54,7 @@ class guarantees the order of unit tests. So that, 'test_something_A' import tuf.tests.repository_setup as setup import tuf.tests.unittest_toolbox as unittest_toolbox -logger = logging.getLogger('tuf') - -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_updater') # References to roledb and keydb dictionaries (improve readability). roledb = tuf.roledb diff --git a/tuf/tests/test_util.py b/tuf/tests/test_util.py index aa4f0d9b..561e1cc7 100755 --- a/tuf/tests/test_util.py +++ b/tuf/tests/test_util.py @@ -30,9 +30,7 @@ import tuf.util as util import tuf.tests.unittest_toolbox as unittest_toolbox -# Disable all logging calls of level CRITICAL and below. -# Comment the line below to enable logging. -logging.disable(logging.CRITICAL) +logger = logging.getLogger('tuf.test_util') class TestUtil(unittest_toolbox.Modified_TestCase): diff --git a/tuf/tests/unittest_toolbox.py b/tuf/tests/unittest_toolbox.py index 5c8b54ff..673c8ceb 100755 --- a/tuf/tests/unittest_toolbox.py +++ b/tuf/tests/unittest_toolbox.py @@ -158,11 +158,6 @@ def setUp(self): def tearDown(self): - # Removing 'tuf.log' file from current working directory. - tuf_log_path = os.path.join(os.getcwd(), 'tuf.log') - if os.path.exists(tuf_log_path): - os.unlink(tuf_log_path) - for cleanup_function in self._cleanup: # Perform clean up by executing clean-up functions. try: diff --git a/tuf/util.py b/tuf/util.py index c1a114a9..6651cb85 100755 --- a/tuf/util.py +++ b/tuf/util.py @@ -27,6 +27,7 @@ import logging import tempfile +import tuf import tuf.hash import tuf.conf import tuf.formats