def test_run_actions_with_one_act(self): # Call the executor and test it out actor = group.Sync('Unit Test Action', {'acts': [dict(self.actor_returns)]}) res = yield actor._run_actions() self.assertEquals(res, None)
def test_run_actions_with_two_acts_one_fails_recoverable(self): # Call the executor and test it out actor = group.Sync( 'Unit Test Action', { 'acts': [ dict(self.actor_returns), dict(self.actor_raises_recoverable_exception) ] }) with self.assertRaises(exceptions.RecoverableActorFailure): yield actor._run_actions()
def test_run_actions_with_two_acts_one_fails_unrecoverable(self): # Call the executor and test it out self.actor_returns['options']['value'] = '123' actor = group.Sync( 'Unit Test Action', { 'acts': [ dict(self.actor_raises_unrecoverable_exception), dict(self.actor_returns), ] }) with self.assertRaises(exceptions.UnrecoverableActorFailure): yield actor._run_actions() # If the second actor gets executed this value would be 123. self.assertEquals(TestActor.last_value, None)
def test_run_actions_continue_on_dry(self): # Call the executor and test it out self.actor_returns['options']['value'] = '123' actor = group.Sync('Unit Test Action', { 'acts': [ dict(self.actor_raises_unrecoverable_exception), dict(self.actor_returns), ] }, dry=True) with self.assertRaises(exceptions.UnrecoverableActorFailure): yield actor._run_actions() # Even after the first actor fails, the second one should get executed. self.assertEquals(TestActor.last_value, '123')
def __init__(self, *args, **kwargs): """Pre-parse the script file and compile actors. Note, we override the default init_tokens={} from the base class and default it to a _copy_ of the os.environ dict. """ super(Macro, self).__init__(*args, **kwargs) # Temporary check that macro is a local file. self._check_macro() self.log.info('Preparing actors from %s' % self.option('macro')) # Take the "init tokens" that were supplied to this actor by its parent # and merge them with the explicitly defined tokens in the actor # definition itself. Give priority to the explicitly defined tokens on # any conflicts. self._init_tokens.update(self.option('tokens')) # Copy the tmp file / download a remote macro macro_file = self._get_macro() # Parse script, and insert tokens. config = self._get_config_from_script(macro_file) # Check schema for compatibility self._check_schema(config) # Instantiate the first actor, but don't execute it. # Any errors raised by this actor should be attributed to it, and not # this Macro actor. No try/catch here if type(config) == list: # List is a Sync group actor self.initial_actor = group.Sync(options={'acts': config}, dry=self._dry) else: # After the schema has been checked, pass in whatever tokens _we_ # got, off to the soon-to-be-created actor. config['init_tokens'] = self._init_tokens.copy() self.initial_actor = actor_utils.get_actor(config, dry=self._dry)
def test_run_actions_with_no_acts(self): # Call the executor and test it out actor = group.Sync('Unit Test Action', {'acts': []}) res = yield actor._run_actions() self.assertEqual(res, None)