Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 1 | # |
| 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 | # |
| 16 | import unittest |
| 17 | import os,sys |
| 18 | import keystoneclient.v2_0.client as ksclient |
| 19 | import keystoneclient.apiclient.exceptions |
| 20 | import neutronclient.v2_0.client as nclient |
| 21 | import neutronclient.common.exceptions |
| 22 | from novaclient import client as nova_client |
| 23 | from neutronclient.v2_0 import client as neutron_client |
| 24 | import neutronclient.v2_0.client as neutronclient |
| 25 | from nose.tools import assert_equal |
| 26 | from CordTestUtils import get_mac, log_test |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 27 | from onosclidriver import OnosCliDriver |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 28 | from OnosCtrl import OnosCtrl |
| 29 | from OnosFlowCtrl import OnosFlowCtrl |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 30 | from OnboardingServiceUtils import OnboardingServiceUtils |
| 31 | from SSHTestAgent import SSHTestAgent |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 32 | from CordTestUtils import running_on_pod, getstatusoutput |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 33 | from CordLogger import CordLogger |
| 34 | from CordTestUtils import log_test as log |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 35 | import requests |
| 36 | import time |
| 37 | import json |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 38 | from VSGAccess import VSGAccess |
| 39 | from CordTestConfig import setup_module, running_on_ciab |
| 40 | from vsgTest import * |
| 41 | log.setLevel('INFO') |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 42 | |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 43 | class onboarding_exchange(CordLogger): |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 44 | 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 Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 54 | on_pod = running_on_pod() |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 55 | vcpe_dhcp = 'vcpe0.222.111' |
| 56 | vsg_exchange = vsg_exchange() |
| 57 | vm_name = 'mysite_exampleservice' |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 58 | |
| 59 | @classmethod |
| 60 | def setUpClass(cls): |
| 61 | OnboardingServiceUtils.setUp() |
| 62 | |
| 63 | @classmethod |
| 64 | def tearDownClass(cls): |
| 65 | OnboardingServiceUtils.tearDown() |
| 66 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 67 | def cliEnter(self, controller = None): |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 68 | retries = 0 |
| 69 | while retries < 30: |
| 70 | self.cli = OnosCliDriver(controller = controller, connect = True) |
| 71 | if self.cli.handle: |
| 72 | break |
| 73 | else: |
| 74 | retries += 1 |
| 75 | time.sleep(2) |
| 76 | |
| 77 | def cliExit(self): |
| 78 | self.cli.disconnect() |
| 79 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 80 | def onos_shutdown(self, controller = None): |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 81 | status = True |
| 82 | self.cliEnter(controller = controller) |
| 83 | try: |
| 84 | self.cli.shutdown(timeout = 10) |
| 85 | except: |
| 86 | log.info('Graceful shutdown of ONOS failed for controller: %s' %controller) |
| 87 | status = False |
| 88 | |
| 89 | self.cliExit() |
| 90 | return status |
| 91 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 92 | def get_exampleservice_vm_public_ip(self, vm_name = 'mysite_exampleservice'): |
| 93 | if not vm_name: |
| 94 | vm_name = self.vm_name |
| 95 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 96 | for service in exampleservices: |
| 97 | if vm_name in service.name: |
| 98 | return service.get_public_ip() |
| 99 | return None |
| 100 | |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 101 | def test_exampleservice_health(self): |
| 102 | """ |
| 103 | Algo: |
| 104 | 1. Login to compute node VM |
| 105 | 2. Get all exampleservice |
| 106 | 3. Ping to all exampleservice |
| 107 | 4. Verifying Ping success |
| 108 | """ |
| 109 | status = OnboardingServiceUtils.health_check() |
| 110 | assert_equal(status, True) |
| 111 | |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 112 | def test_exampleservice_for_login(self): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 113 | if self.on_pod is False: |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 114 | return |
| 115 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 116 | exampleservice_access_status = map(lambda exampleservice: exampleservice.check_access(), exampleservices) |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 117 | status = filter(lambda st: st == False, exampleservice_access_status) |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 118 | assert_equal(len(status), 0) |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 119 | |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 120 | def test_exampleservice_for_default_route_through_testclient(self): |
Chetan Gaonker | 4cff443 | 2017-05-01 17:56:56 +0000 | [diff] [blame] | 121 | if self.on_pod is False: |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 122 | return |
| 123 | ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS) |
| 124 | cmd = "sudo lxc exec testclient -- route | grep default" |
| 125 | status, output = ssh_agent.run_cmd(cmd) |
| 126 | assert_equal(status, True) |
| 127 | |
| 128 | def test_exampleservice_for_service_access_through_testclient(self): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 129 | if self.on_pod is False: |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 130 | return |
| 131 | ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS) |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 132 | cmd = "sudo lxc exec testclient -- ping -c 3 8.8.8.8" |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 133 | status, output = ssh_agent.run_cmd(cmd) |
| 134 | assert_equal( status, True) |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 135 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 136 | def test_exampleservice_for_service_reachability_from_cord_tester(self, vcpe_intf=None): |
| 137 | if self.on_pod is False: |
| 138 | return |
| 139 | if not vcpe_intf: |
| 140 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
| 141 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 142 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 143 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 144 | st, _ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 145 | assert_equal(st, False) |
| 146 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
Chetan Gaonker | c1a4c8a | 2017-04-13 00:24:44 +0000 | [diff] [blame] | 147 | |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 148 | def test_exampleservice_operational_status_from_testclient(self): |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 149 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 150 | ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS) |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 151 | cmd = 'sudo lxc exec testclient -- apt-get install -y curl' |
| 152 | status, _ = ssh_agent.run_cmd(cmd) |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 153 | assert_equal(status, True) |
| 154 | #Test connectivity to ExampleService from test client |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 155 | cmd = 'sudo lxc exec testclient -- curl -s http://{}'.format(vm_public_ip) |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 156 | status, output = ssh_agent.run_cmd(cmd) |
| 157 | assert_equal(status, True) |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 158 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 159 | def test_exampleservice_operational_access_from_cord_tester(self, vcpe_intf=None): |
| 160 | if self.on_pod is False: |
| 161 | return |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 162 | if not vcpe_intf: |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 163 | vcpe_intf = self.vcpe_dhcp |
| 164 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 165 | self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 166 | st, _ = getstatusoutput('curl -s http://{}'.format(vm_public_ip)) |
| 167 | assert_equal(st, False) |
Chetan Gaonker | c685393 | 2017-04-24 22:16:37 +0000 | [diff] [blame] | 168 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 169 | def test_exampleservice_for_service_message(self, service_message='"'+'hello'+'"'): |
| 170 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 171 | vcpe_intf = self.vcpe_dhcp |
| 172 | try: |
| 173 | self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 174 | st,out = getstatusoutput('curl -s http://{}'.format(vm_public_ip)) |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 175 | assert_equal(st, False) |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 176 | output = out.split('\n') |
| 177 | srvs_msg = '' |
| 178 | for line in output: |
| 179 | line = line.split(':') |
| 180 | if line[0].strip() == 'Service Message': |
| 181 | srvs_msg = line[1].strip() |
| 182 | assert_equal(service_message, srvs_msg) |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 183 | finally: |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 184 | self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 185 | |
| 186 | def test_exampleservice_for_tenant_message(self, tenant_message='"'+'world'+'"'): |
| 187 | vcpe_intf = self.vcpe_dhcp |
| 188 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 189 | try: |
| 190 | self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 191 | st,out = getstatusoutput('curl -s http://10.6.1.194') |
| 192 | assert_equal(st, False) |
| 193 | output = out.split('\n') |
| 194 | tnt_msg = '' |
| 195 | for line in output: |
| 196 | line = line.split(':') |
| 197 | if line[0].strip() == 'Tenant Message': |
| 198 | tnt_msg = line[1].strip() |
| 199 | assert_equal(tenant_message, tnt_msg) |
| 200 | finally: |
| 201 | self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 202 | |
| 203 | def test_exampleservice_access_after_subscriber_interface_toggle(self, vcpe_intf=None): |
| 204 | if not vcpe_intf: |
| 205 | vcpe_intf = self.vcpe_dhcp |
| 206 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 207 | try: |
| 208 | self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 209 | #curl request from test container |
| 210 | cmd = 'curl -s http://{}'.format(vm_public_ip) |
| 211 | st,_ = getstatusoutput(cmd) |
| 212 | assert_equal(st, False) |
| 213 | st,_ = getstatusoutput('ifconfig {} down'.format(vcpe_intf)) |
| 214 | time.sleep(1) |
| 215 | assert_equal(st, False) |
| 216 | st,_ = getstatusoutput(cmd) |
| 217 | assert_equal(st, False) |
| 218 | st,_ = getstatusoutput('ifconfig {} up'.format(vcpe_intf)) |
| 219 | time.sleep(1) |
| 220 | self.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 221 | st,_ = getstatusoutput(cmd) |
| 222 | assert_equal(st, False) |
| 223 | finally: |
| 224 | self.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 225 | |
| 226 | def test_exampleservice_access_after_service_paused(self, vcpe_intf=None,vm_name=None): |
| 227 | if not vcpe_intf: |
| 228 | vcpe_intf = self.vcpe_dhcp |
| 229 | if not vm_name: |
| 230 | vm_name = self.vm_name |
| 231 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 232 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 233 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 234 | assert_equal(st, False) |
| 235 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 236 | status = False |
| 237 | for service in exampleservices: |
| 238 | if self.vm_name in service.name: |
| 239 | log.info('pausing mysite-example-server') |
| 240 | service.pause() |
| 241 | time.sleep(1) |
| 242 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 243 | assert_equal(st, True) |
| 244 | service.unpause() |
| 245 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 246 | status = True |
| 247 | assert_equal(status, True) |
| 248 | |
| 249 | def test_exampleservice_access_after_service_is_suspended(self, vcpe_intf=None,vm_name=None): |
| 250 | if not vcpe_intf: |
| 251 | vcpe_intf = self.vcpe_dhcp |
| 252 | if not vm_name: |
| 253 | vm_name = self.vm_name |
| 254 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 255 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 256 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 257 | assert_equal(st, False) |
| 258 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 259 | status = False |
| 260 | for service in exampleservices: |
| 261 | if self.vm_name in service.name: |
| 262 | log.info('suspending mysite-example-server') |
| 263 | service.suspend() |
| 264 | time.sleep(5) |
| 265 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 266 | assert_equal(st, True) |
| 267 | service.resume() |
| 268 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 269 | status = True |
| 270 | assert_equal(status, True) |
| 271 | |
| 272 | def test_exampleservice_access_after_service_restart(self, vcpe_intf=None,vm_name=None): |
| 273 | if not vcpe_intf: |
| 274 | vcpe_intf = self.vcpe_dhcp |
| 275 | if not vm_name: |
| 276 | vm_name = self.vm_name |
| 277 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 278 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 279 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 280 | assert_equal(st, False) |
| 281 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 282 | status = False |
| 283 | for service in exampleservices: |
| 284 | if self.vm_name in service.name: |
| 285 | log.info('restarting mysite-example-server') |
| 286 | service.reboot() |
| 287 | time.sleep(30) |
| 288 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 289 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 290 | assert_equal(st, False) |
| 291 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 292 | status = True |
| 293 | assert_equal(status, True) |
| 294 | |
| 295 | def test_exampleservice_access_after_service_stop(self, vcpe_intf=None,vm_name=None): |
| 296 | if not vcpe_intf: |
| 297 | vcpe_intf = self.vcpe_dhcp |
| 298 | if not vm_name: |
| 299 | vm_name = self.vm_name |
| 300 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 301 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 302 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 303 | assert_equal(st, False) |
| 304 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 305 | status = False |
| 306 | for service in exampleservices: |
| 307 | if self.vm_name in service.name: |
| 308 | log.info('restarting mysite-example-server') |
| 309 | service.stop() |
| 310 | time.sleep(1) |
| 311 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 312 | assert_equal(st, True) |
| 313 | service.start() |
| 314 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 315 | status = True |
| 316 | assert_equal(status, True) |
| 317 | |
| 318 | def test_exampleservice_for_service_message_after_service_stop_and_start(self, service_message='"'+'hello'+'"'): |
| 319 | vm_public_ip = self.get_exampleservice_vm_public_ip() |
| 320 | vcpe_intf = self.vcpe_dhcp |
| 321 | try: |
| 322 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 323 | st,out = getstatusoutput('curl -s http://{}'.format(vm_public_ip)) |
| 324 | assert_equal(st, False) |
| 325 | exampleservices = OnboardingServiceUtils.get_exampleservices() |
| 326 | status = False |
| 327 | for service in exampleservices: |
| 328 | if self.vm_name in service.name: |
| 329 | log.info('stopping mysite-example-server') |
| 330 | service.stop() |
| 331 | time.sleep(5) |
| 332 | st,_ = getstatusoutput('ping -c 1 {}'.format(vm_public_ip)) |
| 333 | assert_equal(st, True) |
| 334 | service.start() |
| 335 | self.vsg_exchange.add_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 336 | time.sleep(50) |
| 337 | st,out = getstatusoutput('curl -s http://{}'.format(vm_public_ip)) |
| 338 | assert_equal(st, False) |
| 339 | output = out.split('\n') |
| 340 | srvs_msg = '' |
| 341 | for line in output: |
| 342 | line = line.split(':') |
| 343 | if line[0].strip() == 'Service Message': |
| 344 | srvs_msg = line[1].strip() |
| 345 | break |
| 346 | assert_equal(service_message, srvs_msg) |
| 347 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
| 348 | status = True |
| 349 | break |
| 350 | assert_equal(status,True) |
| 351 | finally: |
| 352 | self.vsg_exchange.del_static_route_via_vcpe_interface([vm_public_ip],vcpe=vcpe_intf) |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 353 | |
| 354 | def test_multiple_subcriber_access_for_same_exampleservice(self): |
| 355 | ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS) |
| 356 | cmd = "nova list --all-tenants|grep mysite_exampleservice|cut -d '|' -f 2" |
| 357 | status, nova_id = ssh_agent.run_cmd(cmd) |
| 358 | assert_equal(status, True) |
| 359 | #Get public IP of VM |
| 360 | cmd = 'nova interface-list {} |grep -o -m 1 10\.6\.[[:digit:]]*\.[[:digit:]]*'.format(nova_id) |
| 361 | status, public_ip = ssh_agent.run_cmd(cmd) |
| 362 | assert_equal(status, True) |
| 363 | for vcpe in self.dhcp_vcpes: |
| 364 | self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe) |
| 365 | #curl request from test container |
| 366 | curl_cmd = 'curl -s http://{}'.format(public_ip) |
| 367 | st,_ = getstatusoutput(curl_cmd) |
| 368 | assert_equal(st, True) |
| 369 | self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe) |
| 370 | time.sleep(1) |
| 371 | |
Anil Kumar Sanka | 51014ef | 2017-05-24 17:59:17 +0000 | [diff] [blame^] | 372 | def test_exampleservice_after_vcpe_instance_restart(self, vcpe_intf=None,vcpe_name=None): |
Anil Kumar Sanka | e602c5a | 2017-05-10 17:58:03 +0000 | [diff] [blame] | 373 | if not vcpe_intf: |
| 374 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
| 375 | if not vcpe_name: |
| 376 | vcpe_name = self.container_vcpes_reserved[0] |
| 377 | public_ip = self.get_exampleservice_vm_public_ip() |
| 378 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 379 | try: |
| 380 | self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf) |
| 381 | #curl request from test container |
| 382 | curl_cmd = 'curl -s http://{}'.format(public_ip) |
| 383 | st,_ = getstatusoutput(curl_cmd) |
| 384 | assert_equal(st, True) |
| 385 | #restarting example service VM |
| 386 | cmd = 'sudo docker restart {}'.format(vcpe_name) |
| 387 | status, _ = vsg.run_cmd(cmd) |
| 388 | assert_equal(status, True) |
| 389 | time.sleep(10) |
| 390 | st,_ = getstatusoutput(curl_cmd) |
| 391 | assert_equal(st, True) |
| 392 | finally: |
| 393 | self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf) |
| 394 | |
| 395 | def test_exampleservice_after_firewall_rule_added_to_drop_service_running_server_ip_in_vcpe(self): |
| 396 | if not vcpe_intf: |
| 397 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
| 398 | if not vcpe_name: |
| 399 | vcpe_name = self.container_vcpes_reserved[0] |
| 400 | public_ip = self.get_exampleservice_vm_public_ip() |
| 401 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 402 | try: |
| 403 | self.add_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf) |
| 404 | #curl request from test container |
| 405 | curl_cmd = 'curl -s http://{}'.format(public_ip) |
| 406 | st,_ = getstatusoutput(curl_cmd) |
| 407 | assert_equal(st, True) |
| 408 | #restarting example service VM |
| 409 | st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j ACCEPT'.format(vcpe_name,public_ip)) |
| 410 | time.sleep(1) |
| 411 | st,_ = getstatusoutput(curl_cmd) |
| 412 | assert_equal(st, False) |
| 413 | finally: |
| 414 | st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,public_ip)) |
| 415 | self.del_static_route_via_vcpe_interface([public_ip],vcpe=vcpe_intf) |