Failure(), when constructed with no arguments, automatically grabs the "current" exception and traceback.
[4] I recommend separating _respond_failure into two different functions, one for handling failure instances and another for handling string messages.
[5] In the places where you invoke getProcessValue, I think you'll still need to provide an environment in case the script relies on basic things like PATH, etc. It should be reasonable to just pass through os.environ like you do for the getProcessOutputAndValue call.
[1] + def run_parts( script_ dir):
You have an inner run_parts method that doesn't need to exist; you can just inline the code.
[2] + def _respond_ failure( self, failure, opid):
You should use landscape. lib.log. log_failure here to log the failure.
[3] _format_exception and the following code at the end of handle_ change_ ha_service is unnecessary:
+ except Exception, e: failure( self._format_ exception( e), opid)
+ self._respond_
Instead, do
except: _respond_ failure( Failure( ), opid)
self.
Failure(), when constructed with no arguments, automatically grabs the "current" exception and traceback.
[4] I recommend separating _respond_failure into two different functions, one for handling failure instances and another for handling string messages.
[5] In the places where you invoke getProcessValue, I think you'll still need to provide an environment in case the script relies on basic things like PATH, etc. It should be reasonable to just pass through os.environ like you do for the getProcessOutpu tAndValue call.
[6]
+ def validate_ exit_code( code, script): tError( script, code))
+ if code != 0:
+ return fail(CharmScrip
+ else:
+ return succeed("%s succeeded." % script)
This could be rewritten a bit nicer as
if code != 0: r(script, code)
raise CharmScriptErro
else:
return "%s succeeded." % script
[7] Same for parse_output.