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