From f7c4c771388c7ee9c6c18fd2796e00a1283de038 Mon Sep 17 00:00:00 2001 From: zhanghaoyu7 Date: Thu, 5 Nov 2015 15:35:17 +0800 Subject: write ovsdb connection related scripts JIRA:ONOSFW-64 1.ovsdb connection scripts Change-Id: Id51cf1eb3e7545c35ef64156b7dc7618cc69073f --- .../testcases/FUNCovsdbtest/FUNCovsdbtest.params | 48 +++++ .../testcases/FUNCovsdbtest/FUNCovsdbtest.py | 240 +++++++++++++++++++++ .../testcases/FUNCovsdbtest/FUNCovsdbtest.topo | 60 ++++++ .../Teston/testcases/FUNCovsdbtest/__init__.py | 0 .../testcases/FUNCovsdbtest/dependencies/Nbdata.py | 212 ++++++++++++++++++ .../FUNCovsdbtest/dependencies/__init__.py | 0 6 files changed, 560 insertions(+) create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.params create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.py create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.topo create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/__init__.py create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/Nbdata.py create mode 100644 framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/__init__.py diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.params b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.params new file mode 100644 index 00000000..e1128284 --- /dev/null +++ b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.params @@ -0,0 +1,48 @@ + + # CASE - Description + # 1 - Compile ONOS and push it to the test machines + # 2 - Test ovsdb connection and tearDown + # 3 - Test default br-int configuration and vxlan port + # 4 - Test default openflow configuration + # 5 - Test default flows + # 6 - Configure Network Subnet Port + # 7 - Test host go online and ping each other + # 8 - Clear ovs configuration and host configuration + + 1,3,4,2,5,6,7,8 + + + /tests/FUNCovsdbtest/Dependency/ + + + + singlenode + drivers,openflow,proxyarp,mobility + + + + OC1 + 6653 + 6640 + + + + 5 #delaytime for ovsdb connection create and delete + + + + 8181 + /onos/vtn/ + + + + False + master + + + + OCN + OC1 + + + diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.py b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.py new file mode 100644 index 00000000..1cb0ab20 --- /dev/null +++ b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.py @@ -0,0 +1,240 @@ +""" +Description: This test is to check onos set configuration and flows with ovsdb connection. + +List of test cases: +CASE1: Compile ONOS and push it to the test machines +CASE2: Test ovsdb connection and tearDown +CASE3: Test default br-int configuration and vxlan port +CASE4: Test default openflow configuration +CASE5: Test default flows +CASE6: Configure Network Subnet Port +CASE7: Test host go online and ping each other +CASE8: Clear ovs configuration and host configuration +zhanghaoyu7@huawei.com +""" +import os + +class FUNCovsdbtest: + + def __init__( self ): + self.default = '' + + def CASE1( self, main ): + """ + CASE1 is to compile ONOS and push it to the test machines + + Startup sequence: + cell + onos-verify-cell + NOTE: temporary - onos-remove-raft-logs + onos-uninstall + start mininet + git pull + mvn clean install + onos-package + onos-install -f + onos-wait-for-start + start cli sessions + start ovsdb + start vtn apps + """ + import os + main.log.info( "ONOS Single node start " + + "ovsdb test - initialization" ) + main.case( "Setting up test environment" ) + main.caseExplanation = "Setup the test environment including " +\ + "installing ONOS, start ONOS." + + # load some variables from the params file + PULLCODE = False + if main.params[ 'GIT' ][ 'pull' ] == 'True': + PULLCODE = True + gitBranch = main.params[ 'GIT' ][ 'branch' ] + cellName = main.params[ 'ENV' ][ 'cellName' ] + ipList = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] ) + OVSDB1Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip1' ] ) + OVSDB2Ip = os.getenv( main.params[ 'OVSDB' ][ 'ip2' ] ) + + main.step( "Create cell file" ) + cellAppString = main.params[ 'ENV' ][ 'cellApps' ] + main.ONOSbench.createCellFile( main.ONOSbench.ip_address, cellName, + main.OVSDB1.ip_address, + cellAppString, ipList ) + + main.step( "Applying cell variable to environment" ) + cellResult = main.ONOSbench.setCell( cellName ) + verifyResult = main.ONOSbench.verifyCell() + + main.log.info( "Removing raft logs" ) + main.ONOSbench.onosRemoveRaftLogs() + + main.CLIs = [] + main.nodes = [] + main.numCtrls= 1 + + for i in range( 1, main.numCtrls + 1 ): + try: + main.CLIs.append( getattr( main, 'ONOScli' + str( i ) ) ) + main.nodes.append( getattr( main, 'ONOS' + str( i ) ) ) + ipList.append( main.nodes[ -1 ].ip_address ) + except AttributeError: + break + + main.log.info( "Uninstalling ONOS" ) + for node in main.nodes: + main.ONOSbench.onosUninstall( node.ip_address ) + + # Make sure ONOS process is not running + main.log.info( "Killing any ONOS processes" ) + killResults = main.TRUE + for node in main.nodes: + killed = main.ONOSbench.onosKill( node.ip_address ) + killResults = killResults and killed + + cleanInstallResult = main.TRUE + gitPullResult = main.TRUE + main.step( "Git checkout and pull" + gitBranch ) + if PULLCODE: + main.ONOSbench.gitCheckout( gitBranch ) + gitPullResult = main.ONOSbench.gitPull() + # values of 1 or 3 are good + utilities.assert_lesser( expect=0, actual=gitPullResult, + onpass="Git pull successful", + onfail="Git pull failed" ) + + main.ONOSbench.getVersion( report=True ) + + main.step( "Using mvn clean install" ) + cleanInstallResult = main.TRUE + if PULLCODE and gitPullResult == main.TRUE: + cleanInstallResult = main.ONOSbench.cleanInstall() + else: + main.log.warn( "Did not pull new code so skipping mvn" + + "clean install" ) + utilities.assert_equals( expect=main.TRUE, + actual=cleanInstallResult, + onpass="MCI successful", + onfail="MCI failed" ) + + main.step( "Creating ONOS package" ) + packageResult = main.ONOSbench.onosPackage() + utilities.assert_equals( expect=main.TRUE, + actual=packageResult, + onpass="Successfully created ONOS package", + onfail="Failed to create ONOS package" ) + + main.step( "Installing ONOS package" ) + onosInstallResult = main.ONOSbench.onosInstall( + options="-f", node=main.nodes[0].ip_address ) + utilities.assert_equals( expect=main.TRUE, actual=onosInstallResult, + onpass="ONOS install successful", + onfail="ONOS install failed" ) + + main.step( "Checking if ONOS is up yet" ) + print main.nodes[0].ip_address + for i in range( 2 ): + onos1Isup = main.ONOSbench.isup( main.nodes[0].ip_address ) + if onos1Isup: + break + utilities.assert_equals( expect=main.TRUE, actual=onos1Isup, + onpass="ONOS startup successful", + onfail="ONOS startup failed" ) + main.log.step( "Starting ONOS CLI sessions" ) + print main.nodes[0].ip_address + cliResults = main.ONOScli1.startOnosCli( main.nodes[0].ip_address ) + utilities.assert_equals( expect=main.TRUE, actual=cliResults, + onpass="ONOS cli startup successful", + onfail="ONOS cli startup failed" ) + + main.step( "App Ids check" ) + appCheck = main.ONOScli1.appToIDCheck() + + if appCheck !=main.TRUE: + main.log.warn( main.CLIs[0].apps() ) + main.log.warn( main.CLIs[0].appIDs() ) + utilities.assert_equals( expect=main.TRUE, actual=appCheck, + onpass="App Ids seem to be correct", + onfail="Something is wrong with app Ids" ) + if cliResults == main.FALSE: + main.log.error( "Failed to start ONOS,stopping test" ) + main.cleanup() + main.exit() + + main.step( "Install onos-ovsdatabase" ) + installResults = main.ONOScli1.activateApp( "org.onosproject.ovsdb" ) + utilities.assert_equals( expect=main.TRUE, actual=installResults, + onpass="Install onos-ovsdatabase successful", + onfail="Install onos-ovsdatabase failed" ) + + main.step( "Install onos-app-vtnrsc" ) + installResults = main.ONOScli1.activateApp( "org.onosproject.vtnrsc" ) + utilities.assert_equals( expect=main.TRUE, actual=installResults, + onpass="Install onos-app-vtnrsc successful", + onfail="Install onos-app-vtnrsc failed" ) + + main.step( "Install onos-app-vtn" ) + installResults = main.ONOScli1.activateApp( "org.onosproject.vtn" ) + utilities.assert_equals( expect=main.TRUE, actual=installResults, + onpass="Install onos-app-vtn successful", + onfail="Install onos-app-vtn failed" ) + + main.step( "Install onos-app-vtnweb" ) + installResults = main.ONOScli1.activateApp( "org.onosproject.vtnweb" ) + utilities.assert_equals( expect=main.TRUE, actual=installResults, + onpass="Install onos-app-vtnweb successful", + onfail="Install onos-app-vtnweb failed" ) + + def CASE2( self, main ): + + """ + Test ovsdb connection and teardown + """ + import os,sys + import re + import time + + main.case( "Test ovsdb connection and teardown" ) + main.caseExplanation = "Test ovsdb connection create and delete" +\ + " over ovsdb node and onos node " + + ctrlip = os.getenv( main.params[ 'CTRL' ][ 'ip1' ] ) + ovsdbport = main.params[ 'CTRL' ][ 'ovsdbport' ] + delaytime = main.params[ 'TIMER' ][ 'delaytime' ] + + main.step( "Set ovsdb node manager" ) + assignResult = main.OVSDB1.setManager( ip=ctrlip, port=ovsdbport, delaytime=delaytime ) + stepResult = assignResult + utilities.assert_equals( expect=main.TRUE, + actual=stepResult, + onpass="Set ovsdb node manager sucess", + onfail="Set ovsdb node manager failed" ) + + main.step( "Check ovsdb node manager is " + str( ctrlip ) ) + response = main.OVSDB1.getManager() + if re.search( ctrlip, response ): + stepResult = main.TRUE + else: + stepResult = main.FALSE + utilities.assert_equals( expect=main.TRUE, + actual=stepResult, + onpass="Check ovsdb node manager is " + str( response ) , + onfail="Check ovsdb node manager failed" ) + + main.step( "Delete ovsdb node manager" ) + deleteResult = main.OVSDB1.delManager( delaytime=delaytime ) + stepResult = deleteResult + utilities.assert_equals( expect=main.TRUE, + actual=stepResult, + onpass="ovsdb node delete manager sucess", + onfail="ovsdb node delete manager failed" ) + + main.step( "Check ovsdb node delete manager " + str( ctrlip ) ) + response = main.OVSDB1.getManager() + if not re.search( ctrlip, response ): + stepResult = main.TRUE + else: + stepResult = main.FALSE + utilities.assert_equals( expect=main.TRUE, + actual=stepResult, + onpass="Check ovsdb node delete manager sucess", + onfail="Check ovsdb node delete manager failed" ) diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.topo b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.topo new file mode 100644 index 00000000..ae748d2e --- /dev/null +++ b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/FUNCovsdbtest.topo @@ -0,0 +1,60 @@ + + + + + OCN + admin + + OnosDriver + 1 + + + + + + OCN + admin + + OnosCliDriver + 2 + + + + + OC1 + sdn + + OnosDriver + 3 + + + + + OC1 + sdn + + OnosRestDriver + 4 + + + + + OCN + admin + + OvsdbDriver + 5 + + + + + OC1 + sdn + + OvsdbDriver + 6 + + + + + diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/__init__.py b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/Nbdata.py b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/Nbdata.py new file mode 100644 index 00000000..3fde20db --- /dev/null +++ b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/Nbdata.py @@ -0,0 +1,212 @@ +""" +This file provide the data +lanqinglong@huawei.com +""" +import json + +class NetworkData: + + def __init__(self): + self.id = '' + self.state = 'ACTIVE' + self.name = 'onosfw-1' + self.physicalNetwork = 'none' + self.admin_state_up = True + self.tenant_id = '' + self.routerExternal = False + self.type ='LOCAL' + self.segmentationID = '6' + self.shared = False + + def DictoJson(self): + + if self.id =='' or self.tenant_id == '': + print 'Id and tenant id is necessary!' + + Dicdata = {} + if self.id !='': + Dicdata['id'] = self.id + if self.state != '': + Dicdata['status'] = self.state + if self.name !='': + Dicdata['name'] = self.name + if self.physicalNetwork !='': + Dicdata['provider:physical_network'] = self.physicalNetwork + if self.admin_state_up !='': + Dicdata['admin_state_up'] = self.admin_state_up + if self.tenant_id !='': + Dicdata['tenant_id'] = self.tenant_id + if self.routerExternal !='': + Dicdata['router:external'] = self.routerExternal + if self.type !='': + Dicdata['provider:network_type'] = self.type + if self.segmentationID !='': + Dicdata['provider:segmentation_id'] = self.segmentationID + if self.shared !='': + Dicdata['shared'] = self.shared + + Dicdata = {'network': Dicdata} + + return json.dumps(Dicdata,indent=4) + + def Ordered(self,obj): + + if isinstance(obj, dict): + return sorted((k,self.Ordered(v)) for k, v in obj.items()) + if isinstance(obj, list): + return sorted(self.Ordered(x) for x in obj ) + else: + return obj + + def JsonCompare(self,SourceData,DestiData,FirstPara,SecondPara): + + try: + SourceCompareDataDic = json.loads(SourceData) + DestiCompareDataDic = json.loads(DestiData) + except ValueError: + print "SourceData or DestData is not JSON Type!" + return False + + try: + Socom = SourceCompareDataDic[FirstPara][SecondPara] + Decom = DestiCompareDataDic[FirstPara][SecondPara] + except KeyError,error: + print "Key error ,This key is not found:%s"%error + return False + + if str(Socom).lower()== str(Decom).lower(): + return True + else: + print "Source Compare data:"+FirstPara+"."+SecondPara+"="+str(Socom) + print "Dest Compare data: "+FirstPara+"."+SecondPara+"="+str(Decom) + return False + +class SubnetData(NetworkData): + + def __init__(self): + self.id = '' + self.tenant_id = '' + self.network_id = '' + self.nexthop = '192.168.1.1' + self.destination = '192.168.1.1/24' + self.start = '192.168.2.2' + self.end = '192.168.2.254' + self.ipv6_address_mode = 'DHCPV6_STATELESS' + self.ipv6_ra_mode = 'DHCPV6_STATELESS' + self.cidr = '192.168.1.1/24' + self.enable_dhcp = True + self.dns_nameservers = 'aaa' + self.gateway_ip = '192.168.2.1' + self.ip_version = '4' + self.shared = False + self.name = 'demo-subnet' + + def DictoJson(self): + if self.id =='' or self.tenant_id == '': + print 'Id and tenant id is necessary!' + + Dicdata = {} + host_routesdata = [] + host_routesdata.append({'nexthop': self.nexthop,'destination': self.destination}) + allocation_pools = [] + allocation_pools.append({'start': self.start,'end':self.end}) + + if self.id != '': + Dicdata['id'] = self.id + if self.network_id != '': + Dicdata['network_id'] = self.network_id + if self.name != '': + Dicdata['name'] = self.name + if self.nexthop != '': + Dicdata['host_routes'] = host_routesdata + if self.tenant_id != '': + Dicdata['tenant_id'] = self.tenant_id + if self.start != '': + Dicdata['allocation_pools'] = allocation_pools + if self.shared != '': + Dicdata['shared'] = self.shared + if self.ipv6_address_mode != '': + Dicdata['ipv6_address_mode'] = self.ipv6_address_mode + if self.ipv6_ra_mode != '': + Dicdata['ipv6_ra_mode'] = self.ipv6_ra_mode + if self.cidr != '': + Dicdata['cidr'] = self.cidr + if self.enable_dhcp != '': + Dicdata['enable_dhcp'] = self.enable_dhcp + if self.dns_nameservers != '': + Dicdata['dns_nameservers'] = self.dns_nameservers + if self.gateway_ip != '': + Dicdata['gateway_ip'] = self.gateway_ip + if self.ip_version != '': + Dicdata['ip_version'] = self.ip_version + + Dicdata = {'subnet': Dicdata} + + return json.dumps(Dicdata,indent=4) + +class VirtualPortData(NetworkData): + + def __init__(self): + self.id = '' + self.state = 'ACTIVE' + self.bindingHostId = 'fa:16:3e:76:8e:88' + self.allowedAddressPairs = [{'mac_address':'fa:16:3e:76:8e:88','ip_address':'192.168.1.1'}] + self.deviceOwner = 'none' + self.fixedIp = [] + self.securityGroups = [{'securityGroup':'asd'}] + self.adminStateUp = True + self.network_id = '' + self.tenant_id = '' + self.subnet_id = '' + self.bindingvifDetails = 'port_filter' + self.bindingvnicType = 'normal' + self.bindingvifType = 'ovs' + self.macAddress = 'fa:16:3e:76:8e:88' + self.deviceId = 'a08aa' + self.name = 'u' + + def DictoJson(self): + if self.id == '' or self.tenant_id == ' ' or \ + self.network_id == '' or self.subnet_id == '': + print 'Id/tenant id/networkid/subnetId is necessary!' + + Dicdata = {} + fixedIp =[] + fixedIp.append({'subnet_id':self.subnet_id,'ip_address':'192.168.1.4'}) + allocation_pools = [] + + if self.id != '': + Dicdata['id'] = self.id + if self.state != '': + Dicdata['status'] = self.state + if self.bindingHostId != '': + Dicdata['binding:host_id'] = self.bindingHostId + if self.allowedAddressPairs != '': + Dicdata['allowed_address_pairs'] = self.allowedAddressPairs + if self.deviceOwner != '': + Dicdata['device_owner'] = self.deviceOwner + if self.securityGroups != '': + Dicdata['security_groups'] = self.securityGroups + if self.adminStateUp != '': + Dicdata['admin_state_up'] = self.adminStateUp + if self.network_id != '': + Dicdata['network_id'] = self.network_id + if self.tenant_id != '': + Dicdata['tenant_id'] = self.tenant_id + if self.bindingvifDetails != '': + Dicdata['binding:vif_details'] = self.bindingvifDetails + if self.bindingvnicType != '': + Dicdata['binding:vnic_type'] = self.bindingvnicType + if self.bindingvifType != '': + Dicdata['binding:vif_type'] = self.bindingvifType + if self.macAddress != '': + Dicdata['mac_address'] = self.macAddress + if self.deviceId != '': + Dicdata['device_id'] = self.deviceId + if self.name != '': + Dicdata['name'] = self.name + + Dicdata['fixed_ips'] = fixedIp + Dicdata = {'port': Dicdata} + + return json.dumps(Dicdata,indent=4) diff --git a/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/__init__.py b/framework/scripts/function_test/Teston/testcases/FUNCovsdbtest/dependencies/__init__.py new file mode 100644 index 00000000..e69de29b -- cgit 1.2.3-korg