def test_prepare_group_subservices(self): '''Test prepare group with multiple internal dependencies.''' group = ServiceGroup('GROUP') ac_suc1 = Action('start', command='/bin/true') ac_suc2 = Action('start', command='/bin/true') ac_suc3 = Action('start', command='/bin/true') subserv_a = Service('SUB1') subserv_b = Service('SUB2') subserv_c = Service('SUB3') subserv_a.add_action(ac_suc1) subserv_b.add_action(ac_suc2) subserv_c.add_action(ac_suc3) group.add_inter_dep(target=subserv_a) group.add_inter_dep(target=subserv_b) group.add_inter_dep(base=subserv_a, target=subserv_c) group.add_inter_dep(base=subserv_b, target=subserv_c) group.run('start') self.assertEqual(group.status, DONE) self.assertEqual(subserv_a.status, DONE) self.assertEqual(subserv_b.status, DONE) self.assertEqual(subserv_c.status, DONE)
def test_create_action1(self): '''Test instanciation of an Action through a dictionnary''' act = Action('start') act.fromdict({ 'target': 'localhost', 'fanout': 4, 'retry': 5, 'delay': 2, 'errors': 3, 'timeout': 4, 'cmd': '/bin/True', 'desc': 'my desc', 'mode': 'delegate', }) self.assertTrue(act) self.assertEqual(act.name, 'start') self.assertEqual(act.target, NodeSet('localhost')) self.assertEqual(act.fanout, 4) self.assertEqual(act.maxretry, 5) self.assertEqual(act.errors, 3) self.assertEqual(act.delay, 2) self.assertEqual(act.timeout, 4) self.assertEqual(act.command, '/bin/True') self.assertEqual(act.desc, 'my desc') self.assertEqual(act.mode, 'delegate')
def test_create_action1(self): """Test instanciation of an Action through a dictionnary""" act = Action("start") act.fromdict( { "target": "localhost", "fanout": 4, "retry": 5, "delay": 2, "errors": 3, "timeout": 4, "cmd": "/bin/True", "desc": "my desc", "mode": "delegate", } ) self.assertTrue(act) self.assertEqual(act.name, "start") self.assertEqual(act.target, NodeSet("localhost")) self.assertEqual(act.fanout, 4) self.assertEqual(act.maxretry, 5) self.assertEqual(act.errors, 3) self.assertEqual(act.delay, 2) self.assertEqual(act.timeout, 4) self.assertEqual(act.command, "/bin/True") self.assertEqual(act.desc, "my desc") self.assertEqual(act.mode, "delegate")
def test_prepare_with_multiple_require_errors(self): """Test multiple require dependencies errors at different levels.""" serv_base_error = Service('A') serv_ok_warnings = Service('B') serv_error = Service('C') serv_timeout = Service('D') ac_suc = Action(name='start', command='/bin/true') ac_suc2 = Action(name='start', command='/bin/true') ac_suc3 = Action(name='start', command='/bin/true') ac_tim = Action(name='start', command='sleep 3', timeout=0.3) serv_base_error.add_action(ac_suc) serv_ok_warnings.add_action(ac_suc2) serv_error.add_action(ac_suc3) serv_timeout.add_action(ac_tim) serv_base_error.add_dep(serv_ok_warnings) serv_base_error.add_dep(serv_error) serv_ok_warnings.add_dep(serv_timeout, REQUIRE_WEAK) serv_error.add_dep(serv_timeout) serv_base_error.run('start') self.assertEqual(serv_base_error.status, DEP_ERROR) self.assertEqual(serv_ok_warnings.status, DONE) self.assertEqual(serv_error.status, DEP_ERROR) self.assertEqual(serv_timeout.status, TIMEOUT)
def test_prepare_errors_same_level(self): """Test prepare behaviour with two errors at the same level""" serv = Service('BASE') serv_a = Service('DEP_A') serv_b = Service('DEP_B') serv_c = Service('DEP_C') ac_suc = Action(name='start', command='/bin/true') ac_suc2 = Action(name='start', command='/bin/true') ac_err = Action(name='start', command='/bin/false') ac_err2 = Action(name='start', command='dlvlfvlf') serv.add_action(ac_suc) serv_a.add_action(ac_suc2) serv_b.add_action(ac_err) serv_c.add_action(ac_err2) serv.add_dep(serv_a) serv_a.add_dep(serv_b) serv_a.add_dep(serv_c) serv.run('start') self.assertEqual(serv.status, DEP_ERROR) self.assertEqual(serv_a.status, DEP_ERROR) self.assertEqual(serv_b.status, ERROR) self.assertEqual(serv_c.status, ERROR)
def test_prepare_multiple_delay(self): '''Test prepare with dependencies and multiple delays''' serv = Service('BASE_DELAYED') serv_a = Service('A_NOT_DELAYED') serv_b = Service('B_DELAYED') serv_c = Service('C_DELAYED') act_a = Action(name='start', command='/bin/true') act_serv = Action(name='start', command='/bin/true', delay=0.3) act_b = Action(name='start', command='/bin/true', delay=0.3) act_c = Action(name='start', command='/bin/true', delay=0.5) serv.add_action(act_serv) serv_a.add_action(act_a) serv_b.add_action(act_b) serv_c.add_action(act_c) serv.add_dep(serv_a) serv.add_dep(serv_b) serv_a.add_dep(serv_c) serv_b.add_dep(serv_c) serv.run('start') self.assertEqual(serv.status, DONE) self.assert_near(0.3, 0.2, act_serv.duration) self.assertEqual(serv_a.status, DONE) self.assert_near(0.0, 0.2, act_a.duration) self.assertEqual(serv_b.status, DONE) self.assert_near(0.3, 0.2, act_b.duration) self.assertEqual(serv_c.status, DONE) self.assert_near(0.5, 0.2, act_c.duration)
def test_missing_action(self): """Test prepare with service with missing action is ok""" # Graph leaf has no 'status' action s1 = Service("1") s1.add_action(Action('start', command='/bin/true')) s1.add_action(Action('status', command='/bin/true')) s2 = Service("2") s2.add_action(Action('start', command='/bin/true')) s2.add_dep(s1) s2.run('status') self.assertEqual(s1.status, DONE) self.assertEqual(s2.status, MISSING) s1.reset() s2.reset() self.assertEqual(s1.status, NO_STATUS) self.assertEqual(s2.status, NO_STATUS) # 'status' action is propagated to leaf even if '2' has not the # requested action. s3 = Service("3") s3.add_action(Action('start', command='/bin/true')) s3.add_action(Action('status', command='/bin/true')) s3.add_dep(s2) s3.run('status') self.assertEqual(s1.status, DONE) self.assertEqual(s2.status, MISSING) self.assertEqual(s3.status, DONE)
def test_create_action1(self): '''Test instanciation of an Action through a dictionnary''' act = Action('start') act.fromdict( { 'target': 'localhost', 'fanout': 4, 'retry': 5, 'delay': 2, 'errors': 3, 'timeout': 4, 'cmd': '/bin/True', 'desc': 'my desc', 'mode': 'delegate', } ) self.assertTrue(act) self.assertEqual(act.name, 'start') self.assertEqual(act.target, NodeSet('localhost')) self.assertEqual(act.fanout, 4) self.assertEqual(act.maxretry, 5) self.assertEqual(act.errors, 3) self.assertEqual(act.delay, 2) self.assertEqual(act.timeout, 4) self.assertEqual(act.command, '/bin/True') self.assertEqual(act.desc, 'my desc') self.assertEqual(act.mode, 'delegate')
def setUp(self): ''' Set up the graph of services within the service manager Graph _ start group --> service / `- stop ''' CLICommon.setUp(self) # ServiceGroup group = ServiceGroup('ServiceGroup') # Service self.service = service = Service('service') service.desc = 'I am the service' # Actions self.start_action = Action('start', command='/bin/true') self.stop_action = Action('stop', command='/bin/false') self.timeout_action = Action('timeout', command='sleep 1', timeout=0.1) self.start_action.inherits_from(service) self.stop_action.inherits_from(service) service.add_action(self.start_action) service.add_action(self.stop_action) service.add_action(self.timeout_action) # Build graph group.add_inter_dep(target=service) # Register services within the manager self.manager.add_service(group)
def test_local_variables(self): """Test Action local variables""" action = Action("bar") self.assertEqual(action._resolve("I'm %ACTION"), "I'm bar") svc = Service("foo") svc.add_action(action) self.assertEqual(action._resolve("I'm %SERVICE.%ACTION"), "I'm foo.bar")
def test_local_variables(self): '''Test Action local variables''' action = Action('bar') self.assertEqual(action._resolve("I'm %ACTION"), "I'm bar") svc = Service('foo') svc.add_action(action) self.assertEqual(action._resolve("I'm %SERVICE.%ACTION"), "I'm foo.bar")
def test_nb_errors_remote2(self): """Test the method nb_errors() with no error (remote).""" action = Action(name="test", target=HOSTNAME, command="/bin/true") service = Service("test_service") service.add_action(action) service.run("test") self.assertEqual(action.nb_errors(), 0) self.assertEqual(action.status, DONE)
def test_nb_timeout_remote(self): """Test nb_timeout() method (remote mode)""" action = Action(name="start", target=HOSTNAME, command="sleep 3", timeout=0.5) service = Service("test_service") service.add_action(action) service.run("start") self.assertEqual(action.nb_timeout(), 1) self.assertEqual(action.status, TIMEOUT)
def test_add_action(self): """Test add_action's behaviour.""" service = Service('brutus') service.add_action(Action('start')) self.assertTrue(service.has_action('start')) self.assertRaises(ActionAlreadyReferencedError, service.add_action, Action('start')) self.assertRaises(TypeError, service.add_action, None)
def test_action_with_variables(self): """Test variables in action command""" cmd = 'echo %([ "%VAR1" != "" ] && echo "-x %VAR1")' action = Action("start", command=cmd) service = Service("TEST") service.add_actions(action) service.add_var("VAR1", "foo") action.run() self.assertEqual(action.worker.command, "echo -x foo")
def test_nb_errors_remote2(self): """Test the method nb_errors() with no error (remote).""" action = Action(name='test', target=HOSTNAME, command='/bin/true') service = Service('test_service') service.add_action(action) service.run('test') self.assertEqual(action.nodes_error(), NodeSet()) self.assertEqual(action.nb_errors(), 0) self.assertEqual(action.status, DONE)
def test_nb_timeout_local(self): """Test nb_timeout() method (local)""" action = Action(name="start", command="sleep 3", timeout=0.3) service = Service("test_service") service.add_action(action) service.run("start") self.assertEqual(action.nb_errors(), 0) self.assertEqual(action.nb_timeout(), 1) self.assertEqual(action.status, TIMEOUT)
def test_nb_errors_remote(self): """Test the method nb_errors() (remote).""" action = Action(name="start", target="aury[12,13,21]", command="/bin/false") action.errors = 2 service = Service("test_service") service.add_action(action) service.run("start") self.assertEqual(action.nb_errors(), 3) self.assertEqual(action.status, ERROR)
def setUp(self): ''' Set up the graph of services within the service manager Graph __ S2 __ I1 S1 / -- G1 -- (src) / ^ -- (sink) `-- S3 --/ `-- I2 Each node has an action start and an action stop ''' CLICommon.setUp(self) svc1 = Service('S1') svc1.desc = 'I am the service S1' self.svc2 = svc2 = Service('S2') svc2.desc = 'I am the service S2' svc3 = Service('S3') svc3.desc = 'I am the service S3' group1 = ServiceGroup('G1') inter1 = Service('I1') inter1.desc = 'I am the service I1' inter2 = Service('I2') inter2.desc = 'I am the service I2' # Actions S1 start_svc1 = Action('start', HOSTNAME + ', BADNODE', '/bin/true') start_svc1.delay = 1 stop_svc1 = Action('stop', HOSTNAME + ',BADNODE', '/bin/true') stop_svc1.delay = 1 svc1.add_actions(start_svc1, stop_svc1) # Actions S2 svc2.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/true')) svc2.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/true')) # Actions S3 svc3.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/false')) svc3.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/false')) # Actions I1 inter1.add_action(Action('start', HOSTNAME, 'echo ok')) inter1.add_action(Action('stop', HOSTNAME, 'echo ok')) # Actions I2 inter2.add_action(Action('start', HOSTNAME + ',BADNODE', '/bin/true')) inter2.add_action(Action('stop', HOSTNAME + ',BADNODE', '/bin/true')) # Build graph svc1.add_dep(target=svc2) svc1.add_dep(target=svc3) svc3.add_dep(target=group1) inter2.add_dep(inter1) group1.add_inter_dep(target=inter1) group1.add_inter_dep(target=inter2) # Register services within the manager self.manager.add_service(svc1) self.manager.add_service(svc2) self.manager.add_service(svc3) self.manager.add_service(group1)
def test_run_skipped(self): """Run a service with empty target is SKIPPED""" svc = Service('test_service') action = Action('start', target="TEMPNODE", command=":") svc.add_action(action) action.update_target("TEMPNODE", 'DIF') svc.run('start') self.assertEqual(action.status, SKIPPED) self.assertEqual(svc.status, SKIPPED)
def test_failed_nodes(self): """failed nodes are backup""" action = Action('start', command='/bin/false', target=HOSTNAME) service = Service('test') service.add_actions(action) action.run() self.assertEqual(action.failed_nodes, NodeSet(HOSTNAME)) self.assertEqual(action.status, ERROR) # This is propagated to action service self.assertEqual(service.failed_nodes, action.failed_nodes)
def test_action_with_variables(self): """Test variables in action command""" cmd = 'echo %([ "%VAR1" != "" ] && echo "-x %VAR1")' action = Action('start', command=cmd) service = Service('TEST') service.add_actions(action) service.add_var('VAR1', 'foo') service.resolve_all() action.run() self.assertEqual(action.worker.command, 'echo -x foo')
def test_command_output_warning_status(self): '''Test command line output with one action WARNING''' svc = Service('warn') act = Action('go', command='/bin/false') act.errors = 1 svc.add_action(act) self.manager.register_service(svc) self._output_check(['warn', 'go', '-q'], RC_WARNING, """warn [ WARNING ] """)
def test_add_actions(self): """Test the possibility to add multiple actions at the same time""" service = Service('SERV') act_a = Action('start', command='/bin/true') act_b = Action('stop', command='/bin/true') act_c = Action('status', command='/bin/true') service.add_actions(act_a, act_b, act_c) self.assertTrue(service.has_action('start')) self.assertTrue(service.has_action('stop')) self.assertTrue(service.has_action('status'))
def test_nb_timeout_remote(self): """Test nb_timeout() method (remote mode)""" action = Action(name='start', target=HOSTNAME, command='sleep 3', timeout=0.5) service = Service('test_service') service.add_action(action) service.run('start') self.assertEqual(action.nodes_timeout(), NodeSet(HOSTNAME)) self.assertEqual(action.nb_timeout(), 1) self.assertEqual(action.status, TIMEOUT)
def setUp(self): ''' Set up the graph of services within the service manager Graph _ start group --> service / `- stop ''' CLICommon.setUp(self) # ServiceGroup group = ServiceGroup('ServiceGroup') # Service self.service = service = Service('service') service.desc = 'I am the service' # Actions start_action = Action('start', command='/bin/true') stop_action = Action('stop', command='/bin/false') self.timeout_action = Action('timeout', command='sleep 1', timeout=0.1) start_action.inherits_from(service) stop_action.inherits_from(service) service.add_action(start_action) service.add_action(stop_action) service.add_action(self.timeout_action) # Build graph group.add_inter_dep(target=service) # Register services within the manager self.manager.register_services(group, service)
def test_retry_error(self): """Test retry behaviour when errors""" action = Action("start", command="/bin/false") action.delay = 0.1 action.maxretry = 3 service = Service("retry") service.add_action(action) service.run("start") self.assertEqual(action.tries, 4) self.assertEqual(action.status, ERROR) self.assertTrue(0.3 < action.duration < 0.5, "%.3f is not between 0.3 and 0.5" % action.duration)
def test_retry_timeout(self): """Test retry behaviour when timeout""" action = Action("start", command="/bin/sleep 0.5", timeout=0.1) action.delay = 0.1 action.maxretry = 2 service = Service("retry") service.add_action(action) service.run("start") self.assertEqual(action.tries, 3) self.assertEqual(action.status, TIMEOUT) self.assertTrue(0.6 < action.duration < 0.8, "%.3f is not between 0.6 and 0.8" % action.duration)
def test_nb_timeout_local(self): """Test nb_timeout() method (local)""" action = Action(name='start', command='sleep 3', timeout=0.3) service = Service('test_service') service.add_action(action) service.run('start') self.assertEqual(action.nodes_error(), NodeSet()) self.assertEqual(action.nb_errors(), 0) self.assertEqual(action.nodes_timeout(), NodeSet("localhost")) self.assertEqual(action.nb_timeout(), 1) self.assertEqual(action.status, TIMEOUT)
def test_skipped_group(self): """A group with only SKIPPED services should be SKIPPED""" grp = ServiceGroup('group') svc1 = Service('svc1') svc1.add_action(Action('start', target="@NOTHING", command=':')) svc2 = Service('svc2') svc2.add_action(Action('start', target="@NOTHING", command=':')) grp.add_inter_dep(target=svc1) grp.add_inter_dep(target=svc2) grp.run('start') self.assertEqual(grp.status, SKIPPED)
def test_nb_errors_remote(self): """Test the method nb_errors() (remote).""" action = Action(name='start', target='badname[12,13,21]', command='/bin/false') action.errors = 2 service = Service('test_service') service.add_action(action) service.run('start') self.assertEqual(action.nodes_error(), NodeSet("badname[12,13,21]")) self.assertEqual(action.nb_errors(), 3) self.assertEqual(action.status, ERROR)
def test_run_action_with_failed_subaction(self): """Test action running a failed sub action (start->status)""" serv = Service('BASE') act_start = Action('start', command='/bin/true') act_status_fail = Action('status', command='/bin/false') act_start.add_dep(target=act_status_fail) serv.add_actions(act_start, act_status_fail) serv.run('start') self.assertEqual(serv.status, DONE) self.assertTrue(act_start.duration) self.assertTrue(act_status_fail.duration)
def test_inheritance(self): '''Test inheritance between action and services''' ser1 = Service('parent') ser1.target = '127.0.0.1' ser2 = Service('inherited') ser2.add_action(Action('start')) ser2.add_action(Action('stop', "foo")) ser2.inherits_from(ser1) self.assertEqual(ser2.target, NodeSet('127.0.0.1')) self.assertEqual(ser2._actions['start'].target, NodeSet('127.0.0.1')) self.assertEqual(ser2._actions['stop'].target, NodeSet("foo"))
def test_prepare_dep_success(self): """Test prepare an action with a single successful dependency""" a1 = Action("start", command="/bin/true") a2 = Action("status", command="/bin/true") ser = Service("TEST") a1.add_dep(a2) ser.add_actions(a1, a2) a1.run() self.assertEqual(a1.status, DONE) self.assertFalse(a1.duration) self.assertEqual(a2.status, DONE) self.assertTrue(a2.duration)
def test_retry_timeout(self): """Test retry behaviour when timeout""" action = Action('start', command='/bin/sleep 0.5', timeout=0.1) action.delay = 0.1 action.maxretry = 2 service = Service('retry') service.add_action(action) service.run('start') self.assertEqual(action.tries, 3) self.assertEqual(action.status, TIMEOUT) self.assertTrue(0.59 <= action.duration <= 0.8, "%.3f is not between 0.59 and 0.8" % action.duration)
def test_prepare_dep_failed(self): """Test prepare an action with a single failed dependency""" a1 = Action('start', command='/bin/true') a2 = Action('status', command='/bin/false') ser = Service('TEST') a1.add_dep(a2) ser.add_actions(a1, a2) a1.run() self.assertEqual(a1.status, DONE) self.assertTrue(a1.duration) self.assertEqual(a2.status, ERROR) self.assertTrue(a2.duration)
def test_retry_error(self): """Test retry behaviour when errors""" action = Action('start', command='/bin/false') action.delay = 0.1 action.maxretry = 3 service = Service('retry') service.add_action(action) service.run('start') self.assertEqual(action.tries, 4) self.assertEqual(action.status, ERROR) self.assertTrue(0.3 < action.duration < 0.5, "%.3f is not between 0.3 and 0.5" % action.duration)
def test_filter_dep_one_error(self): """error nodes are propagated along 'filter' dependencies""" svc1 = Service('first') svc1.add_action(Action('start', command='false', target=HOSTNAME)) svc2 = Service('second') svc2.add_action(Action('start', command='true', target=HOSTNAME)) svc2.add_dep(svc1, sgth=FILTER) svc2.run('start') self.assertEqual(svc1.status, ERROR) self.assertEqual(svc2.status, SKIPPED)
def test_action_instanciation(self): """Test instanciation of an action.""" action = Action('start') self.assertNotEqual(action, None) self.assertEqual(action.name, 'start') action = Action(name='start', target=HOSTNAME, command='/bin/true') self.assertEqual(action.target, NodeSet(HOSTNAME)) self.assertEqual(action.command, '/bin/true') action = Action(name='start', command='/bin/true', timeout=10, delay=5) self.assertEqual(action.timeout, 10) self.assertEqual(action.delay, 5)
def test_call_services_reversed(self): '''Test service_manager with custom reversed actions''' manager = service_manager_self() s1 = Service('S1') s2 = Service('S2') s1.add_action(Action('wait', command='/bin/true')) s2.add_action(Action('wait', command='/bin/true')) s1.add_dep(s2) manager.register_services(s1, s2) manager.call_services(['S1'], 'wait', conf={"reverse_actions": ['wait']}) self.assertTrue(s1._algo_reversed) self.assertTrue(s2._algo_reversed)
def test_filter_dep_no_error(self): """test FILTER dependency without error""" svc1 = Service('first') svc1.add_action(Action('start', command='/bin/true', target=HOSTNAME)) svc2 = Service('second') svc2.add_action(Action('start', command='/bin/true', target=HOSTNAME)) svc2.add_dep(svc1, sgth=FILTER) svc2.run('start') self.assertEqual(svc1.status, DONE) self.assertEqual(svc2.status, DONE)
def test_reset_service(self): '''Test resest values of a service''' service = Service('brutus') action = Action('start') service.origin = True action.status = DONE service.add_action(action) service._last_action = 'start' service.reset() self.assertFalse(service.origin) self.assertFalse(service._last_action) self.assertEqual(action.status, NO_STATUS) self.assertEqual(service.status, NO_STATUS)
def test_filter_mix_no_target(self): """service without target do not filter service with target""" svc1 = Service('top') svc1.add_action(Action('start', command='false')) svc2 = Service('bottom') svc2.add_action(Action('start', command='true', target='localhost')) svc2.add_dep(svc1, sgth=FILTER) svc2.run('start') self.assertEqual(svc1.status, ERROR) self.assertEqual(svc2.status, DONE)
def test_add_task_weird_values(self): """Test the method add task with task without fanout""" task_manager = action_manager_self() task1 = Action('start') task1.fanout = 60 task2 = Action('stop') task3 = Action('status') task3.fanout = 50 task_manager.add_task(task1) task_manager.add_task(task2) task_manager.add_task(task3) self.assertEqual(task_manager.fanout, 50) self.assertEqual(task_manager.tasks_count, 3)
def test_resolve_all(self): """resolve_all() resolves in all Action properties""" act = Action('start') act.fromdict({ 'variables': { 'label': 'Start action', }, 'desc': "%label", 'cmd': 'service foo %ACTION' }) act.resolve_all() self.assertEqual(act.desc, "Start action") self.assertEqual(act.command, "service foo start")
def test_remove_task(self): """Test the behaviour of the remove_task method""" task_manager = action_manager_self() task1 = Action('start') task1.fanout = 260 task2 = Action('stop') task2.fanout = 85 task3 = Action('status') task3.fanout = 85 task4 = Action('check') task4.fanout = 148 task_manager.add_task(task1) task_manager.add_task(task2) task_manager.add_task(task3) task_manager.add_task(task4) task_manager.remove_task(task2) self.assertEqual(task_manager.fanout, 85) task_manager.remove_task(task3) self.assertEqual(task_manager.fanout, 148) task_manager.remove_task(task4) self.assertEqual(task_manager.fanout, 260) task_manager.remove_task(task1) self.assertFalse(task_manager.fanout) self.assertEqual(task_manager.tasks_count, 0) self.assertEqual(task_manager.tasks_done_count, 4)
def test_filter_dep_timeout(self): """timeout nodes are propagated along 'filter' dependencies""" svc1 = Service('first') svc1.add_action( Action('start', command='sleep 1', target=HOSTNAME, timeout=0.1)) svc2 = Service('second') svc2.add_action(Action('start', command='true', target=HOSTNAME)) svc2.add_dep(svc1, sgth=FILTER) svc2.run('start') self.assertEqual(svc1.status, TIMEOUT) self.assertEqual(svc2.status, SKIPPED)
def test_filter_dep_error_propagation(self): """error nodes are propagated along 'filter' dependencies (one node)""" svc1 = Service('first') tgt = '%s,fakenode' % HOSTNAME svc1.add_action(Action('start', command='true', target=tgt)) svc2 = Service('second') svc2.add_action(Action('start', command='true', target=HOSTNAME)) svc2.add_dep(svc1, sgth=FILTER) svc2.run('start') self.assertEqual(svc1.status, ERROR) self.assertEqual(svc2.status, DONE)
def test_exec_mode(self): """Test exec mode""" action = Action(name='start', command='echo %%h %%rank', target='%s,localhost' % HOSTNAME) action.mode = 'exec' svc = Service('test') svc.add_action(action) svc.resolve_all() svc.run('start') # Need 2 checks because we do not know which target will be used first outputs = [action.worker.node_buffer(HOSTNAME), action.worker.node_buffer('localhost')] self.assertTrue(outputs == ["%s 0" % HOSTNAME, "localhost 1"] or outputs == ["%s 1" % HOSTNAME, "localhost 0"])