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_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_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"])
def test_resolve_all(self): """Test variable resolution in resolve_all()""" srv = Service('svc1') srv.add_var('label', "I am a service") srv.fromdict({ 'desc': "%label", 'actions': { 'start': { 'cmd': 'service foo %ACTION' }, } }) srv.resolve_all() self.assertEqual(srv.desc, "I am a service") self.assertEqual(srv._actions['start'].command, "service foo start")
def test_resolve_all(self): """Test variable resolution in resolve_all()""" srv = Service('svc1') srv.add_var('label', "I am a service") srv.fromdict({ 'desc': "%label", 'actions': { 'start': { 'cmd': 'service foo %ACTION' }, } }) srv.resolve_all() self.assertEqual(srv.desc, "I am a service") self.assertEqual(srv._actions['start'].command, "service foo start")
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).decode(), action.worker.node_buffer('localhost').decode() ] self.assertTrue(outputs == ["%s 0" % HOSTNAME, "localhost 1"] or outputs == ["%s 1" % HOSTNAME, "localhost 0"])