blob: c71024b0b51323e067b5b3cc60e1ba3a3a9c9aa1 [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
andrew@onlab.usb3a48492015-06-04 18:50:10 -04007 * Methods should not be dependent on platform
andrew@onlab.us1bc346b2015-05-21 17:21:16 -04008 * Return main.TRUE on success or comprehensive error message
9 on failure (TBD)
andrew@onlab.usb3a48492015-06-04 18:50:10 -040010 * All methods should be consistent in expected behavior
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040011"""
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040012import time
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040013import json
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040014
15def __init__( self ):
16 self.ip = '127.0.0.1'
17
18def gitPullAndMci( branchName, commitLog=False ):
19 """
20 Pull from branch repository specified and compile changes
21 If commitLog is True, report commit information
22
23 Any errors / warnings will be handled by respective
24 driver function calls
25 """
26 co = main.ONOSbench.gitCheckout( branchName )
27 gp = main.ONOSbench.gitPull()
28 ci = main.ONOSbench.cleanInstall()
29
30 if co and gp and ci == main.TRUE:
31 if commitLog:
32 main.log.report( 'Commit information - ' )
33 main.ONOSbench.getVersion(report=True)
34
35 return main.TRUE
36
37 else:
38 # TODO: Comprehensive error message
39 return 'git pull and mci failed'
40
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040041def initOnosStartupSequence( cellName, appStr, benchIp, mnIp, onosIps ):
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040042 """
43 Startup sequence includes the following:
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040044 * Create cell file
45 * Set cell variables on ONOS bench
46 * Verify cell
47 * Create ONOS package
48 * Force install ONOS package
49 * Start ONOS service
50 * Start ONOS cli
andrew@onlab.usb3a48492015-06-04 18:50:10 -040051
52 Also verifies that Onos is up and running by
53 'isup' driver function which executs
54 'onos-wait-for-start'
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040055 """
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040056
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040057 # NOTE: leave out create cell file until bug addressed
58 #cf = main.ONOSbench.createCellFile( benchIp, cellName, mnIp,
59 # str(appStr), *onosIps )
60 numNodes = len(onosIps)
andrew@onlab.us1bc346b2015-05-21 17:21:16 -040061
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040062 sc = main.ONOSbench.setCell( cellName )
63 vc = main.ONOSbench.verifyCell()
64 op = main.ONOSbench.onosPackage()
65 for addr in onosIps:
66 oi = main.ONOSbench.onosInstall( node = addr )
67
68 time.sleep( 5 )
69
70 iu = main.TRUE
71 for node in onosIps:
72 iu = iu and main.ONOSbench.isup( node )
73
74 cli = main.TRUE
75 for node in range( 0, numNodes ):
76 cli = cli and main.CLIs[node].startOnosCli( onosIps[node] )
77
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -040078 # Check if all nodes are discovered correctly using
79 # 'nodes' command in Onos Cli
80 na = main.TRUE
81 try:
82 nodeCmdJson = json.loads( main.CLIs[0].nodes() )
83 for node in nodeCmdJson:
84 if node['state'] != 'ACTIVE':
85 main.log.warn( str( node['id'] ) +
86 ' Node is not in ACTIVE state.' )
87 na = main.FALSE
88 if na != main.FALSE:
89 main.log.info( 'All nodes discovered successfully' )
90 except Exception:
91 main.log.error( 'nodes command did not execute properly' )
92 return main.FALSE
93
94 if sc and vc and op and oi and iu and cli and na == main.TRUE:
andrew@onlab.us2bcfd8f2015-05-28 19:17:51 -040095 return main.TRUE
96 else:
97 return main.FALSE
98
andrew@onlab.usb3a48492015-06-04 18:50:10 -040099def installOnosFromTar( wgetAddr, nodeIps ):
100 """
101 Install Onos directly from tar.gz file.
102 Due to the nature of the specific steps required
103 to startup Onos in this fashion, all commands
104 required to start Onos from tar.gz will be
105 grouped in this method.
106
107 1) wget latest onos tar.gz on onos node
108 2) untar package
109 3) specify onos-config cluster
110 4) start onos via onos-service
111 5) form onos cluster using onos-form-cluster
112 6) check for successful startup
113
114 Specify the download link for the tar.gz.
115 Provide a list of nodeIps
116
117 Ex) wgetAddr = 'https://mytargzdownload.com/file.tar.gz'
118 nodeIps = ['10.0.0.1', '10.0.0.2']
119 """
120 if isinstance( nodeIps, ( int, basestring ) ):
121 main.log.error( 'Please pass in a list of string nodes' )
122 return main.FALSE
123
124 clusterCount = len( nodeIps )
125
126 main.log.info( 'Initiating Onos installation sequence ' +
127 'using tar.gz ... This may take a few minutes' )
128
129 for node in range( 0, clusterCount ):
130 try:
131 main.ONOSnode[node].handle.sendline( 'wget ' + wgetAddr )
132 main.ONOSnode[node].handle.expect( 'saved' )
133 main.ONOSnode[node].handle.expect( '\$' )
134 main.log.info( 'Successfully downloaded tar.gz ' +
135 'on node: ' + str( main.ONOSips[node] ) )
136 except Exception:
137 # NOTE: Additional exception may be appropriate
138 main.log.error( 'Uncaught exception while ' +
139 'downloading Onos tar.gz: ' +
140 main.ONOSnode[node].handle.before )
141 return main.FALSE
142
143 return main.TRUE
144
andrew@onlab.usd2d36fc2015-05-29 14:27:54 -0400145def addAndStartOnosNode( nodeIps ):
146 """
147 A scale-out scenario that adds specified list of
148 nodes and starts those instances.
149
150 Ex) nodeIps = ['10.0.0.2', '10.0.0.3', 10.0.0.4']
151 """
152 main.log.info( 'addAndStartOnosNode implement me!' )