blob: 906ff0e7dff17d1531bf159ee9f7f95f077d86c6 [file] [log] [blame]
Matteo Scandolo48d3d2d2017-08-08 13:05:27 -07001
2# Copyright 2017-present Open Networking Foundation
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
16
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000017#
18# Copyright 2016-present Ciena Corporation
19#
20# Licensed under the Apache License, Version 2.0 (the "License");
21# you may not use this file except in compliance with the License.
22# You may obtain a copy of the License at
23#
24# http://www.apache.org/licenses/LICENSE-2.0
25#
26# Unless required by applicable law or agreed to in writing, software
27# distributed under the License is distributed on an "AS IS" BASIS,
28# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29# See the License for the specific language governing permissions and
30# limitations under the License.
31#
32import unittest
33import os,sys
34import keystoneclient.v2_0.client as ksclient
35import keystoneclient.apiclient.exceptions
36import neutronclient.v2_0.client as nclient
37import neutronclient.common.exceptions
38from novaclient import client as nova_client
39from neutronclient.v2_0 import client as neutron_client
40import neutronclient.v2_0.client as neutronclient
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000041from nose.tools import assert_equal, assert_not_equal
42from twisted.internet import defer
43from nose.twistedtools import reactor, deferred
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +000044from CordTestUtils import *
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000045from onosclidriver import OnosCliDriver
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000046from OnosCtrl import OnosCtrl
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000047from OltConfig import OltConfig
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000048from OnboardingServiceUtils import OnboardingServiceUtils
49from SSHTestAgent import SSHTestAgent
A R Karthick9dc6e922017-07-12 14:40:16 -070050from CordTestConfig import setup_module, running_on_ciab, teardown_module
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000051from CordLogger import CordLogger
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000052from CordTestUtils import *
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000053from CordTestUtils import log_test as log
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000054import requests
55import time
56import json
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000057from VSGAccess import VSGAccess
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000058log.setLevel('INFO')
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000059
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000060class onboarding_exchange(CordLogger):
Chetan Gaonkerc6853932017-04-24 22:16:37 +000061 ONOS_INSTANCES = 3
62 V_INF1 = 'veth0'
63 device_id = 'of:' + get_mac()
64 TEST_IP = '8.8.8.8'
65 HOST = "10.1.0.1"
66 USER = "vagrant"
67 PASS = "vagrant"
68 head_node = os.getenv('HEAD_NODE', 'prod')
69 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
70 test_path = os.path.dirname(os.path.realpath(__file__))
A R Karthick19771192017-04-25 14:57:05 -070071 on_pod = running_on_pod()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000072 vm_name = 'mysite_exampleservice'
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000073 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
74 restApiXos = None
75 subscriber_account_num = 200
76 subscriber_s_tag = 304
77 subscriber_c_tag = 304
78 subscribers_per_s_tag = 8
79 subscriber_map = {}
80 subscriber_info = []
81 volt_subscriber_info = []
82 restore_methods = []
83 FABRIC_PORT_HEAD_NODE = 1
84 FABRIC_PORT_COMPUTE_NODE = 2
85 APP_NAME = 'org.ciena.xconnect'
86 APP_FILE = os.path.join(test_path, '..', 'apps/xconnect-1.0-SNAPSHOT.oar')
87 NUM_SUBSCRIBERS = 5
88
89 @classmethod
90 def getSubscriberCredentials(cls, subId):
91 """Generate our own account num, s_tag and c_tags"""
92 if subId in cls.subscriber_map:
93 return cls.subscriber_map[subId]
94 account_num = cls.subscriber_account_num
95 cls.subscriber_account_num += 1
96 s_tag, c_tag = cls.subscriber_s_tag, cls.subscriber_c_tag
97 cls.subscriber_c_tag += 1
98 if cls.subscriber_c_tag % cls.subscribers_per_s_tag == 0:
99 cls.subscriber_s_tag += 1
100 cls.subscriber_map[subId] = account_num, s_tag, c_tag
101 return cls.subscriber_map[subId]
102
103 @classmethod
104 def getXosCredentials(cls):
105 onos_cfg = OnosCtrl.get_config()
106 if onos_cfg is None:
107 return None
108 if 'apps' in onos_cfg and \
109 'org.opencord.vtn' in onos_cfg['apps'] and \
110 'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \
111 'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']:
112 xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos']
113 endpoint = xos_cfg['endpoint']
114 user = xos_cfg['user']
115 password = xos_cfg['password']
116 xos_endpoints = endpoint.split(':')
117 xos_host = xos_endpoints[1][len('//'):]
118 xos_port = xos_endpoints[2][:-1]
119 #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password))
120 return dict(host = xos_host, port = xos_port, user = user, password = password)
121
122 return None
123 @classmethod
124 def getSubscriberConfig(cls, num_subscribers):
125 features = {
126 'cdn': True,
127 'uplink_speed': 1000000000,
128 'downlink_speed': 1000000000,
129 'uverse': True,
130 'status': 'enabled'
131 }
132 subscriber_map = []
133 for i in xrange(num_subscribers):
134 subId = 'sub{}'.format(i)
135 account_num, _, _ = cls.getSubscriberCredentials(subId)
136 identity = { 'account_num' : str(account_num),
137 'name' : 'My House {}'.format(i)
138 }
139 sub_info = { 'features' : features,
140 'identity' : identity
141 }
142 subscriber_map.append(sub_info)
143
144 return subscriber_map
145
146 @classmethod
147 def getVoltSubscriberConfig(cls, num_subscribers):
148 voltSubscriberMap = []
149 for i in xrange(num_subscribers):
150 subId = 'sub{}'.format(i)
151 account_num, s_tag, c_tag = cls.getSubscriberCredentials(subId)
152 voltSubscriberInfo = {}
153 voltSubscriberInfo['voltTenant'] = dict(s_tag = str(s_tag),
154 c_tag = str(c_tag),
155 subscriber = '')
156 voltSubscriberInfo['account_num'] = account_num
157 voltSubscriberMap.append(voltSubscriberInfo)
158
159 return voltSubscriberMap
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000160
161 @classmethod
162 def setUpClass(cls):
163 OnboardingServiceUtils.setUp()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000164 cls.controllers = get_controllers()
165 cls.controller = cls.controllers[0]
166 cls.cli = None
167 cls.on_pod = running_on_pod()
168 cls.on_ciab = running_on_ciab()
169 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
170 cls.vcpes = cls.olt.get_vcpes()
171 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
172 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
173 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
174 for i in xrange(len(cls.vcpes_reserved)) ]
175 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
176 cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
177 vcpe_dhcp_reserved = None
178 vcpe_container_reserved = None
179 if cls.vcpes_reserved:
180 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
181 if cls.on_pod is False:
182 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
183 vcpe_container_reserved = cls.container_vcpes_reserved[0]
184
185 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
186 cls.vcpe_container_reserved = vcpe_container_reserved
187 dhcp_vcpe_offset = len(cls.vcpes_reserved)
188 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
189 for i in xrange(len(cls.vcpes_dhcp)) ]
190 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
191 cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
192 vcpe_dhcp = None
193 vcpe_container = None
194 #cache the first dhcp vcpe in the class for quick testing
195 if cls.vcpes_dhcp:
196 vcpe_container = cls.container_vcpes[0]
197 vcpe_dhcp = cls.dhcp_vcpes[0]
198 if cls.on_pod is False:
199 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
200 cls.vcpe_container = vcpe_container_reserved or vcpe_container
201 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
202 VSGAccess.setUp()
203 cls.setUpCordApi()
204 if cls.on_pod is True:
205 cls.openVCPEAccess(cls.volt_subscriber_info)
206
207 @classmethod
208 def setUpCordApi(cls):
209 our_path = os.path.dirname(os.path.realpath(__file__))
210 cord_api_path = os.path.join(our_path, '..', 'cord-api')
211 framework_path = os.path.join(cord_api_path, 'Framework')
212 utils_path = os.path.join(framework_path, 'utils')
213 data_path = os.path.join(cord_api_path, 'Tests', 'data')
214 subscriber_cfg = os.path.join(data_path, 'Subscriber.json')
215 volt_tenant_cfg = os.path.join(data_path, 'VoltTenant.json')
216 num_subscribers = max(cls.NUM_SUBSCRIBERS, 5)
217 cls.subscriber_info = cls.getSubscriberConfig(num_subscribers)
218 cls.volt_subscriber_info = cls.getVoltSubscriberConfig(num_subscribers)
219
220 sys.path.append(utils_path)
221 sys.path.append(framework_path)
222 from restApi import restApi
223 restApiXos = restApi()
224 xos_credentials = cls.getXosCredentials()
225 if xos_credentials is None:
226 restApiXos.controllerIP = cls.HEAD_NODE
227 restApiXos.controllerPort = '9000'
228 else:
229 restApiXos.controllerIP = xos_credentials['host']
230 restApiXos.controllerPort = xos_credentials['port']
231 restApiXos.user = xos_credentials['user']
232 restApiXos.password = xos_credentials['password']
233 cls.restApiXos = restApiXos
234
235 @classmethod
236 def getVoltId(cls, result, subId):
237 if type(result) is not type([]):
238 return None
239 for tenant in result:
240 if str(tenant['subscriber']) == str(subId):
241 return str(tenant['id'])
242 return None
243
244 @classmethod
245 def closeVCPEAccess(cls, volt_subscriber_info):
246 OnosCtrl.uninstall_app(cls.APP_NAME, onos_ip = cls.HEAD_NODE)
247
248 @classmethod
249 def openVCPEAccess(cls, volt_subscriber_info):
250 """
251 This code is used to configure leaf switch for head node access to compute node over fabric.
252 Care is to be taken to avoid overwriting existing/default vcpe flows.
253 The access is opened for generated subscriber info which should not overlap.
254 We target the fabric onos instance on head node.
255 """
256 OnosCtrl.install_app(cls.APP_FILE, onos_ip = cls.HEAD_NODE)
257 time.sleep(2)
258 s_tags = map(lambda tenant: int(tenant['voltTenant']['s_tag']), volt_subscriber_info)
259 #only get unique vlan tags
260 s_tags = list(set(s_tags))
261 devices = OnosCtrl.get_device_ids(controller = cls.HEAD_NODE)
262 if devices:
263 device_config = {}
264 for device in devices:
265 device_config[device] = []
266 for s_tag in s_tags:
267 xconnect_config = {'vlan': s_tag, 'ports' : [ cls.FABRIC_PORT_HEAD_NODE, cls.FABRIC_PORT_COMPUTE_NODE ] }
268 device_config[device].append(xconnect_config)
269
270 cfg = { 'apps' : { 'org.ciena.xconnect' : { 'xconnectTestConfig' : device_config } } }
271 OnosCtrl.config(cfg, controller = cls.HEAD_NODE)
272
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000273
274 @classmethod
275 def tearDownClass(cls):
276 OnboardingServiceUtils.tearDown()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000277 VSGAccess.tearDown()
278 if cls.on_pod is True:
279 cls.closeVCPEAccess(cls.volt_subscriber_info)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000280
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000281 def cliEnter(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000282 retries = 0
283 while retries < 30:
284 self.cli = OnosCliDriver(controller = controller, connect = True)
285 if self.cli.handle:
286 break
287 else:
288 retries += 1
289 time.sleep(2)
290
291 def cliExit(self):
292 self.cli.disconnect()
293
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000294 def onos_shutdown(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000295 status = True
296 self.cliEnter(controller = controller)
297 try:
298 self.cli.shutdown(timeout = 10)
299 except:
300 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
301 status = False
302
303 self.cliExit()
304 return status
305
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000306 def get_exampleservice_vm_public_ip(self, vm_name = 'mysite_exampleservice'):
307 if not vm_name:
308 vm_name = self.vm_name
309 exampleservices = OnboardingServiceUtils.get_exampleservices()
310 for service in exampleservices:
311 if vm_name in service.name:
312 return service.get_public_ip()
313 return None
314
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000315 def add_static_route_via_vcpe_interface(self, routes, vcpe=None,dhcp_ip=True):
316 if not vcpe:
317 vcpe = self.dhcp_vcpes_reserved[0]
318 if dhcp_ip:
319 os.system('dhclient '+vcpe)
320 time.sleep(1)
321 for route in routes:
322 log.info('route is %s'%route)
323 cmd = 'ip route add ' + route + ' via 192.168.0.1 '+ 'dev ' + vcpe
324 os.system(cmd)
325 return True
326
327 def del_static_route_via_vcpe_interface(self,routes,vcpe=None,dhcp_release=True):
328 if not vcpe:
329 vcpe = self.dhcp_vcpes_reserved[0]
330 cmds = []
331 for route in routes:
332 cmd = 'ip route del ' + route + ' via 192.168.0.1 ' + 'dev ' + vcpe
333 os.system(cmd)
334 if dhcp_release:
335 os.system('dhclient '+vcpe+' -r')
336 return True
337
338 def vsg_for_external_connectivity(self, subscriber_index, reserved = False):
339 if reserved is True:
340 if self.on_pod is True:
341 vcpe = self.dhcp_vcpes_reserved[subscriber_index]
342 else:
343 vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index]
344 else:
345 if self.on_pod is True:
346 vcpe = self.dhcp_vcpes[subscriber_index]
347 else:
348 vcpe = self.untagged_dhcp_vcpes[subscriber_index]
349 mgmt = 'eth0'
350 host = '8.8.8.8'
351 self.success = False
352 assert_not_equal(vcpe, None)
353 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
354 assert_not_equal(vcpe_ip, None)
355 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
356 log.info('Sending icmp echo requests to external network 8.8.8.8')
357 st, _ = getstatusoutput('ping -c 3 8.8.8.8')
358 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
359 assert_equal(st, 0)
360
361 @deferred(50)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000362 def test_exampleservice_health(self):
363 """
364 Algo:
365 1. Login to compute node VM
366 2. Get all exampleservice
367 3. Ping to all exampleservice
368 4. Verifying Ping success
369 """
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000370 df = defer.Deferred()
371 def test_exampleservice(df):
372 status = OnboardingServiceUtils.health_check()
373 assert_equal(status, True)
374 df.callback(0)
375 reactor.callLater(0,test_exampleservice,df)
376 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000377
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000378 @deferred(50)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000379 def test_exampleservice_for_login(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000380 """
381 Algo:
382 1. Login to compute node VM
383 2. Get all exampleservice
384 3. Login to all exampleservice
385 4. Verifying Login success
386 """
A R Karthick19771192017-04-25 14:57:05 -0700387 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000388 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000389 df = defer.Deferred()
390 def test_exampleservice(df):
391 exampleservices = OnboardingServiceUtils.get_exampleservices()
392 exampleservice_access_status = map(lambda exampleservice: exampleservice.check_access(), exampleservices)
393 status = filter(lambda st: st == False, exampleservice_access_status)
394 assert_equal(len(status), 0)
395 df.callback(0)
396 reactor.callLater(0,test_exampleservice,df)
397 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000398
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000399 @deferred(30)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000400 def test_exampleservice_for_default_route_through_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000401 """
402 Algo:
403 1. Login to Head node
404 2. Verify default route exists in test client
405 """
Chetan Gaonker4cff4432017-05-01 17:56:56 +0000406 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000407 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000408 df = defer.Deferred()
409 def test_exampleservice(df):
410 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
411 cmd = "sudo lxc exec testclient -- route | grep default"
412 status, output = ssh_agent.run_cmd(cmd)
413 assert_equal(status, True)
414 df.callback(0)
415 reactor.callLater(0,test_exampleservice,df)
416 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000417
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000418 @deferred(50)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000419 def test_exampleservice_for_service_access_through_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000420 """
421 Algo:
422 1. Login to Head node
423 2. Ping to all exampleservice from test client
424 3. Verifying Ping success
425 """
A R Karthick19771192017-04-25 14:57:05 -0700426 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000427 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000428 df = defer.Deferred()
429 def test_exampleservice(df):
430 vm_public_ip = self.get_exampleservice_vm_public_ip()
431 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
432 cmd = "sudo lxc exec testclient -- ping -c 3 {}".format(vm_public_ip)
433 status, output = ssh_agent.run_cmd(cmd)
434 assert_equal( status, True)
435 df.callback(0)
436 reactor.callLater(0,test_exampleservice,df)
437 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000438
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000439 @deferred(30)
440 def test_exampleservice_for_service_reachability_from_cord_tester(self):
441 """
442 Algo:
443 1. Add static route to example service running VM IP in cord-tester
444 2. Ping to the VM IP
445 3. Verifying Ping success
446 """
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000447 if self.on_pod is False:
448 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000449 df = defer.Deferred()
450 def test_exampleservice(df):
451 vm_public_ip = self.get_exampleservice_vm_public_ip()
452 vcpe_intf = self.dhcp_vcpes_reserved[0]
453 try:
454 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
455 st, _ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
456 assert_equal(st, False)
457 except Exception as error:
458 log.info('Got Unexpected error %s'%error)
459 raise
460 finally:
461 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
462 df.callback(0)
463 reactor.callLater(0,test_exampleservice,df)
464 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000465
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000466 @deferred(40)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000467 def test_exampleservice_operational_status_from_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000468 """
469 Algo:
470 1. Login to Head node
471 2. Do curl request to the example service running VM IP from test client
472 3. Verifying curl request success
473 """
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000474 if self.on_pod is False:
475 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000476 df = defer.Deferred()
477 def test_exampleservice(df):
478 vm_public_ip = self.get_exampleservice_vm_public_ip()
479 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
480 cmd = 'sudo lxc exec testclient -- apt-get install -y curl'
481 status, _ = ssh_agent.run_cmd(cmd)
482 assert_equal(status, True)
483 #Test connectivity to ExampleService from test client
484 cmd = 'sudo lxc exec testclient -- curl -s http://{}'.format(vm_public_ip)
485 status, _ = ssh_agent.run_cmd(cmd)
486 assert_equal(status, True)
487 df.callback(0)
488 reactor.callLater(0,test_exampleservice,df)
489 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000490
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000491 @deferred(30)
492 def test_exampleservice_operational_access_from_cord_tester(self):
493 """
494 Algo:
495 1. Add static route to example service running VM IP in cord-tester
496 2. Do curl request to the VM IP
497 3. Verifying curl request success
498 """
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000499 if self.on_pod is False:
500 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000501 vcpe_intf = self.dhcp_vcpes_reserved[0]
502 df = defer.Deferred()
503 def test_exampleservice(df):
504 vm_public_ip = self.get_exampleservice_vm_public_ip()
505 try:
506 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
507 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
508 assert_not_equal(out,'')
509 except Exception as error:
510 log.info('Got Unexpected error %s'%error)
511 raise
512 finally:
513 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
514 df.callback(0)
515 reactor.callLater(0,test_exampleservice,df)
516 return df
517
518 @deferred(40)
519 def test_exampleservice_for_service_message(self, service_message="\"hello\""):
520 """
521 Algo:
522 1. Get dhcp ip to vcpe interface in cord-tester
523 2. Add static route to example service running VM IP in cord-tester
524 3. Do curl request to the VM IP
525 4. Verifying Service message in curl response
526 """
527 if self.on_pod is False:
528 return
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000529 vm_public_ip = self.get_exampleservice_vm_public_ip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000530 vcpe_intf = self.dhcp_vcpes_reserved[0]
531 df = defer.Deferred()
532 def test_exampleservice(df):
533 vm_public_ip = self.get_exampleservice_vm_public_ip()
534 vcpe_intf = self.dhcp_vcpes_reserved[0]
535 try:
536 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
537 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
538 assert_not_equal(out,'')
539 output = out.split('\n')
540 srvs_msg = ''
541 for line in output:
542 line = line.split(':')
543 if line[0].strip() == 'Service Message':
544 srvs_msg = line[1].strip()
545 assert_equal(service_message, srvs_msg)
546 except Exception as error:
547 log.info('Got Unexpected error %s'%error)
548 raise
549 finally:
550 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
551 df.callback(0)
552 reactor.callLater(0,test_exampleservice,df)
553 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000554
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000555 @deferred(40)
556 def test_exampleservice_for_tenant_message(self, tenant_message="\"world\""):
557 """
558 Algo:
559 1. Get dhcp ip to vcpe interface in cord-tester
560 2. Add static route to example service running VM IP in cord-tester
561 3. Do curl request to the VM IP
562 4. Verifying Tenant message in curl response
563 """
564 if self.on_pod is False:
565 return
566 df = defer.Deferred()
567 def test_exampleservice(df):
568 vcpe_intf = self.dhcp_vcpes_reserved[0]
569 vm_public_ip = self.get_exampleservice_vm_public_ip()
570 try:
571 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
572 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
573 assert_not_equal(out,'')
574 output = out.split('\n')
575 tnt_msg = ''
576 for line in output:
577 line = line.split(':')
578 if line[0].strip() == 'Tenant Message':
579 tnt_msg = line[1].strip()
580 assert_equal(tenant_message, tnt_msg)
581 except Exception as error:
582 log.info('Got Unexpected error %s'%error)
583 raise
584 finally:
585 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
586 df.callback(0)
587 reactor.callLater(0,test_exampleservice,df)
588 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000589
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000590 @deferred(60)
591 def test_exampleservice_access_after_subscriber_interface_toggle(self):
592 """
593 Algo:
594 1. Get dhcp ip to vcpe interface in cord-tester
595 2. Add static route to example service running VM IP in cord-tester
596 3. Do curl request to the VM IP
597 4. Verifying curl request success
598 5. Toggle vcpe interface in cord-tester and do curl request again
599 6. Again verify curl request success
600 """
601 if self.on_pod is False:
602 return
603 df = defer.Deferred()
604 def test_exampleservice(df):
605 vm_public_ip = self.get_exampleservice_vm_public_ip()
606 vcpe_intf = self.dhcp_vcpes_reserved[0]
607 try:
608 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
609 #curl request from test container
610 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000611 st, out = getstatusoutput(cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000612 assert_not_equal(out,'')
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000613 st, _ = getstatusoutput('ifconfig {} down'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000614 assert_equal(st, False)
615 time.sleep(1)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000616 st, _ = getstatusoutput('ifconfig {} up'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000617 assert_equal(st, False)
618 time.sleep(1)
619 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
620 st, out = getstatusoutput(cmd)
621 assert_not_equal(out,'')
622 except Exception as error:
623 log.info('Got Unexpected error %s'%error)
624 raise
625 finally:
626 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000627 getstatusoutput('ifconfig {} up'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000628 df.callback(0)
629 reactor.callLater(0,test_exampleservice,df)
630 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000631
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000632
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000633 @deferred(60)
634 def test_exampleservice_access_after_service_paused(self):
635 """
636 Algo:
637 1. Get dhcp ip to vcpe interface in cord-tester
638 2. Add static route to example service running VM IP in cord-tester
639 3. Do curl request to the VM IP
640 4. Verifying curl request success
641 5. Pause example service running VM and do curl request again
642 6. Verify curl response is an empty output
643 """
644 if self.on_pod is False:
645 return
646 df = defer.Deferred()
647 def test_exampleservice(df):
648 service_vm = None
649 vm_public_ip = self.get_exampleservice_vm_public_ip()
650 vcpe_intf = self.dhcp_vcpes_reserved[0]
651 exampleservices = OnboardingServiceUtils.get_exampleservices()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000652 for service in exampleservices:
653 if self.vm_name in service.name:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000654 service_vm = service
655 break
656 assert_not_equal(service_vm,None)
657 try:
658 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
659 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
660 assert_not_equal(out,'')
661 log.info('Pausing example service running vm')
662 service_vm.pause()
663 time.sleep(2)
664 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
665 assert_equal(out,'')
666 service_vm.unpause()
667 time.sleep(3)
668 except Exception as error:
669 log.info('Got Unexpected error %s'%error)
670 service_vm.unpause()
671 time.sleep(3)
672 raise
673 finally:
674 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
675 df.callback(0)
676 reactor.callLater(0,test_exampleservice,df)
677 return df
678
679 #Test failing. server state goes to error after resuming
680 @deferred(60)
681 def test_exampleservice_access_after_service_is_suspended(self):
682 """
683 Algo:
684 1. Get dhcp ip to vcpe interface in cord-tester
685 2. Add static route to example service running VM IP in cord-tester
686 3. Do curl request to the VM IP
687 4. Verifying curl request success
688 5. Suspend example service running VM and do curl request again
689 6. Verify curl response is an empty output
690 7. Resume suspended VM and do curl request now
691 8. Verifying curl request success
692 """
693 if self.on_pod is False:
694 return
695 df = defer.Deferred()
696 def test_exampleservice(df):
697 service_vm = None
698 vm_public_ip = self.get_exampleservice_vm_public_ip()
699 vcpe_intf = self.dhcp_vcpes_reserved[0]
700 exampleservices = OnboardingServiceUtils.get_exampleservices()
701 for service in exampleservices:
702 if self.vm_name in service.name:
703 service_vm = service
704 break
705 assert_not_equal(service_vm,None)
706 try:
707 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
708 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
709 assert_not_equal(out,'')
710 log.info('Suspending example service running vm')
711 service_vm.suspend()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000712 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000713 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
714 assert_equal(out,'')
715 service_vm.resume()
716 time.sleep(5)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000717 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
718 assert_not_equal(out,'')
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000719 except Exception as error:
720 log.info('Got Unexpected error %s'%error)
721 service_vm.stop()
722 time.sleep(1)
723 service_vm.start()
724 time.sleep(5)
725 raise
726 finally:
727 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
728 df.callback(0)
729 reactor.callLater(0,test_exampleservice,df)
730 return df
731
732 @deferred(60)
733 def test_exampleservice_access_after_service_restart(self):
734 """
735 Algo:
736 1. Get dhcp ip to vcpe interface in cord-tester
737 2. Add static route to example service running VM IP in cord-tester
738 3. Do curl request to the VM IP
739 4. Verifying curl request success
740 5. Restart example service running VM and do curl request again
741 9. Verifying curl request success
742 """
743 if self.on_pod is False:
744 return
745 df = defer.Deferred()
746 def test_exampleservice(df):
747 service_vm = None
748 vm_public_ip = self.get_exampleservice_vm_public_ip()
749 vcpe_intf = self.dhcp_vcpes_reserved[0]
750 exampleservices = OnboardingServiceUtils.get_exampleservices()
751 for service in exampleservices:
752 if self.vm_name in service.name:
753 service_vm = service
754 break
755 assert_not_equal(service_vm,None)
756 try:
757 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000758 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000759 assert_not_equal(out,'')
760 log.info('Restarting example service running vm')
761 service_vm.reboot()
762 time.sleep(5)
763 clock = 0
764 status = False
765 while(clock <= 30):
766 time.sleep(5)
767 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
768 if out != '':
769 status = True
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000770 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000771 clock += 5
772 assert_equal(status, True)
773 except Exception as error:
774 log.info('Got Unexpected error %s'%error)
775 raise
776 finally:
777 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
778 df.callback(0)
779 reactor.callLater(0,test_exampleservice,df)
780 return df
781
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000782 #not test. vSG VM goes down after restart
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000783 @deferred(70)
784 def test_exampleservice_access_after_vsg_vm_restart(self):
785 """
786 Algo:
787 1. Get dhcp ip to vcpe interface in cord-tester
788 2. Add static route to example service running VM IP in cord-tester
789 3. Do curl request to the VM IP
790 4. Verifying curl request success
791 5. Restart vSG VM and do curl request again
792 9. Verifying curl request success
793 """
794 if self.on_pod is False:
795 return
796 df = defer.Deferred()
797 def test_exampleservice(df):
798 service_vm = None
799 vm_public_ip = self.get_exampleservice_vm_public_ip()
800 vcpe_intf = self.dhcp_vcpes_reserved[0]
801 vcpe_name = self.container_vcpes_reserved [0]
802 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
803 try:
804 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000805 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000806 assert_not_equal(out,'')
807 log.info('Restarting vSG VM')
808 vsg.reboot()
809 time.sleep(5)
810 clock = 0
811 status = False
812 while(clock <= 40):
813 time.sleep(5)
814 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
815 if out != '':
816 status = True
817 break
818 clock += 5
819 assert_equal(status, True)
820 except Exception as error:
821 log.info('Got Unexpected error %s'%error)
822 raise
823 finally:
824 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
825 df.callback(0)
826 reactor.callLater(0,test_exampleservice,df)
827 return df
828
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000829 @deferred(80)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000830 def test_exampleservice_access_after_service_stop(self):
831 """
832 Algo:
833 1. Get dhcp ip to vcpe interface in cord-tester
834 2. Add static route to example service running VM IP in cord-tester
835 3. Do curl request to the VM IP
836 4. Verifying curl request success
837 5. Stop example service running VM and do curl request again
838 6. Verify curl response is an empty output
839 7. Start stopped VM and do curl request now
840 8. Verifying curl request success
841 """
842 if self.on_pod is False:
843 return
844 df = defer.Deferred()
845 def test_exampleservice(df):
846 service_vm = None
847 vm_public_ip = self.get_exampleservice_vm_public_ip()
848 vcpe_intf = self.dhcp_vcpes_reserved[0]
849 exampleservices = OnboardingServiceUtils.get_exampleservices()
850 for service in exampleservices:
851 if self.vm_name in service.name:
852 service_vm = service
853 break
854 assert_not_equal(service_vm,None)
855 try:
856 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
857 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
858 assert_not_equal(out,'')
859 log.info('Stopping example service running vm')
860 service_vm.stop()
861 time.sleep(5)
862 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
863 assert_equal(out,'')
864 service_vm.start()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000865 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000866 clock = 0
867 status = False
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000868 while(clock <= 60):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000869 time.sleep(5)
870 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
871 if out != '':
872 status = True
873 break
874 clock += 5
875 assert_equal(status, True)
876 except Exception as error:
877 log.info('Got Unexpected error %s'%error)
878 service_vm.start()
879 raise
880 finally:
881 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
882 df.callback(0)
883 reactor.callLater(0,test_exampleservice,df)
884 return df
885
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000886 @deferred(80)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000887 def test_exampleservice_for_service_message_after_service_stop_and_start(self, service_message="\"hello\""):
888 """
889 Algo:
890 1. Get dhcp ip to vcpe interface in cord-tester
891 2. Add static route to example service running VM IP in cord-tester
892 3. Do curl request to the VM IP
893 4. Verifying curl request success
894 5. Stop example service running VM and do curl request again
895 6. Verify curl response is an empty output
896 7. Start stopped VM and do curl request now
897 8. Verifying Service message in curl response
898 """
899 if self.on_pod is False:
900 return
901 df = defer.Deferred()
902 def test_exampleservice(df):
903 service_vm = None
904 vm_public_ip = self.get_exampleservice_vm_public_ip()
905 vcpe_intf = self.dhcp_vcpes_reserved[0]
906 exampleservices = OnboardingServiceUtils.get_exampleservices()
907 for service in exampleservices:
908 if self.vm_name in service.name:
909 service_vm = service
910 break
911 assert_not_equal(service_vm,None)
912 try:
913 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
914 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
915 assert_not_equal(out,'')
916 log.info('Stopping example service running VM')
917 service_vm.stop()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000918 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000919 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
920 assert_equal(out,'')
921 service.start()
922 time.sleep(5)
923 clock = 0
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000924 while(clock <= 60):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000925 time.sleep(5)
926 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
927 if out != '':
928 output = out.split('\n')
929 srvs_msg = None
930 for line in output:
931 line = line.split(':')
932 if line[0].strip() == 'Service Message':
933 srvs_msg = line[1].strip()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000934 clock = 60
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000935 break
936 clock += 5
937 assert_equal(service_message, srvs_msg)
938 except Exception as error:
939 log.info('Got Unexpected error %s'%error)
940 service_vm.start()
941 time.sleep(5)
942 finally:
943 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
944 df.callback(0)
945 reactor.callLater(0,test_exampleservice,df)
946 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000947
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +0000948 @deferred(80)
949 def test_exampleservice_for_tenant_message_after_service_restart(self,tenant_message="\"world\""):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000950 """
951 Algo:
952 1. Get dhcp ip to vcpe interface in cord-tester
953 2. Add static route to example service running VM IP in cord-tester
954 3. Do curl request to the VM IP
955 4. Verifying curl request success
956 5. Restart example service running VM and do curl request again
957 6. Verifying Tenant message in curl response
958 """
959 if self.on_pod is False:
960 return
961 df = defer.Deferred()
962 def test_exampleservice(df):
963 service_vm = None
964 vm_public_ip = self.get_exampleservice_vm_public_ip()
965 vcpe_intf = self.dhcp_vcpes_reserved[0]
966 exampleservices = OnboardingServiceUtils.get_exampleservices()
967 for service in exampleservices:
968 if self.vm_name in service.name:
969 service_vm = service
970 break
971 assert_not_equal(service_vm,None)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000972 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000973 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000974 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000975 assert_not_equal(out,'')
976 log.info('Restarting example service running VM')
977 service_vm.reboot()
978 time.sleep(5)
979 clock = 0
980 while(clock <= 40):
981 time.sleep(5)
982 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
983 if out != '':
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000984 output = out.split('\n')
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000985 tnnt_msg = None
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000986 for line in output:
987 line = line.split(':')
988 if line[0].strip() == 'Tenant Message':
989 tnnt_msg = line[1].strip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000990 clock = 40
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000991 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000992 clock += 5
993 assert_equal(tenant_message, tnnt_msg)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000994 except Exception as error:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000995 log.info('Got Unexpected error %s'%error)
996 raise
997 finally:
998 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000999 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001000 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001001 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001002
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001003 @deferred(50)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001004 def test_exampleservice_access_after_vcpe_instance_restart(self):
1005 """
1006 Algo:
1007 1. Get dhcp ip to vcpe interface in cord-tester
1008 2. Add static route to example service running VM IP in cord-tester
1009 3. Do curl request to the VM IP
1010 4. Verifying curl request success
1011 5. Restart vcpe instance and do curl request again
1012 8. Verifying curl request success
1013 """
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001014 if self.on_pod is False:
1015 return
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001016 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001017 def test_exampleservice(df):
1018 vcpe_intf = self.dhcp_vcpes_reserved[0]
1019 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001020 vm_public_ip = self.get_exampleservice_vm_public_ip()
1021 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1022 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001023 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001024 #curl request from test container
1025 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1026 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001027 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001028 #restarting example service VM
1029 cmd = 'sudo docker restart {}'.format(vcpe_name)
1030 status, _ = vsg.run_cmd(cmd)
1031 assert_equal(status, True)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001032 time.sleep(5)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001033 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1034 clock = 0
1035 status = False
1036 while(clock <= 30):
1037 time.sleep(5)
1038 st, out = getstatusoutput(curl_cmd)
1039 if out != '':
1040 status = True
1041 break
1042 clock += 5
1043 assert_equal(status,True)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001044 except Exception as error:
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001045 log.info('Got Unexpeted error %s'%error)
1046 raise
1047 finally:
1048 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001049 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001050 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001051 return df
1052
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001053 @deferred(50)
1054 def test_exampleservice_access_after_vcpe_instance_wan_interface_toggle(self):
1055 """
1056 Algo:
1057 1. Get dhcp ip to vcpe interface in cord-tester
1058 2. Add static route to example service running VM IP in cord-tester
1059 3. Do curl request to the VM IP
1060 4. Verifying curl request success
1061 5. Restart vcpe instance and do curl request again
1062 8. Verifying curl request success
1063 """
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001064 if self.on_pod is False:
1065 return
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001066 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001067 def test_exampleservice(df):
1068 vcpe_intf = self.dhcp_vcpes_reserved[0]
1069 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001070 vm_public_ip = self.get_exampleservice_vm_public_ip()
1071 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001072 wan_intf = 'eth0'
1073 mgmt = 'eth0'
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001074 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001075 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001076 #curl request from test container
1077 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1078 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001079 assert_not_equal(out,'')
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001080 st = VSGAccess.vcpe_wan_down(vcpe_name)
1081 if st is False:
1082 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe_intf)
1083 assert_not_equal(st, '0')
1084 time.sleep(2)
1085 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001086 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1087 st, out = getstatusoutput(curl_cmd)
1088 assert_equal(out,'')
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001089 st = VSGAccess.vcpe_wan_up(vcpe_name)
1090 if st is False:
1091 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe_intf)
1092 assert_not_equal(st, '0')
1093 time.sleep(5)
1094 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001095 st, out = getstatusoutput(curl_cmd)
1096 assert_not_equal(out,'')
1097 except Exception as error:
1098 log.info('Got Unexpeted error %s'%error)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001099 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name,wan_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001100 raise
1101 finally:
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001102 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001103 df.callback(0)
1104 reactor.callLater(0,test_exampleservice,df)
1105 return df
1106
1107 @deferred(30)
1108 def test_exampleservice_access_after_firewall_rule_added_to_drop_service_running_server_in_vcpe_instance(self):
1109 """
1110 Algo:
1111 1. Get dhcp ip to vcpe interface in cord-tester
1112 2. Add static route to example service running VM IP in cord-tester
1113 3. Do curl request to the VM IP
1114 4. Verifying curl request success
1115 5. Add a firewall rule in vcpe instance to drop packets destined to example service VM
1116 6. Do curl request now
1117 7. Verifying curl response is an empty output
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001118 8. Delete the firewall rule and do curl request again
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001119 9. Verifying curl request success
1120 """
1121 df = defer.Deferred()
1122 def test_exampleservice(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
1123 vcpe_intf = self.dhcp_vcpes_reserved[0]
1124 vcpe_name = self.container_vcpes_reserved[0]
1125 vm_public_ip = self.get_exampleservice_vm_public_ip()
1126 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1127 try:
1128 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1129 #curl request from test container
1130 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1131 st, out = getstatusoutput(curl_cmd)
1132 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001133 #restarting example service VM
1134 cmd = 'sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
1135 status, _ = vsg.run_cmd(cmd)
1136 assert_equal(status, True)
1137 time.sleep(1)
1138 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001139 assert_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001140 except Exception as error:
1141 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001142 raise
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001143 finally:
1144 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip))
1145 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001146 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001147 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001148 return df
1149
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001150
1151 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
1152 if self.on_pod is False:
1153 return ''
1154 if subscriber_info is None:
1155 subscriber_info = self.subscriber_info[index]
1156 if volt_subscriber_info is None:
1157 volt_subscriber_info = self.volt_subscriber_info[index]
1158 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1159 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1160 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1161 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1162 subId = ''
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001163 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001164 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
1165 assert_equal(result, True)
1166 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1167 assert_not_equal(result, None)
1168 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1169 assert_not_equal(subId, '0')
1170 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
1171 volt_tenant = volt_subscriber_info['voltTenant']
1172 #update the subscriber id in the tenant info before making the rest
1173 volt_tenant['subscriber'] = subId
1174 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
1175 assert_equal(result, True)
1176 #if the vsg instance was already instantiated, then reduce delay
1177 if c_tag % self.subscribers_per_s_tag == 0:
1178 delay = 350
1179 else:
1180 delay = 90
1181 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
1182 time.sleep(delay)
1183 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
1184 self.vsg_for_external_connectivity(index)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001185 finally:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001186 return subId
1187
1188 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
1189 if self.on_pod is False:
1190 return
1191 if subscriber_info is None:
1192 subscriber_info = self.subscriber_info[index]
1193 if volt_subscriber_info is None:
1194 volt_subscriber_info = self.volt_subscriber_info[index]
1195 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1196 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1197 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1198 log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1199 if not subId:
1200 #get the subscriber id first
1201 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1202 assert_not_equal(result, None)
1203 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1204 assert_not_equal(subId, '0')
1205 if not voltId:
1206 #get the volt id for the subscriber
1207 result = self.restApiXos.ApiGet('TENANT_VOLT')
1208 assert_not_equal(result, None)
1209 voltId = self.getVoltId(result, subId)
1210 assert_not_equal(voltId, None)
1211 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
1212 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
1213 assert_equal(status, True)
1214 #Delete the tenant
1215 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
1216 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
1217
1218 def vsg_xos_subscriber_id(self, index):
1219 log.info('index and its type are %s, %s'%(index, type(index)))
1220 volt_subscriber_info = self.volt_subscriber_info[index]
1221 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1222 assert_not_equal(result, None)
1223 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1224 return subId
1225
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001226 @deferred(500)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001227 def test_xos_subcriber_access_exampleservice(self,index=0):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001228 """
1229 Algo:
1230 1. Create two vcpe instances using XOS
1231 2. Add static route to example service running VM IP in cord-tester
1232 3. Do curl request to the VM IP
1233 4. Verifying curl request success
1234 5. Repeat steps for both vcpes
1235 """
1236 df = defer.Deferred()
1237 def test_exampleservice(df):
1238 vm_public_ip = self.get_exampleservice_vm_public_ip()
1239 vcpe_intf = self.dhcp_vcpes[0]
1240 subId = self.vsg_xos_subscriber_id(index)
1241 if subId == '0':
1242 subId = self.vsg_xos_subscriber_create(index)
1243 assert_not_equal(subId,'0')
1244 try:
1245 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1246 time.sleep(1)
1247 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1248 st,out = getstatusoutput(cmd)
1249 assert_not_equal(out,'')
1250 except Exception as error:
1251 log.info('Got unexpected error %s'%error)
1252 raise
1253 finally:
1254 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001255 self.vsg_xos_subscriber_delete(index, subId = subId)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001256 df.callback(0)
1257 reactor.callLater(0,test_exampleservice,df)
1258 return df
1259
1260 @deferred(500)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001261 def test_exampleservice_multiple_subcribers_access_same_service(self,index1=0,index2=1):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001262 """
1263 Algo:
1264 1. Create two vcpe instances using XOS
1265 2. Add static route to example service running VM IP in cord-tester
1266 3. Do curl request to the VM IP
1267 4. Verifying curl request success
1268 5. Repeat steps for both vcpes
1269 """
1270 df = defer.Deferred()
1271 def test_exampleservice(df):
1272 vm_public_ip = self.get_exampleservice_vm_public_ip()
1273 vcpe_intf1 = self.dhcp_vcpes[0]
1274 vcpe_intf2 = self.dhcp_vcpes[1]
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001275 subId1 = self.vsg_xos_subscriber_id(index1)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001276 if subId1 == '0':
1277 subId1 = self.vsg_xos_subscriber_create(index1)
1278 assert_not_equal(subId1,'0')
1279 subId2 = self.vsg_xos_subscriber_id(index2)
1280 if subId2 == '0':
1281 subId2 = self.vsg_xos_subscriber_create(index2)
1282 assert_not_equal(subId2,'0')
1283 try:
1284 for vcpe in [vcpe_intf1,vcpe_intf2]:
1285 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1286 time.sleep(1)
1287 status = False
1288 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1289 st,out = getstatusoutput(cmd)
1290 assert_not_equal(out,'')
1291 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1292 time.sleep(1)
1293 except Exception as error:
1294 log.info('Got unexpected error %s'%error)
1295 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1296 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001297 self.vsg_xos_subscriber_delete(index1, subId = subId1)
1298 self.vsg_xos_subscriber_delete(index2, subId = subId2)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001299 raise
1300 df.callback(0)
1301 reactor.callLater(0,test_exampleservice,df)
1302 return df