created broader test category under scripts
[onosfw.git] / framework / scripts / tests / Teston / testcases / FUNCvirNetNB / dependencies / Nbdata.py
1 """
2 This file provide the data
3 lanqinglong@huawei.com
4 """
5 import json
6
7 class NetworkData:
8
9     def __init__(self):
10         self.id = ''
11         self.state = 'ACTIVE'
12         self.name = 'onosfw-1'
13         self.physicalNetwork = 'none'
14         self.admin_state_up = True
15         self.tenant_id = ''
16         self.routerExternal = False
17         self.type ='LOCAL'
18         self.segmentationID = '6'
19         self.shared = False
20
21     def DictoJson(self):
22
23         if self.id =='' or self.tenant_id == '':
24             print 'Id and tenant id is necessary!'
25
26         Dicdata = {}
27         if self.id !='':
28             Dicdata['id'] = self.id
29         if self.state != '':
30             Dicdata['status'] = self.state
31         if self.name !='':
32             Dicdata['name'] = self.name
33         if self.physicalNetwork !='':
34             Dicdata['provider:physical_network'] = self.physicalNetwork
35         if self.admin_state_up !='':
36             Dicdata['admin_state_up'] = self.admin_state_up
37         if self.tenant_id !='':
38             Dicdata['tenant_id'] = self.tenant_id
39         if self.routerExternal !='':
40             Dicdata['router:external'] = self.routerExternal
41         if self.type !='':
42             Dicdata['provider:network_type'] = self.type
43         if self.segmentationID !='':
44             Dicdata['provider:segmentation_id'] = self.segmentationID
45         if self.shared !='':
46             Dicdata['shared'] = self.shared
47
48         Dicdata = {'network': Dicdata}
49
50         return json.dumps(Dicdata,indent=4)
51
52     def Ordered(self,obj):
53
54         if isinstance(obj, dict):
55             return sorted((k,self.Ordered(v)) for k,  v in obj.items())
56         if isinstance(obj, list):
57             return sorted(self.Ordered(x) for x in obj )
58         else:
59             return obj
60
61     def JsonCompare(self,SourceData,DestiData,FirstPara,SecondPara):
62
63         try:
64             SourceCompareDataDic = json.loads(SourceData)
65             DestiCompareDataDic = json.loads(DestiData)
66         except ValueError:
67             print "SourceData or DestData is not JSON Type!"
68             return False
69
70         try:
71             Socom = SourceCompareDataDic[FirstPara][SecondPara]
72             Decom = DestiCompareDataDic[FirstPara][SecondPara]
73         except KeyError,error:
74             print "Key error ,This key is not found:%s"%error
75             return False
76
77         if str(Socom).lower()== str(Decom).lower():
78             return True
79         else:
80             print "Source Compare data:"+FirstPara+"."+SecondPara+"="+str(Socom)
81             print "Dest Compare data: "+FirstPara+"."+SecondPara+"="+str(Decom)
82             return False
83
84 class SubnetData(NetworkData):
85
86     def __init__(self):
87         self.id = ''
88         self.tenant_id = ''
89         self.network_id = ''
90         self.nexthop = '192.168.1.1'
91         self.destination = '192.168.1.1/24'
92         self.start = '192.168.2.2'
93         self.end = '192.168.2.254'
94         self.ipv6_address_mode = 'DHCPV6_STATELESS'
95         self.ipv6_ra_mode = 'DHCPV6_STATELESS'
96         self.cidr = '192.168.1.1/24'
97         self.enable_dhcp = True
98         self.dns_nameservers = 'aaa'
99         self.gateway_ip = '192.168.2.1'
100         self.ip_version = '4'
101         self.shared = False
102         self.name = 'demo-subnet'
103
104     def DictoJson(self):
105         if self.id =='' or self.tenant_id == '':
106             print 'Id and tenant id is necessary!'
107
108         Dicdata = {}
109         host_routesdata = []
110         host_routesdata.append({'nexthop': self.nexthop,'destination': self.destination})
111         allocation_pools = []
112         allocation_pools.append({'start': self.start,'end':self.end})
113
114         if self.id != '':
115             Dicdata['id'] = self.id
116         if self.network_id != '':
117             Dicdata['network_id'] = self.network_id
118         if self.name != '':
119             Dicdata['name'] = self.name
120         if self.nexthop != '':
121             Dicdata['host_routes'] = host_routesdata
122         if self.tenant_id != '':
123             Dicdata['tenant_id'] = self.tenant_id
124         if self.start != '':
125             Dicdata['allocation_pools'] = allocation_pools
126         if self.shared != '':
127             Dicdata['shared'] = self.shared
128         if self.ipv6_address_mode != '':
129             Dicdata['ipv6_address_mode'] = self.ipv6_address_mode
130         if self.ipv6_ra_mode != '':
131             Dicdata['ipv6_ra_mode'] = self.ipv6_ra_mode
132         if self.cidr != '':
133             Dicdata['cidr'] = self.cidr
134         if self.enable_dhcp != '':
135             Dicdata['enable_dhcp'] = self.enable_dhcp
136         if self.dns_nameservers != '':
137             Dicdata['dns_nameservers'] = self.dns_nameservers
138         if self.gateway_ip != '':
139             Dicdata['gateway_ip'] = self.gateway_ip
140         if self.ip_version != '':
141             Dicdata['ip_version'] = self.ip_version
142
143         Dicdata = {'subnet': Dicdata}
144
145         return json.dumps(Dicdata,indent=4)
146
147 class VirtualPortData(NetworkData):
148
149     def __init__(self):
150         self.id = ''
151         self.state = 'ACTIVE'
152         self.bindingHostId = 'fa:16:3e:76:8e:88'
153         self.allowedAddressPairs = [{'mac_address':'fa:16:3e:76:8e:88','ip_address':'192.168.1.1'}]
154         self.deviceOwner = 'none'
155         self.fixedIp = []
156         self.securityGroups = [{'securityGroup':'asd'}]
157         self.adminStateUp = True
158         self.network_id = ''
159         self.tenant_id = ''
160         self.subnet_id = ''
161         self.bindingvifDetails = 'port_filter'
162         self.bindingvnicType = 'normal'
163         self.bindingvifType = 'ovs'
164         self.macAddress = 'fa:16:3e:76:8e:88'
165         self.deviceId = 'a08aa'
166         self.name = 'u'
167
168     def DictoJson(self):
169         if self.id == '' or self.tenant_id == ' ' or \
170            self.network_id == '' or self.subnet_id == '':
171             print 'Id/tenant id/networkid/subnetId is necessary!'
172
173         Dicdata = {}
174         fixedIp =[]
175         fixedIp.append({'subnet_id':self.subnet_id,'ip_address':'192.168.1.4'})
176         allocation_pools = []
177
178         if self.id != '':
179             Dicdata['id'] = self.id
180         if self.state != '':
181             Dicdata['status'] = self.state
182         if self.bindingHostId != '':
183             Dicdata['binding:host_id'] = self.bindingHostId
184         if self.allowedAddressPairs != '':
185             Dicdata['allowed_address_pairs'] = self.allowedAddressPairs
186         if self.deviceOwner != '':
187             Dicdata['device_owner'] = self.deviceOwner
188         if self.securityGroups != '':
189             Dicdata['security_groups'] = self.securityGroups
190         if self.adminStateUp != '':
191             Dicdata['admin_state_up'] = self.adminStateUp
192         if self.network_id != '':
193             Dicdata['network_id'] = self.network_id
194         if self.tenant_id != '':
195             Dicdata['tenant_id'] = self.tenant_id
196         if self.bindingvifDetails != '':
197             Dicdata['binding:vif_details'] = self.bindingvifDetails
198         if self.bindingvnicType != '':
199             Dicdata['binding:vnic_type'] = self.bindingvnicType
200         if self.bindingvifType != '':
201             Dicdata['binding:vif_type'] = self.bindingvifType
202         if self.macAddress != '':
203             Dicdata['mac_address'] = self.macAddress
204         if self.deviceId != '':
205             Dicdata['device_id'] = self.deviceId
206         if self.name != '':
207             Dicdata['name'] = self.name
208
209         Dicdata['fixed_ips'] = fixedIp
210         Dicdata = {'port': Dicdata}
211
212         return json.dumps(Dicdata,indent=4)