andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 1 | """ |
| 2 | FuncPlatform |
| 3 | |
| 4 | A functional test designed to test the environment and |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 5 | gather information on startup -> shutdown related issues. |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 6 | |
| 7 | Future works may also include security mode startup / |
| 8 | shutdown check and cfg get and set. |
| 9 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 10 | Abstracting the collection of commands that go hand in hand |
| 11 | should allow easy rearrangement of steps to replicate or |
| 12 | create scenarios. |
| 13 | For example: |
| 14 | CASE N - Represents a particular scenario |
| 15 | Steps - Represents abstraction methods called from |
| 16 | dependency |
| 17 | 1. Bring ONOS 1 up |
| 18 | 2. Activate application X |
| 19 | 3. Activate application Y |
| 20 | 4. Deactivate application X |
| 21 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 22 | The ideal platform test script should have incredible |
| 23 | robustness to possible exceptions and report the most |
| 24 | useful error messages. |
| 25 | |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 26 | contributers to contact for help: |
| 27 | andrew@onlab.us |
| 28 | """ |
| 29 | |
| 30 | class FuncPlatform: |
| 31 | def __init__( self ): |
| 32 | self.default = '' |
| 33 | |
| 34 | def CASE1( self, main ): |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 35 | """ |
| 36 | Main scope initialization case |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 37 | Must include to run any other test cases |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 38 | """ |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 39 | import imp |
| 40 | |
andrew@onlab.us | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 41 | # NOTE: Hardcoded application name subject to change |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 42 | # closely monitor and make changes when necessary |
| 43 | # (or implement ways to dynamically get names) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 44 | main.appList = { |
| 45 | 'bgprouter' : 'org.onosproject.bgprouter', |
| 46 | 'config' : 'org.onosproject.config', |
| 47 | 'cordfabric' : 'org.onosproject.cordfabric', |
| 48 | 'demo' : 'org.onosproject.demo', |
| 49 | 'distributedprimitives' : 'org.onosproject.distributedprimitives', |
| 50 | 'election' : 'org.onosproject.election', |
| 51 | 'flowrule' : 'org.onosproject.flowrule', |
| 52 | 'fwd' : 'org.onosproject.fwd', |
| 53 | 'intentperf' : 'org.onosproject.intentperf', |
| 54 | 'messagingperf' : 'org.onosproject.messagingperf', |
| 55 | 'metrics' : 'org.onosproject.metrics', |
| 56 | 'mobility' : 'org.onosproject.mobility', |
| 57 | 'netconf' : 'org.onosproject.netconf', |
| 58 | 'null' : 'org.onosproject.null', |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 59 | 'optical' : 'org.onosproject.optical', |
| 60 | 'pcep' : 'org.onosproject.pcep', |
| 61 | 'proxyarp' : 'org.onosproject.proxyarp', |
| 62 | 'reactive.routing' : 'org.onosproject.reactive.routing', |
| 63 | 'sdnip' : 'org.onosproject.sdnip', |
| 64 | 'segmentrouting' : 'org.onosproject.segmentrouting', |
| 65 | 'tunnel' : 'org.onosproject.tunnel', |
| 66 | 'virtualbng' : 'org.onosproject.virtualbng', |
| 67 | 'xosintegration' : 'org.onosproject.xosintegration' |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 68 | } |
| 69 | # List of ONOS ip's specififed in params |
| 70 | main.ONOSips = [] |
| 71 | main.CLIs = [] |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 72 | main.ONOSnode = [] |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 73 | |
| 74 | for node in range( 0, int(main.params['CTRL']['num']) ): |
| 75 | main.ONOSips.append( main.params['CTRL']['ip'+str(node+1)] ) |
| 76 | main.CLIs.append( |
| 77 | getattr( main, 'ONOS' + str(node+1) + 'cli' ) ) |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 78 | main.ONOSnode.append( |
| 79 | getattr( main, 'ONOS' + str(node+1) ) ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 80 | |
| 81 | # Application source and name definitions |
| 82 | startupSrc = main.params['DEP']['startupSrc'] |
| 83 | startupClassName = main.params['DEP']['startupClassName'] |
| 84 | |
| 85 | appClassName = main.params['DEP']['appClassName'] |
| 86 | appSrc = main.params['DEP']['appSrc'] |
| 87 | |
| 88 | logClassName = main.params['DEP']['logClassName'] |
| 89 | logSrc = main.params['DEP']['logSrc'] |
| 90 | |
| 91 | shutdownClassName = main.params['DEP']['shutdownClassName'] |
| 92 | shutdownSrc = main.params['DEP']['shutdownSrc'] |
| 93 | |
| 94 | # Importing dependency class(es) |
| 95 | # Refer to source files in Dependency folder to |
| 96 | # make changes to its respective methods |
| 97 | # Be weary of naming collisions |
| 98 | try: |
| 99 | main.startup = imp.load_source( startupClassName, startupSrc ) |
| 100 | main.app = imp.load_source( appClassName, appSrc ) |
| 101 | main.onosLog = imp.load_source( logClassName, logSrc ) |
| 102 | main.shutdown = imp.load_source( shutdownClassName, shutdownSrc ) |
| 103 | except ImportError: |
| 104 | main.log.error( 'Error importing class file(s). Please ' + |
| 105 | 'check file location' ) |
| 106 | main.cleanup() |
| 107 | main.exit() |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 108 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 109 | def CASE2( self, main ): |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 110 | import time |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 111 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 112 | cellName = main.params['CELL']['name'] |
| 113 | appStr = main.params['CELL']['appStr'] |
| 114 | benchIp = main.params['BENCH']['ip'] |
| 115 | branchName = main.params['GIT']['branchName'] |
| 116 | gitPull = main.params['GIT']['pull'] |
| 117 | mnIp = main.params['MN']['ip'] |
| 118 | |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 119 | main.case( 'Setup environment and install ONOS' ) |
| 120 | if gitPull == 'on': |
| 121 | main.step( 'Git pull and clean install' ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 122 | gitPullResult = main.startup.gitPullAndMci( branchName ) |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 123 | utilities.assert_equals( expect=main.TRUE, |
| 124 | actual=gitPullResult, |
| 125 | onpass='Git pull and install successful', |
| 126 | onfail='Git pull and install failed: ' + |
| 127 | str(gitPullResult) ) |
| 128 | |
| 129 | main.step( 'Initiate ONOS startup sequence' ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 130 | startupResult = main.startup.initOnosStartupSequence( |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 131 | cellName, appStr, benchIp, mnIp, main.ONOSips ) |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 132 | utilities.assert_equals( expect=main.TRUE, |
| 133 | actual=startupResult, |
| 134 | onpass='ONOS startup sequence successful', |
| 135 | onfail='ONOS startup sequence failed: ' + |
| 136 | str(startupResult) ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 137 | |
| 138 | def CASE3( self, main ): |
| 139 | import time |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 140 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 141 | main.case( 'Activate applications and check installation' ) |
andrew@onlab.us | 484ef83 | 2015-05-29 16:08:27 -0400 | [diff] [blame] | 142 | |
| 143 | # NOTE: Test only |
| 144 | # Unceremoniously kill onos 2 |
| 145 | main.ONOSbench.onosDie( '10.128.174.2' ) |
| 146 | |
| 147 | time.sleep( 30 ) |
| 148 | |
| 149 | main.step( 'Sample Onos log check' ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 150 | logResult = main.onosLog.checkOnosLog( main.ONOSips[0] ) |
andrew@onlab.us | 484ef83 | 2015-05-29 16:08:27 -0400 | [diff] [blame] | 151 | main.log.info( logResult ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 152 | # TODO: Define pass criteria |
| 153 | utilities.assert_equals( expect=main.TRUE, |
| 154 | actual=main.TRUE, |
| 155 | onpass= 'Logging successful', |
| 156 | onfail= 'Logging failed ' ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 157 | |
| 158 | # Sample app activation |
| 159 | main.step( 'Activating applications metrics and fwd' ) |
| 160 | appList = ['metrics', 'fwd'] |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 161 | appResult = main.app.activate( appList ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 162 | utilities.assert_equals( expect=main.TRUE, |
| 163 | actual=appResult, |
| 164 | onpass= 'App activation of ' + str(appList) + ' successful', |
| 165 | onfail= 'App activation failed ' + str(appResult) ) |
| 166 | |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 167 | def CASE4( self, main ): |
| 168 | """ |
| 169 | Download ONOS tar.gz built from latest nightly |
| 170 | (following tutorial on wiki) and run ONOS directly on the |
| 171 | instance |
| 172 | """ |
| 173 | import imp |
| 174 | |
| 175 | targz = main.params['DEP']['targz'] |
| 176 | clusterCount = main.params['CTRL']['num'] |
| 177 | |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 178 | main.case( 'Install ONOS from onos.tar.gz file' ) |
| 179 | |
| 180 | main.step( 'Killing all ONOS instances previous started' ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 181 | killResult = main.shutdown.killOnosNodes( main.ONOSips ) |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 182 | utilities.assert_equals( expect=main.TRUE, |
| 183 | actual = killResult, |
| 184 | onpass = 'All Onos nodes successfully killed', |
| 185 | onfail = 'Onos nodes were not successfully killed' ) |
| 186 | |
| 187 | main.step( 'Starting ONOS using tar.gz on all nodes' ) |
andrew@onlab.us | 19b5e04 | 2015-06-05 13:14:02 -0400 | [diff] [blame] | 188 | installResult = main.startup.installOnosFromTar( targz, main.ONOSips ) |
andrew@onlab.us | b3a4849 | 2015-06-04 18:50:10 -0400 | [diff] [blame] | 189 | utilities.assert_equals( expect=main.TRUE, |
| 190 | actual = installResult, |
| 191 | onpass= 'Onos tar.gz installation successful', |
| 192 | onfail= 'Onos tar.gz installation failed' ) |
| 193 | |
| 194 | |