blob: 718fa91d270e27f025f77e018691dae32741a92f [file] [log] [blame]
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +00001#
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 keystoneclient.v2_0.client as ksclient
19import keystoneclient.apiclient.exceptions
20import neutronclient.v2_0.client as nclient
21import neutronclient.common.exceptions
22from novaclient import client as nova_client
23from neutronclient.v2_0 import client as neutron_client
24import neutronclient.v2_0.client as neutronclient
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000025from nose.tools import assert_equal, assert_not_equal
26from twisted.internet import defer
27from nose.twistedtools import reactor, deferred
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +000028from CordTestUtils import *
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000029from onosclidriver import OnosCliDriver
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000030from OnosCtrl import OnosCtrl
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000031from OltConfig import OltConfig
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000032from OnboardingServiceUtils import OnboardingServiceUtils
33from SSHTestAgent import SSHTestAgent
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +000034from CordTestConfig import setup_module, running_on_ciab
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000035from CordLogger import CordLogger
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000036from CordTestUtils import *
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000037from CordTestUtils import log_test as log
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000038import requests
39import time
40import json
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000041from VSGAccess import VSGAccess
42from CordTestConfig import setup_module, running_on_ciab
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000043log.setLevel('INFO')
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000044
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000045class onboarding_exchange(CordLogger):
Chetan Gaonkerc6853932017-04-24 22:16:37 +000046 ONOS_INSTANCES = 3
47 V_INF1 = 'veth0'
48 device_id = 'of:' + get_mac()
49 TEST_IP = '8.8.8.8'
50 HOST = "10.1.0.1"
51 USER = "vagrant"
52 PASS = "vagrant"
53 head_node = os.getenv('HEAD_NODE', 'prod')
54 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
55 test_path = os.path.dirname(os.path.realpath(__file__))
A R Karthick19771192017-04-25 14:57:05 -070056 on_pod = running_on_pod()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000057 vm_name = 'mysite_exampleservice'
Anil Kumar Sanka601242d2017-06-09 22:15:19 +000058 olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json'))
59 restApiXos = None
60 subscriber_account_num = 200
61 subscriber_s_tag = 304
62 subscriber_c_tag = 304
63 subscribers_per_s_tag = 8
64 subscriber_map = {}
65 subscriber_info = []
66 volt_subscriber_info = []
67 restore_methods = []
68 FABRIC_PORT_HEAD_NODE = 1
69 FABRIC_PORT_COMPUTE_NODE = 2
70 APP_NAME = 'org.ciena.xconnect'
71 APP_FILE = os.path.join(test_path, '..', 'apps/xconnect-1.0-SNAPSHOT.oar')
72 NUM_SUBSCRIBERS = 5
73
74 @classmethod
75 def getSubscriberCredentials(cls, subId):
76 """Generate our own account num, s_tag and c_tags"""
77 if subId in cls.subscriber_map:
78 return cls.subscriber_map[subId]
79 account_num = cls.subscriber_account_num
80 cls.subscriber_account_num += 1
81 s_tag, c_tag = cls.subscriber_s_tag, cls.subscriber_c_tag
82 cls.subscriber_c_tag += 1
83 if cls.subscriber_c_tag % cls.subscribers_per_s_tag == 0:
84 cls.subscriber_s_tag += 1
85 cls.subscriber_map[subId] = account_num, s_tag, c_tag
86 return cls.subscriber_map[subId]
87
88 @classmethod
89 def getXosCredentials(cls):
90 onos_cfg = OnosCtrl.get_config()
91 if onos_cfg is None:
92 return None
93 if 'apps' in onos_cfg and \
94 'org.opencord.vtn' in onos_cfg['apps'] and \
95 'cordvtn' in onos_cfg['apps']['org.opencord.vtn'] and \
96 'xos' in onos_cfg['apps']['org.opencord.vtn']['cordvtn']:
97 xos_cfg = onos_cfg['apps']['org.opencord.vtn']['cordvtn']['xos']
98 endpoint = xos_cfg['endpoint']
99 user = xos_cfg['user']
100 password = xos_cfg['password']
101 xos_endpoints = endpoint.split(':')
102 xos_host = xos_endpoints[1][len('//'):]
103 xos_port = xos_endpoints[2][:-1]
104 #log.info('xos_host: %s, port: %s, user: %s, password: %s' %(xos_host, xos_port, user, password))
105 return dict(host = xos_host, port = xos_port, user = user, password = password)
106
107 return None
108 @classmethod
109 def getSubscriberConfig(cls, num_subscribers):
110 features = {
111 'cdn': True,
112 'uplink_speed': 1000000000,
113 'downlink_speed': 1000000000,
114 'uverse': True,
115 'status': 'enabled'
116 }
117 subscriber_map = []
118 for i in xrange(num_subscribers):
119 subId = 'sub{}'.format(i)
120 account_num, _, _ = cls.getSubscriberCredentials(subId)
121 identity = { 'account_num' : str(account_num),
122 'name' : 'My House {}'.format(i)
123 }
124 sub_info = { 'features' : features,
125 'identity' : identity
126 }
127 subscriber_map.append(sub_info)
128
129 return subscriber_map
130
131 @classmethod
132 def getVoltSubscriberConfig(cls, num_subscribers):
133 voltSubscriberMap = []
134 for i in xrange(num_subscribers):
135 subId = 'sub{}'.format(i)
136 account_num, s_tag, c_tag = cls.getSubscriberCredentials(subId)
137 voltSubscriberInfo = {}
138 voltSubscriberInfo['voltTenant'] = dict(s_tag = str(s_tag),
139 c_tag = str(c_tag),
140 subscriber = '')
141 voltSubscriberInfo['account_num'] = account_num
142 voltSubscriberMap.append(voltSubscriberInfo)
143
144 return voltSubscriberMap
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000145
146 @classmethod
147 def setUpClass(cls):
148 OnboardingServiceUtils.setUp()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000149 cls.controllers = get_controllers()
150 cls.controller = cls.controllers[0]
151 cls.cli = None
152 cls.on_pod = running_on_pod()
153 cls.on_ciab = running_on_ciab()
154 cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file)
155 cls.vcpes = cls.olt.get_vcpes()
156 cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp')
157 cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved')
158 cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag'])
159 for i in xrange(len(cls.vcpes_reserved)) ]
160 cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ]
161 cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ]
162 vcpe_dhcp_reserved = None
163 vcpe_container_reserved = None
164 if cls.vcpes_reserved:
165 vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0]
166 if cls.on_pod is False:
167 vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0]
168 vcpe_container_reserved = cls.container_vcpes_reserved[0]
169
170 cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved
171 cls.vcpe_container_reserved = vcpe_container_reserved
172 dhcp_vcpe_offset = len(cls.vcpes_reserved)
173 cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag'])
174 for i in xrange(len(cls.vcpes_dhcp)) ]
175 cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ]
176 cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ]
177 vcpe_dhcp = None
178 vcpe_container = None
179 #cache the first dhcp vcpe in the class for quick testing
180 if cls.vcpes_dhcp:
181 vcpe_container = cls.container_vcpes[0]
182 vcpe_dhcp = cls.dhcp_vcpes[0]
183 if cls.on_pod is False:
184 vcpe_dhcp = cls.untagged_dhcp_vcpes[0]
185 cls.vcpe_container = vcpe_container_reserved or vcpe_container
186 cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp
187 VSGAccess.setUp()
188 cls.setUpCordApi()
189 if cls.on_pod is True:
190 cls.openVCPEAccess(cls.volt_subscriber_info)
191
192 @classmethod
193 def setUpCordApi(cls):
194 our_path = os.path.dirname(os.path.realpath(__file__))
195 cord_api_path = os.path.join(our_path, '..', 'cord-api')
196 framework_path = os.path.join(cord_api_path, 'Framework')
197 utils_path = os.path.join(framework_path, 'utils')
198 data_path = os.path.join(cord_api_path, 'Tests', 'data')
199 subscriber_cfg = os.path.join(data_path, 'Subscriber.json')
200 volt_tenant_cfg = os.path.join(data_path, 'VoltTenant.json')
201 num_subscribers = max(cls.NUM_SUBSCRIBERS, 5)
202 cls.subscriber_info = cls.getSubscriberConfig(num_subscribers)
203 cls.volt_subscriber_info = cls.getVoltSubscriberConfig(num_subscribers)
204
205 sys.path.append(utils_path)
206 sys.path.append(framework_path)
207 from restApi import restApi
208 restApiXos = restApi()
209 xos_credentials = cls.getXosCredentials()
210 if xos_credentials is None:
211 restApiXos.controllerIP = cls.HEAD_NODE
212 restApiXos.controllerPort = '9000'
213 else:
214 restApiXos.controllerIP = xos_credentials['host']
215 restApiXos.controllerPort = xos_credentials['port']
216 restApiXos.user = xos_credentials['user']
217 restApiXos.password = xos_credentials['password']
218 cls.restApiXos = restApiXos
219
220 @classmethod
221 def getVoltId(cls, result, subId):
222 if type(result) is not type([]):
223 return None
224 for tenant in result:
225 if str(tenant['subscriber']) == str(subId):
226 return str(tenant['id'])
227 return None
228
229 @classmethod
230 def closeVCPEAccess(cls, volt_subscriber_info):
231 OnosCtrl.uninstall_app(cls.APP_NAME, onos_ip = cls.HEAD_NODE)
232
233 @classmethod
234 def openVCPEAccess(cls, volt_subscriber_info):
235 """
236 This code is used to configure leaf switch for head node access to compute node over fabric.
237 Care is to be taken to avoid overwriting existing/default vcpe flows.
238 The access is opened for generated subscriber info which should not overlap.
239 We target the fabric onos instance on head node.
240 """
241 OnosCtrl.install_app(cls.APP_FILE, onos_ip = cls.HEAD_NODE)
242 time.sleep(2)
243 s_tags = map(lambda tenant: int(tenant['voltTenant']['s_tag']), volt_subscriber_info)
244 #only get unique vlan tags
245 s_tags = list(set(s_tags))
246 devices = OnosCtrl.get_device_ids(controller = cls.HEAD_NODE)
247 if devices:
248 device_config = {}
249 for device in devices:
250 device_config[device] = []
251 for s_tag in s_tags:
252 xconnect_config = {'vlan': s_tag, 'ports' : [ cls.FABRIC_PORT_HEAD_NODE, cls.FABRIC_PORT_COMPUTE_NODE ] }
253 device_config[device].append(xconnect_config)
254
255 cfg = { 'apps' : { 'org.ciena.xconnect' : { 'xconnectTestConfig' : device_config } } }
256 OnosCtrl.config(cfg, controller = cls.HEAD_NODE)
257
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000258
259 @classmethod
260 def tearDownClass(cls):
261 OnboardingServiceUtils.tearDown()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000262 VSGAccess.tearDown()
263 if cls.on_pod is True:
264 cls.closeVCPEAccess(cls.volt_subscriber_info)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000265
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000266 def cliEnter(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000267 retries = 0
268 while retries < 30:
269 self.cli = OnosCliDriver(controller = controller, connect = True)
270 if self.cli.handle:
271 break
272 else:
273 retries += 1
274 time.sleep(2)
275
276 def cliExit(self):
277 self.cli.disconnect()
278
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000279 def onos_shutdown(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000280 status = True
281 self.cliEnter(controller = controller)
282 try:
283 self.cli.shutdown(timeout = 10)
284 except:
285 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
286 status = False
287
288 self.cliExit()
289 return status
290
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000291 def get_exampleservice_vm_public_ip(self, vm_name = 'mysite_exampleservice'):
292 if not vm_name:
293 vm_name = self.vm_name
294 exampleservices = OnboardingServiceUtils.get_exampleservices()
295 for service in exampleservices:
296 if vm_name in service.name:
297 return service.get_public_ip()
298 return None
299
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000300 def add_static_route_via_vcpe_interface(self, routes, vcpe=None,dhcp_ip=True):
301 if not vcpe:
302 vcpe = self.dhcp_vcpes_reserved[0]
303 if dhcp_ip:
304 os.system('dhclient '+vcpe)
305 time.sleep(1)
306 for route in routes:
307 log.info('route is %s'%route)
308 cmd = 'ip route add ' + route + ' via 192.168.0.1 '+ 'dev ' + vcpe
309 os.system(cmd)
310 return True
311
312 def del_static_route_via_vcpe_interface(self,routes,vcpe=None,dhcp_release=True):
313 if not vcpe:
314 vcpe = self.dhcp_vcpes_reserved[0]
315 cmds = []
316 for route in routes:
317 cmd = 'ip route del ' + route + ' via 192.168.0.1 ' + 'dev ' + vcpe
318 os.system(cmd)
319 if dhcp_release:
320 os.system('dhclient '+vcpe+' -r')
321 return True
322
323 def vsg_for_external_connectivity(self, subscriber_index, reserved = False):
324 if reserved is True:
325 if self.on_pod is True:
326 vcpe = self.dhcp_vcpes_reserved[subscriber_index]
327 else:
328 vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index]
329 else:
330 if self.on_pod is True:
331 vcpe = self.dhcp_vcpes[subscriber_index]
332 else:
333 vcpe = self.untagged_dhcp_vcpes[subscriber_index]
334 mgmt = 'eth0'
335 host = '8.8.8.8'
336 self.success = False
337 assert_not_equal(vcpe, None)
338 vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt)
339 assert_not_equal(vcpe_ip, None)
340 log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe))
341 log.info('Sending icmp echo requests to external network 8.8.8.8')
342 st, _ = getstatusoutput('ping -c 3 8.8.8.8')
343 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe)
344 assert_equal(st, 0)
345
346 @deferred(50)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000347 def test_exampleservice_health(self):
348 """
349 Algo:
350 1. Login to compute node VM
351 2. Get all exampleservice
352 3. Ping to all exampleservice
353 4. Verifying Ping success
354 """
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000355 df = defer.Deferred()
356 def test_exampleservice(df):
357 status = OnboardingServiceUtils.health_check()
358 assert_equal(status, True)
359 df.callback(0)
360 reactor.callLater(0,test_exampleservice,df)
361 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000362
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000363 @deferred(50)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000364 def test_exampleservice_for_login(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000365 """
366 Algo:
367 1. Login to compute node VM
368 2. Get all exampleservice
369 3. Login to all exampleservice
370 4. Verifying Login success
371 """
A R Karthick19771192017-04-25 14:57:05 -0700372 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000373 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000374 df = defer.Deferred()
375 def test_exampleservice(df):
376 exampleservices = OnboardingServiceUtils.get_exampleservices()
377 exampleservice_access_status = map(lambda exampleservice: exampleservice.check_access(), exampleservices)
378 status = filter(lambda st: st == False, exampleservice_access_status)
379 assert_equal(len(status), 0)
380 df.callback(0)
381 reactor.callLater(0,test_exampleservice,df)
382 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000383
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000384 @deferred(30)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000385 def test_exampleservice_for_default_route_through_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000386 """
387 Algo:
388 1. Login to Head node
389 2. Verify default route exists in test client
390 """
Chetan Gaonker4cff4432017-05-01 17:56:56 +0000391 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000392 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000393 df = defer.Deferred()
394 def test_exampleservice(df):
395 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
396 cmd = "sudo lxc exec testclient -- route | grep default"
397 status, output = ssh_agent.run_cmd(cmd)
398 assert_equal(status, True)
399 df.callback(0)
400 reactor.callLater(0,test_exampleservice,df)
401 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000402
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000403 @deferred(50)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000404 def test_exampleservice_for_service_access_through_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000405 """
406 Algo:
407 1. Login to Head node
408 2. Ping to all exampleservice from test client
409 3. Verifying Ping success
410 """
A R Karthick19771192017-04-25 14:57:05 -0700411 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000412 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000413 df = defer.Deferred()
414 def test_exampleservice(df):
415 vm_public_ip = self.get_exampleservice_vm_public_ip()
416 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
417 cmd = "sudo lxc exec testclient -- ping -c 3 {}".format(vm_public_ip)
418 status, output = ssh_agent.run_cmd(cmd)
419 assert_equal( status, True)
420 df.callback(0)
421 reactor.callLater(0,test_exampleservice,df)
422 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000423
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000424 @deferred(30)
425 def test_exampleservice_for_service_reachability_from_cord_tester(self):
426 """
427 Algo:
428 1. Add static route to example service running VM IP in cord-tester
429 2. Ping to the VM IP
430 3. Verifying Ping success
431 """
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000432 if self.on_pod is False:
433 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000434 df = defer.Deferred()
435 def test_exampleservice(df):
436 vm_public_ip = self.get_exampleservice_vm_public_ip()
437 vcpe_intf = self.dhcp_vcpes_reserved[0]
438 try:
439 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
440 st, _ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
441 assert_equal(st, False)
442 except Exception as error:
443 log.info('Got Unexpected error %s'%error)
444 raise
445 finally:
446 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
447 df.callback(0)
448 reactor.callLater(0,test_exampleservice,df)
449 return df
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000450
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000451 @deferred(40)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000452 def test_exampleservice_operational_status_from_testclient(self):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000453 """
454 Algo:
455 1. Login to Head node
456 2. Do curl request to the example service running VM IP from test client
457 3. Verifying curl request success
458 """
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000459 if self.on_pod is False:
460 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000461 df = defer.Deferred()
462 def test_exampleservice(df):
463 vm_public_ip = self.get_exampleservice_vm_public_ip()
464 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
465 cmd = 'sudo lxc exec testclient -- apt-get install -y curl'
466 status, _ = ssh_agent.run_cmd(cmd)
467 assert_equal(status, True)
468 #Test connectivity to ExampleService from test client
469 cmd = 'sudo lxc exec testclient -- curl -s http://{}'.format(vm_public_ip)
470 status, _ = ssh_agent.run_cmd(cmd)
471 assert_equal(status, True)
472 df.callback(0)
473 reactor.callLater(0,test_exampleservice,df)
474 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000475
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000476 @deferred(30)
477 def test_exampleservice_operational_access_from_cord_tester(self):
478 """
479 Algo:
480 1. Add static route to example service running VM IP in cord-tester
481 2. Do curl request to the VM IP
482 3. Verifying curl request success
483 """
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000484 if self.on_pod is False:
485 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000486 vcpe_intf = self.dhcp_vcpes_reserved[0]
487 df = defer.Deferred()
488 def test_exampleservice(df):
489 vm_public_ip = self.get_exampleservice_vm_public_ip()
490 try:
491 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
492 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
493 assert_not_equal(out,'')
494 except Exception as error:
495 log.info('Got Unexpected error %s'%error)
496 raise
497 finally:
498 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
499 df.callback(0)
500 reactor.callLater(0,test_exampleservice,df)
501 return df
502
503 @deferred(40)
504 def test_exampleservice_for_service_message(self, service_message="\"hello\""):
505 """
506 Algo:
507 1. Get dhcp ip to vcpe interface in cord-tester
508 2. Add static route to example service running VM IP in cord-tester
509 3. Do curl request to the VM IP
510 4. Verifying Service message in curl response
511 """
512 if self.on_pod is False:
513 return
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000514 vm_public_ip = self.get_exampleservice_vm_public_ip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000515 vcpe_intf = self.dhcp_vcpes_reserved[0]
516 df = defer.Deferred()
517 def test_exampleservice(df):
518 vm_public_ip = self.get_exampleservice_vm_public_ip()
519 vcpe_intf = self.dhcp_vcpes_reserved[0]
520 try:
521 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
522 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
523 assert_not_equal(out,'')
524 output = out.split('\n')
525 srvs_msg = ''
526 for line in output:
527 line = line.split(':')
528 if line[0].strip() == 'Service Message':
529 srvs_msg = line[1].strip()
530 assert_equal(service_message, srvs_msg)
531 except Exception as error:
532 log.info('Got Unexpected error %s'%error)
533 raise
534 finally:
535 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
536 df.callback(0)
537 reactor.callLater(0,test_exampleservice,df)
538 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000539
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000540 @deferred(40)
541 def test_exampleservice_for_tenant_message(self, tenant_message="\"world\""):
542 """
543 Algo:
544 1. Get dhcp ip to vcpe interface in cord-tester
545 2. Add static route to example service running VM IP in cord-tester
546 3. Do curl request to the VM IP
547 4. Verifying Tenant message in curl response
548 """
549 if self.on_pod is False:
550 return
551 df = defer.Deferred()
552 def test_exampleservice(df):
553 vcpe_intf = self.dhcp_vcpes_reserved[0]
554 vm_public_ip = self.get_exampleservice_vm_public_ip()
555 try:
556 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
557 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
558 assert_not_equal(out,'')
559 output = out.split('\n')
560 tnt_msg = ''
561 for line in output:
562 line = line.split(':')
563 if line[0].strip() == 'Tenant Message':
564 tnt_msg = line[1].strip()
565 assert_equal(tenant_message, tnt_msg)
566 except Exception as error:
567 log.info('Got Unexpected error %s'%error)
568 raise
569 finally:
570 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
571 df.callback(0)
572 reactor.callLater(0,test_exampleservice,df)
573 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000574
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000575 @deferred(60)
576 def test_exampleservice_access_after_subscriber_interface_toggle(self):
577 """
578 Algo:
579 1. Get dhcp ip to vcpe interface in cord-tester
580 2. Add static route to example service running VM IP in cord-tester
581 3. Do curl request to the VM IP
582 4. Verifying curl request success
583 5. Toggle vcpe interface in cord-tester and do curl request again
584 6. Again verify curl request success
585 """
586 if self.on_pod is False:
587 return
588 df = defer.Deferred()
589 def test_exampleservice(df):
590 vm_public_ip = self.get_exampleservice_vm_public_ip()
591 vcpe_intf = self.dhcp_vcpes_reserved[0]
592 try:
593 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
594 #curl request from test container
595 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000596 st, out = getstatusoutput(cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000597 assert_not_equal(out,'')
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000598 st, _ = getstatusoutput('ifconfig {} down'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000599 assert_equal(st, False)
600 time.sleep(1)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000601 st, _ = getstatusoutput('ifconfig {} up'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000602 assert_equal(st, False)
603 time.sleep(1)
604 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
605 st, out = getstatusoutput(cmd)
606 assert_not_equal(out,'')
607 except Exception as error:
608 log.info('Got Unexpected error %s'%error)
609 raise
610 finally:
611 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000612 getstatusoutput('ifconfig {} up'.format(vcpe_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000613 df.callback(0)
614 reactor.callLater(0,test_exampleservice,df)
615 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000616
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000617
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000618 @deferred(60)
619 def test_exampleservice_access_after_service_paused(self):
620 """
621 Algo:
622 1. Get dhcp ip to vcpe interface in cord-tester
623 2. Add static route to example service running VM IP in cord-tester
624 3. Do curl request to the VM IP
625 4. Verifying curl request success
626 5. Pause example service running VM and do curl request again
627 6. Verify curl response is an empty output
628 """
629 if self.on_pod is False:
630 return
631 df = defer.Deferred()
632 def test_exampleservice(df):
633 service_vm = None
634 vm_public_ip = self.get_exampleservice_vm_public_ip()
635 vcpe_intf = self.dhcp_vcpes_reserved[0]
636 exampleservices = OnboardingServiceUtils.get_exampleservices()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000637 for service in exampleservices:
638 if self.vm_name in service.name:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000639 service_vm = service
640 break
641 assert_not_equal(service_vm,None)
642 try:
643 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
644 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
645 assert_not_equal(out,'')
646 log.info('Pausing example service running vm')
647 service_vm.pause()
648 time.sleep(2)
649 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
650 assert_equal(out,'')
651 service_vm.unpause()
652 time.sleep(3)
653 except Exception as error:
654 log.info('Got Unexpected error %s'%error)
655 service_vm.unpause()
656 time.sleep(3)
657 raise
658 finally:
659 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
660 df.callback(0)
661 reactor.callLater(0,test_exampleservice,df)
662 return df
663
664 #Test failing. server state goes to error after resuming
665 @deferred(60)
666 def test_exampleservice_access_after_service_is_suspended(self):
667 """
668 Algo:
669 1. Get dhcp ip to vcpe interface in cord-tester
670 2. Add static route to example service running VM IP in cord-tester
671 3. Do curl request to the VM IP
672 4. Verifying curl request success
673 5. Suspend example service running VM and do curl request again
674 6. Verify curl response is an empty output
675 7. Resume suspended VM and do curl request now
676 8. Verifying curl request success
677 """
678 if self.on_pod is False:
679 return
680 df = defer.Deferred()
681 def test_exampleservice(df):
682 service_vm = None
683 vm_public_ip = self.get_exampleservice_vm_public_ip()
684 vcpe_intf = self.dhcp_vcpes_reserved[0]
685 exampleservices = OnboardingServiceUtils.get_exampleservices()
686 for service in exampleservices:
687 if self.vm_name in service.name:
688 service_vm = service
689 break
690 assert_not_equal(service_vm,None)
691 try:
692 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
693 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
694 assert_not_equal(out,'')
695 log.info('Suspending example service running vm')
696 service_vm.suspend()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000697 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000698 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
699 assert_equal(out,'')
700 service_vm.resume()
701 time.sleep(5)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000702 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
703 assert_not_equal(out,'')
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000704 except Exception as error:
705 log.info('Got Unexpected error %s'%error)
706 service_vm.stop()
707 time.sleep(1)
708 service_vm.start()
709 time.sleep(5)
710 raise
711 finally:
712 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
713 df.callback(0)
714 reactor.callLater(0,test_exampleservice,df)
715 return df
716
717 @deferred(60)
718 def test_exampleservice_access_after_service_restart(self):
719 """
720 Algo:
721 1. Get dhcp ip to vcpe interface in cord-tester
722 2. Add static route to example service running VM IP in cord-tester
723 3. Do curl request to the VM IP
724 4. Verifying curl request success
725 5. Restart example service running VM and do curl request again
726 9. Verifying curl request success
727 """
728 if self.on_pod is False:
729 return
730 df = defer.Deferred()
731 def test_exampleservice(df):
732 service_vm = None
733 vm_public_ip = self.get_exampleservice_vm_public_ip()
734 vcpe_intf = self.dhcp_vcpes_reserved[0]
735 exampleservices = OnboardingServiceUtils.get_exampleservices()
736 for service in exampleservices:
737 if self.vm_name in service.name:
738 service_vm = service
739 break
740 assert_not_equal(service_vm,None)
741 try:
742 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000743 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000744 assert_not_equal(out,'')
745 log.info('Restarting example service running vm')
746 service_vm.reboot()
747 time.sleep(5)
748 clock = 0
749 status = False
750 while(clock <= 30):
751 time.sleep(5)
752 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
753 if out != '':
754 status = True
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000755 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000756 clock += 5
757 assert_equal(status, True)
758 except Exception as error:
759 log.info('Got Unexpected error %s'%error)
760 raise
761 finally:
762 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
763 df.callback(0)
764 reactor.callLater(0,test_exampleservice,df)
765 return df
766
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000767 #not test. vSG VM goes down after restart
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000768 @deferred(70)
769 def test_exampleservice_access_after_vsg_vm_restart(self):
770 """
771 Algo:
772 1. Get dhcp ip to vcpe interface in cord-tester
773 2. Add static route to example service running VM IP in cord-tester
774 3. Do curl request to the VM IP
775 4. Verifying curl request success
776 5. Restart vSG VM and do curl request again
777 9. Verifying curl request success
778 """
779 if self.on_pod is False:
780 return
781 df = defer.Deferred()
782 def test_exampleservice(df):
783 service_vm = None
784 vm_public_ip = self.get_exampleservice_vm_public_ip()
785 vcpe_intf = self.dhcp_vcpes_reserved[0]
786 vcpe_name = self.container_vcpes_reserved [0]
787 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
788 try:
789 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000790 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000791 assert_not_equal(out,'')
792 log.info('Restarting vSG VM')
793 vsg.reboot()
794 time.sleep(5)
795 clock = 0
796 status = False
797 while(clock <= 40):
798 time.sleep(5)
799 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
800 if out != '':
801 status = True
802 break
803 clock += 5
804 assert_equal(status, True)
805 except Exception as error:
806 log.info('Got Unexpected error %s'%error)
807 raise
808 finally:
809 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
810 df.callback(0)
811 reactor.callLater(0,test_exampleservice,df)
812 return df
813
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000814 @deferred(80)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000815 def test_exampleservice_access_after_service_stop(self):
816 """
817 Algo:
818 1. Get dhcp ip to vcpe interface in cord-tester
819 2. Add static route to example service running VM IP in cord-tester
820 3. Do curl request to the VM IP
821 4. Verifying curl request success
822 5. Stop example service running VM and do curl request again
823 6. Verify curl response is an empty output
824 7. Start stopped VM and do curl request now
825 8. Verifying curl request success
826 """
827 if self.on_pod is False:
828 return
829 df = defer.Deferred()
830 def test_exampleservice(df):
831 service_vm = None
832 vm_public_ip = self.get_exampleservice_vm_public_ip()
833 vcpe_intf = self.dhcp_vcpes_reserved[0]
834 exampleservices = OnboardingServiceUtils.get_exampleservices()
835 for service in exampleservices:
836 if self.vm_name in service.name:
837 service_vm = service
838 break
839 assert_not_equal(service_vm,None)
840 try:
841 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
842 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
843 assert_not_equal(out,'')
844 log.info('Stopping example service running vm')
845 service_vm.stop()
846 time.sleep(5)
847 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
848 assert_equal(out,'')
849 service_vm.start()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000850 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000851 clock = 0
852 status = False
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000853 while(clock <= 60):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000854 time.sleep(5)
855 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
856 if out != '':
857 status = True
858 break
859 clock += 5
860 assert_equal(status, True)
861 except Exception as error:
862 log.info('Got Unexpected error %s'%error)
863 service_vm.start()
864 raise
865 finally:
866 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
867 df.callback(0)
868 reactor.callLater(0,test_exampleservice,df)
869 return df
870
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000871 @deferred(80)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000872 def test_exampleservice_for_service_message_after_service_stop_and_start(self, service_message="\"hello\""):
873 """
874 Algo:
875 1. Get dhcp ip to vcpe interface in cord-tester
876 2. Add static route to example service running VM IP in cord-tester
877 3. Do curl request to the VM IP
878 4. Verifying curl request success
879 5. Stop example service running VM and do curl request again
880 6. Verify curl response is an empty output
881 7. Start stopped VM and do curl request now
882 8. Verifying Service message in curl response
883 """
884 if self.on_pod is False:
885 return
886 df = defer.Deferred()
887 def test_exampleservice(df):
888 service_vm = None
889 vm_public_ip = self.get_exampleservice_vm_public_ip()
890 vcpe_intf = self.dhcp_vcpes_reserved[0]
891 exampleservices = OnboardingServiceUtils.get_exampleservices()
892 for service in exampleservices:
893 if self.vm_name in service.name:
894 service_vm = service
895 break
896 assert_not_equal(service_vm,None)
897 try:
898 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
899 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
900 assert_not_equal(out,'')
901 log.info('Stopping example service running VM')
902 service_vm.stop()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000903 time.sleep(5)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000904 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
905 assert_equal(out,'')
906 service.start()
907 time.sleep(5)
908 clock = 0
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000909 while(clock <= 60):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000910 time.sleep(5)
911 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
912 if out != '':
913 output = out.split('\n')
914 srvs_msg = None
915 for line in output:
916 line = line.split(':')
917 if line[0].strip() == 'Service Message':
918 srvs_msg = line[1].strip()
Anil Kumar Sanka4f449aa2017-06-13 20:54:56 +0000919 clock = 60
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000920 break
921 clock += 5
922 assert_equal(service_message, srvs_msg)
923 except Exception as error:
924 log.info('Got Unexpected error %s'%error)
925 service_vm.start()
926 time.sleep(5)
927 finally:
928 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
929 df.callback(0)
930 reactor.callLater(0,test_exampleservice,df)
931 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000932
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +0000933 @deferred(80)
934 def test_exampleservice_for_tenant_message_after_service_restart(self,tenant_message="\"world\""):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000935 """
936 Algo:
937 1. Get dhcp ip to vcpe interface in cord-tester
938 2. Add static route to example service running VM IP in cord-tester
939 3. Do curl request to the VM IP
940 4. Verifying curl request success
941 5. Restart example service running VM and do curl request again
942 6. Verifying Tenant message in curl response
943 """
944 if self.on_pod is False:
945 return
946 df = defer.Deferred()
947 def test_exampleservice(df):
948 service_vm = None
949 vm_public_ip = self.get_exampleservice_vm_public_ip()
950 vcpe_intf = self.dhcp_vcpes_reserved[0]
951 exampleservices = OnboardingServiceUtils.get_exampleservices()
952 for service in exampleservices:
953 if self.vm_name in service.name:
954 service_vm = service
955 break
956 assert_not_equal(service_vm,None)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000957 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000958 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000959 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000960 assert_not_equal(out,'')
961 log.info('Restarting example service running VM')
962 service_vm.reboot()
963 time.sleep(5)
964 clock = 0
965 while(clock <= 40):
966 time.sleep(5)
967 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
968 if out != '':
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000969 output = out.split('\n')
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000970 tnnt_msg = None
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000971 for line in output:
972 line = line.split(':')
973 if line[0].strip() == 'Tenant Message':
974 tnnt_msg = line[1].strip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000975 clock = 40
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000976 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000977 clock += 5
978 assert_equal(tenant_message, tnnt_msg)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000979 except Exception as error:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000980 log.info('Got Unexpected error %s'%error)
981 raise
982 finally:
983 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000984 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000985 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000986 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000987
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000988 @deferred(50)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000989 def test_exampleservice_access_after_vcpe_instance_restart(self):
990 """
991 Algo:
992 1. Get dhcp ip to vcpe interface in cord-tester
993 2. Add static route to example service running VM IP in cord-tester
994 3. Do curl request to the VM IP
995 4. Verifying curl request success
996 5. Restart vcpe instance and do curl request again
997 8. Verifying curl request success
998 """
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +0000999 if self.on_pod is False:
1000 return
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001001 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001002 def test_exampleservice(df):
1003 vcpe_intf = self.dhcp_vcpes_reserved[0]
1004 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001005 vm_public_ip = self.get_exampleservice_vm_public_ip()
1006 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1007 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001008 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001009 #curl request from test container
1010 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1011 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001012 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001013 #restarting example service VM
1014 cmd = 'sudo docker restart {}'.format(vcpe_name)
1015 status, _ = vsg.run_cmd(cmd)
1016 assert_equal(status, True)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001017 time.sleep(5)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001018 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1019 clock = 0
1020 status = False
1021 while(clock <= 30):
1022 time.sleep(5)
1023 st, out = getstatusoutput(curl_cmd)
1024 if out != '':
1025 status = True
1026 break
1027 clock += 5
1028 assert_equal(status,True)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001029 except Exception as error:
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001030 log.info('Got Unexpeted error %s'%error)
1031 raise
1032 finally:
1033 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001034 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001035 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001036 return df
1037
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001038 @deferred(50)
1039 def test_exampleservice_access_after_vcpe_instance_wan_interface_toggle(self):
1040 """
1041 Algo:
1042 1. Get dhcp ip to vcpe interface in cord-tester
1043 2. Add static route to example service running VM IP in cord-tester
1044 3. Do curl request to the VM IP
1045 4. Verifying curl request success
1046 5. Restart vcpe instance and do curl request again
1047 8. Verifying curl request success
1048 """
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001049 if self.on_pod is False:
1050 return
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001051 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001052 def test_exampleservice(df):
1053 vcpe_intf = self.dhcp_vcpes_reserved[0]
1054 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001055 vm_public_ip = self.get_exampleservice_vm_public_ip()
1056 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001057 wan_intf = 'eth0'
1058 mgmt = 'eth0'
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001059 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001060 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001061 #curl request from test container
1062 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1063 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001064 assert_not_equal(out,'')
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001065 st = VSGAccess.vcpe_wan_down(vcpe_name)
1066 if st is False:
1067 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe_intf)
1068 assert_not_equal(st, '0')
1069 time.sleep(2)
1070 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001071 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1072 st, out = getstatusoutput(curl_cmd)
1073 assert_equal(out,'')
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001074 st = VSGAccess.vcpe_wan_up(vcpe_name)
1075 if st is False:
1076 VSGAccess.restore_interface_config(mgmt, vcpe = vcpe_intf)
1077 assert_not_equal(st, '0')
1078 time.sleep(5)
1079 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001080 st, out = getstatusoutput(curl_cmd)
1081 assert_not_equal(out,'')
1082 except Exception as error:
1083 log.info('Got Unexpeted error %s'%error)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001084 vsg.run_cmd('sudo docker restart {}'.format(vcpe_name,wan_intf))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001085 raise
1086 finally:
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001087 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001088 df.callback(0)
1089 reactor.callLater(0,test_exampleservice,df)
1090 return df
1091
1092 @deferred(30)
1093 def test_exampleservice_access_after_firewall_rule_added_to_drop_service_running_server_in_vcpe_instance(self):
1094 """
1095 Algo:
1096 1. Get dhcp ip to vcpe interface in cord-tester
1097 2. Add static route to example service running VM IP in cord-tester
1098 3. Do curl request to the VM IP
1099 4. Verifying curl request success
1100 5. Add a firewall rule in vcpe instance to drop packets destined to example service VM
1101 6. Do curl request now
1102 7. Verifying curl response is an empty output
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001103 8. Delete the firewall rule and do curl request again
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001104 9. Verifying curl request success
1105 """
1106 df = defer.Deferred()
1107 def test_exampleservice(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
1108 vcpe_intf = self.dhcp_vcpes_reserved[0]
1109 vcpe_name = self.container_vcpes_reserved[0]
1110 vm_public_ip = self.get_exampleservice_vm_public_ip()
1111 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1112 try:
1113 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1114 #curl request from test container
1115 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1116 st, out = getstatusoutput(curl_cmd)
1117 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001118 #restarting example service VM
1119 cmd = 'sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
1120 status, _ = vsg.run_cmd(cmd)
1121 assert_equal(status, True)
1122 time.sleep(1)
1123 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001124 assert_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001125 except Exception as error:
1126 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001127 raise
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001128 finally:
1129 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip))
1130 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001131 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001132 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001133 return df
1134
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001135
1136 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
1137 if self.on_pod is False:
1138 return ''
1139 if subscriber_info is None:
1140 subscriber_info = self.subscriber_info[index]
1141 if volt_subscriber_info is None:
1142 volt_subscriber_info = self.volt_subscriber_info[index]
1143 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1144 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1145 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1146 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1147 subId = ''
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001148 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001149 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
1150 assert_equal(result, True)
1151 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1152 assert_not_equal(result, None)
1153 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1154 assert_not_equal(subId, '0')
1155 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
1156 volt_tenant = volt_subscriber_info['voltTenant']
1157 #update the subscriber id in the tenant info before making the rest
1158 volt_tenant['subscriber'] = subId
1159 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
1160 assert_equal(result, True)
1161 #if the vsg instance was already instantiated, then reduce delay
1162 if c_tag % self.subscribers_per_s_tag == 0:
1163 delay = 350
1164 else:
1165 delay = 90
1166 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
1167 time.sleep(delay)
1168 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
1169 self.vsg_for_external_connectivity(index)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001170 finally:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001171 return subId
1172
1173 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
1174 if self.on_pod is False:
1175 return
1176 if subscriber_info is None:
1177 subscriber_info = self.subscriber_info[index]
1178 if volt_subscriber_info is None:
1179 volt_subscriber_info = self.volt_subscriber_info[index]
1180 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1181 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1182 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1183 log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1184 if not subId:
1185 #get the subscriber id first
1186 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1187 assert_not_equal(result, None)
1188 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1189 assert_not_equal(subId, '0')
1190 if not voltId:
1191 #get the volt id for the subscriber
1192 result = self.restApiXos.ApiGet('TENANT_VOLT')
1193 assert_not_equal(result, None)
1194 voltId = self.getVoltId(result, subId)
1195 assert_not_equal(voltId, None)
1196 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
1197 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
1198 assert_equal(status, True)
1199 #Delete the tenant
1200 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
1201 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
1202
1203 def vsg_xos_subscriber_id(self, index):
1204 log.info('index and its type are %s, %s'%(index, type(index)))
1205 volt_subscriber_info = self.volt_subscriber_info[index]
1206 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1207 assert_not_equal(result, None)
1208 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1209 return subId
1210
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001211 @deferred(500)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001212 def test_xos_subcriber_access_exampleservice(self,index=0):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001213 """
1214 Algo:
1215 1. Create two vcpe instances using XOS
1216 2. Add static route to example service running VM IP in cord-tester
1217 3. Do curl request to the VM IP
1218 4. Verifying curl request success
1219 5. Repeat steps for both vcpes
1220 """
1221 df = defer.Deferred()
1222 def test_exampleservice(df):
1223 vm_public_ip = self.get_exampleservice_vm_public_ip()
1224 vcpe_intf = self.dhcp_vcpes[0]
1225 subId = self.vsg_xos_subscriber_id(index)
1226 if subId == '0':
1227 subId = self.vsg_xos_subscriber_create(index)
1228 assert_not_equal(subId,'0')
1229 try:
1230 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1231 time.sleep(1)
1232 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1233 st,out = getstatusoutput(cmd)
1234 assert_not_equal(out,'')
1235 except Exception as error:
1236 log.info('Got unexpected error %s'%error)
1237 raise
1238 finally:
1239 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001240 self.vsg_xos_subscriber_delete(index, subId = subId)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001241 df.callback(0)
1242 reactor.callLater(0,test_exampleservice,df)
1243 return df
1244
1245 @deferred(500)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001246 def test_exampleservice_multiple_subcribers_access_same_service(self,index1=0,index2=1):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001247 """
1248 Algo:
1249 1. Create two vcpe instances using XOS
1250 2. Add static route to example service running VM IP in cord-tester
1251 3. Do curl request to the VM IP
1252 4. Verifying curl request success
1253 5. Repeat steps for both vcpes
1254 """
1255 df = defer.Deferred()
1256 def test_exampleservice(df):
1257 vm_public_ip = self.get_exampleservice_vm_public_ip()
1258 vcpe_intf1 = self.dhcp_vcpes[0]
1259 vcpe_intf2 = self.dhcp_vcpes[1]
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001260 subId1 = self.vsg_xos_subscriber_id(index1)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001261 if subId1 == '0':
1262 subId1 = self.vsg_xos_subscriber_create(index1)
1263 assert_not_equal(subId1,'0')
1264 subId2 = self.vsg_xos_subscriber_id(index2)
1265 if subId2 == '0':
1266 subId2 = self.vsg_xos_subscriber_create(index2)
1267 assert_not_equal(subId2,'0')
1268 try:
1269 for vcpe in [vcpe_intf1,vcpe_intf2]:
1270 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1271 time.sleep(1)
1272 status = False
1273 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1274 st,out = getstatusoutput(cmd)
1275 assert_not_equal(out,'')
1276 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1277 time.sleep(1)
1278 except Exception as error:
1279 log.info('Got unexpected error %s'%error)
1280 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1281 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
Chetan Gaonker2f85a8f2017-06-13 20:53:32 +00001282 self.vsg_xos_subscriber_delete(index1, subId = subId1)
1283 self.vsg_xos_subscriber_delete(index2, subId = subId2)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001284 raise
1285 df.callback(0)
1286 reactor.callLater(0,test_exampleservice,df)
1287 return df
1288