blob: ca7783820b89811421cbc1de7ea444f9bbd46bfc [file] [log] [blame]
andrew@onlab.us1bc346b2015-05-21 17:21:16 -04001
2"""
3Startup related methods for ONOS
4
5Guidelines:
6 * Group sequential functionalities together
7 * Methods should not prohibit cross platform execution
8 * Return main.TRUE on success or comprehensive error message
9 on failure (TBD)
10"""
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040011import time
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040012import json
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040013
14def __init__( self ):
15 self.ip = '127.0.0.1'
16
17def gitPullAndMci( branchName, commitLog=False ):
18 """
19 Pull from branch repository specified and compile changes
20 If commitLog is True, report commit information
21
22 Any errors / warnings will be handled by respective
23 driver function calls
24 """
25 co = main.ONOSbench.gitCheckout( branchName )
26 gp = main.ONOSbench.gitPull()
27 ci = main.ONOSbench.cleanInstall()
28
29 if co and gp and ci == main.TRUE:
30 if commitLog:
31 main.log.report( 'Commit information - ' )
32 main.ONOSbench.getVersion(report=True)
33
34 return main.TRUE
35
36 else:
37 # TODO: Comprehensive error message
38 return 'git pull and mci failed'
39
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040040def initOnosStartupSequence( cellName, appStr, benchIp, mnIp, onosIps ):
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040041 """
42 Startup sequence includes the following:
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040043 * Create cell file
44 * Set cell variables on ONOS bench
45 * Verify cell
46 * Create ONOS package
47 * Force install ONOS package
48 * Start ONOS service
49 * Start ONOS cli
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040050 """
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040051
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040052 # NOTE: leave out create cell file until bug addressed
53 #cf = main.ONOSbench.createCellFile( benchIp, cellName, mnIp,
54 # str(appStr), *onosIps )
55 numNodes = len(onosIps)
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040056
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040057 sc = main.ONOSbench.setCell( cellName )
58 vc = main.ONOSbench.verifyCell()
59 op = main.ONOSbench.onosPackage()
60 for addr in onosIps:
61 oi = main.ONOSbench.onosInstall( node = addr )
62
63 time.sleep( 5 )
64
65 iu = main.TRUE
66 for node in onosIps:
67 iu = iu and main.ONOSbench.isup( node )
68
69 cli = main.TRUE
70 for node in range( 0, numNodes ):
71 cli = cli and main.CLIs[node].startOnosCli( onosIps[node] )
72
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040073 # Check if all nodes are discovered correctly using
74 # 'nodes' command in Onos Cli
75 na = main.TRUE
76 try:
77 nodeCmdJson = json.loads( main.CLIs[0].nodes() )
78 for node in nodeCmdJson:
79 if node['state'] != 'ACTIVE':
80 main.log.warn( str( node['id'] ) +
81 ' Node is not in ACTIVE state.' )
82 na = main.FALSE
83 if na != main.FALSE:
84 main.log.info( 'All nodes discovered successfully' )
85 except Exception:
86 main.log.error( 'nodes command did not execute properly' )
87 return main.FALSE
88
89 if sc and vc and op and oi and iu and cli and na == main.TRUE:
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040090 return main.TRUE
91 else:
92 return main.FALSE
93
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040094def addAndStartOnosNode( nodeIps ):
95 """
96 A scale-out scenario that adds specified list of
97 nodes and starts those instances.
98
99 Ex) nodeIps = ['10.0.0.2', '10.0.0.3', 10.0.0.4']
100 """
101 main.log.info( 'addAndStartOnosNode implement me!' )
102