blob: b8011d2ca294bf23a0594233edf8d81355ff1cc9 [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
25from nose.tools import assert_equal
26from CordTestUtils import get_mac, log_test
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000027from onosclidriver import OnosCliDriver
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000028from OnosCtrl import OnosCtrl
29from OnosFlowCtrl import OnosFlowCtrl
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000030from OnboardingServiceUtils import OnboardingServiceUtils
31from SSHTestAgent import SSHTestAgent
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000032from CordTestUtils import running_on_pod, getstatusoutput
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000033from CordLogger import CordLogger
34from CordTestUtils import log_test as log
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000035import requests
36import time
37import json
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000038from VSGAccess import VSGAccess
39from CordTestConfig import setup_module, running_on_ciab
40from vsgTest import *
41log.setLevel('INFO')
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000042
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +000043class onboarding_exchange(CordLogger):
Chetan Gaonkerc6853932017-04-24 22:16:37 +000044 ONOS_INSTANCES = 3
45 V_INF1 = 'veth0'
46 device_id = 'of:' + get_mac()
47 TEST_IP = '8.8.8.8'
48 HOST = "10.1.0.1"
49 USER = "vagrant"
50 PASS = "vagrant"
51 head_node = os.getenv('HEAD_NODE', 'prod')
52 HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node
53 test_path = os.path.dirname(os.path.realpath(__file__))
A R Karthick19771192017-04-25 14:57:05 -070054 on_pod = running_on_pod()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000055 vcpe_dhcp = 'vcpe0.222.111'
56 vsg_exchange = vsg_exchange()
57 vm_name = 'mysite_exampleservice'
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000058
59 @classmethod
60 def setUpClass(cls):
61 OnboardingServiceUtils.setUp()
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +000062 cls.vsg_exchange.setUpClass()
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000063
64 @classmethod
65 def tearDownClass(cls):
66 OnboardingServiceUtils.tearDown()
67
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000068 def cliEnter(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000069 retries = 0
70 while retries < 30:
71 self.cli = OnosCliDriver(controller = controller, connect = True)
72 if self.cli.handle:
73 break
74 else:
75 retries += 1
76 time.sleep(2)
77
78 def cliExit(self):
79 self.cli.disconnect()
80
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000081 def onos_shutdown(self, controller = None):
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +000082 status = True
83 self.cliEnter(controller = controller)
84 try:
85 self.cli.shutdown(timeout = 10)
86 except:
87 log.info('Graceful shutdown of ONOS failed for controller: %s' %controller)
88 status = False
89
90 self.cliExit()
91 return status
92
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +000093 def get_exampleservice_vm_public_ip(self, vm_name = 'mysite_exampleservice'):
94 if not vm_name:
95 vm_name = self.vm_name
96 exampleservices = OnboardingServiceUtils.get_exampleservices()
97 for service in exampleservices:
98 if vm_name in service.name:
99 return service.get_public_ip()
100 return None
101
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000102 def test_exampleservice_health(self):
103 """
104 Algo:
105 1. Login to compute node VM
106 2. Get all exampleservice
107 3. Ping to all exampleservice
108 4. Verifying Ping success
109 """
110 status = OnboardingServiceUtils.health_check()
111 assert_equal(status, True)
112
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000113 def test_exampleservice_for_login(self):
A R Karthick19771192017-04-25 14:57:05 -0700114 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000115 return
116 exampleservices = OnboardingServiceUtils.get_exampleservices()
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000117 exampleservice_access_status = map(lambda exampleservice: exampleservice.check_access(), exampleservices)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000118 status = filter(lambda st: st == False, exampleservice_access_status)
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000119 assert_equal(len(status), 0)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000120
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000121 def test_exampleservice_for_default_route_through_testclient(self):
Chetan Gaonker4cff4432017-05-01 17:56:56 +0000122 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000123 return
124 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
125 cmd = "sudo lxc exec testclient -- route | grep default"
126 status, output = ssh_agent.run_cmd(cmd)
127 assert_equal(status, True)
128
129 def test_exampleservice_for_service_access_through_testclient(self):
A R Karthick19771192017-04-25 14:57:05 -0700130 if self.on_pod is False:
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000131 return
132 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000133 cmd = "sudo lxc exec testclient -- ping -c 3 8.8.8.8"
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000134 status, output = ssh_agent.run_cmd(cmd)
135 assert_equal( status, True)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000136
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000137 def test_exampleservice_for_service_reachability_from_cord_tester(self, vcpe_intf=None):
138 if self.on_pod is False:
139 return
140 if not vcpe_intf:
141 vcpe_intf = self.dhcp_vcpes_reserved[0]
142 vm_public_ip = self.get_exampleservice_vm_public_ip()
143 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
144 vm_public_ip = self.get_exampleservice_vm_public_ip()
145 st, _ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
146 assert_equal(st, False)
147 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Chetan Gaonkerc1a4c8a2017-04-13 00:24:44 +0000148
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000149 def test_exampleservice_operational_status_from_testclient(self):
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000150 vm_public_ip = self.get_exampleservice_vm_public_ip()
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000151 ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS)
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000152 cmd = 'sudo lxc exec testclient -- apt-get install -y curl'
153 status, _ = ssh_agent.run_cmd(cmd)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000154 assert_equal(status, True)
155 #Test connectivity to ExampleService from test client
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000156 cmd = 'sudo lxc exec testclient -- curl -s http://{}'.format(vm_public_ip)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000157 status, output = ssh_agent.run_cmd(cmd)
158 assert_equal(status, True)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000159
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000160 def test_exampleservice_operational_access_from_cord_tester(self, vcpe_intf=None):
161 if self.on_pod is False:
162 return
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000163 if not vcpe_intf:
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000164 vcpe_intf = self.vcpe_dhcp
165 vm_public_ip = self.get_exampleservice_vm_public_ip()
166 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
167 st, _ = getstatusoutput('curl -s http://{}'.format(vm_public_ip))
168 assert_equal(st, False)
Chetan Gaonkerc6853932017-04-24 22:16:37 +0000169
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000170 def test_exampleservice_for_service_message(self, service_message='"'+'hello'+'"'):
171 vm_public_ip = self.get_exampleservice_vm_public_ip()
172 vcpe_intf = self.vcpe_dhcp
173 try:
174 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
175 st,out = getstatusoutput('curl -s http://{}'.format(vm_public_ip))
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000176 assert_equal(st, False)
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000177 output = out.split('\n')
178 srvs_msg = ''
179 for line in output:
180 line = line.split(':')
181 if line[0].strip() == 'Service Message':
182 srvs_msg = line[1].strip()
183 assert_equal(service_message, srvs_msg)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000184 finally:
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000185 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
186
187 def test_exampleservice_for_tenant_message(self, tenant_message='"'+'world'+'"'):
188 vcpe_intf = self.vcpe_dhcp
189 vm_public_ip = self.get_exampleservice_vm_public_ip()
190 try:
191 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
192 st,out = getstatusoutput('curl -s http://10.6.1.194')
193 assert_equal(st, False)
194 output = out.split('\n')
195 tnt_msg = ''
196 for line in output:
197 line = line.split(':')
198 if line[0].strip() == 'Tenant Message':
199 tnt_msg = line[1].strip()
200 assert_equal(tenant_message, tnt_msg)
201 finally:
202 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
203
204 def test_exampleservice_access_after_subscriber_interface_toggle(self, vcpe_intf=None):
205 if not vcpe_intf:
206 vcpe_intf = self.vcpe_dhcp
207 vm_public_ip = self.get_exampleservice_vm_public_ip()
208 try:
209 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
210 #curl request from test container
211 cmd = 'curl -s http://{}'.format(vm_public_ip)
212 st,_ = getstatusoutput(cmd)
213 assert_equal(st, False)
214 st,_ = getstatusoutput('ifconfig {} down'.format(vcpe_intf))
215 time.sleep(1)
216 assert_equal(st, False)
217 st,_ = getstatusoutput(cmd)
218 assert_equal(st, False)
219 st,_ = getstatusoutput('ifconfig {} up'.format(vcpe_intf))
220 time.sleep(1)
221 self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
222 st,_ = getstatusoutput(cmd)
223 assert_equal(st, False)
224 finally:
225 self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
226
227 def test_exampleservice_access_after_service_paused(self, vcpe_intf=None,vm_name=None):
228 if not vcpe_intf:
229 vcpe_intf = self.vcpe_dhcp
230 if not vm_name:
231 vm_name = self.vm_name
232 vm_public_ip = self.get_exampleservice_vm_public_ip()
233 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
234 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
235 assert_equal(st, False)
236 exampleservices = OnboardingServiceUtils.get_exampleservices()
237 status = False
238 for service in exampleservices:
239 if self.vm_name in service.name:
240 log.info('pausing mysite-example-server')
241 service.pause()
242 time.sleep(1)
243 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
244 assert_equal(st, True)
245 service.unpause()
246 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
247 status = True
248 assert_equal(status, True)
249
250 def test_exampleservice_access_after_service_is_suspended(self, vcpe_intf=None,vm_name=None):
251 if not vcpe_intf:
252 vcpe_intf = self.vcpe_dhcp
253 if not vm_name:
254 vm_name = self.vm_name
255 vm_public_ip = self.get_exampleservice_vm_public_ip()
256 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
257 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
258 assert_equal(st, False)
259 exampleservices = OnboardingServiceUtils.get_exampleservices()
260 status = False
261 for service in exampleservices:
262 if self.vm_name in service.name:
263 log.info('suspending mysite-example-server')
264 service.suspend()
265 time.sleep(5)
266 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
267 assert_equal(st, True)
268 service.resume()
269 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
270 status = True
271 assert_equal(status, True)
272
273 def test_exampleservice_access_after_service_restart(self, vcpe_intf=None,vm_name=None):
274 if not vcpe_intf:
275 vcpe_intf = self.vcpe_dhcp
276 if not vm_name:
277 vm_name = self.vm_name
278 vm_public_ip = self.get_exampleservice_vm_public_ip()
279 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
280 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
281 assert_equal(st, False)
282 exampleservices = OnboardingServiceUtils.get_exampleservices()
283 status = False
284 for service in exampleservices:
285 if self.vm_name in service.name:
286 log.info('restarting mysite-example-server')
287 service.reboot()
288 time.sleep(30)
289 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
290 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
291 assert_equal(st, False)
292 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
293 status = True
294 assert_equal(status, True)
295
296 def test_exampleservice_access_after_service_stop(self, vcpe_intf=None,vm_name=None):
297 if not vcpe_intf:
298 vcpe_intf = self.vcpe_dhcp
299 if not vm_name:
300 vm_name = self.vm_name
301 vm_public_ip = self.get_exampleservice_vm_public_ip()
302 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
303 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
304 assert_equal(st, False)
305 exampleservices = OnboardingServiceUtils.get_exampleservices()
306 status = False
307 for service in exampleservices:
308 if self.vm_name in service.name:
309 log.info('restarting mysite-example-server')
310 service.stop()
311 time.sleep(1)
312 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
313 assert_equal(st, True)
314 service.start()
315 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
316 status = True
317 assert_equal(status, True)
318
319 def test_exampleservice_for_service_message_after_service_stop_and_start(self, service_message='"'+'hello'+'"'):
320 vm_public_ip = self.get_exampleservice_vm_public_ip()
321 vcpe_intf = self.vcpe_dhcp
322 try:
323 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
324 st,out = getstatusoutput('curl -s http://{}'.format(vm_public_ip))
325 assert_equal(st, False)
326 exampleservices = OnboardingServiceUtils.get_exampleservices()
327 status = False
328 for service in exampleservices:
329 if self.vm_name in service.name:
330 log.info('stopping mysite-example-server')
331 service.stop()
332 time.sleep(5)
333 st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip))
334 assert_equal(st, True)
335 service.start()
336 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
337 time.sleep(50)
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000338 st,out = getstatusoutput('curl -s http://{} --max-time 10'.format(vm_public_ip))
Anil Kumar Sanka51014ef2017-05-24 17:59:17 +0000339 assert_equal(st, False)
340 output = out.split('\n')
341 srvs_msg = ''
342 for line in output:
343 line = line.split(':')
344 if line[0].strip() == 'Service Message':
345 srvs_msg = line[1].strip()
346 break
347 assert_equal(service_message, srvs_msg)
348 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
349 status = True
350 break
351 assert_equal(status,True)
352 finally:
353 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000354
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000355 @deferred(150)
356 def test_exampleservice_for_tenant_message_after_service_restart(self,service_message='"'+'world'+'"'):
357 df = defer.Deferred()
358 def test_xos_subscriber(df):
359 vm_public_ip = self.get_exampleservice_vm_public_ip()
360 vcpe_intf = self.vcpe_dhcp
361 try:
362 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
363 st,out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
364 if out:
365 st = True
366 assert_equal(st, True)
367 exampleservices = OnboardingServiceUtils.get_exampleservices()
368 status = False
369 for service in exampleservices:
370 if self.vm_name in service.name:
371 log.info('restarting mysite-example-server')
372 service.reboot()
373 time.sleep(20)
374 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
375 time = 0
376 while(time <= 100):
377 time.sleep(10)
378 st, out = getstatusoutput('curl -s http://{} --max-time 5'.format(vm_public_ip))
379 if out:
380 st = True
381 break
382 time += 10
383 assert_equal(st,True)
384 output = out.split('\n')
385 tnnt_msg = ''
386 for line in output:
387 line = line.split(':')
388 if line[0].strip() == 'Tenant Message':
389 tnnt_msg = line[1].strip()
390 break
391 assert_equal(tenant_message, tnnt_msg)
392 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
393 status = True
394 break
395 assert_equal(status,True)
396 except Exception as error:
397 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
398 log.info('Got Unexpected error %s'%error)
399 raise
400 df.callback(0)
401 reactor.callLater(0,test_xos_subscriber,df)
402 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000403
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000404 @deferred(30)
405 def test_multiple_subcribers_access_for_same_exampleservice(self,index=0):
406 df = defer.Deferred()
407 def test_xos_subscriber(df):
408 vm_public_ip = self.get_exampleservice_vm_public_ip()
409 vcpe_intf1 = self.vcpe_dhcp
410 vcpe_intf2 = 'vcpe1.304.304'
411 subId = self.vsg_exchange.vsg_xos_subscriber_id(index)
412 if subId == '0':
413 subId = self.vsg_exchange.vsg_xos_subscriber_create(index)
414 assert_not_equal(subId,'0')
415 try:
416 for vcpe in [vcpe_intf1,vcpe_intf2]:
417 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe)
418 time.sleep(1)
419 #curl request from test container
420 st, out = getstatusoutput('route -n')
421 log.info('route -n out is %s'%out)
422 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
423 st,out = getstatusoutput(curl_cmd)
424 if out:
425 st = True
426 assert_equal(st, True)
427 log.info('examle service access success for subscriber %s'%vcpe)
428 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe)
429 time.sleep(1)
430 except Exception as error:
431 log.info('Got unexpected error %s'%error)
432 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf1)
433 self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf2)
434 raise
435 df.callback(0)
436 reactor.callLater(0,test_xos_subscriber,df)
437 return df
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000438
Anil Kumar Sankaac6c0b22017-05-26 21:18:40 +0000439 @deferred(50)
440 def test_exampleservice_access_after_vcpe_instance_restart(self,vcpe_intf=None,vcpe_name=None):
441 df = defer.Deferred()
442 def test_xos_subscriber(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
443 if not vcpe_intf:
444 vcpe_intf = self.vsg_exchange.dhcp_vcpes_reserved[0]
445 if not vcpe_name:
446 vcpe_name = self.vsg_exchange.container_vcpes_reserved[0]
447 vm_public_ip = self.get_exampleservice_vm_public_ip()
448 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
449 try:
450 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
451 #curl request from test container
452 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
453 st, out = getstatusoutput(curl_cmd)
454 if out:
455 st = True
456 assert_equal(st, True)
457 #restarting example service VM
458 cmd = 'sudo docker restart {}'.format(vcpe_name)
459 status, _ = vsg.run_cmd(cmd)
460 assert_equal(status, True)
461 time.sleep(10)
462 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
463 st, out = getstatusoutput(curl_cmd)
464 if out:
465 st = True
466 assert_equal(st, True)
467 except Exception as error:
468 log.info('Got Unexpeted error %s'%error)
469 self.vsg_exchange.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
470 raise
471 df.callback(0)
472 reactor.callLater(0,test_xos_subscriber,df)
473 return df
474
475 @deferred(30)
476 def test_exampleservice_access_after_firewall_rule_added_to_drop_service_running_server_in_vcpe_instance(self,vcpe_intf=None,vcpe_name=None):
477 df = defer.Deferred()
478 def test_xos_subscriber(df,vcpe_intf=vcpe_intf,vcpe_name=vcpe_name):
479 if not vcpe_intf:
480 vcpe_intf = self.vsg_exchange.dhcp_vcpes_reserved[0]
481 if not vcpe_name:
482 vcpe_name = self.vsg_exchange.container_vcpes_reserved[0]
483 vm_public_ip = self.get_exampleservice_vm_public_ip()
484 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
485 try:
486 self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf)
487 #curl request from test container
488 curl_cmd = 'curl -s http://{} --max-time 5'.format(vm_public_ip)
489 st, out = getstatusoutput(curl_cmd)
490 if out:
491 st = True
492 assert_equal(st, True)
493 #restarting example service VM
494 cmd = 'sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
495 status, _ = vsg.run_cmd(cmd)
496 assert_equal(status, True)
497 time.sleep(1)
498 st, out = getstatusoutput(curl_cmd)
499 if out:
500 st = True
501 assert_equal(st, True)
502 cmd = 'sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
503 except Exception as error:
504 log.info('Got Unexpeted error %s'%error)
505 cmd = 'sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,vm_public_ip)
506 status, _ = vsg.run_cmd(cmd)
507 self.vsg_exchange.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
508 raise
509 df.callback(0)
510 reactor.callLater(0,test_xos_subscriber,df)
511 return df
512
513 def test_exampleservice_after_firewall_rule_added_to_drop_service_running_server_in_vcpe(self):
Anil Kumar Sankae602c5a2017-05-10 17:58:03 +0000514 if not vcpe_intf:
515 vcpe_intf = self.dhcp_vcpes_reserved[0]
516 if not vcpe_name:
517 vcpe_name = self.container_vcpes_reserved[0]
518 public_ip = self.get_exampleservice_vm_public_ip()
519 vsg = VSGAccess.get_vcpe_vsg(vcpe_name)
520 try:
521 self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)
522 #curl request from test container
523 curl_cmd = 'curl -s http://{}'.format(public_ip)
524 st,_ = getstatusoutput(curl_cmd)
525 assert_equal(st, True)
526 #restarting example service VM
527 st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j ACCEPT'.format(vcpe_name,public_ip))
528 time.sleep(1)
529 st,_ = getstatusoutput(curl_cmd)
530 assert_equal(st, False)
531 finally:
532 st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,public_ip))
533 self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf)