def test_executionplan(): from paradrop.core.plan import executionplan as excplan from paradrop.core.plan import struct update = Mock() # Simulate a module that fails during the generatePlans step. badModule = Mock() badModule.generatePlans = Mock(return_value=True) update.updateModuleList = [badModule] assert excplan.generatePlans(update) # This one should succeed. update.updateModuleList = [struct] assert excplan.generatePlans(update) is None excplan.aggregatePlans(update) # Make a list of dummy functions to run plans = list() plans.append((do_nothing, ("data",))) plans.append((make_dummy(do_nothing), ("data",))) plans.append((do_nothing, ("skipped",))) plans.append(None) # Popping None will end the loop. plans.reverse() abortPlans = list(plans) # Should return False for success update.plans = Mock() update.plans.getNextTodo = plans.pop update.plans.getNextAbort = abortPlans.pop assert excplan.executePlans(update) is False assert excplan.abortPlans(update) is False # Make a plan with non-callable ("fail" string) to cause an error plans = list() def fail(data): pass plans.append((fail, ("data",))) plans.append((fail, ("data",))) # Need two failures to break abortPlans plans.append(None) # Popping None will end the loop. plans.reverse() abortPlans = list(plans) # Should return True for failure update.plans = Mock() update.plans.getNextTodo = plans.pop update.plans.getNextAbort = abortPlans.pop assert excplan.executePlans(update) assert excplan.abortPlans(update)
def test_docstrings(): update = update_object.UpdateChute({ "updateClass": "CHUTE", "updateType": "create", "name": "test", "tok": 0 }) executionplan.generatePlans(update) executionplan.aggregatePlans(update) for prio, func, abort in update.plans.plans: if func.func.__doc__ is None: raise Exception("{}.{} has no docstring.".format( func.func.__module__, func.func.__name__))
def execute(self): """ The function that actually walks through the main process required to create the chute. It follows the executeplan module through the paces of: 1) Generate the plans for each plan module 2) Prioritize the plans 3) Execute the plans If at any point we fail then this function will directly take care of completing the update process with an error state and will close the API connection. """ if not self.execute_called: # Save a timestamp from when we started execution. self.startTime = time.time() # Generate the plans we need to setup the chute if (executionplan.generatePlans(self)): out.warn('Failed to generate plans\n') self.complete(success=False, message=self.failure) return # Aggregate those plans executionplan.aggregatePlans(self) self.execute_called = True # Execute on those plans exec_result = executionplan.executePlans(self) if isinstance(exec_result, defer.Deferred): return exec_result elif exec_result is True: # Getting here means we need to abort what we did res = executionplan.abortPlans(self) # Did aborting also fail? This is bad! if (res): ################################################################################### # Getting here means the abort system thinks it wasn't able to get the system # back into the state it was in prior to this update. ################################################################################### out.err('TODO: What do we do when we fail during abort?\n') pass # Report the failure back to the user self.complete(success=False, message=self.failure) return # Respond to the API server to let them know the result self.complete(success=True, message='Chute {} {} success'.format( self.name, self.updateType))
""" priomap = dict() for item in dir(plangraph): value = getattr(plangraph, item) if isinstance(value, int): priomap[value] = item return priomap if __name__ == "__main__": priomap = loadPriorityMap() update = UpdateChute({ "updateClass": "CHUTE", "updateType": "create", "name": "test", "tok": 0 }) executionplan.generatePlans(update) executionplan.aggregatePlans(update) for prio, func, abort in update.plans.plans: print("Module: {}".format(func.func.__module__)) print("Function: {}".format(func.func.__name__)) print("Priority: {} ({})".format(priomap[prio], prio)) if func.func.__doc__ is None: print("\n Function has no docstring.\n") else: print(func.func.__doc__)