From a690e9739aa91c1115b6417386f1025ca1176adc Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Fri, 21 Nov 2014 11:03:02 -0500 Subject: [PATCH 1/3] Import a required module 'softwareupdater.py' raises an exception when it tries to update its local time via NTP during an update. The message logged is '[do_rsync] Unable to update ntp time. Not updating', however, updating the time via NTP was found to be functioning correctly. After some tracing and troubleshooting, the root cause of the NTP exception was found to be an import issue: 'global name 'time_updatetime' is not defined'. It appears 'softwareupdater.py' has not been importing a required 'time.r2py' module. It is unclear how this module has been working correctly until now. (perhaps repy2 changed the way imports are handled?) In addition to issues with exception handling, the softwareupdater.py unit tests produce diffrent results after every invocation (temp files are not properly removed, processes killed, etc?) --- softwareupdater.py | 1 + 1 file changed, 1 insertion(+) diff --git a/softwareupdater.py b/softwareupdater.py index 8fec6c3..6f7a34d 100644 --- a/softwareupdater.py +++ b/softwareupdater.py @@ -54,6 +54,7 @@ dy_import_module_symbols("signeddata.r2py") dy_import_module_symbols("sha.r2py") +dy_import_module_symbols("time.r2py") # Armon: The port that should be used to update our time using NTP TIME_PORT = 51234 From 4185620ed6504a16845e747845b75198ba44cb50 Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Mon, 24 Nov 2014 10:52:46 -0500 Subject: [PATCH 2/3] Use dy_import_module() to avoid name clashes and add header block to softwareupdater.py --- softwareupdater.py | 59 ++++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 23 deletions(-) diff --git a/softwareupdater.py b/softwareupdater.py index 6f7a34d..5489bd2 100644 --- a/softwareupdater.py +++ b/softwareupdater.py @@ -1,22 +1,24 @@ -""" -Author: Justin Cappos - -Start Date: August 4, 2008 - -Description: -A software updater for the node manager. The focus is to make it secure, -robust, and simple (in that order). - -Usage: ./softwareupdater.py - +""" + + softwareupdater.py -Updated 1/23/2009 use servicelogger to log errors - Xuanhua (Sean)s Ren + + August 4, 2008. + + Updated January 23, 2009. + Use servicelogger to log errors - Xuanhua (Sean)s Ren + + Justin Cappos. + + A software updater for the node manager. The focus is to make it secure, + robust, and simple (in that order). + + Usage: ./softwareupdater.py """ - import sys import os @@ -30,9 +32,10 @@ import daemon - -# this is being done so that the resources accounting doesn't interfere with logging +# This is being done so that the resources accounting doesn't interfere with +# logging. from repyportability import * + _context = locals() add_dy_support(_context) @@ -51,6 +54,14 @@ # Import servicelogger to do logging import servicelogger +# VLAD: Use dy_import_module(). Previous import statements used +# dy_import_module_symbols() and imported all of the module's names into +# the local namespace, which can potentially lead to name clashes. It also +# decreased readability because a function's origin was not apparent. +signeddata = dy_import_module('signeddata.r2py') +sha = dy_import_module('sha.r2py') +time = dy_import_module('time.r2py') + dy_import_module_symbols("signeddata.r2py") dy_import_module_symbols("sha.r2py") @@ -152,7 +163,7 @@ def get_file_hash(filename): filedata = fileobj.read() fileobj.close() - return sha_hexhash(filedata) + return sha.sha_hexhash(filedata) @@ -296,7 +307,8 @@ def do_rsync(serverpath, destdir, tempdir): newmetafileobject.close() # Incorrectly signed, we don't update... - if not signeddata_issignedcorrectly(newmetafiledata, softwareupdatepublickey): + if not signeddata.signeddata_issignedcorrectly(newmetafiledata, + softwareupdatepublickey): safe_log("[do_rsync] New metainfo not signed correctly. Not updating.") return [] @@ -312,10 +324,10 @@ def do_rsync(serverpath, destdir, tempdir): else: try: # Armon: Update our time via NTP, before we check the meta info - time_updatetime(TIME_PORT) + time.time_updatetime(TIME_PORT) except Exception: try: - time_updatetime(TIME_PORT_2) + time.time_updatetime(TIME_PORT_2) except Exception: # Steven: Sometimes we can't successfully update our time, so this is # better than generating a traceback. @@ -323,8 +335,9 @@ def do_rsync(serverpath, destdir, tempdir): return [] # they're both good. Let's compare them... - shoulduse, reasons = signeddata_shouldtrust(oldmetafiledata,newmetafiledata,softwareupdatepublickey) - + shoulduse, reasons = \ + signeddata.signeddata_shouldtrust(oldmetafiledata, newmetafiledata, + softwareupdatepublickey) if shoulduse == True: # great! All is well... pass @@ -351,13 +364,13 @@ def do_rsync(serverpath, destdir, tempdir): # we should distrust. - Brent reasons.remove('Public keys do not match') for comment in reasons: - if comment in signeddata_fatal_comments: + if comment in signeddata.signeddata_fatal_comments: # If there is a different fatal comment still there, still log it # and don't perform the update. safe_log("[do_rsync] Serious problem with signed metainfo: " + str(reasons)) return [] - if comment in signeddata_warning_comments: + if comment in signeddata.signeddata_warning_comments: # If there is a different warning comment still there, log the # warning. We will take care of specific behavior shortly. safe_log("[do_rsync] " + str(comment)) From 05a99516e3a50313b6dbdb346c6b1f71f3d5e7ef Mon Sep 17 00:00:00 2001 From: Vladimir Diaz Date: Mon, 24 Nov 2014 13:18:39 -0500 Subject: [PATCH 3/3] Remove the obsolete dy_import_module_symbols() calls --- softwareupdater.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/softwareupdater.py b/softwareupdater.py index 5489bd2..44bfb73 100644 --- a/softwareupdater.py +++ b/softwareupdater.py @@ -62,11 +62,6 @@ sha = dy_import_module('sha.r2py') time = dy_import_module('time.r2py') - -dy_import_module_symbols("signeddata.r2py") -dy_import_module_symbols("sha.r2py") -dy_import_module_symbols("time.r2py") - # Armon: The port that should be used to update our time using NTP TIME_PORT = 51234 TIME_PORT_2 = 42345