blob: b00b183cd595712435eb7240bc1e2ad95da1ab34 [file] [log] [blame]
zhanghaoyu7474d8c62015-08-26 14:53:28 +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/x/voMg>,
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"""
zhanghaoyu7474d8c62015-08-26 14:53:28 +080022This file provide the data
23lanqinglong@huawei.com
24"""
25import json
26
Jon Hall8638b562017-05-24 16:39:59 -070027
zhanghaoyu7474d8c62015-08-26 14:53:28 +080028class NetworkData:
29
Jon Hall8638b562017-05-24 16:39:59 -070030 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080031 self.id = ''
32 self.state = 'ACTIVE'
33 self.name = 'onosfw-1'
34 self.physicalNetwork = 'none'
35 self.admin_state_up = True
36 self.tenant_id = ''
37 self.routerExternal = False
Jon Hall8638b562017-05-24 16:39:59 -070038 self.type = 'LOCAL'
zhanghaoyu7474d8c62015-08-26 14:53:28 +080039 self.segmentationID = '6'
40 self.shared = False
41
Jon Hall8638b562017-05-24 16:39:59 -070042 def DictoJson( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080043
Jon Hall8638b562017-05-24 16:39:59 -070044 if self.id == '' or self.tenant_id == '':
zhanghaoyu7474d8c62015-08-26 14:53:28 +080045 print 'Id and tenant id is necessary!'
46
47 Dicdata = {}
Jon Hall8638b562017-05-24 16:39:59 -070048 if self.id != '':
49 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +080050 if self.state != '':
Jon Hall8638b562017-05-24 16:39:59 -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
zhanghaoyu7474d8c62015-08-26 14:53:28 +080068
Jon Hall8638b562017-05-24 16:39:59 -070069 Dicdata = { 'network': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +080070
Jon Hall8638b562017-05-24 16:39:59 -070071 return json.dumps( Dicdata, indent=4 )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080072
Jon Hall8638b562017-05-24 16:39:59 -070073 def Ordered( self, obj ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080074
Jon Hall8638b562017-05-24 16:39:59 -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 )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080079 else:
80 return obj
81
Jon Hall8638b562017-05-24 16:39:59 -070082 def JsonCompare( self, SourceData, DestiData, FirstPara, SecondPara ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +080083
84 try:
Jon Hall8638b562017-05-24 16:39:59 -070085 SourceCompareDataDic = json.loads( SourceData )
86 DestiCompareDataDic = json.loads( DestiData )
zhanghaoyu7474d8c62015-08-26 14:53:28 +080087 except ValueError:
88 print "SourceData or DestData is not JSON Type!"
89 return False
90
91 try:
Jon Hall8638b562017-05-24 16:39:59 -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
zhanghaoyu7474d8c62015-08-26 14:53:28 +080096 return False
97
Jon Hall8638b562017-05-24 16:39:59 -070098 if str( Socom ).lower() == str( Decom ).lower():
zhanghaoyu7474d8c62015-08-26 14:53:28 +080099 return True
100 else:
Jon Hall8638b562017-05-24 16:39:59 -0700101 print "Source Compare data:" + FirstPara + "." + SecondPara + "=" + str( Socom )
102 print "Dest Compare data: " + FirstPara + "." + SecondPara + "=" + str( Decom )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800103 return False
104
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800105
Jon Hall8638b562017-05-24 16:39:59 -0700106class SubnetData( NetworkData ):
107
108 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +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'
119 self.enable_dhcp = True
120 self.dns_nameservers = 'aaa'
121 self.gateway_ip = '192.168.2.1'
122 self.ip_version = '4'
123 self.shared = False
124 self.name = 'demo-subnet'
125
Jon Hall8638b562017-05-24 16:39:59 -0700126 def DictoJson( self ):
127 if self.id == '' or self.tenant_id == '':
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800128 print 'Id and tenant id is necessary!'
129
130 Dicdata = {}
131 host_routesdata = []
Jon Hall8638b562017-05-24 16:39:59 -0700132 host_routesdata.append( { 'nexthop': self.nexthop, 'destination': self.destination } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800133 allocation_pools = []
Jon Hall8638b562017-05-24 16:39:59 -0700134 allocation_pools.append( { 'start': self.start, 'end': self.end } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800135
136 if self.id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700137 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800138 if self.network_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700139 Dicdata[ 'network_id' ] = self.network_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800140 if self.name != '':
Jon Hall8638b562017-05-24 16:39:59 -0700141 Dicdata[ 'name' ] = self.name
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800142 if self.nexthop != '':
Jon Hall8638b562017-05-24 16:39:59 -0700143 Dicdata[ 'host_routes' ] = host_routesdata
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800144 if self.tenant_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700145 Dicdata[ 'tenant_id' ] = self.tenant_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800146 if self.start != '':
Jon Hall8638b562017-05-24 16:39:59 -0700147 Dicdata[ 'allocation_pools' ] = allocation_pools
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800148 if self.shared != '':
Jon Hall8638b562017-05-24 16:39:59 -0700149 Dicdata[ 'shared' ] = self.shared
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800150 if self.ipv6_address_mode != '':
Jon Hall8638b562017-05-24 16:39:59 -0700151 Dicdata[ 'ipv6_address_mode' ] = self.ipv6_address_mode
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800152 if self.ipv6_ra_mode != '':
Jon Hall8638b562017-05-24 16:39:59 -0700153 Dicdata[ 'ipv6_ra_mode' ] = self.ipv6_ra_mode
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800154 if self.cidr != '':
Jon Hall8638b562017-05-24 16:39:59 -0700155 Dicdata[ 'cidr' ] = self.cidr
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800156 if self.enable_dhcp != '':
Jon Hall8638b562017-05-24 16:39:59 -0700157 Dicdata[ 'enable_dhcp' ] = self.enable_dhcp
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800158 if self.dns_nameservers != '':
Jon Hall8638b562017-05-24 16:39:59 -0700159 Dicdata[ 'dns_nameservers' ] = self.dns_nameservers
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800160 if self.gateway_ip != '':
Jon Hall8638b562017-05-24 16:39:59 -0700161 Dicdata[ 'gateway_ip' ] = self.gateway_ip
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800162 if self.ip_version != '':
Jon Hall8638b562017-05-24 16:39:59 -0700163 Dicdata[ 'ip_version' ] = self.ip_version
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800164
Jon Hall8638b562017-05-24 16:39:59 -0700165 Dicdata = { 'subnet': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800166
Jon Hall8638b562017-05-24 16:39:59 -0700167 return json.dumps( Dicdata, indent=4 )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800168
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800169
Jon Hall8638b562017-05-24 16:39:59 -0700170class VirtualPortData( NetworkData ):
171
172 def __init__( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800173 self.id = ''
174 self.state = 'ACTIVE'
175 self.bindingHostId = 'fa:16:3e:76:8e:88'
Jon Hall8638b562017-05-24 16:39:59 -0700176 self.allowedAddressPairs = [ { 'mac_address': 'fa:16:3e:76:8e:88', 'ip_address': '192.168.1.1' } ]
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800177 self.deviceOwner = 'none'
178 self.fixedIp = []
Jon Hall8638b562017-05-24 16:39:59 -0700179 self.securityGroups = [ { 'securityGroup': 'asd' } ]
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800180 self.adminStateUp = True
181 self.network_id = ''
182 self.tenant_id = ''
183 self.subnet_id = ''
184 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 Hall8638b562017-05-24 16:39:59 -0700191 def DictoJson( self ):
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800192 if self.id == '' or self.tenant_id == ' ' or \
193 self.network_id == '' or self.subnet_id == '':
194 print 'Id/tenant id/networkid/subnetId is necessary!'
195
196 Dicdata = {}
Jon Hall8638b562017-05-24 16:39:59 -0700197 fixedIp = []
198 fixedIp.append( { 'subnet_id': self.subnet_id, 'ip_address': '192.168.1.4' } )
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800199 allocation_pools = []
200
201 if self.id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700202 Dicdata[ 'id' ] = self.id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800203 if self.state != '':
Jon Hall8638b562017-05-24 16:39:59 -0700204 Dicdata[ 'status' ] = self.state
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800205 if self.bindingHostId != '':
Jon Hall8638b562017-05-24 16:39:59 -0700206 Dicdata[ 'binding:host_id' ] = self.bindingHostId
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800207 if self.allowedAddressPairs != '':
Jon Hall8638b562017-05-24 16:39:59 -0700208 Dicdata[ 'allowed_address_pairs' ] = self.allowedAddressPairs
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800209 if self.deviceOwner != '':
Jon Hall8638b562017-05-24 16:39:59 -0700210 Dicdata[ 'device_owner' ] = self.deviceOwner
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800211 if self.securityGroups != '':
Jon Hall8638b562017-05-24 16:39:59 -0700212 Dicdata[ 'security_groups' ] = self.securityGroups
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800213 if self.adminStateUp != '':
Jon Hall8638b562017-05-24 16:39:59 -0700214 Dicdata[ 'admin_state_up' ] = self.adminStateUp
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800215 if self.network_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700216 Dicdata[ 'network_id' ] = self.network_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800217 if self.tenant_id != '':
Jon Hall8638b562017-05-24 16:39:59 -0700218 Dicdata[ 'tenant_id' ] = self.tenant_id
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800219 if self.bindingvifDetails != '':
Jon Hall8638b562017-05-24 16:39:59 -0700220 Dicdata[ 'binding:vif_details' ] = self.bindingvifDetails
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800221 if self.bindingvnicType != '':
Jon Hall8638b562017-05-24 16:39:59 -0700222 Dicdata[ 'binding:vnic_type' ] = self.bindingvnicType
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800223 if self.bindingvifType != '':
Jon Hall8638b562017-05-24 16:39:59 -0700224 Dicdata[ 'binding:vif_type' ] = self.bindingvifType
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800225 if self.macAddress != '':
Jon Hall8638b562017-05-24 16:39:59 -0700226 Dicdata[ 'mac_address' ] = self.macAddress
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800227 if self.deviceId != '':
Jon Hall8638b562017-05-24 16:39:59 -0700228 Dicdata[ 'device_id' ] = self.deviceId
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800229 if self.name != '':
Jon Hall8638b562017-05-24 16:39:59 -0700230 Dicdata[ 'name' ] = self.name
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800231
Jon Hall8638b562017-05-24 16:39:59 -0700232 Dicdata[ 'fixed_ips' ] = fixedIp
233 Dicdata = { 'port': Dicdata }
zhanghaoyu7474d8c62015-08-26 14:53:28 +0800234
Jon Hall8638b562017-05-24 16:39:59 -0700235 return json.dumps( Dicdata, indent=4 )