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 | d2d36fc | 2015-05-29 14:27:54 -0400 | [diff] [blame] | 39 | # NOTE: Hardcoded application name subject to change |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 40 | # closely monitor and make changes when necessary |
| 41 | # (or implement ways to dynamically get names) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 42 | main.appList = { |
| 43 | 'bgprouter' : 'org.onosproject.bgprouter', |
| 44 | 'config' : 'org.onosproject.config', |
| 45 | 'cordfabric' : 'org.onosproject.cordfabric', |
| 46 | 'demo' : 'org.onosproject.demo', |
| 47 | 'distributedprimitives' : 'org.onosproject.distributedprimitives', |
| 48 | 'election' : 'org.onosproject.election', |
| 49 | 'flowrule' : 'org.onosproject.flowrule', |
| 50 | 'fwd' : 'org.onosproject.fwd', |
| 51 | 'intentperf' : 'org.onosproject.intentperf', |
| 52 | 'messagingperf' : 'org.onosproject.messagingperf', |
| 53 | 'metrics' : 'org.onosproject.metrics', |
| 54 | 'mobility' : 'org.onosproject.mobility', |
| 55 | 'netconf' : 'org.onosproject.netconf', |
| 56 | 'null' : 'org.onosproject.null', |
| 57 | 'optical' : 'org.onosproject.optical' |
| 58 | } |
| 59 | # List of ONOS ip's specififed in params |
| 60 | main.ONOSips = [] |
| 61 | main.CLIs = [] |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 62 | main.ONOSnode = [] |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 63 | |
| 64 | for node in range( 0, int(main.params['CTRL']['num']) ): |
| 65 | main.ONOSips.append( main.params['CTRL']['ip'+str(node+1)] ) |
| 66 | main.CLIs.append( |
| 67 | getattr( main, 'ONOS' + str(node+1) + 'cli' ) ) |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 68 | main.ONOSnode.append( |
| 69 | getattr( main, 'ONOS' + str(node+1) ) ) |
| 70 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 71 | def CASE2( self, main ): |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 72 | import time |
| 73 | import imp |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 74 | |
| 75 | startupSrc = main.params['DEP']['startupSrc'] |
| 76 | startupClassName = main.params['DEP']['startupClassName'] |
| 77 | cellName = main.params['CELL']['name'] |
| 78 | appStr = main.params['CELL']['appStr'] |
| 79 | benchIp = main.params['BENCH']['ip'] |
| 80 | branchName = main.params['GIT']['branchName'] |
| 81 | gitPull = main.params['GIT']['pull'] |
| 82 | mnIp = main.params['MN']['ip'] |
| 83 | |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 84 | # importing dependency class(es) |
| 85 | # Refer to source files in Dependency folder to |
| 86 | # make changes to its respective methods |
| 87 | try: |
| 88 | startup = imp.load_source( startupClassName, startupSrc ) |
| 89 | except ImportError: |
| 90 | main.log.error( "Error importing class " + |
| 91 | str(startupClassName) + " from " + str(startupSrc) ) |
| 92 | main.cleanup() |
| 93 | main.exit() |
| 94 | |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 95 | main.case( 'Setup environment and install ONOS' ) |
| 96 | if gitPull == 'on': |
| 97 | main.step( 'Git pull and clean install' ) |
| 98 | gitPullResult = startup.gitPullAndMci( branchName ) |
| 99 | utilities.assert_equals( expect=main.TRUE, |
| 100 | actual=gitPullResult, |
| 101 | onpass='Git pull and install successful', |
| 102 | onfail='Git pull and install failed: ' + |
| 103 | str(gitPullResult) ) |
| 104 | |
| 105 | main.step( 'Initiate ONOS startup sequence' ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 106 | startupResult = startup.initOnosStartupSequence( |
| 107 | cellName, appStr, benchIp, mnIp, main.ONOSips ) |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 108 | utilities.assert_equals( expect=main.TRUE, |
| 109 | actual=startupResult, |
| 110 | onpass='ONOS startup sequence successful', |
| 111 | onfail='ONOS startup sequence failed: ' + |
| 112 | str(startupResult) ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 113 | |
| 114 | def CASE3( self, main ): |
| 115 | import time |
| 116 | import imp |
andrew@onlab.us | 1bc346b | 2015-05-21 17:21:16 -0400 | [diff] [blame] | 117 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 118 | main.case( 'Activate applications and check installation' ) |
| 119 | # Activate applications and check consistency |
| 120 | # across clusters |
| 121 | appClassName = main.params['DEP']['appClassName'] |
| 122 | appSrc = main.params['DEP']['appSrc'] |
| 123 | |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 124 | logClassName = main.params['DEP']['logClassName'] |
| 125 | logSrc = main.params['DEP']['logSrc'] |
| 126 | |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 127 | # Import application file to use its methods |
| 128 | try: |
| 129 | app = imp.load_source( appClassName, appSrc ) |
andrew@onlab.us | 9da18f2 | 2015-05-28 21:10:24 -0400 | [diff] [blame] | 130 | onosLog = imp.load_source( logClassName, logSrc ) |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 131 | except ImportError: |
| 132 | main.log.error( "Error importing class " + |
| 133 | str(startupClassName) + " from " + str(startupSrc) ) |
| 134 | main.cleanup() |
| 135 | main.exit() |
andrew@onlab.us | 484ef83 | 2015-05-29 16:08:27 -0400 | [diff] [blame^] | 136 | |
| 137 | # NOTE: Test only |
| 138 | # Unceremoniously kill onos 2 |
| 139 | main.ONOSbench.onosDie( '10.128.174.2' ) |
| 140 | |
| 141 | time.sleep( 30 ) |
| 142 | |
| 143 | main.step( 'Sample Onos log check' ) |
| 144 | logResult = onosLog.checkOnosLog( main.ONOSips[0] ) |
| 145 | main.log.info( logResult ) |
| 146 | # TODO: Define assertion pass / fail criteria |
andrew@onlab.us | 2bcfd8f | 2015-05-28 19:17:51 -0400 | [diff] [blame] | 147 | |
| 148 | # Sample app activation |
| 149 | main.step( 'Activating applications metrics and fwd' ) |
| 150 | appList = ['metrics', 'fwd'] |
| 151 | appResult = app.activate( appList ) |
| 152 | utilities.assert_equals( expect=main.TRUE, |
| 153 | actual=appResult, |
| 154 | onpass= 'App activation of ' + str(appList) + ' successful', |
| 155 | onfail= 'App activation failed ' + str(appResult) ) |
| 156 | |
| 157 | |
| 158 | |