blob: 8243b9f12d600a3dbb00cde122fc696a6f55aaf4 [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
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000028from CordTestUtils import get_mac, log_test
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 Sanka51014ef2017-05-24 17:59:17 +000034from CordTestUtils import running_on_pod, getstatusoutput
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 """
459 df = defer.Deferred()
460 def test_exampleservice(df):
461 vm_public_ip = self.get_exampleservice_vm_public_ip()
462 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
463 cmd = 'sudo lxc exec testclient -- apt-get install -y curl'
464 status, _ = ssh_agent.run_cmd(cmd)
465 assert_equal(status, True)
466 #Test connectivity to ExampleService from test client
467 cmd = 'sudo lxc exec testclient -- curl -s http://{}'.format(vm_public_ip)
468 status, _ = ssh_agent.run_cmd(cmd)
469 assert_equal(status, True)
470 df.callback(0)
471 reactor.callLater(0,test_exampleservice,df)
472 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000473
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000474 @deferred(30)
475 def test_exampleservice_operational_access_from_cord_tester(self):
476 """
477 Algo:
478 1. Add static route to example service running VM IP in cord-tester
479 2. Do curl request to the VM IP
480 3. Verifying curl request success
481 """
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000482 if self.on_pod is False:
483 return
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000484 vcpe_intf = self.dhcp_vcpes_reserved[0]
485 df = defer.Deferred()
486 def test_exampleservice(df):
487 vm_public_ip = self.get_exampleservice_vm_public_ip()
488 try:
489 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
490 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
491 assert_not_equal(out,'')
492 except Exception as error:
493 log.info('Got Unexpected error %s'%error)
494 raise
495 finally:
496 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
497 df.callback(0)
498 reactor.callLater(0,test_exampleservice,df)
499 return df
500
501 @deferred(40)
502 def test_exampleservice_for_service_message(self, service_message="\"hello\""):
503 """
504 Algo:
505 1. Get dhcp ip to vcpe interface in cord-tester
506 2. Add static route to example service running VM IP in cord-tester
507 3. Do curl request to the VM IP
508 4. Verifying Service message in curl response
509 """
510 if self.on_pod is False:
511 return
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000512 vm_public_ip = self.get_exampleservice_vm_public_ip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000513 vcpe_intf = self.dhcp_vcpes_reserved[0]
514 df = defer.Deferred()
515 def test_exampleservice(df):
516 vm_public_ip = self.get_exampleservice_vm_public_ip()
517 vcpe_intf = self.dhcp_vcpes_reserved[0]
518 try:
519 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
520 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
521 assert_not_equal(out,'')
522 output = out.split('\n')
523 srvs_msg = ''
524 for line in output:
525 line = line.split(':')
526 if line[0].strip() == 'Service Message':
527 srvs_msg = line[1].strip()
528 assert_equal(service_message, srvs_msg)
529 except Exception as error:
530 log.info('Got Unexpected error %s'%error)
531 raise
532 finally:
533 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
534 df.callback(0)
535 reactor.callLater(0,test_exampleservice,df)
536 return df
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000537
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000538 @deferred(40)
539 def test_exampleservice_for_tenant_message(self, tenant_message="\"world\""):
540 """
541 Algo:
542 1. Get dhcp ip to vcpe interface in cord-tester
543 2. Add static route to example service running VM IP in cord-tester
544 3. Do curl request to the VM IP
545 4. Verifying Tenant message in curl response
546 """
547 if self.on_pod is False:
548 return
549 df = defer.Deferred()
550 def test_exampleservice(df):
551 vcpe_intf = self.dhcp_vcpes_reserved[0]
552 vm_public_ip = self.get_exampleservice_vm_public_ip()
553 try:
554 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
555 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
556 assert_not_equal(out,'')
557 output = out.split('\n')
558 tnt_msg = ''
559 for line in output:
560 line = line.split(':')
561 if line[0].strip() == 'Tenant Message':
562 tnt_msg = line[1].strip()
563 assert_equal(tenant_message, tnt_msg)
564 except Exception as error:
565 log.info('Got Unexpected error %s'%error)
566 raise
567 finally:
568 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
569 df.callback(0)
570 reactor.callLater(0,test_exampleservice,df)
571 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000572
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000573 @deferred(60)
574 def test_exampleservice_access_after_subscriber_interface_toggle(self):
575 """
576 Algo:
577 1. Get dhcp ip to vcpe interface in cord-tester
578 2. Add static route to example service running VM IP in cord-tester
579 3. Do curl request to the VM IP
580 4. Verifying curl request success
581 5. Toggle vcpe interface in cord-tester and do curl request again
582 6. Again verify curl request success
583 """
584 if self.on_pod is False:
585 return
586 df = defer.Deferred()
587 def test_exampleservice(df):
588 vm_public_ip = self.get_exampleservice_vm_public_ip()
589 vcpe_intf = self.dhcp_vcpes_reserved[0]
590 try:
591 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
592 #curl request from test container
593 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
594 st,_ = getstatusoutput(cmd)
595 assert_not_equal(out,'')
596 st,_ = getstatusoutput('ifconfig {} down'.format(vcpe_intf))
597 assert_equal(st, False)
598 time.sleep(1)
599 st,_ = getstatusoutput('ifconfig {} up'.format(vcpe_intf))
600 assert_equal(st, False)
601 time.sleep(1)
602 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
603 st, out = getstatusoutput(cmd)
604 assert_not_equal(out,'')
605 except Exception as error:
606 log.info('Got Unexpected error %s'%error)
607 raise
608 finally:
609 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
610 df.callback(0)
611 reactor.callLater(0,test_exampleservice,df)
612 return df
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000613
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000614
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000615 @deferred(60)
616 def test_exampleservice_access_after_service_paused(self):
617 """
618 Algo:
619 1. Get dhcp ip to vcpe interface in cord-tester
620 2. Add static route to example service running VM IP in cord-tester
621 3. Do curl request to the VM IP
622 4. Verifying curl request success
623 5. Pause example service running VM and do curl request again
624 6. Verify curl response is an empty output
625 """
626 if self.on_pod is False:
627 return
628 df = defer.Deferred()
629 def test_exampleservice(df):
630 service_vm = None
631 vm_public_ip = self.get_exampleservice_vm_public_ip()
632 vcpe_intf = self.dhcp_vcpes_reserved[0]
633 exampleservices = OnboardingServiceUtils.get_exampleservices()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000634 for service in exampleservices:
635 if self.vm_name in service.name:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000636 service_vm = service
637 break
638 assert_not_equal(service_vm,None)
639 try:
640 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
641 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
642 assert_not_equal(out,'')
643 log.info('Pausing example service running vm')
644 service_vm.pause()
645 time.sleep(2)
646 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
647 assert_equal(out,'')
648 service_vm.unpause()
649 time.sleep(3)
650 except Exception as error:
651 log.info('Got Unexpected error %s'%error)
652 service_vm.unpause()
653 time.sleep(3)
654 raise
655 finally:
656 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
657 df.callback(0)
658 reactor.callLater(0,test_exampleservice,df)
659 return df
660
661 #Test failing. server state goes to error after resuming
662 @deferred(60)
663 def test_exampleservice_access_after_service_is_suspended(self):
664 """
665 Algo:
666 1. Get dhcp ip to vcpe interface in cord-tester
667 2. Add static route to example service running VM IP in cord-tester
668 3. Do curl request to the VM IP
669 4. Verifying curl request success
670 5. Suspend example service running VM and do curl request again
671 6. Verify curl response is an empty output
672 7. Resume suspended VM and do curl request now
673 8. Verifying curl request success
674 """
675 if self.on_pod is False:
676 return
677 df = defer.Deferred()
678 def test_exampleservice(df):
679 service_vm = None
680 vm_public_ip = self.get_exampleservice_vm_public_ip()
681 vcpe_intf = self.dhcp_vcpes_reserved[0]
682 exampleservices = OnboardingServiceUtils.get_exampleservices()
683 for service in exampleservices:
684 if self.vm_name in service.name:
685 service_vm = service
686 break
687 assert_not_equal(service_vm,None)
688 try:
689 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
690 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
691 assert_not_equal(out,'')
692 log.info('Suspending example service running vm')
693 service_vm.suspend()
694 time.sleep(2)
695 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
696 assert_equal(out,'')
697 service_vm.resume()
698 time.sleep(5)
699 except Exception as error:
700 log.info('Got Unexpected error %s'%error)
701 service_vm.stop()
702 time.sleep(1)
703 service_vm.start()
704 time.sleep(5)
705 raise
706 finally:
707 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
708 df.callback(0)
709 reactor.callLater(0,test_exampleservice,df)
710 return df
711
712 @deferred(60)
713 def test_exampleservice_access_after_service_restart(self):
714 """
715 Algo:
716 1. Get dhcp ip to vcpe interface in cord-tester
717 2. Add static route to example service running VM IP in cord-tester
718 3. Do curl request to the VM IP
719 4. Verifying curl request success
720 5. Restart example service running VM and do curl request again
721 9. Verifying curl request success
722 """
723 if self.on_pod is False:
724 return
725 df = defer.Deferred()
726 def test_exampleservice(df):
727 service_vm = None
728 vm_public_ip = self.get_exampleservice_vm_public_ip()
729 vcpe_intf = self.dhcp_vcpes_reserved[0]
730 exampleservices = OnboardingServiceUtils.get_exampleservices()
731 for service in exampleservices:
732 if self.vm_name in service.name:
733 service_vm = service
734 break
735 assert_not_equal(service_vm,None)
736 try:
737 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
738 st,_ = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
739 assert_not_equal(out,'')
740 log.info('Restarting example service running vm')
741 service_vm.reboot()
742 time.sleep(5)
743 clock = 0
744 status = False
745 while(clock <= 30):
746 time.sleep(5)
747 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
748 if out != '':
749 status = True
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000750 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000751 clock += 5
752 assert_equal(status, True)
753 except Exception as error:
754 log.info('Got Unexpected error %s'%error)
755 raise
756 finally:
757 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
758 df.callback(0)
759 reactor.callLater(0,test_exampleservice,df)
760 return df
761
762 @deferred(70)
763 def test_exampleservice_access_after_vsg_vm_restart(self):
764 """
765 Algo:
766 1. Get dhcp ip to vcpe interface in cord-tester
767 2. Add static route to example service running VM IP in cord-tester
768 3. Do curl request to the VM IP
769 4. Verifying curl request success
770 5. Restart vSG VM and do curl request again
771 9. Verifying curl request success
772 """
773 if self.on_pod is False:
774 return
775 df = defer.Deferred()
776 def test_exampleservice(df):
777 service_vm = None
778 vm_public_ip = self.get_exampleservice_vm_public_ip()
779 vcpe_intf = self.dhcp_vcpes_reserved[0]
780 vcpe_name = self.container_vcpes_reserved [0]
781 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
782 try:
783 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
784 st,_ = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
785 assert_not_equal(out,'')
786 log.info('Restarting vSG VM')
787 vsg.reboot()
788 time.sleep(5)
789 clock = 0
790 status = False
791 while(clock <= 40):
792 time.sleep(5)
793 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
794 if out != '':
795 status = True
796 break
797 clock += 5
798 assert_equal(status, True)
799 except Exception as error:
800 log.info('Got Unexpected error %s'%error)
801 raise
802 finally:
803 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
804 df.callback(0)
805 reactor.callLater(0,test_exampleservice,df)
806 return df
807
808 @deferred(60)
809 def test_exampleservice_access_after_service_stop(self):
810 """
811 Algo:
812 1. Get dhcp ip to vcpe interface in cord-tester
813 2. Add static route to example service running VM IP in cord-tester
814 3. Do curl request to the VM IP
815 4. Verifying curl request success
816 5. Stop example service running VM and do curl request again
817 6. Verify curl response is an empty output
818 7. Start stopped VM and do curl request now
819 8. Verifying curl request success
820 """
821 if self.on_pod is False:
822 return
823 df = defer.Deferred()
824 def test_exampleservice(df):
825 service_vm = None
826 vm_public_ip = self.get_exampleservice_vm_public_ip()
827 vcpe_intf = self.dhcp_vcpes_reserved[0]
828 exampleservices = OnboardingServiceUtils.get_exampleservices()
829 for service in exampleservices:
830 if self.vm_name in service.name:
831 service_vm = service
832 break
833 assert_not_equal(service_vm,None)
834 try:
835 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
836 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
837 assert_not_equal(out,'')
838 log.info('Stopping example service running vm')
839 service_vm.stop()
840 time.sleep(5)
841 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
842 assert_equal(out,'')
843 service_vm.start()
844 time.sleep(15)
845 clock = 0
846 status = False
847 while(clock <= 40):
848 time.sleep(5)
849 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
850 if out != '':
851 status = True
852 break
853 clock += 5
854 assert_equal(status, True)
855 except Exception as error:
856 log.info('Got Unexpected error %s'%error)
857 service_vm.start()
858 raise
859 finally:
860 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
861 df.callback(0)
862 reactor.callLater(0,test_exampleservice,df)
863 return df
864
865 @deferred(60)
866 def test_exampleservice_for_service_message_after_service_stop_and_start(self, service_message="\"hello\""):
867 """
868 Algo:
869 1. Get dhcp ip to vcpe interface in cord-tester
870 2. Add static route to example service running VM IP in cord-tester
871 3. Do curl request to the VM IP
872 4. Verifying curl request success
873 5. Stop example service running VM and do curl request again
874 6. Verify curl response is an empty output
875 7. Start stopped VM and do curl request now
876 8. Verifying Service message in curl response
877 """
878 if self.on_pod is False:
879 return
880 df = defer.Deferred()
881 def test_exampleservice(df):
882 service_vm = None
883 vm_public_ip = self.get_exampleservice_vm_public_ip()
884 vcpe_intf = self.dhcp_vcpes_reserved[0]
885 exampleservices = OnboardingServiceUtils.get_exampleservices()
886 for service in exampleservices:
887 if self.vm_name in service.name:
888 service_vm = service
889 break
890 assert_not_equal(service_vm,None)
891 try:
892 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
893 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
894 assert_not_equal(out,'')
895 log.info('Stopping example service running VM')
896 service_vm.stop()
897 time.sleep(1)
898 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
899 assert_equal(out,'')
900 service.start()
901 time.sleep(5)
902 clock = 0
903 while(clock <= 30):
904 time.sleep(5)
905 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
906 if out != '':
907 output = out.split('\n')
908 srvs_msg = None
909 for line in output:
910 line = line.split(':')
911 if line[0].strip() == 'Service Message':
912 srvs_msg = line[1].strip()
913 clock = 30
914 break
915 clock += 5
916 assert_equal(service_message, srvs_msg)
917 except Exception as error:
918 log.info('Got Unexpected error %s'%error)
919 service_vm.start()
920 time.sleep(5)
921 finally:
922 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
923 df.callback(0)
924 reactor.callLater(0,test_exampleservice,df)
925 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000926
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000927 @deferred(150)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000928 def test_exampleservice_for_tenant_message_after_service_restart(self,service_message="\"world\""):
929 """
930 Algo:
931 1. Get dhcp ip to vcpe interface in cord-tester
932 2. Add static route to example service running VM IP in cord-tester
933 3. Do curl request to the VM IP
934 4. Verifying curl request success
935 5. Restart example service running VM and do curl request again
936 6. Verifying Tenant message in curl response
937 """
938 if self.on_pod is False:
939 return
940 df = defer.Deferred()
941 def test_exampleservice(df):
942 service_vm = None
943 vm_public_ip = self.get_exampleservice_vm_public_ip()
944 vcpe_intf = self.dhcp_vcpes_reserved[0]
945 exampleservices = OnboardingServiceUtils.get_exampleservices()
946 for service in exampleservices:
947 if self.vm_name in service.name:
948 service_vm = service
949 break
950 assert_not_equal(service_vm,None)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000951 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000952 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000953 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000954 assert_not_equal(out,'')
955 log.info('Restarting example service running VM')
956 service_vm.reboot()
957 time.sleep(5)
958 clock = 0
959 while(clock <= 40):
960 time.sleep(5)
961 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
962 if out != '':
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000963 output = out.split('\n')
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000964 tnnt_msg = None
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000965 for line in output:
966 line = line.split(':')
967 if line[0].strip() == 'Tenant Message':
968 tnnt_msg = line[1].strip()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000969 clock = 40
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000970 break
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000971 clock += 5
972 assert_equal(tenant_message, tnnt_msg)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000973 except Exception as error:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000974 log.info('Got Unexpected error %s'%error)
975 raise
976 finally:
977 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000978 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000979 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000980 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000981
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000982 @deferred(50)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000983 def test_exampleservice_access_after_vcpe_instance_restart(self):
984 """
985 Algo:
986 1. Get dhcp ip to vcpe interface in cord-tester
987 2. Add static route to example service running VM IP in cord-tester
988 3. Do curl request to the VM IP
989 4. Verifying curl request success
990 5. Restart vcpe instance and do curl request again
991 8. Verifying curl request success
992 """
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000993 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000994 def test_exampleservice(df):
995 vcpe_intf = self.dhcp_vcpes_reserved[0]
996 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000997 vm_public_ip = self.get_exampleservice_vm_public_ip()
998 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
999 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001000 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001001 #curl request from test container
1002 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1003 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001004 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001005 #restarting example service VM
1006 cmd = 'sudo docker restart {}'.format(vcpe_name)
1007 status, _ = vsg.run_cmd(cmd)
1008 assert_equal(status, True)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001009 time.sleep(5)
1010 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001011 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 except Exception as error:
1014 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001015 raise
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001016 finally:
1017 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001018 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001019 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001020 return df
1021
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001022 @deferred(50)
1023 def test_exampleservice_access_after_vcpe_instance_wan_interface_toggle(self):
1024 """
1025 Algo:
1026 1. Get dhcp ip to vcpe interface in cord-tester
1027 2. Add static route to example service running VM IP in cord-tester
1028 3. Do curl request to the VM IP
1029 4. Verifying curl request success
1030 5. Restart vcpe instance and do curl request again
1031 8. Verifying curl request success
1032 """
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001033 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001034 def test_exampleservice(df):
1035 vcpe_intf = self.dhcp_vcpes_reserved[0]
1036 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001037 vm_public_ip = self.get_exampleservice_vm_public_ip()
1038 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001039 wan_intf = 'eth0'
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001040 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001041 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001042 #curl request from test container
1043 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1044 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001045 assert_not_equal(out,'')
1046 #restarting example service VM
1047 cmd = 'sudo docker exec {} ifconfig down {}'.format(vcpe_name,wan_intf)
1048 status, _ = vsg.run_cmd(cmd)
1049 assert_equal(status, True)
1050 time.sleep(1)
1051 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1052 st, out = getstatusoutput(curl_cmd)
1053 assert_equal(out,'')
1054 cmd = 'sudo docker exec {} ifconfig up {}'.format(vcpe_name,wan_intf)
1055 status, _ = vsg.run_cmd(cmd)
1056 assert_equal(status, True)
1057 time.sleep(1)
1058 st, out = getstatusoutput(curl_cmd)
1059 assert_not_equal(out,'')
1060 except Exception as error:
1061 log.info('Got Unexpeted error %s'%error)
1062 vsg.run_cmd('sudo docker exec {} ifconfig up {}'.format(vcpe_name,wan_intf))
1063 raise
1064 finally:
1065 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
1066 df.callback(0)
1067 reactor.callLater(0,test_exampleservice,df)
1068 return df
1069
1070 @deferred(30)
1071 def test_exampleservice_access_after_firewall_rule_added_to_drop_service_running_server_in_vcpe_instance(self):
1072 """
1073 Algo:
1074 1. Get dhcp ip to vcpe interface in cord-tester
1075 2. Add static route to example service running VM IP in cord-tester
1076 3. Do curl request to the VM IP
1077 4. Verifying curl request success
1078 5. Add a firewall rule in vcpe instance to drop packets destined to example service VM
1079 6. Do curl request now
1080 7. Verifying curl response is an empty output
1081 8. Delete the firewall rule and do curl request agian
1082 9. Verifying curl request success
1083 """
1084 df = defer.Deferred()
1085 def test_exampleservice(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
1086 vcpe_intf = self.dhcp_vcpes_reserved[0]
1087 vcpe_name = self.container_vcpes_reserved[0]
1088 vm_public_ip = self.get_exampleservice_vm_public_ip()
1089 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1090 try:
1091 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1092 #curl request from test container
1093 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1094 st, out = getstatusoutput(curl_cmd)
1095 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001096 #restarting example service VM
1097 cmd = 'sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
1098 status, _ = vsg.run_cmd(cmd)
1099 assert_equal(status, True)
1100 time.sleep(1)
1101 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001102 assert_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001103 except Exception as error:
1104 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001105 raise
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001106 finally:
1107 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip))
1108 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001109 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001110 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001111 return df
1112
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001113
1114 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
1115 if self.on_pod is False:
1116 return ''
1117 if subscriber_info is None:
1118 subscriber_info = self.subscriber_info[index]
1119 if volt_subscriber_info is None:
1120 volt_subscriber_info = self.volt_subscriber_info[index]
1121 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1122 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1123 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1124 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1125 subId = ''
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001126 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001127 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
1128 assert_equal(result, True)
1129 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1130 assert_not_equal(result, None)
1131 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1132 assert_not_equal(subId, '0')
1133 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
1134 volt_tenant = volt_subscriber_info['voltTenant']
1135 #update the subscriber id in the tenant info before making the rest
1136 volt_tenant['subscriber'] = subId
1137 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
1138 assert_equal(result, True)
1139 #if the vsg instance was already instantiated, then reduce delay
1140 if c_tag % self.subscribers_per_s_tag == 0:
1141 delay = 350
1142 else:
1143 delay = 90
1144 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
1145 time.sleep(delay)
1146 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
1147 self.vsg_for_external_connectivity(index)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001148 finally:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001149 return subId
1150
1151 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', 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('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1162 if not subId:
1163 #get the subscriber id first
1164 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1165 assert_not_equal(result, None)
1166 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1167 assert_not_equal(subId, '0')
1168 if not voltId:
1169 #get the volt id for the subscriber
1170 result = self.restApiXos.ApiGet('TENANT_VOLT')
1171 assert_not_equal(result, None)
1172 voltId = self.getVoltId(result, subId)
1173 assert_not_equal(voltId, None)
1174 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
1175 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
1176 assert_equal(status, True)
1177 #Delete the tenant
1178 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
1179 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
1180
1181 def vsg_xos_subscriber_id(self, index):
1182 log.info('index and its type are %s, %s'%(index, type(index)))
1183 volt_subscriber_info = self.volt_subscriber_info[index]
1184 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1185 assert_not_equal(result, None)
1186 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1187 return subId
1188
1189 def test_vsg_xos_subscriber_create_reserved(self):
1190 if self.on_pod is False:
1191 return
1192 tags_reserved = [ (int(vcpe['s_tag']), int(vcpe['c_tag'])) for vcpe in self.vcpes_reserved ]
1193 volt_tenants = self.restApiXos.ApiGet('TENANT_VOLT')
1194 subscribers = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1195 reserved_tenants = filter(lambda tenant: (int(tenant['s_tag']), int(tenant['c_tag'])) in tags_reserved, volt_tenants)
1196 reserved_config = []
1197 for tenant in reserved_tenants:
1198 for subscriber in subscribers:
1199 if int(subscriber['id']) == int(tenant['subscriber']):
1200 volt_subscriber_info = {}
1201 volt_subscriber_info['voltTenant'] = dict(s_tag = tenant['s_tag'],
1202 c_tag = tenant['c_tag'],
1203 subscriber = tenant['subscriber'])
1204 volt_subscriber_info['volt_id'] = tenant['id']
1205 volt_subscriber_info['account_num'] = subscriber['identity']['account_num']
1206 reserved_config.append( (subscriber, volt_subscriber_info) )
1207 break
1208 else:
1209 log.info('Subscriber not found for tenant %s, s_tag: %s, c_tag: %s' %(str(tenant['subscriber']),
1210 str(tenant['s_tag']),
1211 str(tenant['c_tag'])))
1212
1213 for subscriber_info, volt_subscriber_info in reserved_config:
1214 self.vsg_xos_subscriber_delete(0,
1215 subId = str(subscriber_info['id']),
1216 voltId = str(volt_subscriber_info['volt_id']),
1217 subscriber_info = subscriber_info,
1218 volt_subscriber_info = volt_subscriber_info)
1219 subId = self.vsg_xos_subscriber_create(0,
1220 subscriber_info = subscriber_info,
1221 volt_subscriber_info = volt_subscriber_info)
1222 log.info('Created reserved subscriber %s' %(subId))
1223
1224 def test_vsg_xos_subscriber_create_all(self):
1225 for index in xrange(len(self.subscriber_info)):
1226 #check if the index exists
1227 subId = self.vsg_xos_subscriber_id(index)
1228 if subId and subId != '0':
1229 self.vsg_xos_subscriber_delete(index, subId = subId)
1230 subId = self.vsg_xos_subscriber_create(index)
1231 log.info('Created Subscriber %s' %(subId))
1232
1233 def test_vsg_xos_subscriber_delete_all(self):
1234 for index in xrange(len(self.subscriber_info)):
1235 subId = self.vsg_xos_subscriber_id(index)
1236 if subId and subId != '0':
1237 self.vsg_xos_subscriber_delete(index, subId = subId)
1238
1239 @deferred(500)
1240 def test_exampleservice_xos_subcriber_access_exampleservice(self,index=0):
1241 """
1242 Algo:
1243 1. Create two vcpe instances using XOS
1244 2. Add static route to example service running VM IP in cord-tester
1245 3. Do curl request to the VM IP
1246 4. Verifying curl request success
1247 5. Repeat steps for both vcpes
1248 """
1249 df = defer.Deferred()
1250 def test_exampleservice(df):
1251 vm_public_ip = self.get_exampleservice_vm_public_ip()
1252 vcpe_intf = self.dhcp_vcpes[0]
1253 subId = self.vsg_xos_subscriber_id(index)
1254 if subId == '0':
1255 subId = self.vsg_xos_subscriber_create(index)
1256 assert_not_equal(subId,'0')
1257 try:
1258 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1259 time.sleep(1)
1260 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1261 st,out = getstatusoutput(cmd)
1262 assert_not_equal(out,'')
1263 except Exception as error:
1264 log.info('Got unexpected error %s'%error)
1265 raise
1266 finally:
1267 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1268 df.callback(0)
1269 reactor.callLater(0,test_exampleservice,df)
1270 return df
1271
1272 @deferred(500)
1273 def test_exampleservice_multiple_subcribers_access_same_service(self,index1=0,index2=1):
1274 """
1275 Algo:
1276 1. Create two vcpe instances using XOS
1277 2. Add static route to example service running VM IP in cord-tester
1278 3. Do curl request to the VM IP
1279 4. Verifying curl request success
1280 5. Repeat steps for both vcpes
1281 """
1282 df = defer.Deferred()
1283 def test_exampleservice(df):
1284 vm_public_ip = self.get_exampleservice_vm_public_ip()
1285 vcpe_intf1 = self.dhcp_vcpes[0]
1286 vcpe_intf2 = self.dhcp_vcpes[1]
1287 subId1 = self.vsg_xos_subscriber_id(index)
1288 if subId1 == '0':
1289 subId1 = self.vsg_xos_subscriber_create(index1)
1290 assert_not_equal(subId1,'0')
1291 subId2 = self.vsg_xos_subscriber_id(index2)
1292 if subId2 == '0':
1293 subId2 = self.vsg_xos_subscriber_create(index2)
1294 assert_not_equal(subId2,'0')
1295 try:
1296 for vcpe in [vcpe_intf1,vcpe_intf2]:
1297 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1298 time.sleep(1)
1299 status = False
1300 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1301 st,out = getstatusoutput(cmd)
1302 assert_not_equal(out,'')
1303 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1304 time.sleep(1)
1305 except Exception as error:
1306 log.info('Got unexpected error %s'%error)
1307 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1308 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1309 raise
1310 df.callback(0)
1311 reactor.callLater(0,test_exampleservice,df)
1312 return df
1313