35 testMaster: ROS integration test cases for master XML-RPC API 37 To run, invoke nodes/testMaster 40 import os, sys, getopt, traceback, logging, socket
41 import datetime, math, random
43 from xmlrpc.client
import DateTime, ServerProxy
45 from xmlrpclib
import DateTime, ServerProxy
49 from testSlave
import msMain
51 MYPKG =
'test_rosmaster' 55 singletest =
'testGetFlowNames' 61 raise Exception(
"name is None")
62 rmachine, raddr, rport = apiSuccess(master.getNodeAddress(callerId, name))
64 assert rmachine == machine,
"Node [%s] is running on '%s' instead of '%s'"%(name, rmachine, machine)
66 assert rport == port,
"Node [%s] is running on '%s' instead of '%s'"%(name, rport, port)
68 assert rport,
"Node [%s] does not have a registered port"%name
70 if addr ==
'localhost':
71 addr = socket.gethostname()
72 if raddr ==
'localhost':
73 raddr = socket.gethostname()
74 addrinfo = socket.getaddrinfo(addr, 0, 0, 0, socket.SOL_TCP)
75 raddrinfo = socket.getaddrinfo(raddr, 0, 0, 0, socket.SOL_TCP)
76 assert raddrinfo == addrinfo,
"%s!=%s" % (raddrinfo, addrinfo)
78 apiSuccess(ServerProxy(
"http://%s:%s/"%(raddr, rport)).getPid(
''))
81 graph = apiSuccess(master.getGraph(
''))
82 diff = set(graph[0]) ^ set(graphNodes)
83 assert not diff,
"Graph nodes %s does not match expected %s: %s"%(graph[0], graphNodes, diff)
85 expectedFlows = [
"%s:%s:1"%f
for f
in graphFlows]
87 remoteFlows = [
"%s:%s:%s"%(src,snk,c)
for (src,snk,c)
in graph[1]]
88 if expectedFlows
or remoteFlows:
90 diff = set(expectedFlows) ^ set(remoteFlows)
91 assert not diff,
"Graph flows %s does not match expected %s: %s"%(expectedFlows, remoteFlows, diff)
95 for (k, v)
in myState.items():
97 assert apiSuccess(master.hasParam(callerId, k))
98 print "verifying parameter %s"%k
99 v2 = apiSuccess(master.getParam(callerId, k))
100 if isinstance(v2, DateTime):
101 assert DateTime(v) == v2,
"[%s]: %s != %s, %s"%(k, v, v2, v2.__class__)
103 assert v == v2,
"[%s]: %s != %s, %s"%(k, v, v2, v2.__class__)
104 paramNames = myState.keys()
105 remoteParamNames = apiSuccess(master.getParamNames(callerId))
106 assert not set(paramNames) ^ set(remoteParamNames),
"parameter server keys do not match local" 109 """Parameter Server API Test Cases""" 112 super(ParamServerTestCase, self).
setUp()
115 super(ParamServerTestCase, self).
tearDown()
118 for type, vals
in testVals:
121 callerId =
"%s.node"%ctx
126 key =
"%s-%s"%(type,count)
127 print "master.setParam(%s,%s,%s)"%(callerId, key, val)
128 master.setParam(callerId, key, val)
130 assert apiSuccess(master.hasParam(callerId, key))
132 trueKey =
"%s.%s"%(ctx, key)
135 myState[trueKey] = val
138 assert "getParam failed on type[%s], val[%s]"%(type,val)
142 """testParamValues: test storage of all XML-RPC compatible types""" 144 from xmlrpc.client
import Binary
146 from xmlrpclib
import Binary
148 [
'int', [0, 1024, 2147483647, -2147483647]],
149 [
'boolean', [
True,
False]],
150 [
'string', [
'',
'\0',
'x',
'hello',
''.join([chr(n)
for n
in range(0, 255)])]],
151 [
'double', [0.0, math.pi, -math.pi, 3.4028235e+38, -3.4028235e+38]],
153 [
'datetime', [datetime.datetime(2005, 12, 6, 12, 13, 14), datetime.datetime(1492, 12, 6, 12, 13, 14)]],
154 [
'base64', [Binary(
''), Binary(
'\0'), Binary(
''.join([chr(n)
for n
in range(0, 255)]))]],
155 [
'struct', [{
"a": 2,
"b": 4},
156 {
"a" :
"b",
"c" :
"d"},
157 {
"a" : {
"b" : {
"c" :
"d"}}}]],
158 [
'array', [[], [1, 2, 3], [
'a',
'b',
'c'], [0.0, 0.1, 0.2, 2.0, 2.1, -4.0],
159 [1,
'a', math.pi], [[1, 2, 3], [
'a',
'b',
'c'], [1.0, 2.1, 3.2]]]
164 print "Putting parameters onto the server" 166 contexts = [
'',
'scope1',
'scope2',
'scope.subscope1',
'scope.sub1.sub2']
171 print "Deleting all of our parameters" 173 paramKeys = myState.keys()
174 for key
in paramKeys:
175 apiSuccess(master.deleteParam(
'', key))
180 """testEncapsulation: test encapsulation: setting same parameter at different levels""" 185 testContexts = [
'',
'en',
'en.sub1',
'en.sub2',
'en.sub1.sub2']
186 for c
in testContexts:
188 testVal = random.randint(-1000000, 100000)
190 callerId =
"%s.node"%c
191 trueKey =
"%s.%s"%(c,testKey)
195 master.setParam(callerId, testKey, testVal)
196 myState[trueKey] = testVal
198 v1 = apiSuccess(master.getParam(
'', trueKey))
199 v2 = apiSuccess(master.getParam(callerId, testKey))
200 assert v1 == v2,
"[%s]: %s vs. [%s,%s]: %s"%(trueKey, v1, callerId, testKey, v2)
202 assert apiSuccess(master.hasParam(callerId, testKey)), testKey
203 assert apiSuccess(master.hasParam(
'node', trueKey)), trueKey
212 testContexts = [
'',
'sub1',
'sub1.sub2',
'sub1.sub2.sub3']
213 for c
in testContexts:
215 callerId =
"%s.node"%c
219 testVal = random.randint(-1000000, 100000)
220 master.setParam(callerId, testKey, testVal)
221 trueKey = callerId+testKey
222 myState[trueKey] = testVal
224 v1 = apiSuccess(master.getParam(
'node', trueKey))
225 v2 = apiSuccess(master.getParam(callerId, testKey))
226 assert v1 == v2,
"[%s]: %s vs. [%s,%s]: %s"%(trueKey, v1, callerId, testKey, v2)
228 assert apiSuccess(master.hasParam(callerId, testKey)), testKey
229 assert apiSuccess(master.hasParam(
'node', trueKey)), trueKey
232 testKey =
"altnode.param2" 233 testVal = random.randint(-1000000, 100000)
234 master.setParam(callerId, testKey, testVal)
236 trueKey =
"%s.%s"%(c,testKey)
237 altCallerId =
"%s.altnode"%c
240 altCallerId =
"altnode" 241 myState[trueKey] = testVal
243 v1 = apiSuccess(master.getParam(altCallerId,
".param2"))
244 v2 = apiSuccess(master.getParam(callerId, testKey))
247 assert apiSuccess(master.hasParam(callerId, testKey)), testKey
248 assert apiSuccess(master.hasParam(altCallerId,
".param2"))
253 """testScopeUp: test that parameter server can chain up scopes to find/delete parameters""" 258 testVal = random.randint(-1000000, 100000)
259 master.setParam(
'',
'uparam1', testVal)
260 myState[
'uparam1'] = testVal
261 assert testVal == apiSuccess(master.getParam(
'node',
'uparam1'))
262 assert testVal == apiSuccess(master.getParam(
'uptest.node',
'uparam1'))
263 assert testVal == apiSuccess(master.getParam(
'uptest.sub1.node',
'uparam1'))
264 assert testVal == apiSuccess(master.getParam(
'uptest.sub1.sub2.node',
'uparam1'))
266 testVal = random.randint(-1000000, 100000)
267 master.setParam(
'uptest2.sub1.node',
'uparam2', testVal)
268 myState[
'uptest2.sub1.uparam2'] = testVal
269 assert testVal == apiSuccess(master.getParam(
'uptest2.sub1.node',
'uparam2'))
270 assert testVal == apiSuccess(master.getParam(
'uptest2.sub1.sub2.node',
'uparam2'))
271 assert testVal == apiSuccess(master.getParam(
'uptest2.sub1.sub2.sub3.node',
'uparam2'))
275 apiSuccess(master.deleteParam(
'uptest.sub1.sub2.node',
'uparam1'))
276 del myState[
'uparam1']
278 apiSuccess(master.deleteParam(
'uptest2.sub1.sub2.sub3.node',
'uparam2'))
279 del myState[
'uptest2.sub1.uparam2']
283 """testScopeDown: test scoping rules for sub contexts""" 289 testVal = random.randint(-1000000, 100000)
290 master.setParam(
'down.one.two.three.node',
'dparam1', testVal)
291 myState[
'down.one.two.three.dparam1'] = testVal
293 assert not apiSuccess(master.hasParam(
'down.one',
'dparam1'))
294 assert not apiSuccess(master.hasParam(
'down.one.two',
'dparam1'))
295 apiError(master.getParam(
'down.one.node',
'dparam1'))
296 apiError(master.getParam(
'down.one.two.node',
'dparam1'))
299 testVal = random.randint(-1000000, 100000)
300 master.setParam(
'node',
'down2.dparam2', testVal)
301 myState[
'down2.dparam2'] = testVal
302 assert testVal == apiSuccess(master.getParam(
'down2.node',
'dparam2'))
303 assert testVal == apiSuccess(master.getParam(
'',
'down2.dparam2'))
305 assert not apiSuccess(master.hasParam(
'down2.node',
'down2.dparam2'))
306 apiError(master.getParam(
'down2.node',
'down2.dparam2'))
310 testVal = random.randint(-1000000, 100000)
311 master.setParam(
'node',
'down3.sub.dparam3', testVal)
312 myState[
'down3.sub.dparam3'] = testVal
313 assert testVal == apiSuccess(master.getParam(
'down3.sub.node',
'dparam3'))
314 assert testVal == apiSuccess(master.getParam(
'down3.node',
'sub.dparam3'))
315 assert testVal == apiSuccess(master.getParam(
'',
'down3.sub.dparam3'))
316 assert testVal == apiSuccess(master.getParam(
'down3.sub.sub2.node',
'dparam3'))
318 assert not apiSuccess(master.hasParam(
'down3.sub.node',
'sub.dparam3'))
319 assert not apiSuccess(master.hasParam(
'down3.sub.node',
'down3.sub.dparam3'))
320 apiError(master.getParam(
'down3.sub.node',
'sub.dparam3'))
321 apiError(master.getParam(
'down3.sub.node',
'down3.sub.dparam3'))
325 master.setParam(
'node',
'down4.sub.dparam4A', testVal)
326 apiSuccess(master.deleteParam(
'down4.sub.node',
'dparam4A'))
328 assert not apiSuccess(master.hasParam(
'down4.sub',
'dparam4A'))
329 master.setParam(
'node',
'down4.sub.dparam4B', testVal)
330 apiSuccess(master.deleteParam(
'down4.node',
'sub.dparam4B'))
332 assert not apiSuccess(master.hasParam(
'down4.sub',
'dparam4B'))
333 master.setParam(
'node',
'down4.sub.dparam4C', testVal)
334 apiSuccess(master.deleteParam(
'',
'down4.sub.dparam4C'))
336 assert not apiSuccess(master.hasParam(
'down4.sub.node',
'dparam4C'))
340 """Master API Test Cases -- those not covered by ParamServer and AddKillNode""" 343 super(MasterTestCase, self).
setUp()
346 super(MasterTestCase, self).
tearDown()
349 flows = apiSuccess(master.getFlowNames(
'node1',
''))
350 assert len(flows) == len(state.values()),
"Master reported a different number of flows" 351 for val
in state.values():
352 assert val
in flows,
"flows does not contain %s : %s"%(val, flows)
358 type =
'common_flows/String' 360 apiSuccess(master.registerNode(callerId,
'node1',
'localhost', 1234, []))
361 for i
in range(1, 4):
362 for dir
in [
'inflow',
'outflow']:
363 locator =
'node1:%s%s'%(dir, i)
364 apiSuccess(master.registerFlow(callerId,
'node1', locator, dir, type))
365 state[locator] = [locator, dir, type, 0]
368 apiError(master.promoteFlow(callerId,
'node1:notAFlow',
'node1:newNotAFlow'))
370 apiError(master.promoteFlow(callerId,
':outflow1',
'node1:newNotAFlow'))
375 apiSuccess(master.promoteFlow(callerId,
'node1:outflow1',
':outflow1'))
376 state[
':outflow1'] = [
':outflow1', dir, type, 1]
378 apiSuccess(master.promoteFlow(callerId,
'.:outflow2',
':outflow2'))
379 state[
':outflow2'] = [
':outflow2', dir, type, 1]
385 [
'node1:inflow1',
'node1:newInflow1'],
386 [
'node1:inflow2',
'sibling:inflow2'],
387 [
'node1:inflow3',
'node1:subgraph1:inflow3']
389 for source, target
in tests:
390 apiSuccess(master.promoteFlow(callerId, source, target))
391 state[target] = [target, dir, type, 1]
396 apiError(master.promoteFlow(callerId,
'node1:outflow1',
'node1:outflow2'))
397 apiError(master.promoteFlow(callerId,
'node1:outflow2',
':outflow1'))
398 apiError(master.promoteFlow(callerId,
'node1:inflow1',
'sibling:inflow2'))
407 type =
'common_flows/String' 408 for callerId
in [
'node1',
'subgraph.node1',
'grandparent.parent.node1']:
410 apiSuccess(master.registerNode(callerId,
'node1',
'localhost', 1234, []))
411 for i
in range(1, 4):
412 for dir
in [
'inflow',
'outflow']:
414 locator =
'node1:%s%s'%(dir, i)
416 locator =
'.:%s%s'%(dir, i)
417 apiSuccess(master.registerFlow(callerId,
'node1', locator, dir, type))
418 realLocator =
'%s:%s%s'%(callerId, dir, i)
419 state[realLocator] = [realLocator, dir, type, 0]
421 apiError(master.registerFlow(callerId,
'notNode',
'notANode:outflow',
'outflow', type))
423 apiError(master.registerFlow(callerId,
'node1',
'',
'outflow', type))
424 apiError(master.registerFlow(callerId,
'node1',
'badflow1',
'outflow', type))
426 apiError(master.registerFlow(callerId,
'node1',
'node1:badflow2',
'spiralflow', type))
428 apiError(master.registerFlow(callerId,
'node1',
'node1:badflow3',
'outflow',
''))
429 apiError(master.registerFlow(callerId,
'node1',
'node1:badflow4',
'outflow',
'faketype'))
432 apiError(master.registerFlow(callerId,
'node1',
'node1:outflow1',
'outflow', type))
433 apiSuccess(master.promoteFlow(callerId,
'node1:outflow1',
'node1:newOutflow1'))
434 state[
'%s:newOutflow1'%callerId] = [
'node1:newOutflow1', dir, type, 1]
435 apiError(master.registerFlow(callerId,
'node1',
'node1:newOutflow1',
'outflow', type))
442 type =
'common_flows/String' 443 for callerId
in [
'node1',
'subgraph.node1',
'grandparent.parent.node1']:
445 apiSuccess(master.registerNode(callerId,
'node1',
'localhost', 1234, []))
446 for i
in range(1, 4):
447 for dir
in [
'inflow',
'outflow']:
449 locator = rlocator =
'node1:%s%s'%(dir, i)
451 locator =
'.:%s%s'%(dir, i)
452 rlocator =
'node1:%s%s'%(dir, i)
453 apiSuccess(master.registerFlow(callerId,
'node1', locator, dir, type))
454 realLocator =
'%s:%s%s'%(callerId, dir, i)
455 state[realLocator] = [realLocator, dir, type, 0]
460 apiError(master.unregisterFlow(callerId,
'notANode:outflow'))
461 apiError(master.unregisterFlow(callerId,
''))
462 apiError(master.unregisterFlow(callerId.replace(
'node1',
'node2'),
'outflow1'))
464 apiSuccess(master.unregisterFlow(callerId,
'node1:outflow1'))
465 del state[
'%s:outflow1'%callerId]
466 apiSuccess(master.unregisterFlow(callerId,
'.:outflow2'))
467 del state[
'%s:outflow2'%callerId]
468 apiSuccess(master.unregisterFlow(callerId.replace(
'node1',
'node2'),
'node1:outflow3'))
469 del state[
'%s:outflow3'%callerId]
470 apiSuccess(master.unregisterFlow(
'master',
'%s:inflow1'%callerId))
471 del state[
'%s:inflow1'%callerId]
476 apiError(master.unregisterFlow(callerId,
'node1:outflow1'))
479 apiSuccess(master.promoteFlow(callerId,
'node1:inflow3',
':inflow3A'))
480 apiSuccess(master.promoteFlow(callerId,
':inflow3A',
':inflow3B'))
482 apiSuccess(master.unregisterFlow(callerId,
'node1:inflow3'))
483 del state[
'%s:inflow3'%callerId]
490 subgraph =
'sub1.sub2' 492 port = apiSuccess(master.addNode(
'caller', subgraph, name, pkg, node, TEST_MACHINE, 0))
495 testFlowNames = [
"%s:%s"%(name, v)
for v
in [
"in",
"out"]]
496 print "FLOW NAMES", apiSuccess(master.getFlowNames(
'master',
''))
497 flows = apiSuccess(master.getFlowNames(
'%s.caller'%subgraph,
''))
498 assert not set([x[0]
for x
in flows]) ^ set(testFlowNames),
"%s vs. %s"%([x[0]
for x
in flows], testFlowNames)
500 inDirs = [x[1]
for x
in flows
if x[0].endswith(
':in')]
501 outDirs = [x[1]
for x
in flows
if x[0].endswith(
':out')]
502 assert not filter(
lambda x: x !=
"inflow", inDirs), inDirs
503 assert not filter(
lambda x: x !=
"outflow", outDirs), outDirs
504 assert not filter(
lambda x: x !=
"common_flows/String", [x[2]
for x
in flows])
505 assert not filter(
lambda x: x, [x[3]
for x
in flows])
508 testFlowNames = [
"%s.%s:%s"%(subgraph, name, v)
for v
in [
"in",
"out"]]
509 flows = apiSuccess(master.getFlowNames(
'caller', subgraph))
510 assert not set([x[0]
for x
in flows]) ^ set(testFlowNames),
"%s vs. %s"%([x[0]
for x
in flows], testFlowNames)
511 flows = apiSuccess(master.getFlowNames(
'caller',
"%s.%s"%(subgraph, name)))
512 assert not set([x[0]
for x
in flows]) ^ set(testFlowNames),
"%s vs. %s"%([x[0]
for x
in flows], testFlowNames)
514 testFlowNames = [
"sub2.%s:%s"%(name, v)
for v
in [
"in",
"out"]]
515 flows = apiSuccess(master.getFlowNames(
'sub1.caller',
'sub2'))
516 assert not set([x[0]
for x
in flows]) ^ set(testFlowNames),
"%s vs. %s"%([x[0]
for x
in flows], testFlowNames)
519 testFlowNames = [
"%s.%s:%s"%(subgraph, name, v)
for v
in [
"in",
"out"]]
520 flows = apiSuccess(master.getFlowNames(
'caller',
''))
521 flowNames = [x[0]
for x
in flows]
522 assert not set(flowNames) ^ set(testFlowNames)
526 def validate(val, callerId, name, port):
527 assert len(val) == 3,
"getNodeAddress did not return 3-element list for value field" 528 assert type(val[0]) == str
and type(val[1]) == str
and type(val[2]) == int,\
529 "getNodeAddress did not return (str, str, int) for value field" 538 code, msg, val = master.getNodeAddress(
'',
'testGetNodeAddress-fake')
539 assert code == -1,
"getNodeAddress did not return failure code 0 for non-existent node" 540 assert len(val) == 3,
"getNodeAddress did not return 3-element list for value field in error case" 541 assert type(val[0]) == str
and type(val[1]) == str
and type(val[2]) == int,\
542 "getNodeAddress did not return (str, str, int) for value field in error case" 545 name =
'testGetNodeAddress-1' 548 apiSuccess(master.addNode(
'',
'', name, pkg, node, TEST_MACHINE, port))
549 val = apiSuccess(master.getNodeAddress(
'', name))
550 validate(val,
'', name, port)
553 name =
'testGetNodeAddress-2' 555 apiSuccess(master.addNode(
'',
'gna1.gna2', name, pkg, node, TEST_MACHINE, port))
559 [
'gna1.gna2.node', name],
560 [
'gna1.node',
'gna2.%s'%name],
561 [
'',
'gna1.gna2.%s'%name],
563 [
'gna1.gna2.gna3.node', name],
566 callerId, name = test
567 validate(apiSuccess(master.getNodeAddress(callerId, name)), callerId, name, port)
570 val = apiError(master.getNodeAddress(
'gna1.gna2',
'gna3.%s'%name))
573 testUri =
"http://localhost:%s/"%port
575 ServerProxy(testUri).getPid(
'node')
576 self.fail(
"test node is still running")
581 """testAddKillNode: test adding then killing nodes""" 585 apiError(master.killNode(
'node',
'nonexistentNode'))
586 name =
'testAddKillA' 587 port = apiSuccess(master.addNode(
'node',
'subgraph', name, pkg, node, TEST_MACHINE, 0))
589 apiError(master.killNode(
'different.subgraph.node', name))
591 apiError(master.killNode(
'node', name))
593 apiError(master.killNode(
'subgraph.sub2.node', name))
595 apiSuccess(master.killNode(
'subgraph.node', name))
598 tests = [[
'node',
'',
'testAddKillB'],
599 [
'node',
'g1.g2',
'testAddKillB'],
600 [
'node',
'g1',
'testAddKillB'],
601 [
'g1.g2.node',
'g3',
'testAddKillB'],
603 for callerId, subcontext, nodeName
in tests:
604 port = apiSuccess(master.addNode(callerId, subcontext, nodeName, pkg, node, TEST_MACHINE, 0))
606 name =
"%s.%s"%(subcontext, nodeName)
609 apiSuccess(master.killNode(callerId, name))
613 """testAddNode: test master.addNode(callerId, subcontext, name, pkg, pkgNode, machine, port)""" 615 graphNodes = [
'master']
621 [
'', 12,
'testAddNodeError1', pkg, node, TEST_MACHINE, 0],
623 [
'',
'', 123, pkg, node, TEST_MACHINE, 0],
625 [
'',
'',
'testAddNodeError2', 123, node, TEST_MACHINE, 0],
627 [
'',
'',
'testAddNodeError3', pkg,
'', TEST_MACHINE, 0],
628 [
'',
'',
'testAddNodeError4', pkg, 123, TEST_MACHINE, 0],
630 [
'',
'',
'testAddNodeError6', pkg, node,
'unknown', 0],
631 [
'',
'',
'testAddNodeError7', pkg,
'noNode', 123, 0],
633 [
'',
'',
'testAddNodeError8', pkg, node, TEST_MACHINE, -80],
634 [
'',
'',
'testAddNodeError9', pkg, node, TEST_MACHINE,
"80"],
638 apiError(master.addNode(*args))
640 self.fail(
"addNodeError case failed with args[%s] and exception [%s]"%(args, e))
642 apiFail(master.addNode(
'',
'',
'testAddNodeFail1', pkg,
'notANode', TEST_MACHINE, 0))
645 tests = [[[
'',
'testAddNode1'], [TEST_MACHINE, 7980]],
646 [[
'',
'testAddNode2'], [TEST_MACHINE, 0]],
647 [[
'',
'testAddNode3'], [
'', 0]],
648 [[
'',
'testAddNode4'], [TEST_MACHINE, 0]],
649 [[
'',
'testAddNode5'], [TEST_MACHINE, 0]],
650 [[
'',
'testAddNode6'], [TEST_MACHINE, 0]],
651 [[
'',
'testAddNode7'], [TEST_MACHINE, 0]],
653 [[
'push',
'testAddNode8'], [TEST_MACHINE, 0]],
654 [[
'push.one.two',
'testAddNode9'], [TEST_MACHINE, 0]],
655 [[
'stanford.addNodeTest',
'testAddNodeA'], [TEST_MACHINE, 0]],
656 [[
'wg.addNodeTest',
'testAddNodeA'], [TEST_MACHINE, 0]],
658 for fullname, args
in tests:
659 print "testAddNode: testing", fullname
660 subcontext, name = fullname
662 fullname =
'%s.%s'%(subcontext, name)
666 apiSuccess(master.addNode(
'', subcontext, name, pkg, node, machine, port))
668 graphNodes.append(fullname)
671 apiSuccess(master.addNode(
'', subcontext, name, pkg, node, machine, port))
676 port = apiSuccess(master.addNode(
'node',
'duplicate.test',
'nodeA', pkg, node, TEST_MACHINE, 0))
677 apiError(master.addNode(
'node',
'duplicate.test',
'nodeA', pkg, node, TEST_MACHINE, port + 1))
678 apiError(master.addNode(
'node',
'duplicate.test',
'nodeA', pkg+
'foo', node, TEST_MACHINE, port))
679 apiError(master.addNode(
'node',
'duplicate.test',
'nodeA', pkg, node+
'foo', TEST_MACHINE, port))
689 host, port = masterAddr
692 apiError(master.addMachine(
'node',
'', self.rosRoot, host, 22,
'',
''))
693 apiError(master.addMachine(
'node', 123, self.rosRoot, host, 22,
'',
''))
695 apiError(master.addMachine(
'node',
'name',
'', host, 22,
'',
''))
696 apiError(master.addMachine(
'node',
'name', 123, host, 22,
'',
''))
698 apiError(master.addMachine(
'node',
'name',
'',
'', 22,
'',
''))
699 apiError(master.addMachine(
'node',
'name',
'', 123, 22,
'',
''))
701 apiError(master.addMachine(
'node',
'name',
'', host, -22,
'',
''))
702 apiError(master.addMachine(
'node',
'name',
'', host,
"22",
'',
''))
705 [
'node',
'testAddMachine-1'],
706 [
'g1.node',
'testAddMachine-2'],
707 [
'g1.g2.g3.node',
'testAddMachine-3'],
708 [
'g1.g2.node',
'testAddMachine-4'],
710 rosRoot = self.rosRoot
711 for callerId, m
in tests:
712 apiSuccess(master.addMachine(callerId, m, rosRoot, host, 22,
'',
''))
714 apiSuccess(master.addMachine(callerId, m, rosRoot, host, 22,
'',
''))
716 apiError(master.addMachine(callerId, m, rosRoot+
'/foo/', host, 22,
'',
''))
717 apiError(master.addMachine(callerId, m, rosRoot,
'www.google.com', 22,
'',
''))
718 apiError(master.addMachine(callerId, m, rosRoot, host, 21,
'',
''))
719 apiError(master.addMachine(callerId, m, rosRoot, host, 22,
'fake-user',
''))
720 apiError(master.addMachine(callerId, m, rosRoot, host, 22,
'',
'fake-password'))
732 apiError(master.registerNode(
'',
'',
'localhost', 80, flows))
734 apiError(master.registerNode(
'',
'registerNodeFail2',
'', 80, flows))
736 apiError(master.registerNode(
'',
'registerNodeFail3',
'localhost', -80, flows))
737 apiError(master.registerNode(
'',
'registerNodeFail4',
'localhost', 0, flows))
744 [
'',
'registerNodeExternal-1'],
745 [
'',
'rne.registerNodeExternal-2'],
746 [
'rne',
'registerNodeExternal-3'],
747 [
'',
'rne.rne2.rne3.registerNodeExternal-4'],
748 [
'rne',
'rne2.rne3.registerNodeExternal-5'],
749 [
'rne.rne2.rne3',
'registerNodeExternal-6'],
751 for context, name
in testCases:
754 fullName =
"%s.%s"%(context, name)
755 callerId =
"%s.node"%context
759 startTestNode(fullName)
762 timeoutT = time.time() + 4.0
765 while time.time() < timeoutT
and not val:
767 _, _, val = node.getPid(
'')
770 assert val,
"unable to start test node for registerNode test case" 772 verifyNodeAddress(master, callerId, name,
None, testNodeAddr[0], testNodeAddr[1])
779 graphNodes = [
'master']
781 machine = TEST_MACHINE
782 for i
in range(1, 5):
783 apiSuccess(master.addNode(
'm',
'',
'baseTcfNode-%s'%i, pkg, node, machine, 0))
784 graphNodes.append(
'baseTcfNode-%s'%i)
785 apiSuccess(master.addNode(
'm',
'',
'tcfNode-%s'%i, pkg, node, machine, 0))
786 graphNodes.append(
'tcfNode-%s'%i)
787 apiSuccess(master.addNode(
'm',
'tcf1',
'tcfNode-%s'%i, pkg, node, machine, 0))
788 graphNodes.append(
'tcf1.tcfNode-%s'%i)
789 apiSuccess(master.addNode(
'm',
'tcf2',
'tcfNode-%s'%i, pkg, node, machine, 0))
790 graphNodes.append(
'tcf2.tcfNode-%s'%i)
791 apiSuccess(master.addNode(
'm',
'tcf1.sub1',
'tcfNode-%s'%i, pkg, node, machine, 0))
792 graphNodes.append(
'tcf1.sub1.tcfNode-%s'%i)
793 apiSuccess(master.addNode(
'm',
'tcf2.sub1',
'tcfNode-%s'%i, pkg, node, machine, 0))
794 graphNodes.append(
'tcf2.sub1.tcfNode-%s'%i)
795 apiSuccess(master.addNode(
'm',
'tcf3',
'tcfNode3-%s'%i, pkg, node, machine, 0))
796 graphNodes.append(
'tcf3.tcfNode3-%s'%i)
804 [
'node.tcf1',
'baseTcfNode-1:out',
'tcfNode-1:in'],
805 [
'tcf1.node',
'tcfNode-1:out',
'baseTcfNode-1:in'],
806 [
'tcf1.tcfNode-1',
'tcfNode-1:out',
'tcf1.tcfNode-1:in'],
807 [
'tcf1.tcfNode-1',
':out',
'tcf1.tcfNode-1:in'],
808 [
'tcf1.tcfNode-1',
'tcf1.tcfNode-2:out',
':in'],
809 [
'tcf1.node',
'tcf1.tcfNode-1:out',
'tcfNode-1:in'],
810 [
'tcf1.node',
'tcf2.tcfNode-1:out',
'tcfNode-1:in'],
811 [
'tcf1.node',
'tcfNode-1:out',
'tcf2.tcfNode-1:in'],
812 [
'tcf1.node',
'sub1.tcfNode-1:out',
'tcf2.sub1.tcfNode-1:in'],
813 [
'tcf1.sub1.node',
'baseTcfNode-1:out',
'tcfNode-1:in'],
814 [
'tcf1.sub1.node',
'sub1.tcfNode-1:out',
'tcfNode-1:in'],
815 [
'tcf1.sub1.node',
'tcf2.tcfNode-1:out',
'tcfNode-1:in'],
817 for callerId, source, sink
in illegal:
818 apiError(master.connectFlow(callerId, source, sink, reliable))
823 [
'node',
'tcfNode-1:out',
'tcfNode-2:in',
'tcfNode-1:out',
'tcfNode-2:in',],
824 [
'tcfNode-1',
'tcf1.tcfNode-1:out',
'tcf1.tcfNode-2:in',
'tcf1.tcfNode-1:out',
'tcf1.tcfNode-2:in'],
825 [
'tcf2.tcfNode-1',
'tcfNode-1:out',
'tcfNode-2:in',
'tcf2.tcfNode-1:out',
'tcf2.tcfNode-2:in'],
826 [
'tcf1.tcfNode-2',
'sub1.tcfNode-1:out',
'sub1.tcfNode-2:in',
'tcf1.sub1.tcfNode-1:out',
'tcf1.sub1.tcfNode-2:in'],
827 [
'tcf2.tcfNode-1',
'tcfNode-1:out',
'sub1.tcfNode-1:in',
'tcf2.tcfNode-1:out',
'tcf2.sub1.tcfNode-1:in'],
830 [
'tcf2.sub1.tcfNode-1',
'.:out',
'tcfNode-2:in',
'tcf2.sub1.tcfNode-1:out',
'tcf2.sub1.tcfNode-2:in'],
831 [
'tcf3.tcfNode3-2',
'tcfNode3-1:out',
'.:in',
'tcf3.tcfNode3-1:out',
'tcf3.tcfNode3-2:in'],
833 for callerId, source, sink, sourceFull, sinkFull
in singleCase:
834 apiSuccess(master.connectFlow(callerId, source, sink, reliable))
835 graphFlows.append((sourceFull, sinkFull))
840 apiError(master.connectFlow(
'tcf2.node',
'tcfNode-1:out',
'tcfNode-2:in', reliable))
841 apiError(master.connectFlow(
'node',
'tcf1.tcfNode-1:out',
'tcf1.tcfNode-2:in', reliable))
850 master.killFlow(callerId, source, sink)
854 assert master
is not None,
"master is None" 855 masterUri = apiSuccess(master.getMasterUri(
''))
856 assert masterUri == apiSuccess(master.getMasterUri(
'a.different.id')), master.getMasterUri(
'a.different.id')
857 assert (getMasterUri() == masterUri)
or \
858 (getMasterUriAlt() == masterUri), masterUri
860 pid = apiSuccess(master.getPid(
''))
861 assert pid == apiSuccess(master.getPid(
'a.different.id')), master.getPid(
'a.different.id')
863 apiError(master.getPid(0))
864 apiError(master.getMasterUri(0))
867 master.shutdown(
'some.id')
872 code, status, val = master.getPid(
'')
873 assert code < 1,
"Master is still running after shutdown" 878 return msMain(argv, stdout, env, [ParamServerTestCase, MasterTestCase], singletest)
880 if __name__ ==
'__main__':
def testRegisterNode(self)
def testConnectFlow(self)
def testParamValues(self)
def testGetFlowNames(self)
def testRegisterFlow(self)
def verifyNodeAddress(master, callerId, name, machine, addr, port)
def testGraphState(master, graphNodes, graphFlows)
def _verifyNodeDead(self, port)
def testPromoteFlow(self)
def testRegisterNode_Flows(self)
def testEncapsulation(self)
def testGetNodeAddress(self)
def testMasterMain(argv, stdout, env)
def _verifyFlowNameState(self, master, state)
def testAddKillNode(self)
def testDotLocalNames(self)
def testUnregisterFlow(self)
def testParamState(master, myState)
def _testSetParam(self, ctx, myState, testVals, master)