blob: 55a661bb447e8afc1b9b10f3386223eb16dd0af2 [file] [log] [blame]
lanqinglong77124b02015-08-06 11:47:38 +08001"""
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -07002Copyright 2015 Open Networking Foundation ( ONF )
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -07003
4Please refer questions to either the onos test mailing list at <onos-test@onosproject.org>,
5the System Testing Plans and Results wiki page at <https://wiki.onosproject.org/xoMg>,
6or 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
Jeremy Ronquillo23fb2162017-09-15 14:59:57 -070011 ( at your option ) any later version.
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070012
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"""
Jeremy Ronquillob27ce4c2017-07-17 12:41:28 -070021"""
lanqinglong77124b02015-08-06 11:47:38 +080022This file provide the data
23lanqinglong@huawei.com
24"""
25import json
26
Jon Hallf52840a2017-05-24 16:49:52 -070027
lanqinglong77124b02015-08-06 11:47:38 +080028class NetworkData:
29
Jon Hallf52840a2017-05-24 16:49:52 -070030 def __init__( self ):
lanqinglong77124b02015-08-06 11:47:38 +080031 self.id = ''
32 self.state = 'ACTIVE'
33 self.name = 'onosfw-1'
34 self.physicalNetwork = 'none'
lanqinglongd0dda2e2015-08-25 11:02:48 +080035 self.admin_state_up = True
lanqinglong77124b02015-08-06 11:47:38 +080036 self.tenant_id = ''
lanqinglongd0dda2e2015-08-25 11:02:48 +080037 self.routerExternal = False
Jon Hallf52840a2017-05-24 16:49:52 -070038 self.type = 'LOCAL'
lanqinglong77124b02015-08-06 11:47:38 +080039 self.segmentationID = '6'
lanqinglongd0dda2e2015-08-25 11:02:48 +080040 self.shared = False
lanqinglong77124b02015-08-06 11:47:38 +080041
Jon Hallf52840a2017-05-24 16:49:52 -070042 def DictoJson( self ):
lanqinglong77124b02015-08-06 11:47:38 +080043
Jon Hallf52840a2017-05-24 16:49:52 -070044 if self.id == '' or self.tenant_id == '':
lanqinglong77124b02015-08-06 11:47:38 +080045 print 'Id and tenant id is necessary!'
46
47 Dicdata = {}
Jon Hallf52840a2017-05-24 16:49:52 -070048 if self.id != '':
49 Dicdata[ 'id' ] = self.id
lanqinglong77124b02015-08-06 11:47:38 +080050 if self.state != '':
Jon Hallf52840a2017-05-24 16:49:52 -070051 Dicdata[ 'status' ] = self.state
52 if self.name != '':
53 Dicdata[ 'name' ] = self.name
54 if self.physicalNetwork != '':
55 Dicdata[ 'provider:physical_network' ] = self.physicalNetwork
56 if self.admin_state_up != '':
57 Dicdata[ 'admin_state_up' ] = self.admin_state_up
58 if self.tenant_id != '':
59 Dicdata[ 'tenant_id' ] = self.tenant_id
60 if self.routerExternal != '':
61 Dicdata[ 'router:external' ] = self.routerExternal
62 if self.type != '':
63 Dicdata[ 'provider:network_type' ] = self.type
64 if self.segmentationID != '':
65 Dicdata[ 'provider:segmentation_id' ] = self.segmentationID
66 if self.shared != '':
67 Dicdata[ 'shared' ] = self.shared
lanqinglong77124b02015-08-06 11:47:38 +080068
Jon Hallf52840a2017-05-24 16:49:52 -070069 Dicdata = { 'network': Dicdata }
lanqinglong77124b02015-08-06 11:47:38 +080070
Jon Hallf52840a2017-05-24 16:49:52 -070071 return json.dumps( Dicdata, indent=4 )
lanqinglong77124b02015-08-06 11:47:38 +080072
Jon Hallf52840a2017-05-24 16:49:52 -070073 def Ordered( self, obj ):
lanqinglong77124b02015-08-06 11:47:38 +080074
Jon Hallf52840a2017-05-24 16:49:52 -070075 if isinstance( obj, dict ):
76 return sorted( ( k, self.Ordered( v ) ) for k, v in obj.items() )
77 if isinstance( obj, list ):
78 return sorted( self.Ordered( x ) for x in obj )
lanqinglong77124b02015-08-06 11:47:38 +080079 else:
80 return obj
81
Jon Hallf52840a2017-05-24 16:49:52 -070082 def JsonCompare( self, SourceData, DestiData, FirstPara, SecondPara ):
lanqinglong77124b02015-08-06 11:47:38 +080083
84 try:
Jon Hallf52840a2017-05-24 16:49:52 -070085 SourceCompareDataDic = json.loads( SourceData )
86 DestiCompareDataDic = json.loads( DestiData )
lanqinglong77124b02015-08-06 11:47:38 +080087 except ValueError:
88 print "SourceData or DestData is not JSON Type!"
89 return False
90
lanqinglonge675e922015-08-13 21:17:28 +080091 try:
Jon Hallf52840a2017-05-24 16:49:52 -070092 Socom = SourceCompareDataDic[ FirstPara ][ SecondPara ]
93 Decom = DestiCompareDataDic[ FirstPara ][ SecondPara ]
94 except KeyError as error:
95 print "Key error ,This key is not found:%s" % error
lanqinglongd0dda2e2015-08-25 11:02:48 +080096 return False
lanqinglonge675e922015-08-13 21:17:28 +080097
Jon Hallf52840a2017-05-24 16:49:52 -070098 if str( Socom ).lower() == str( Decom ).lower():
lanqinglong77124b02015-08-06 11:47:38 +080099 return True
100 else:
Jon Hallf52840a2017-05-24 16:49:52 -0700101 print "Source Compare data:" + FirstPara + "." + SecondPara + "=" + str( Socom )
102 print "Dest Compare data: " + FirstPara + "." + SecondPara + "=" + str( Decom )
lanqinglong77124b02015-08-06 11:47:38 +0800103 return False
104
lanqinglong77124b02015-08-06 11:47:38 +0800105
Jon Hallf52840a2017-05-24 16:49:52 -0700106class SubnetData( NetworkData ):
107
108 def __init__( self ):
lanqinglong77124b02015-08-06 11:47:38 +0800109 self.id = ''
110 self.tenant_id = ''
111 self.network_id = ''
112 self.nexthop = '192.168.1.1'
113 self.destination = '192.168.1.1/24'
114 self.start = '192.168.2.2'
115 self.end = '192.168.2.254'
116 self.ipv6_address_mode = 'DHCPV6_STATELESS'
117 self.ipv6_ra_mode = 'DHCPV6_STATELESS'
118 self.cidr = '192.168.1.1/24'
lanqinglongd0dda2e2015-08-25 11:02:48 +0800119 self.enable_dhcp = True
lanqinglong77124b02015-08-06 11:47:38 +0800120 self.dns_nameservers = 'aaa'
121 self.gateway_ip = '192.168.2.1'
lanqinglongd0dda2e2015-08-25 11:02:48 +0800122 self.ip_version = '4'
123 self.shared = False
lanqinglong77124b02015-08-06 11:47:38 +0800124 self.name = 'demo-subnet'
125
Jon Hallf52840a2017-05-24 16:49:52 -0700126 def DictoJson( self ):
127 if self.id == '' or self.tenant_id == '':
lanqinglong77124b02015-08-06 11:47:38 +0800128 print 'Id and tenant id is necessary!'
129
130 Dicdata = {}
131 host_routesdata = []
Jon Hallf52840a2017-05-24 16:49:52 -0700132 host_routesdata.append( { 'nexthop': self.nexthop, 'destination': self.destination } )
lanqinglong77124b02015-08-06 11:47:38 +0800133 allocation_pools = []
Jon Hallf52840a2017-05-24 16:49:52 -0700134 allocation_pools.append( { 'start': self.start, 'end': self.end } )
lanqinglong77124b02015-08-06 11:47:38 +0800135
136 if self.id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700137 Dicdata[ 'id' ] = self.id
lanqinglong77124b02015-08-06 11:47:38 +0800138 if self.network_id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700139 Dicdata[ 'network_id' ] = self.network_id
lanqinglong77124b02015-08-06 11:47:38 +0800140 if self.name != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700141 Dicdata[ 'name' ] = self.name
lanqinglong77124b02015-08-06 11:47:38 +0800142 if self.nexthop != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700143 Dicdata[ 'host_routes' ] = host_routesdata
lanqinglong77124b02015-08-06 11:47:38 +0800144 if self.tenant_id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700145 Dicdata[ 'tenant_id' ] = self.tenant_id
lanqinglong77124b02015-08-06 11:47:38 +0800146 if self.start != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700147 Dicdata[ 'allocation_pools' ] = allocation_pools
lanqinglong77124b02015-08-06 11:47:38 +0800148 if self.shared != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700149 Dicdata[ 'shared' ] = self.shared
lanqinglong77124b02015-08-06 11:47:38 +0800150 if self.ipv6_address_mode != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700151 Dicdata[ 'ipv6_address_mode' ] = self.ipv6_address_mode
lanqinglong77124b02015-08-06 11:47:38 +0800152 if self.ipv6_ra_mode != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700153 Dicdata[ 'ipv6_ra_mode' ] = self.ipv6_ra_mode
lanqinglong77124b02015-08-06 11:47:38 +0800154 if self.cidr != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700155 Dicdata[ 'cidr' ] = self.cidr
lanqinglong77124b02015-08-06 11:47:38 +0800156 if self.enable_dhcp != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700157 Dicdata[ 'enable_dhcp' ] = self.enable_dhcp
lanqinglong77124b02015-08-06 11:47:38 +0800158 if self.dns_nameservers != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700159 Dicdata[ 'dns_nameservers' ] = self.dns_nameservers
lanqinglong77124b02015-08-06 11:47:38 +0800160 if self.gateway_ip != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700161 Dicdata[ 'gateway_ip' ] = self.gateway_ip
lanqinglong77124b02015-08-06 11:47:38 +0800162 if self.ip_version != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700163 Dicdata[ 'ip_version' ] = self.ip_version
lanqinglong77124b02015-08-06 11:47:38 +0800164
Jon Hallf52840a2017-05-24 16:49:52 -0700165 Dicdata = { 'subnet': Dicdata }
lanqinglong77124b02015-08-06 11:47:38 +0800166
Jon Hallf52840a2017-05-24 16:49:52 -0700167 return json.dumps( Dicdata, indent=4 )
lanqinglong77124b02015-08-06 11:47:38 +0800168
lanqinglong77124b02015-08-06 11:47:38 +0800169
Jon Hallf52840a2017-05-24 16:49:52 -0700170class VirtualPortData( NetworkData ):
171
172 def __init__( self ):
lanqinglong77124b02015-08-06 11:47:38 +0800173 self.id = ''
174 self.state = 'ACTIVE'
175 self.bindingHostId = 'fa:16:3e:76:8e:88'
Jon Hallf52840a2017-05-24 16:49:52 -0700176 self.allowedAddressPairs = [ { 'mac_address': 'fa:16:3e:76:8e:88', 'ip_address': '192.168.1.1' } ]
lanqinglong77124b02015-08-06 11:47:38 +0800177 self.deviceOwner = 'none'
178 self.fixedIp = []
Jon Hallf52840a2017-05-24 16:49:52 -0700179 self.securityGroups = [ { 'securityGroup': 'asd' } ]
lanqinglongd0dda2e2015-08-25 11:02:48 +0800180 self.adminStateUp = True
181 self.network_id = ''
182 self.tenant_id = ''
183 self.subnet_id = ''
lanqinglong77124b02015-08-06 11:47:38 +0800184 self.bindingvifDetails = 'port_filter'
185 self.bindingvnicType = 'normal'
186 self.bindingvifType = 'ovs'
187 self.macAddress = 'fa:16:3e:76:8e:88'
188 self.deviceId = 'a08aa'
189 self.name = 'u'
190
Jon Hallf52840a2017-05-24 16:49:52 -0700191 def DictoJson( self ):
lanqinglongd0dda2e2015-08-25 11:02:48 +0800192 if self.id == '' or self.tenant_id == ' ' or \
193 self.network_id == '' or self.subnet_id == '':
lanqinglong77124b02015-08-06 11:47:38 +0800194 print 'Id/tenant id/networkid/subnetId is necessary!'
195
196 Dicdata = {}
Jon Hallf52840a2017-05-24 16:49:52 -0700197 fixedIp = []
198 fixedIp.append( { 'subnet_id': self.subnet_id, 'ip_address': '192.168.1.4' } )
lanqinglong77124b02015-08-06 11:47:38 +0800199 allocation_pools = []
200
201 if self.id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700202 Dicdata[ 'id' ] = self.id
lanqinglong77124b02015-08-06 11:47:38 +0800203 if self.state != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700204 Dicdata[ 'status' ] = self.state
lanqinglong77124b02015-08-06 11:47:38 +0800205 if self.bindingHostId != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700206 Dicdata[ 'binding:host_id' ] = self.bindingHostId
lanqinglong77124b02015-08-06 11:47:38 +0800207 if self.allowedAddressPairs != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700208 Dicdata[ 'allowed_address_pairs' ] = self.allowedAddressPairs
lanqinglong77124b02015-08-06 11:47:38 +0800209 if self.deviceOwner != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700210 Dicdata[ 'device_owner' ] = self.deviceOwner
lanqinglong77124b02015-08-06 11:47:38 +0800211 if self.securityGroups != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700212 Dicdata[ 'security_groups' ] = self.securityGroups
lanqinglong77124b02015-08-06 11:47:38 +0800213 if self.adminStateUp != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700214 Dicdata[ 'admin_state_up' ] = self.adminStateUp
lanqinglongd0dda2e2015-08-25 11:02:48 +0800215 if self.network_id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700216 Dicdata[ 'network_id' ] = self.network_id
lanqinglongd0dda2e2015-08-25 11:02:48 +0800217 if self.tenant_id != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700218 Dicdata[ 'tenant_id' ] = self.tenant_id
lanqinglong77124b02015-08-06 11:47:38 +0800219 if self.bindingvifDetails != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700220 Dicdata[ 'binding:vif_details' ] = self.bindingvifDetails
lanqinglong77124b02015-08-06 11:47:38 +0800221 if self.bindingvnicType != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700222 Dicdata[ 'binding:vnic_type' ] = self.bindingvnicType
lanqinglong77124b02015-08-06 11:47:38 +0800223 if self.bindingvifType != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700224 Dicdata[ 'binding:vif_type' ] = self.bindingvifType
lanqinglong77124b02015-08-06 11:47:38 +0800225 if self.macAddress != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700226 Dicdata[ 'mac_address' ] = self.macAddress
lanqinglong77124b02015-08-06 11:47:38 +0800227 if self.deviceId != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700228 Dicdata[ 'device_id' ] = self.deviceId
lanqinglong77124b02015-08-06 11:47:38 +0800229 if self.name != '':
Jon Hallf52840a2017-05-24 16:49:52 -0700230 Dicdata[ 'name' ] = self.name
lanqinglong77124b02015-08-06 11:47:38 +0800231
Jon Hallf52840a2017-05-24 16:49:52 -0700232 Dicdata[ 'fixed_ips' ] = fixedIp
233 Dicdata = { 'port': Dicdata }
lanqinglong77124b02015-08-06 11:47:38 +0800234
Jon Hallf52840a2017-05-24 16:49:52 -0700235 return json.dumps( Dicdata, indent=4 )