blob: f15871d0e7251f17b6c914e8ca8cc8d34113bc78 [file] [log] [blame]
ChetanGaonker901727c2016-11-29 14:05:03 -08001#
2# Copyright 2016-present Ciena Corporation
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15#
16import unittest
17import os,sys
18import os
19import keystoneclient.v2_0.client as ksclient
20import keystoneclient.apiclient.exceptions
21import neutronclient.v2_0.client as nclient
22import neutronclient.common.exceptions
23import novaclient.v1_1.client as novaclient
24from multiprocessing import Pool
25from nose.tools import assert_equal
26from CordLogger import CordLogger
ChetanGaonkerd65b7612016-12-07 01:01:20 -080027log.setLevel('INFO')
ChetanGaonker901727c2016-11-29 14:05:03 -080028
29class cordvtn_exchange(CordLogger):
30
31 app = 'org.opencord.cordvtn'
32
33 @classmethod
34 def setUpClass(cls):
35 cls.olt = OltConfig()
36 cls.port_map, _ = cls.olt.olt_port_map()
37 if not cls.port_map:
38 cls.port_map = g_subscriber_port_map
39 cls.iface = cls.port_map[1]
40
41 def setUp(self):
42 ''' Activate the cord vtn app'''
43 super(dhcp_exchange, self).setUp()
44 self.maxDiff = None ##for assert_equal compare outputs on failure
45 self.onos_ctrl = OnosCtrl(self.app)
46 status, _ = self.onos_ctrl.activate()
47 assert_equal(status, True)
48 time.sleep(3)
49
50 def tearDown(self):
51 '''Deactivate the cord vtn app'''
52 self.onos_ctrl.deactivate()
53 super(dhcp_exchange, self).tearDown()
54
55 def onos_load_config(self, config):
56 status, code = OnosCtrl.config(config)
57 if status is False:
58 log.info('JSON request returned status %d' %code)
59 assert_equal(status, True)
60 time.sleep(3)
61
62 def create_tenant(tenant_name):
63 new_tenant = keystone.tenants.create(tenant_name=tenant_name,
64 description="CORD Tenant \
65 created",
66 enabled=True)
67 tenant_id = new_tenant.id
68 tenant_status = True
69 user_data = []
70 for j in range(2):
71 j += 1
72 user_name = tenant_name + '-user-' + str(j)
73 user_data.append(create_user(user_name, tenant_id))
74
75 print " Tenant and User Created"
76
77 tenant_data = {'tenant_name': tenant_name,
78 'tenant_id': tenant_id,
79 'status': tenant_status}
80 return tenant_data
81
82 def create_user(user_name, tenant_id):
83 new_user = keystone.users.create(name=user_name,
84 password="ubuntu",
85 tenant_id=tenant_id)
86 print(' - Created User %s' % user_name)
87 keystone.roles.add_user_role(new_user, member_role, tenant_id)
88 if assign_admin:
89 admin_user = keystone.users.find(name='admin')
90 admin_role = keystone.roles.find(name='admin')
91 keystone.roles.add_user_role(admin_user, admin_role, tenant_id)
92 user_data = {'name': new_user.name,
93 'id': new_user.id}
94 return user_data
95
96 def delete_tenant(tenant_name):
97 tenant = keystone.tenants.find(name=tenant_name)
98 for j in range(2):
99 j += 1
100 user_name = tenant_name + '-user-' + str(j)
101 delete_user(user_name, tenant.id)
102 tenant.delete()
103 print(' - Deleted Tenant %s ' % tenant_name)
104 return True
105
106 def delete_user(user_name, tenant_id):
107 user = keystone.users.find(name=user_name)
108 user.delete()
109
110 print(' - Deleted User %s' % user_name)
111 return True
112
113 def get_neutron_credentials():
114 d = {}
115 d['username'] = os.environ['OS_USERNAME']
116 d['password'] = os.environ['OS_PASSWORD']
117 d['auth_url'] = os.environ['OS_AUTH_URL']
118 d['tenant_name'] = os.environ['OS_TENANT_NAME']
119 return d
120
121
122 def create_network(i):
123 neutron_credentials = get_neutron_credentials()
124 neutron = neutron_client.Client(**neutron_credentials)
125 json = {'network': {'name': 'network-' + str(i),
126 'admin_state_up': True}}
127 while True:
128 neutron.create_network(body=json)
129 print '\nnetwork-' + str(i) + ' created'
130 break
131
132 pool = Pool(processes=5)
133 os.system("neutron quota-update --network 105")
134 for i in range(1,5):
135 pool.apply_async(create_network, (i, ))
136 pool.close()
137 pool.join()
138
ChetanGaonkerd65b7612016-12-07 01:01:20 -0800139 def test_cordvtn_for_create_network(self):
140 network = {'name': self.network_name, 'admin_state_up': True}
141 self.neutron.create_network({'network':network})
142 log.info("Created network:{0}".format(self.network_name))
143
144 def test_cordvtn_to_create_net_work_with_subnet(self):
145 network_name = self.network_name
146 network = {'name': network_name, 'admin_state_up': True}
147 network_info = self.neutron.create_network({'network':network})
148 network_id = network_info['network']['id']
149
150 log.info("Created network:{0}".format(network_id))
151 self.network_ids.append(network_id)
152 subnet_count = 1
153 for cidr in self.subnet_cidrs:
154 gateway_ip = str(list(cidr)[1])
155 subnet = {"network_id": network_id, "ip_version":4,
156 "cidr":str(cidr), "enable_dhcp":True,
157 "host_routes":[{"destination":"0.0.0.0/0", "nexthop":gateway_ip}]
158 }
159 subnet = {"name":"subnet-"+str(subnet_count), "network_id": network_id, "ip_version":4, "cidr":str(cidr), "enable_dhcp":True}
160 print subnet
161 self.neutron.create_subnet({'subnet':subnet})
162 log.info("Created subnet:{0}".format(str(cidr)))
163 if not self.number_of_subnet - 1:
164 break
165 self.number_of_subnet -= 1
166 subnet_count += 1
167
168 def test_cordvtn_subnet_limit(self):
169 network_name = uuid.uuid4().get_hex()
170 network = {'name': network_name, 'admin_state_up': True}
171 network_info = self.neutron.create_network({'network':network})
172 log.info("Created network:{0}".format(network_name))
173 network_id = network_info['network']['id']
174 self.network_ids.append(network_id)
175 subnet_cidrs = ['11.2.2.0/29', '11.2.2.8/29']
176 for cidr in subnet_cidrs:
177 subnet = {"network_id": network_id, "ip_version":4, "cidr": cidr}
178 subnet_info = self.neutron.create_subnet({'subnet':subnet})
179 subnet_id = subnet_info['subnet']['id']
180 log.info("Created subnet:{0}".format(cidr))
181 while True:
182 port = {"network_id": network_id, "admin_state_up": True}
183 port_info = self.neutron.create_port({'port':port})
184 port_id = port_info['port']['id']
185 self.port_ids.append(port_id)
186 log.info("Created Port:{0}".format(port_info['port']['id']))
187 if not self.quota_limit:
188 break
189 self.quota_limit -= 1
190
191 def test_cordvtn_floatingip_limit(self):
192 while True:
193 floatingip = {"floating_network_id": self.floating_nw_id}
194 fip_info = self.neutron.create_floatingip({'floatingip':floatingip})
195 fip_id = fip_info['floatingip']['id']
196 log.info("Created Floating IP:{0}".format(fip_id))
197 self.fip_ids.append(fip_id)
198 if not self.quota_limit:
199 break
200 self.quota_limit -= 1
201
ChetanGaonker901727c2016-11-29 14:05:03 -0800202 def test_cordvtn_basic_tenant(self):
203 pass
204
205 def test_cordvtn_mgmt_network(self):
206 pass
207
208 def test_cordvtn_data_network(self):
209 pass
210
211 def test_cordvtn_public_network(self):
212 pass
213
214 def test_cordvtn_in_same_network(self):
215 pass
216
217 def test_cordvtn_local_mgmt_network(self):
218 pass
219
220 def test_cordvtn_service_dependency(self):
221 pass
222
223 def test_cordvtn_service_dependency_with_xos(self):
224 pass
225
226 def test_cordvtn_vsg_xos_service_profile(self):
227 pass
228
229 def test_cordvtn_access_agent(self):
230 pass
231
232 def test_cordvtn_network_creation(self):
233 pass
234
235 def test_cordvtn_removing_service_network(self):
236 pass
237
238 def test_cordvtn_web_application(self):
239 pass
240
241 def test_cordvtn_service_port(self):
242 pass