lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 1 | """ |
Jeremy Ronquillo | b27ce4c | 2017-07-17 12:41:28 -0700 | [diff] [blame^] | 2 | Copyright 2015 Open Networking Foundation (ONF) |
| 3 | |
| 4 | Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>, |
| 5 | the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/xoMg>, |
| 6 | or the System Testing Guide page at <https://wiki.onosproject.org/x/WYQg> |
| 7 | |
| 8 | TestON is free software: you can redistribute it and/or modify |
| 9 | it under the terms of the GNU General Public License as published by |
| 10 | the Free Software Foundation, either version 2 of the License, or |
| 11 | (at your option) any later version. |
| 12 | |
| 13 | TestON is distributed in the hope that it will be useful, |
| 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | GNU General Public License for more details. |
| 17 | |
| 18 | You should have received a copy of the GNU General Public License |
| 19 | along with TestON. If not, see <http://www.gnu.org/licenses/>. |
| 20 | """ |
| 21 | |
| 22 | """ |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 23 | This file provide the data |
| 24 | lanqinglong@huawei.com |
| 25 | """ |
| 26 | import json |
| 27 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 28 | |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 29 | class NetworkData: |
| 30 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 31 | def __init__( self ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 32 | self.id = '' |
| 33 | self.state = 'ACTIVE' |
| 34 | self.name = 'onosfw-1' |
| 35 | self.physicalNetwork = 'none' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 36 | self.admin_state_up = True |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 37 | self.tenant_id = '' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 38 | self.routerExternal = False |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 39 | self.type = 'LOCAL' |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 40 | self.segmentationID = '6' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 41 | self.shared = False |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 42 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 43 | def DictoJson( self ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 44 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 45 | if self.id == '' or self.tenant_id == '': |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 46 | print 'Id and tenant id is necessary!' |
| 47 | |
| 48 | Dicdata = {} |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 49 | if self.id != '': |
| 50 | Dicdata[ 'id' ] = self.id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 51 | if self.state != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 52 | Dicdata[ 'status' ] = self.state |
| 53 | if self.name != '': |
| 54 | Dicdata[ 'name' ] = self.name |
| 55 | if self.physicalNetwork != '': |
| 56 | Dicdata[ 'provider:physical_network' ] = self.physicalNetwork |
| 57 | if self.admin_state_up != '': |
| 58 | Dicdata[ 'admin_state_up' ] = self.admin_state_up |
| 59 | if self.tenant_id != '': |
| 60 | Dicdata[ 'tenant_id' ] = self.tenant_id |
| 61 | if self.routerExternal != '': |
| 62 | Dicdata[ 'router:external' ] = self.routerExternal |
| 63 | if self.type != '': |
| 64 | Dicdata[ 'provider:network_type' ] = self.type |
| 65 | if self.segmentationID != '': |
| 66 | Dicdata[ 'provider:segmentation_id' ] = self.segmentationID |
| 67 | if self.shared != '': |
| 68 | Dicdata[ 'shared' ] = self.shared |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 69 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 70 | Dicdata = { 'network': Dicdata } |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 71 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 72 | return json.dumps( Dicdata, indent=4 ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 73 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 74 | def Ordered( self, obj ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 75 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 76 | if isinstance( obj, dict ): |
| 77 | return sorted( ( k, self.Ordered( v ) ) for k, v in obj.items() ) |
| 78 | if isinstance( obj, list ): |
| 79 | return sorted( self.Ordered( x ) for x in obj ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 80 | else: |
| 81 | return obj |
| 82 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 83 | def JsonCompare( self, SourceData, DestiData, FirstPara, SecondPara ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 84 | |
| 85 | try: |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 86 | SourceCompareDataDic = json.loads( SourceData ) |
| 87 | DestiCompareDataDic = json.loads( DestiData ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 88 | except ValueError: |
| 89 | print "SourceData or DestData is not JSON Type!" |
| 90 | return False |
| 91 | |
lanqinglong | e675e92 | 2015-08-13 21:17:28 +0800 | [diff] [blame] | 92 | try: |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 93 | Socom = SourceCompareDataDic[ FirstPara ][ SecondPara ] |
| 94 | Decom = DestiCompareDataDic[ FirstPara ][ SecondPara ] |
| 95 | except KeyError as error: |
| 96 | print "Key error ,This key is not found:%s" % error |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 97 | return False |
lanqinglong | e675e92 | 2015-08-13 21:17:28 +0800 | [diff] [blame] | 98 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 99 | if str( Socom ).lower() == str( Decom ).lower(): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 100 | return True |
| 101 | else: |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 102 | print "Source Compare data:" + FirstPara + "." + SecondPara + "=" + str( Socom ) |
| 103 | print "Dest Compare data: " + FirstPara + "." + SecondPara + "=" + str( Decom ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 104 | return False |
| 105 | |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 106 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 107 | class SubnetData( NetworkData ): |
| 108 | |
| 109 | def __init__( self ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 110 | self.id = '' |
| 111 | self.tenant_id = '' |
| 112 | self.network_id = '' |
| 113 | self.nexthop = '192.168.1.1' |
| 114 | self.destination = '192.168.1.1/24' |
| 115 | self.start = '192.168.2.2' |
| 116 | self.end = '192.168.2.254' |
| 117 | self.ipv6_address_mode = 'DHCPV6_STATELESS' |
| 118 | self.ipv6_ra_mode = 'DHCPV6_STATELESS' |
| 119 | self.cidr = '192.168.1.1/24' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 120 | self.enable_dhcp = True |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 121 | self.dns_nameservers = 'aaa' |
| 122 | self.gateway_ip = '192.168.2.1' |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 123 | self.ip_version = '4' |
| 124 | self.shared = False |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 125 | self.name = 'demo-subnet' |
| 126 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 127 | def DictoJson( self ): |
| 128 | if self.id == '' or self.tenant_id == '': |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 129 | print 'Id and tenant id is necessary!' |
| 130 | |
| 131 | Dicdata = {} |
| 132 | host_routesdata = [] |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 133 | host_routesdata.append( { 'nexthop': self.nexthop, 'destination': self.destination } ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 134 | allocation_pools = [] |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 135 | allocation_pools.append( { 'start': self.start, 'end': self.end } ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 136 | |
| 137 | if self.id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 138 | Dicdata[ 'id' ] = self.id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 139 | if self.network_id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 140 | Dicdata[ 'network_id' ] = self.network_id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 141 | if self.name != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 142 | Dicdata[ 'name' ] = self.name |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 143 | if self.nexthop != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 144 | Dicdata[ 'host_routes' ] = host_routesdata |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 145 | if self.tenant_id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 146 | Dicdata[ 'tenant_id' ] = self.tenant_id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 147 | if self.start != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 148 | Dicdata[ 'allocation_pools' ] = allocation_pools |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 149 | if self.shared != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 150 | Dicdata[ 'shared' ] = self.shared |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 151 | if self.ipv6_address_mode != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 152 | Dicdata[ 'ipv6_address_mode' ] = self.ipv6_address_mode |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 153 | if self.ipv6_ra_mode != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 154 | Dicdata[ 'ipv6_ra_mode' ] = self.ipv6_ra_mode |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 155 | if self.cidr != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 156 | Dicdata[ 'cidr' ] = self.cidr |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 157 | if self.enable_dhcp != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 158 | Dicdata[ 'enable_dhcp' ] = self.enable_dhcp |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 159 | if self.dns_nameservers != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 160 | Dicdata[ 'dns_nameservers' ] = self.dns_nameservers |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 161 | if self.gateway_ip != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 162 | Dicdata[ 'gateway_ip' ] = self.gateway_ip |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 163 | if self.ip_version != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 164 | Dicdata[ 'ip_version' ] = self.ip_version |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 165 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 166 | Dicdata = { 'subnet': Dicdata } |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 167 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 168 | return json.dumps( Dicdata, indent=4 ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 169 | |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 170 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 171 | class VirtualPortData( NetworkData ): |
| 172 | |
| 173 | def __init__( self ): |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 174 | self.id = '' |
| 175 | self.state = 'ACTIVE' |
| 176 | self.bindingHostId = 'fa:16:3e:76:8e:88' |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 177 | self.allowedAddressPairs = [ { 'mac_address': 'fa:16:3e:76:8e:88', 'ip_address': '192.168.1.1' } ] |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 178 | self.deviceOwner = 'none' |
| 179 | self.fixedIp = [] |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 180 | self.securityGroups = [ { 'securityGroup': 'asd' } ] |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 181 | self.adminStateUp = True |
| 182 | self.network_id = '' |
| 183 | self.tenant_id = '' |
| 184 | self.subnet_id = '' |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 185 | self.bindingvifDetails = 'port_filter' |
| 186 | self.bindingvnicType = 'normal' |
| 187 | self.bindingvifType = 'ovs' |
| 188 | self.macAddress = 'fa:16:3e:76:8e:88' |
| 189 | self.deviceId = 'a08aa' |
| 190 | self.name = 'u' |
| 191 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 192 | def DictoJson( self ): |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 193 | if self.id == '' or self.tenant_id == ' ' or \ |
| 194 | self.network_id == '' or self.subnet_id == '': |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 195 | print 'Id/tenant id/networkid/subnetId is necessary!' |
| 196 | |
| 197 | Dicdata = {} |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 198 | fixedIp = [] |
| 199 | fixedIp.append( { 'subnet_id': self.subnet_id, 'ip_address': '192.168.1.4' } ) |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 200 | allocation_pools = [] |
| 201 | |
| 202 | if self.id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 203 | Dicdata[ 'id' ] = self.id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 204 | if self.state != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 205 | Dicdata[ 'status' ] = self.state |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 206 | if self.bindingHostId != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 207 | Dicdata[ 'binding:host_id' ] = self.bindingHostId |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 208 | if self.allowedAddressPairs != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 209 | Dicdata[ 'allowed_address_pairs' ] = self.allowedAddressPairs |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 210 | if self.deviceOwner != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 211 | Dicdata[ 'device_owner' ] = self.deviceOwner |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 212 | if self.securityGroups != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 213 | Dicdata[ 'security_groups' ] = self.securityGroups |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 214 | if self.adminStateUp != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 215 | Dicdata[ 'admin_state_up' ] = self.adminStateUp |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 216 | if self.network_id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 217 | Dicdata[ 'network_id' ] = self.network_id |
lanqinglong | d0dda2e | 2015-08-25 11:02:48 +0800 | [diff] [blame] | 218 | if self.tenant_id != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 219 | Dicdata[ 'tenant_id' ] = self.tenant_id |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 220 | if self.bindingvifDetails != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 221 | Dicdata[ 'binding:vif_details' ] = self.bindingvifDetails |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 222 | if self.bindingvnicType != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 223 | Dicdata[ 'binding:vnic_type' ] = self.bindingvnicType |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 224 | if self.bindingvifType != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 225 | Dicdata[ 'binding:vif_type' ] = self.bindingvifType |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 226 | if self.macAddress != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 227 | Dicdata[ 'mac_address' ] = self.macAddress |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 228 | if self.deviceId != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 229 | Dicdata[ 'device_id' ] = self.deviceId |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 230 | if self.name != '': |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 231 | Dicdata[ 'name' ] = self.name |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 232 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 233 | Dicdata[ 'fixed_ips' ] = fixedIp |
| 234 | Dicdata = { 'port': Dicdata } |
lanqinglong | 77124b0 | 2015-08-06 11:47:38 +0800 | [diff] [blame] | 235 | |
Jon Hall | f52840a | 2017-05-24 16:49:52 -0700 | [diff] [blame] | 236 | return json.dumps( Dicdata, indent=4 ) |