blob: 6b0b4f6bb02d85eba9115e67c8a12160a593da80 [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
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000933 @deferred(150)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +0000934 def test_exampleservice_for_tenant_message_after_service_restart(self,service_message="\"world\""):
935 """
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 """
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000999 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001000 def test_exampleservice(df):
1001 vcpe_intf = self.dhcp_vcpes_reserved[0]
1002 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001003 vm_public_ip = self.get_exampleservice_vm_public_ip()
1004 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1005 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001006 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001007 #curl request from test container
1008 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1009 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001010 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001011 #restarting example service VM
1012 cmd = 'sudo docker restart {}'.format(vcpe_name)
1013 status, _ = vsg.run_cmd(cmd)
1014 assert_equal(status, True)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001015 time.sleep(5)
1016 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001017 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001018 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001019 except Exception as error:
1020 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001021 raise
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001022 finally:
1023 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001024 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001025 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001026 return df
1027
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001028 @deferred(50)
1029 def test_exampleservice_access_after_vcpe_instance_wan_interface_toggle(self):
1030 """
1031 Algo:
1032 1. Get dhcp ip to vcpe interface in cord-tester
1033 2. Add static route to example service running VM IP in cord-tester
1034 3. Do curl request to the VM IP
1035 4. Verifying curl request success
1036 5. Restart vcpe instance and do curl request again
1037 8. Verifying curl request success
1038 """
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001039 df = defer.Deferred()
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001040 def test_exampleservice(df):
1041 vcpe_intf = self.dhcp_vcpes_reserved[0]
1042 vcpe_name = self.container_vcpes_reserved[0]
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001043 vm_public_ip = self.get_exampleservice_vm_public_ip()
1044 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001045 wan_intf = 'eth0'
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001046 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001047 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001048 #curl request from test container
1049 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1050 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001051 assert_not_equal(out,'')
1052 #restarting example service VM
1053 cmd = 'sudo docker exec {} ifconfig down {}'.format(vcpe_name,wan_intf)
1054 status, _ = vsg.run_cmd(cmd)
1055 assert_equal(status, True)
1056 time.sleep(1)
1057 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1058 st, out = getstatusoutput(curl_cmd)
1059 assert_equal(out,'')
1060 cmd = 'sudo docker exec {} ifconfig up {}'.format(vcpe_name,wan_intf)
1061 status, _ = vsg.run_cmd(cmd)
1062 assert_equal(status, True)
1063 time.sleep(1)
1064 st, out = getstatusoutput(curl_cmd)
1065 assert_not_equal(out,'')
1066 except Exception as error:
1067 log.info('Got Unexpeted error %s'%error)
1068 vsg.run_cmd('sudo docker exec {} ifconfig up {}'.format(vcpe_name,wan_intf))
1069 raise
1070 finally:
1071 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
1072 df.callback(0)
1073 reactor.callLater(0,test_exampleservice,df)
1074 return df
1075
1076 @deferred(30)
1077 def test_exampleservice_access_after_firewall_rule_added_to_drop_service_running_server_in_vcpe_instance(self):
1078 """
1079 Algo:
1080 1. Get dhcp ip to vcpe interface in cord-tester
1081 2. Add static route to example service running VM IP in cord-tester
1082 3. Do curl request to the VM IP
1083 4. Verifying curl request success
1084 5. Add a firewall rule in vcpe instance to drop packets destined to example service VM
1085 6. Do curl request now
1086 7. Verifying curl response is an empty output
1087 8. Delete the firewall rule and do curl request agian
1088 9. Verifying curl request success
1089 """
1090 df = defer.Deferred()
1091 def test_exampleservice(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
1092 vcpe_intf = self.dhcp_vcpes_reserved[0]
1093 vcpe_name = self.container_vcpes_reserved[0]
1094 vm_public_ip = self.get_exampleservice_vm_public_ip()
1095 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
1096 try:
1097 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1098 #curl request from test container
1099 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1100 st, out = getstatusoutput(curl_cmd)
1101 assert_not_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001102 #restarting example service VM
1103 cmd = 'sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
1104 status, _ = vsg.run_cmd(cmd)
1105 assert_equal(status, True)
1106 time.sleep(1)
1107 st, out = getstatusoutput(curl_cmd)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001108 assert_equal(out,'')
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001109 except Exception as error:
1110 log.info('Got Unexpeted error %s'%error)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001111 raise
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001112 finally:
1113 vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip))
1114 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001115 df.callback(0)
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001116 reactor.callLater(0,test_exampleservice,df)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +00001117 return df
1118
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001119
1120 def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None):
1121 if self.on_pod is False:
1122 return ''
1123 if subscriber_info is None:
1124 subscriber_info = self.subscriber_info[index]
1125 if volt_subscriber_info is None:
1126 volt_subscriber_info = self.volt_subscriber_info[index]
1127 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1128 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1129 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1130 log.info('Creating tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1131 subId = ''
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001132 try:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001133 result = self.restApiXos.ApiPost('TENANT_SUBSCRIBER', subscriber_info)
1134 assert_equal(result, True)
1135 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1136 assert_not_equal(result, None)
1137 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1138 assert_not_equal(subId, '0')
1139 log.info('Subscriber ID for account num %s = %s' %(str(volt_subscriber_info['account_num']), subId))
1140 volt_tenant = volt_subscriber_info['voltTenant']
1141 #update the subscriber id in the tenant info before making the rest
1142 volt_tenant['subscriber'] = subId
1143 result = self.restApiXos.ApiPost('TENANT_VOLT', volt_tenant)
1144 assert_equal(result, True)
1145 #if the vsg instance was already instantiated, then reduce delay
1146 if c_tag % self.subscribers_per_s_tag == 0:
1147 delay = 350
1148 else:
1149 delay = 90
1150 log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay))
1151 time.sleep(delay)
1152 log.info('Testing for external connectivity to VCPE %s' %(vcpe))
1153 self.vsg_for_external_connectivity(index)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +00001154 finally:
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001155 return subId
1156
1157 def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None):
1158 if self.on_pod is False:
1159 return
1160 if subscriber_info is None:
1161 subscriber_info = self.subscriber_info[index]
1162 if volt_subscriber_info is None:
1163 volt_subscriber_info = self.volt_subscriber_info[index]
1164 s_tag = int(volt_subscriber_info['voltTenant']['s_tag'])
1165 c_tag = int(volt_subscriber_info['voltTenant']['c_tag'])
1166 vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag)
1167 log.info('Deleting tenant with s_tag: %d, c_tag: %d' %(s_tag, c_tag))
1168 if not subId:
1169 #get the subscriber id first
1170 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1171 assert_not_equal(result, None)
1172 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1173 assert_not_equal(subId, '0')
1174 if not voltId:
1175 #get the volt id for the subscriber
1176 result = self.restApiXos.ApiGet('TENANT_VOLT')
1177 assert_not_equal(result, None)
1178 voltId = self.getVoltId(result, subId)
1179 assert_not_equal(voltId, None)
1180 log.info('Deleting subscriber ID %s for account num %s' %(subId, str(volt_subscriber_info['account_num'])))
1181 status = self.restApiXos.ApiDelete('TENANT_SUBSCRIBER', subId)
1182 assert_equal(status, True)
1183 #Delete the tenant
1184 log.info('Deleting VOLT Tenant ID %s for subscriber %s' %(voltId, subId))
1185 self.restApiXos.ApiDelete('TENANT_VOLT', voltId)
1186
1187 def vsg_xos_subscriber_id(self, index):
1188 log.info('index and its type are %s, %s'%(index, type(index)))
1189 volt_subscriber_info = self.volt_subscriber_info[index]
1190 result = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1191 assert_not_equal(result, None)
1192 subId = self.restApiXos.getSubscriberId(result, volt_subscriber_info['account_num'])
1193 return subId
1194
1195 def test_vsg_xos_subscriber_create_reserved(self):
1196 if self.on_pod is False:
1197 return
1198 tags_reserved = [ (int(vcpe['s_tag']), int(vcpe['c_tag'])) for vcpe in self.vcpes_reserved ]
1199 volt_tenants = self.restApiXos.ApiGet('TENANT_VOLT')
1200 subscribers = self.restApiXos.ApiGet('TENANT_SUBSCRIBER')
1201 reserved_tenants = filter(lambda tenant: (int(tenant['s_tag']), int(tenant['c_tag'])) in tags_reserved, volt_tenants)
1202 reserved_config = []
1203 for tenant in reserved_tenants:
1204 for subscriber in subscribers:
1205 if int(subscriber['id']) == int(tenant['subscriber']):
1206 volt_subscriber_info = {}
1207 volt_subscriber_info['voltTenant'] = dict(s_tag = tenant['s_tag'],
1208 c_tag = tenant['c_tag'],
1209 subscriber = tenant['subscriber'])
1210 volt_subscriber_info['volt_id'] = tenant['id']
1211 volt_subscriber_info['account_num'] = subscriber['identity']['account_num']
1212 reserved_config.append( (subscriber, volt_subscriber_info) )
1213 break
1214 else:
1215 log.info('Subscriber not found for tenant %s, s_tag: %s, c_tag: %s' %(str(tenant['subscriber']),
1216 str(tenant['s_tag']),
1217 str(tenant['c_tag'])))
1218
1219 for subscriber_info, volt_subscriber_info in reserved_config:
1220 self.vsg_xos_subscriber_delete(0,
1221 subId = str(subscriber_info['id']),
1222 voltId = str(volt_subscriber_info['volt_id']),
1223 subscriber_info = subscriber_info,
1224 volt_subscriber_info = volt_subscriber_info)
1225 subId = self.vsg_xos_subscriber_create(0,
1226 subscriber_info = subscriber_info,
1227 volt_subscriber_info = volt_subscriber_info)
1228 log.info('Created reserved subscriber %s' %(subId))
1229
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001230 @deferred(500)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00001231 def test_exampleservice_xos_subscriber_access_exampleservice(self,index=0):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001232 """
1233 Algo:
1234 1. Create two vcpe instances using XOS
1235 2. Add static route to example service running VM IP in cord-tester
1236 3. Do curl request to the VM IP
1237 4. Verifying curl request success
1238 5. Repeat steps for both vcpes
1239 """
1240 df = defer.Deferred()
1241 def test_exampleservice(df):
1242 vm_public_ip = self.get_exampleservice_vm_public_ip()
1243 vcpe_intf = self.dhcp_vcpes[0]
1244 subId = self.vsg_xos_subscriber_id(index)
1245 if subId == '0':
1246 subId = self.vsg_xos_subscriber_create(index)
1247 assert_not_equal(subId,'0')
1248 try:
1249 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1250 time.sleep(1)
1251 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1252 st,out = getstatusoutput(cmd)
1253 assert_not_equal(out,'')
1254 except Exception as error:
1255 log.info('Got unexpected error %s'%error)
1256 raise
1257 finally:
1258 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
1259 df.callback(0)
1260 reactor.callLater(0,test_exampleservice,df)
1261 return df
1262
1263 @deferred(500)
Chetan Gaonkerfe1048f2017-06-13 20:16:25 +00001264 def test_exampleservice_multiple_subscribers_access_same_service(self,index1=0,index2=1):
Anil Kumar Sanka601242d2017-06-09 22:15:19 +00001265 """
1266 Algo:
1267 1. Create two vcpe instances using XOS
1268 2. Add static route to example service running VM IP in cord-tester
1269 3. Do curl request to the VM IP
1270 4. Verifying curl request success
1271 5. Repeat steps for both vcpes
1272 """
1273 df = defer.Deferred()
1274 def test_exampleservice(df):
1275 vm_public_ip = self.get_exampleservice_vm_public_ip()
1276 vcpe_intf1 = self.dhcp_vcpes[0]
1277 vcpe_intf2 = self.dhcp_vcpes[1]
1278 subId1 = self.vsg_xos_subscriber_id(index)
1279 if subId1 == '0':
1280 subId1 = self.vsg_xos_subscriber_create(index1)
1281 assert_not_equal(subId1,'0')
1282 subId2 = self.vsg_xos_subscriber_id(index2)
1283 if subId2 == '0':
1284 subId2 = self.vsg_xos_subscriber_create(index2)
1285 assert_not_equal(subId2,'0')
1286 try:
1287 for vcpe in [vcpe_intf1,vcpe_intf2]:
1288 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1289 time.sleep(1)
1290 status = False
1291 cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
1292 st,out = getstatusoutput(cmd)
1293 assert_not_equal(out,'')
1294 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1295 time.sleep(1)
1296 except Exception as error:
1297 log.info('Got unexpected error %s'%error)
1298 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
1299 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
1300 raise
1301 df.callback(0)
1302 reactor.callLater(0,test_exampleservice,df)
1303 return df
1304