Matteo Scandolo | 48d3d2d | 2017-08-08 13:05:27 -0700 | [diff] [blame] | 1 | |
| 2 | # Copyright 2017-present Open Networking Foundation |
| 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 | |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 17 | #copyright 2016-present Ciena Corporation |
| 18 | # |
| 19 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 20 | # you may not use this file except in compliance with the License. |
| 21 | # You may obtain a copy of the License at |
| 22 | # |
| 23 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 24 | # |
| 25 | # Unless required by applicable law or agreed to in writing, software |
| 26 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 27 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 28 | # See the License for the specific language governing permissions and |
| 29 | # limitations under the License. |
| 30 | # |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 31 | import time |
| 32 | import os |
A.R Karthick | 282f0d3 | 2017-03-28 16:43:59 -0700 | [diff] [blame] | 33 | import sys |
| 34 | import json |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 35 | import requests |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 36 | from nose.tools import * |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 37 | from twisted.internet import defer |
| 38 | from nose.twistedtools import reactor, deferred |
A.R Karthick | 33cfdbe | 2017-03-17 18:03:48 -0700 | [diff] [blame] | 39 | from CordTestUtils import * |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 40 | from OltConfig import OltConfig |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 41 | from onosclidriver import OnosCliDriver |
A.R Karthick | 9ccd0d0 | 2017-03-16 17:11:08 -0700 | [diff] [blame] | 42 | from SSHTestAgent import SSHTestAgent |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 43 | from CordLogger import CordLogger |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 44 | from VSGAccess import VSGAccess |
A R Karthick | 933f5b5 | 2017-03-27 15:27:16 -0700 | [diff] [blame] | 45 | from CordTestUtils import log_test as log |
A R Karthick | 9dc6e92 | 2017-07-12 14:40:16 -0700 | [diff] [blame] | 46 | from CordTestConfig import setup_module, running_on_ciab, teardown_module |
A.R Karthick | a9b594d | 2017-03-29 16:25:22 -0700 | [diff] [blame] | 47 | from OnosCtrl import OnosCtrl |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 48 | from CordContainer import Onos |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 49 | from CordSubscriberUtils import CordSubscriberUtils, XosUtils |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 50 | log.setLevel('INFO') |
| 51 | |
| 52 | class vsg_exchange(CordLogger): |
| 53 | ONOS_INSTANCES = 3 |
| 54 | V_INF1 = 'veth0' |
| 55 | device_id = 'of:' + get_mac() |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 56 | TEST_IP = '8.8.8.8' |
| 57 | HOST = "10.1.0.1" |
| 58 | USER = "vagrant" |
| 59 | PASS = "vagrant" |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 60 | head_node = os.getenv('HEAD_NODE', 'prod') |
A.R Karthick | 9ccd0d0 | 2017-03-16 17:11:08 -0700 | [diff] [blame] | 61 | HEAD_NODE = head_node + '.cord.lab' if len(head_node.split('.')) == 1 else head_node |
A R Karthick | 03f40aa | 2017-03-20 19:33:55 -0700 | [diff] [blame] | 62 | test_path = os.path.dirname(os.path.realpath(__file__)) |
A.R Karthick | 5968e0d | 2017-05-16 14:50:46 -0700 | [diff] [blame] | 63 | olt_conf_file = os.getenv('OLT_CONFIG_FILE', os.path.join(test_path, '..', 'setup/olt_config.json')) |
A.R Karthick | 282f0d3 | 2017-03-28 16:43:59 -0700 | [diff] [blame] | 64 | restApiXos = None |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 65 | cord_subscriber = None |
| 66 | SUBSCRIBER_ACCOUNT_NUM = 200 |
| 67 | SUBSCRIBER_S_TAG = 304 |
| 68 | SUBSCRIBER_C_TAG = 304 |
| 69 | SUBSCRIBERS_PER_S_TAG = 8 |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 70 | subscriber_info = [] |
| 71 | volt_subscriber_info = [] |
A R Karthick | 9a16a11 | 2017-04-07 15:40:05 -0700 | [diff] [blame] | 72 | restore_methods = [] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 73 | TIMEOUT=120 |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 74 | FABRIC_PORT_HEAD_NODE = 1 |
| 75 | FABRIC_PORT_COMPUTE_NODE = 2 |
| 76 | APP_NAME = 'org.ciena.xconnect' |
| 77 | APP_FILE = os.path.join(test_path, '..', 'apps/xconnect-1.0-SNAPSHOT.oar') |
A.R Karthick | 50f4d9a | 2017-04-20 16:44:19 -0700 | [diff] [blame] | 78 | NUM_SUBSCRIBERS = 5 |
A R Karthick | 0a4ca3a | 2017-03-30 09:36:53 -0700 | [diff] [blame] | 79 | |
| 80 | @classmethod |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 81 | def setUpCordApi(cls, **subscriber_config): |
| 82 | num_subscribers = subscriber_config.get('num_subscribers', cls.NUM_SUBSCRIBERS) |
| 83 | account_num = subscriber_config.get('account_num', cls.SUBSCRIBER_ACCOUNT_NUM) |
| 84 | s_tag = subscriber_config.get('s_tag', cls.SUBSCRIBER_S_TAG) |
| 85 | c_tag = subscriber_config.get('c_tag', cls.SUBSCRIBER_C_TAG) |
| 86 | subscribers_per_s_tag = subscriber_config.get('subscribers_per_s_tag', cls.SUBSCRIBERS_PER_S_TAG) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 87 | cls.cord_subscriber = CordSubscriberUtils(num_subscribers, |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 88 | account_num = account_num, |
| 89 | s_tag = s_tag, |
| 90 | c_tag = c_tag, |
| 91 | subscribers_per_s_tag = subscribers_per_s_tag) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 92 | cls.restApiXos = XosUtils.getRestApi() |
A R Karthick | 97e0885 | 2017-04-26 10:06:38 -0700 | [diff] [blame] | 93 | |
| 94 | @classmethod |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 95 | def closeVCPEAccess(cls, volt_subscriber_info): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 96 | OnosCtrl.uninstall_app(cls.APP_NAME, onos_ip = cls.HEAD_NODE) |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 97 | |
| 98 | @classmethod |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 99 | def openVCPEAccess(cls, volt_subscriber_info): |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 100 | """ |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 101 | This code is used to configure leaf switch for head node access to compute node over fabric. |
| 102 | Care is to be taken to avoid overwriting existing/default vcpe flows. |
| 103 | The access is opened for generated subscriber info which should not overlap. |
| 104 | We target the fabric onos instance on head node. |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 105 | """ |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 106 | version = Onos.getVersion(onos_ip = cls.HEAD_NODE) |
| 107 | app_version = '1.0-SNAPSHOT' |
| 108 | major = int(version.split('.')[0]) |
| 109 | minor = int(version.split('.')[1]) |
| 110 | if major > 1: |
| 111 | app_version = '2.0-SNAPSHOT' |
| 112 | elif major == 1 and minor > 10: |
| 113 | app_version = '2.0-SNAPSHOT' |
| 114 | cls.APP_FILE = os.path.join(cls.test_path, '..', 'apps/xconnect-{}.oar'.format(app_version)) |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 115 | OnosCtrl.install_app(cls.APP_FILE, onos_ip = cls.HEAD_NODE) |
| 116 | time.sleep(2) |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 117 | s_tags = map(lambda tenant: int(tenant['voltTenant']['s_tag']), volt_subscriber_info) |
| 118 | #only get unique vlan tags |
| 119 | s_tags = list(set(s_tags)) |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 120 | devices = OnosCtrl.get_device_ids(controller = cls.HEAD_NODE) |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 121 | if devices: |
| 122 | device_config = {} |
| 123 | for device in devices: |
| 124 | device_config[device] = [] |
| 125 | for s_tag in s_tags: |
| 126 | xconnect_config = {'vlan': s_tag, 'ports' : [ cls.FABRIC_PORT_HEAD_NODE, cls.FABRIC_PORT_COMPUTE_NODE ] } |
| 127 | device_config[device].append(xconnect_config) |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 128 | |
A R Karthick | b0cec7c | 2017-04-21 10:42:54 -0700 | [diff] [blame] | 129 | cfg = { 'apps' : { 'org.ciena.xconnect' : { 'xconnectTestConfig' : device_config } } } |
| 130 | OnosCtrl.config(cfg, controller = cls.HEAD_NODE) |
A.R Karthick | b145da8 | 2017-04-20 14:45:43 -0700 | [diff] [blame] | 131 | |
| 132 | @classmethod |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 133 | def vsgSetup(cls, **subscriber_config): |
A.R Karthick | 33cfdbe | 2017-03-17 18:03:48 -0700 | [diff] [blame] | 134 | cls.controllers = get_controllers() |
| 135 | cls.controller = cls.controllers[0] |
| 136 | cls.cli = None |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 137 | cls.on_pod = running_on_pod() |
| 138 | cls.on_ciab = running_on_ciab() |
A R Karthick | 03f40aa | 2017-03-20 19:33:55 -0700 | [diff] [blame] | 139 | cls.olt = OltConfig(olt_conf_file = cls.olt_conf_file) |
| 140 | cls.vcpes = cls.olt.get_vcpes() |
| 141 | cls.vcpes_dhcp = cls.olt.get_vcpes_by_type('dhcp') |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 142 | cls.vcpes_reserved = cls.olt.get_vcpes_by_type('reserved') |
| 143 | cls.dhcp_vcpes_reserved = [ 'vcpe{}.{}.{}'.format(i, cls.vcpes_reserved[i]['s_tag'], cls.vcpes_reserved[i]['c_tag']) |
| 144 | for i in xrange(len(cls.vcpes_reserved)) ] |
| 145 | cls.untagged_dhcp_vcpes_reserved = [ 'vcpe{}'.format(i) for i in xrange(len(cls.vcpes_reserved)) ] |
| 146 | cls.container_vcpes_reserved = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_reserved ] |
| 147 | vcpe_dhcp_reserved = None |
| 148 | vcpe_container_reserved = None |
| 149 | if cls.vcpes_reserved: |
| 150 | vcpe_dhcp_reserved = cls.dhcp_vcpes_reserved[0] |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 151 | if cls.on_pod is False: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 152 | vcpe_dhcp_reserved = cls.untagged_dhcp_vcpes_reserved[0] |
| 153 | vcpe_container_reserved = cls.container_vcpes_reserved[0] |
| 154 | |
| 155 | cls.vcpe_dhcp_reserved = vcpe_dhcp_reserved |
| 156 | cls.vcpe_container_reserved = vcpe_container_reserved |
| 157 | dhcp_vcpe_offset = len(cls.vcpes_reserved) |
A R Karthick | 927129c | 2017-04-25 14:08:02 -0700 | [diff] [blame] | 158 | cls.dhcp_vcpes = [ 'vcpe{}.{}.{}'.format(i+dhcp_vcpe_offset, cls.vcpes_dhcp[i]['s_tag'], cls.vcpes_dhcp[i]['c_tag']) |
| 159 | for i in xrange(len(cls.vcpes_dhcp)) ] |
| 160 | cls.untagged_dhcp_vcpes = [ 'vcpe{}'.format(i+dhcp_vcpe_offset) for i in xrange(len(cls.vcpes_dhcp)) ] |
| 161 | cls.container_vcpes = [ 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) for vcpe in cls.vcpes_dhcp ] |
A R Karthick | 03f40aa | 2017-03-20 19:33:55 -0700 | [diff] [blame] | 162 | vcpe_dhcp = None |
A R Karthick | 03f40aa | 2017-03-20 19:33:55 -0700 | [diff] [blame] | 163 | vcpe_container = None |
| 164 | #cache the first dhcp vcpe in the class for quick testing |
| 165 | if cls.vcpes_dhcp: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 166 | vcpe_container = cls.container_vcpes[0] |
| 167 | vcpe_dhcp = cls.dhcp_vcpes[0] |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 168 | if cls.on_pod is False: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 169 | vcpe_dhcp = cls.untagged_dhcp_vcpes[0] |
| 170 | cls.vcpe_container = vcpe_container_reserved or vcpe_container |
| 171 | cls.vcpe_dhcp = vcpe_dhcp_reserved or vcpe_dhcp |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 172 | VSGAccess.setUp() |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 173 | cls.setUpCordApi(**subscriber_config) |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 174 | if cls.on_pod is True: |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 175 | cls.openVCPEAccess(cls.cord_subscriber.volt_subscriber_info) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 176 | |
A.R Karthick | 33cfdbe | 2017-03-17 18:03:48 -0700 | [diff] [blame] | 177 | @classmethod |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 178 | def setUpClass(cls): |
| 179 | num_subscribers = max(cls.NUM_SUBSCRIBERS, 5) |
| 180 | cls.vsgSetup(num_subscribers = num_subscribers) |
| 181 | |
| 182 | @classmethod |
| 183 | def vsgTeardown(cls): |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 184 | VSGAccess.tearDown() |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 185 | if cls.on_pod is True: |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 186 | cls.closeVCPEAccess(cls.cord_subscriber.volt_subscriber_info) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 187 | |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 188 | @classmethod |
| 189 | def tearDownClass(cls): |
| 190 | cls.vsgTeardown() |
| 191 | |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 192 | def onos_shutdown(self, controller = None): |
| 193 | status = True |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 194 | cli = Onos.cliEnter(onos_ip = controller) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 195 | try: |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 196 | cli.shutdown(timeout = 10) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 197 | except: |
| 198 | log.info('Graceful shutdown of ONOS failed for controller: %s' %controller) |
| 199 | status = False |
| 200 | |
A R Karthick | b608d40 | 2017-06-02 11:48:41 -0700 | [diff] [blame] | 201 | Onos.cliExit(cli) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 202 | return status |
| 203 | |
A.R Karthick | 9ccd0d0 | 2017-03-16 17:11:08 -0700 | [diff] [blame] | 204 | def log_set(self, level = None, app = 'org.onosproject'): |
| 205 | CordLogger.logSet(level = level, app = app, controllers = self.controllers, forced = True) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 206 | |
A R Karthick | 9a16a11 | 2017-04-07 15:40:05 -0700 | [diff] [blame] | 207 | @classmethod |
| 208 | def get_dhcp(cls, vcpe, mgmt = 'eth0'): |
| 209 | """Get DHCP for vcpe interface saving management settings""" |
| 210 | |
| 211 | def put_dhcp(): |
| 212 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 213 | |
| 214 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 215 | if vcpe_ip is not None: |
| 216 | cls.restore_methods.append(put_dhcp) |
| 217 | return vcpe_ip |
| 218 | |
| 219 | @classmethod |
| 220 | def config_restore(cls): |
| 221 | """Restore the vsg test configuration on test case failures""" |
| 222 | for restore_method in cls.restore_methods: |
| 223 | restore_method() |
| 224 | |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 225 | def get_vsg_vcpe_pair(self): |
| 226 | vcpes = self.vcpes_dhcp |
| 227 | vcpe_containers = [] |
| 228 | vsg_vcpe = {} |
| 229 | for vcp in vcpes: |
| 230 | vcpe_container = 'vcpe-{}-{}'.format(vcp['s_tag'], vcp['c_tag']) |
| 231 | vcpe_containers.append(vcpe_container) |
| 232 | vsg = VSGAccess.get_vcpe_vsg(vcpe_container) |
| 233 | vsg_vcpe[vcpe_container]=str(vsg.get_ip()) |
| 234 | return vsg_vcpe |
| 235 | |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 236 | def get_vcpe_containers_and_interfaces(self): |
| 237 | vcpe_containers = {} |
| 238 | vcpe_interfaces = [] |
| 239 | vcpes = self.vcpes_dhcp |
| 240 | count = 0 |
| 241 | for vcpe in vcpes: |
| 242 | vcpe_intf = 'vcpe{}.{}.{}'.format(count,vcpe['s_tag'],vcpe['c_tag']) |
| 243 | vcpe_interfaces.append(vcpe_intf) |
| 244 | vcpe_container = 'vcpe-{}-{}'.format(vcpe['s_tag'], vcpe['c_tag']) |
| 245 | vcpe_containers[vcpe_intf] = vcpe_container |
| 246 | count += 1 |
| 247 | log.info('vcpe interfaces are %s'%vcpe_interfaces) |
| 248 | log.info('vcpe containers are %s'%vcpe_containers) |
| 249 | return vcpe_interfaces,vcpe_containers |
| 250 | |
| 251 | def get_vcpe_interface_dhcp_ip(self,vcpe=None): |
| 252 | if not vcpe: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 253 | vcpe = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 254 | st, _ = getstatusoutput('dhclient {}'.format(vcpe)) |
| 255 | vcpe_ip = get_ip(vcpe) |
| 256 | return vcpe_ip |
| 257 | |
| 258 | def release_vcpe_interface_dhcp_ip(self,vcpe=None): |
| 259 | if not vcpe: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 260 | vcpe = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 261 | st, _ = getstatusoutput('dhclient {} -r'.format(vcpe)) |
| 262 | vcpe_ip = get_ip(vcpe) |
| 263 | assert_equal(vcpe_ip, None) |
| 264 | |
| 265 | def add_static_route_via_vcpe_interface(self, routes, vcpe=None,dhcp_ip=True): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 266 | if not vcpe: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 267 | vcpe = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 268 | if dhcp_ip: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 269 | os.system('dhclient '+vcpe) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 270 | time.sleep(1) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 271 | for route in routes: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 272 | log.info('route is %s'%route) |
| 273 | cmd = 'ip route add ' + route + ' via 192.168.0.1 '+ 'dev ' + vcpe |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 274 | os.system(cmd) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 275 | return True |
| 276 | |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 277 | def del_static_route_via_vcpe_interface(self,routes,vcpe=None,dhcp_release=True): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 278 | if not vcpe: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 279 | vcpe = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 280 | cmds = [] |
| 281 | for route in routes: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 282 | cmd = 'ip route del ' + route + ' via 192.168.0.1 ' + 'dev ' + vcpe |
| 283 | os.system(cmd) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 284 | if dhcp_release: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 285 | os.system('dhclient '+vcpe+' -r') |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 286 | return True |
| 287 | |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 288 | def vsg_for_external_connectivity(self, subscriber_index, reserved = False): |
| 289 | if reserved is True: |
| 290 | if self.on_pod is True: |
| 291 | vcpe = self.dhcp_vcpes_reserved[subscriber_index] |
| 292 | else: |
| 293 | vcpe = self.untagged_dhcp_vcpes_reserved[subscriber_index] |
| 294 | else: |
| 295 | if self.on_pod is True: |
| 296 | vcpe = self.dhcp_vcpes[subscriber_index] |
| 297 | else: |
| 298 | vcpe = self.untagged_dhcp_vcpes[subscriber_index] |
| 299 | mgmt = 'eth0' |
| 300 | host = '8.8.8.8' |
| 301 | self.success = False |
| 302 | assert_not_equal(vcpe, None) |
| 303 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 304 | assert_not_equal(vcpe_ip, None) |
| 305 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 306 | log.info('Sending icmp echo requests to external network 8.8.8.8') |
| 307 | st, _ = getstatusoutput('ping -c 3 8.8.8.8') |
| 308 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 309 | assert_equal(st, 0) |
| 310 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 311 | def get_vsg_health_check(self, vsg_name=None): |
| 312 | if self.on_pod is False: |
| 313 | return |
| 314 | if vsg_name is None: |
| 315 | vcpe = self.container_vcpes_reserved[0] |
| 316 | vsg = VSGAccess.get_vcpe_vsg(vcpe) |
| 317 | status = vsg.get_health() |
| 318 | return status |
| 319 | else: |
| 320 | vsgs = VSGAccess.get_vsgs() |
| 321 | for vsg in vsgs: |
| 322 | if vsg.name == vsg_name: |
| 323 | status = vsg.get_health() |
| 324 | return status |
| 325 | return None |
| 326 | |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 327 | def test_vsg_health(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 328 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 329 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 330 | 1. Login to compute node VM |
| 331 | 2. Get all vSGs |
| 332 | 3. Ping to all vSGs |
| 333 | 4. Verifying Ping success |
| 334 | """ |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 335 | status = True |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 336 | if self.on_pod is True: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 337 | status = VSGAccess.health_check() |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 338 | assert_equal(status, True) |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 339 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 340 | def test_vsg_health_check(self, vsg_name=None, verify_status=True): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 341 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 342 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 343 | 1. If vsg name not specified, Get vsg corresponding to vcpe |
| 344 | 1. Login to compute mode VM |
| 345 | 3. Ping to the vSG |
| 346 | 4. Verifying Ping success |
| 347 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 348 | st = self.get_vsg_health_check(vsg_name=vsg_name) |
| 349 | assert_equal(st,verify_status) |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 350 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 351 | @deferred(30) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 352 | def test_vsg_for_vcpe(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 353 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 354 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 355 | 1. Get list of all compute nodes created using Openstack |
| 356 | 2. Login to compute mode VM |
| 357 | 3. Get all vSGs |
| 358 | 4. Verifying atleast one compute node and one vSG created |
| 359 | """ |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 360 | df = defer.Deferred() |
| 361 | def vsg_for_vcpe_df(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 362 | if self.on_pod is True: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 363 | vsgs = VSGAccess.get_vsgs() |
| 364 | compute_nodes = VSGAccess.get_compute_nodes() |
| 365 | time.sleep(14) |
| 366 | assert_not_equal(len(vsgs), 0) |
| 367 | assert_not_equal(len(compute_nodes), 0) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 368 | df.callback(0) |
| 369 | reactor.callLater(0,vsg_for_vcpe_df,df) |
| 370 | return df |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 371 | |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 372 | def test_vsg_for_login(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 373 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 374 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 375 | 1. Login to compute node VM |
| 376 | 2. Get all vSGs |
| 377 | 3. Verifying login to vSG is success |
| 378 | """ |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 379 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 380 | return |
A R Karthick | d0fdf3b | 2017-03-21 16:54:22 -0700 | [diff] [blame] | 381 | vsgs = VSGAccess.get_vsgs() |
| 382 | vsg_access_status = map(lambda vsg: vsg.check_access(), vsgs) |
A.R Karthick | 33cfdbe | 2017-03-17 18:03:48 -0700 | [diff] [blame] | 383 | status = filter(lambda st: st == False, vsg_access_status) |
| 384 | assert_equal(len(status), 0) |
| 385 | |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 386 | def test_vsg_for_default_route_through_testclient(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 387 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 388 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 389 | 1. Login to head node |
| 390 | 2. Verifying for default route in lxc test client |
| 391 | """ |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 392 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 393 | return |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 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 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 399 | @deferred(30) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 400 | def test_vsg_for_external_connectivity_through_testclient(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 401 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 402 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 403 | 1. Login to head node |
| 404 | 2. On head node, executing ping to 8.8.8.8 from lxc test client |
| 405 | 3. Verifying for the ping success |
| 406 | """ |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 407 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 408 | return |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 409 | df = defer.Deferred() |
| 410 | def test_external_connectivity(df): |
| 411 | ssh_agent = SSHTestAgent(host = self.HEAD_NODE, user = self.USER, password = self.PASS) |
| 412 | cmd = "sudo lxc exec testclient -- ping -c 3 8.8.8.8" |
| 413 | status, output = ssh_agent.run_cmd(cmd) |
| 414 | assert_equal( status, True) |
| 415 | df.callback(0) |
| 416 | reactor.callLater(0,test_external_connectivity,df) |
| 417 | return df |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 418 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 419 | @deferred(30) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 420 | def test_vsg_for_external_connectivity(self): |
| 421 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 422 | Test Method: |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 423 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 424 | 2. Verifying vcpe interface gets dhcp IP |
| 425 | 3. Ping to 8.8.8.8 and Verifying ping should success |
| 426 | 4. Restoring management interface configuration in cord-tester |
| 427 | """ |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 428 | reserved = True |
| 429 | if self.on_pod: |
| 430 | reserved = self.on_ciab |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 431 | df = defer.Deferred() |
| 432 | def test_external_connectivity(df): |
| 433 | self.vsg_for_external_connectivity(0, reserved = reserved) |
| 434 | df.callback(0) |
| 435 | reactor.callLater(0,test_external_connectivity,df) |
| 436 | return df |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 437 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 438 | @deferred(30) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 439 | def test_vsg_for_external_connectivity_to_google(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 440 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 441 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 442 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 443 | 2. Verifying vcpe interface gets dhcp IP |
| 444 | 3. Ping to www.google.com and Verifying ping should success |
| 445 | 4. Restoring management interface configuration in cord-tester |
| 446 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 447 | df = defer.Deferred() |
| 448 | def test_external_connectivity(df): |
| 449 | host = 'www.google.com' |
| 450 | vcpe = self.dhcp_vcpes_reserved[0] |
| 451 | mgmt = 'eth0' |
| 452 | assert_not_equal(vcpe, None) |
| 453 | try: |
| 454 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 455 | assert_not_equal(vcpe_ip, None) |
| 456 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 457 | log.info('Sending icmp ping requests to %s' %host) |
| 458 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 459 | assert_equal(st, 0) |
| 460 | except Exception as error: |
| 461 | log.info('Got Unexpected error %s'%error) |
| 462 | raise |
| 463 | finally: |
| 464 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 465 | df.callback(0) |
| 466 | reactor.callLater(0,test_external_connectivity,df) |
| 467 | return df |
Anil Kumar Sanka | 87115b0 | 2017-03-14 17:46:47 +0000 | [diff] [blame] | 468 | |
A R Karthick | b261805 | 2017-05-10 09:23:22 -0700 | [diff] [blame] | 469 | def retrieve_content_from_host_to_validate_path_mtu(self, host): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 470 | vcpe = self.dhcp_vcpes_reserved[0] |
A R Karthick | b261805 | 2017-05-10 09:23:22 -0700 | [diff] [blame] | 471 | mgmt = 'eth0' |
| 472 | assert_not_equal(vcpe, None) |
| 473 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 474 | assert_not_equal(vcpe_ip, None) |
| 475 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 476 | log.info('Initiating get requests to %s' %host) |
| 477 | r = requests.get('http://{}'.format(host)) |
| 478 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 479 | return r.status_code |
| 480 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 481 | @deferred(30) |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 482 | def test_vsg_to_retrieve_content_from_google_to_validate_path_mtu(self): |
| 483 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 484 | Test Method: |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 485 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 486 | 2. Verifying vcpe interface gets dhcp IP |
| 487 | 3. Retrieve contents from www.google.com and Verify response status is 200 ok. |
| 488 | 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework. |
| 489 | (Based on website response, size differs, needs check on MTU) |
| 490 | 4. Restoring management interface configuration in cord-tester |
| 491 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 492 | df = defer.Deferred() |
| 493 | def test_external_connectivity(df): |
| 494 | status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.google.com') |
| 495 | assert_equal(status_code, 200) |
| 496 | df.callback(0) |
| 497 | reactor.callLater(0,test_external_connectivity,df) |
| 498 | return df |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 499 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 500 | @deferred(30) |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 501 | def test_vsg_to_retrieve_content_from_rediff_to_validate_path_mtu(self): |
| 502 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 503 | Test Method: |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 504 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 505 | 2. Verifying vcpe interface gets dhcp IP |
| 506 | 3. Retrieve contents from www.rediff.com and Verify response status is 200 ok. |
| 507 | 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework. |
| 508 | (Based on website response, size differs, needs check on MTU) |
| 509 | 4. Restoring management interface configuration in cord-tester |
| 510 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 511 | df = defer.Deferred() |
| 512 | def test_external_connectivity(df): |
| 513 | status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.rediff.com') |
| 514 | assert_equal(status_code, 200) |
| 515 | df.callback(0) |
| 516 | reactor.callLater(0,test_external_connectivity,df) |
| 517 | return df |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 518 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 519 | @deferred(30) |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 520 | def test_vsg_to_retrieve_content_from_yahoo_to_validate_path_mtu(self): |
| 521 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 522 | Test Method: |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 523 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 524 | 2. Verifying vcpe interface gets dhcp IP |
| 525 | 3. Retrieve contents from www.yahoo.com and Verify response status is 200 ok. |
| 526 | 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework. |
| 527 | (Based on website response, size differs, needs check on MTU) |
| 528 | 4. Restoring management interface configuration in cord-tester |
| 529 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 530 | df = defer.Deferred() |
| 531 | def test_external_connectivity(df): |
| 532 | status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.yahoo.com') |
| 533 | assert_equal(status_code, 200) |
| 534 | df.callback(0) |
| 535 | reactor.callLater(0,test_external_connectivity,df) |
| 536 | return df |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 537 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 538 | @deferred(30) |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 539 | def test_vsg_to_retrieve_content_from_facebook_to_validate_path_mtu(self): |
| 540 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 541 | Test Method: |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 542 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 543 | 2. Verifying vcpe interface gets dhcp IP |
| 544 | 3. Retrieve contents from www.facebook.com and Verify response status is 200 ok. |
| 545 | 4. This validates path mtu for end to end traffic with request to retrieve web contents in cord framework. |
| 546 | (Based on website response, size differs, needs check on MTU) |
| 547 | 4. Restoring management interface configuration in cord-tester |
| 548 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 549 | df = defer.Deferred() |
| 550 | def test_external_connectivity(df): |
| 551 | status_code = self.retrieve_content_from_host_to_validate_path_mtu('www.facebook.com') |
| 552 | assert_equal(status_code, 200) |
| 553 | df.callback(0) |
| 554 | reactor.callLater(0,test_external_connectivity,df) |
| 555 | return df |
Chetan Gaonker | 0bf7631 | 2017-05-09 16:48:10 +0000 | [diff] [blame] | 556 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 557 | |
| 558 | @deferred(30) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 559 | def test_vsg_for_external_connectivity_to_invalid_host(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 560 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 561 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 562 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 563 | 2. Verifying vcpe interface gets dhcp IP |
| 564 | 3. Ping to www.goglee.com and Verifying ping should not success |
| 565 | 4. Restoring management interface configuration in cord-tester |
| 566 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 567 | df = defer.Deferred() |
| 568 | def test_external_connectivity(df): |
| 569 | host = 'www.goglee.com' |
| 570 | vcpe = self.dhcp_vcpes_reserved[0] |
| 571 | mgmt = 'eth0' |
| 572 | assert_not_equal(vcpe, None) |
| 573 | try: |
| 574 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 575 | assert_not_equal(vcpe_ip, None) |
| 576 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 577 | log.info('Sending icmp ping requests to non existent host %s' %host) |
| 578 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 579 | assert_not_equal(st, 0) |
| 580 | except Exception as error: |
| 581 | log.info('Got Unexpected error %s'%error) |
| 582 | raise |
| 583 | finally: |
| 584 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 585 | df.callback(0) |
| 586 | reactor.callLater(0,test_external_connectivity,df) |
| 587 | return df |
Anil Kumar Sanka | 87115b0 | 2017-03-14 17:46:47 +0000 | [diff] [blame] | 588 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 589 | @deferred(30) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 590 | def test_vsg_for_external_connectivity_with_ttl_1(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 591 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 592 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 593 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 594 | 2. Verifying vcpe interface gets dhcp IP |
| 595 | 3. Ping to 8.8.8.8 with ttl set to 1 |
| 596 | 4. Verifying ping should not success |
| 597 | 5. Restoring management interface configuration in cord-tester |
| 598 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 599 | df = defer.Deferred() |
| 600 | def test_external_connectivity(df): |
| 601 | host = '8.8.8.8' |
| 602 | vcpe = self.dhcp_vcpes_reserved[0] |
| 603 | mgmt = 'eth0' |
| 604 | assert_not_equal(vcpe, None) |
| 605 | try: |
| 606 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 607 | assert_not_equal(vcpe_ip, None) |
| 608 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 609 | log.info('Sending icmp ping requests to host %s with ttl 1' %host) |
| 610 | st, _ = getstatusoutput('ping -c 1 -t 1 {}'.format(host)) |
| 611 | assert_not_equal(st, 0) |
| 612 | except Exception as error: |
| 613 | log.info('Got Unexpected error %s'%error) |
| 614 | raise |
| 615 | finally: |
| 616 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 617 | df.callback(0) |
| 618 | reactor.callLater(0,test_external_connectivity,df) |
| 619 | return df |
Anil Kumar Sanka | 87115b0 | 2017-03-14 17:46:47 +0000 | [diff] [blame] | 620 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 621 | @deferred(60) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 622 | def test_vsg_for_external_connectivity_with_wan_interface_toggle_in_vcpe(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 623 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 624 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 625 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 626 | 2. Verifying vcpe interface gets dhcp IP |
A.R Karthick | 8f7f1b6 | 2017-04-06 18:25:07 -0700 | [diff] [blame] | 627 | 3. Ping to 8.8.8.8 and Verifying ping succeeds |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 628 | 4. Now down the WAN interface of vcpe |
A.R Karthick | 8f7f1b6 | 2017-04-06 18:25:07 -0700 | [diff] [blame] | 629 | 5. Ping to 8.8.8.8 and Verifying ping fails |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 630 | 6. Now Up the WAN interface of vcpe |
A.R Karthick | 8f7f1b6 | 2017-04-06 18:25:07 -0700 | [diff] [blame] | 631 | 7. Ping to 8.8.8.8 and Verifying ping succeeds |
| 632 | 8. Restoring management interface configuration in cord-tester |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 633 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 634 | df = defer.Deferred() |
| 635 | def test_external_connectivity(df): |
| 636 | if self.on_pod is False: |
| 637 | return |
| 638 | host = '8.8.8.8' |
| 639 | mgmt = 'eth0' |
| 640 | vcpe = self.dhcp_vcpes_reserved[0] |
| 641 | vcpe_name = self.container_vcpes_reserved[0] |
| 642 | assert_not_equal(vcpe_name, None) |
| 643 | assert_not_equal(vcpe, None) |
| 644 | #first get dhcp on the vcpe interface |
| 645 | try: |
| 646 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 647 | assert_not_equal(vcpe_ip, None) |
| 648 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 649 | log.info('Sending ICMP pings to host %s' %(host)) |
| 650 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 651 | if st != 0: |
| 652 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 653 | assert_equal(st, 0) |
| 654 | #bring down the wan interface and check again |
| 655 | st = VSGAccess.vcpe_wan_down(vcpe_name) |
| 656 | if st is False: |
| 657 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 658 | assert_equal(st, True) |
| 659 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 660 | if st == 0: |
| 661 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 662 | assert_not_equal(st, 0) |
| 663 | st = VSGAccess.vcpe_wan_up(vcpe_name) |
| 664 | if st is False: |
| 665 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 666 | assert_equal(st, True) |
| 667 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 668 | assert_equal(st, 0) |
| 669 | except Exception as error: |
| 670 | log.info('Got Unexpected error %s'%error) |
| 671 | raise |
| 672 | finally: |
| 673 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 674 | df.callback(0) |
| 675 | reactor.callLater(0,test_external_connectivity,df) |
| 676 | return df |
Anil Kumar Sanka | 87115b0 | 2017-03-14 17:46:47 +0000 | [diff] [blame] | 677 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 678 | @deferred(60) |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 679 | def test_vsg_for_external_connectivity_with_lan_interface_toggle_in_vcpe(self): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 680 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 681 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 682 | 1. Get dhcp IP to vcpe interface in cord-tester |
| 683 | 2. Verifying vcpe interface gets dhcp IP |
| 684 | 3. Ping to 8.8.8.8 and Verifying ping should success |
| 685 | 4. Now down the LAN interface of vcpe |
| 686 | 5. Ping to 8.8.8.8 and Verifying ping should not success |
| 687 | 6. Now Up the LAN interface of vcpe |
| 688 | 7. Ping to 8.8.8.8 and Verifying ping should success |
| 689 | 8. Restoring management interface configuration in cord-tester |
| 690 | """ |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 691 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 692 | return |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 693 | df = defer.Deferred() |
| 694 | def test_external_connectivity(df): |
| 695 | host = '8.8.8.8' |
| 696 | mgmt = 'eth0' |
| 697 | vcpe = self.dhcp_vcpes_reserved[0] |
| 698 | vcpe_name = self.container_vcpes_reserved[0] |
| 699 | assert_not_equal(vcpe, None) |
| 700 | assert_not_equal(vcpe_name, None) |
| 701 | #first get dhcp on the vcpe interface |
| 702 | try: |
| 703 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe, mgmt = mgmt) |
| 704 | assert_not_equal(vcpe_ip, None) |
| 705 | log.info('Got DHCP IP %s for %s' %(vcpe_ip, vcpe)) |
| 706 | log.info('Sending ICMP pings to host %s' %(host)) |
| 707 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 708 | if st != 0: |
| 709 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 710 | assert_equal(st, 0) |
| 711 | #bring down the lan interface and check again |
| 712 | st = VSGAccess.vcpe_lan_down(vcpe_name) |
| 713 | if st is False: |
| 714 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 715 | assert_equal(st, True) |
| 716 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 717 | if st == 0: |
| 718 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 719 | assert_not_equal(st, 0) |
| 720 | st = VSGAccess.vcpe_lan_up(vcpe_name) |
| 721 | if st is False: |
| 722 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 723 | assert_equal(st, True) |
| 724 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 725 | assert_equal(st, 0) |
| 726 | except Exception as error: |
| 727 | log.info('Got Unexpected error %s'%error) |
| 728 | raise |
| 729 | finally: |
| 730 | VSGAccess.restore_interface_config(mgmt, vcpe = vcpe) |
| 731 | df.callback(0) |
| 732 | reactor.callLater(0,test_external_connectivity,df) |
| 733 | return df |
Chetan Gaonker | 5241883 | 2017-01-26 23:03:13 +0000 | [diff] [blame] | 734 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 735 | @deferred(120) |
Chetan Gaonker | fe1048f | 2017-06-13 20:16:25 +0000 | [diff] [blame] | 736 | def test_vsg_multiple_subscribers_for_same_vcpe_instance(self): |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 737 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 738 | Test Method: |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 739 | 1. Create a vcpe instance |
| 740 | 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance |
| 741 | 3. Verify all the interfaces gets dhcp IP in same subnet |
| 742 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 743 | df = defer.Deferred() |
| 744 | def test_external_connectivity(df): |
| 745 | vcpe_intfs,containers = self.get_vcpe_containers_and_interfaces() |
| 746 | for vcpe in vcpe_intfs: |
| 747 | vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe) |
| 748 | assert_not_equal(vcpe_ip,None) |
| 749 | for vcpe in vcpe_intfs: |
| 750 | self.release_vcpe_interface_dhcp_ip(vcpe=vcpe) |
| 751 | df.callback(0) |
| 752 | reactor.callLater(0,test_external_connectivity,df) |
| 753 | return df |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 754 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 755 | @deferred(120) |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 756 | def test_vsg_for_multiple_subscribers_with_same_vcpe_instance_and_validate_external_connectivity(self): |
| 757 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 758 | Test Method: |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 759 | 1. Create a vcpe instance |
| 760 | 2. Create multiple vcpe interfaces in cord-tester with same s-tag and c-tag to access vcpe instance |
| 761 | 3. Verify all the interfaces gets dhcp IP in same subnet |
| 762 | 4. From cord-tester ping to external with vcpe interface option |
| 763 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 764 | df = defer.Deferred() |
| 765 | def test_external_connectivity(df): |
| 766 | host = '8.8.8.8' |
| 767 | vcpe_intfs, containers = self.get_vcpe_containers_and_interfaces() |
| 768 | try: |
| 769 | for vcpe in vcpe_intfs: |
| 770 | vcpe_ip = self.get_vcpe_interface_dhcp_ip(vcpe=vcpe) |
| 771 | assert_not_equal(vcpe_ip,None) |
| 772 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_ip=False) |
| 773 | st, _ = getstatusoutput('ping -I {} -c 3 {}'.format(vcpe,host)) |
| 774 | assert_equal(st, 0) |
| 775 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe,dhcp_release=False) |
| 776 | except Exception as error: |
| 777 | log.info('Got Unexpected error %s'%error) |
| 778 | raise |
| 779 | finally: |
| 780 | for vcpe in vcpe_intfs: |
| 781 | self.release_vcpe_interface_dhcp_ip(vcpe=vcpe) |
| 782 | df.callback(0) |
| 783 | reactor.callLater(0,test_external_connectivity,df) |
| 784 | return df |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 785 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 786 | @deferred(30) |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 787 | def test_vsg_vcpe_interface_and_validate_dhcp_ip_after_interface_toggle(self): |
| 788 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 789 | Test Method: |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 790 | 1. Create a vcpe instance |
| 791 | 2. Create a vcpe interface in cord-tester |
| 792 | 3. Verify the interface gets dhcp IP |
| 793 | 4. Toggle the interface |
| 794 | 5. Verify the interface gets dhcp IP |
| 795 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 796 | df = defer.Deferred() |
| 797 | def test_external_connectivity(df): |
| 798 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
| 799 | host = '8.8.8.8' |
| 800 | try: |
| 801 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 802 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 803 | assert_equal(st, 0) |
| 804 | os.system('ifconfig {} down'.format(vcpe_intf)) |
| 805 | time.sleep(1) |
| 806 | os.system('ifconfig {} up'.format(vcpe_intf)) |
| 807 | time.sleep(1) |
| 808 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 809 | assert_equal(st, 0) |
| 810 | except Exception as error: |
| 811 | log.info('Got Unexpected error %s'%error) |
| 812 | raise |
| 813 | finally: |
| 814 | self.del_static_route_via_vcpe_interface([host], vcpe=vcpe_intf) |
| 815 | df.callback(0) |
| 816 | reactor.callLater(0,test_external_connectivity,df) |
| 817 | return df |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 818 | |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 819 | @deferred(TIMEOUT) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 820 | def test_vsg_for_external_connectivity_after_restarting_vcpe_instance(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 821 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 822 | Test Method: |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 823 | 1. Get vSG corresponding to vcpe |
| 824 | 2. Get dhcp ip to vcpe interface |
| 825 | 3. Add static route to destination route in test container |
| 826 | 4. From test container ping to destination route and verify ping success |
| 827 | 5. Login to compute node and execute command to pause vcpe container |
| 828 | 6. From test container ping to destination route and verify ping success |
| 829 | """ |
| 830 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 831 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 832 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 833 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 834 | df = defer.Deferred() |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 835 | def test_external_connectivity(df): |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 836 | if self.on_pod is False: |
| 837 | df.callback(0) |
| 838 | return |
| 839 | host = '8.8.8.8' |
| 840 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 841 | try: |
| 842 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 843 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 844 | assert_equal(st, False) |
| 845 | st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 846 | clock = 0 |
| 847 | status = False |
| 848 | while(clock <= 20): |
| 849 | time.sleep(5) |
| 850 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 851 | if st == False: |
| 852 | status = True |
| 853 | break |
| 854 | clock += 5 |
| 855 | assert_equal(status, True) |
| 856 | except Exception as error: |
| 857 | log.info('Got Unexpected error %s'%error) |
| 858 | vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
| 859 | raise |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 860 | finally: |
| 861 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 862 | df.callback(0) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 863 | reactor.callLater(0, test_external_connectivity, df) |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 864 | return df |
| 865 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 866 | @nottest #Setup getting distrubed if vSG VM restart |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 867 | @deferred(TIMEOUT) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 868 | def test_vsg_for_external_connectivity_after_restarting_vsg_vm(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 869 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 870 | Test Method: |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 871 | 1. Get vSG corresponding to vcpe |
| 872 | 2. Get dhcp ip to vcpe interface |
| 873 | 3. Add static route to destination route in test container |
| 874 | 4. From test container ping to destination route and verify ping success |
| 875 | 5. Login to compute node and execute command to pause vcpe container |
| 876 | 6. From test container ping to destination route and verify ping success |
| 877 | """ |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 878 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 879 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 880 | df = defer.Deferred() |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 881 | def test_external_connectivity(df): |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 882 | if self.on_pod is False: |
| 883 | df.callback(0) |
| 884 | return |
| 885 | host = '8.8.8.8' |
| 886 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 887 | try: |
| 888 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 889 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 890 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 891 | vsg.reboot() |
| 892 | clock = 0 |
| 893 | status = False |
| 894 | while(clock <= 30): |
| 895 | time.sleep(5) |
| 896 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 897 | if st == False: |
| 898 | status = True |
| 899 | break |
| 900 | clock += 5 |
| 901 | assert_equal(status, True) |
| 902 | except Exception as error: |
| 903 | log.info('Got Unexpected error %s'%error) |
| 904 | vsg.reboot() |
| 905 | raise |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 906 | finally: |
| 907 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 908 | df.callback(0) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 909 | reactor.callLater(0, test_external_connectivity, df) |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 910 | return df |
| 911 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 912 | @deferred(60) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 913 | def test_vsg_for_external_connectivity_with_vcpe_container_paused(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 914 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 915 | Test Method: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 916 | 1. Get vSG corresponding to vcpe |
| 917 | 2. Get dhcp ip to vcpe interface |
| 918 | 3. Add static route to destination route in test container |
| 919 | 4. From test container ping to destination route and verify ping success |
| 920 | 5. Login to compute node and execute command to pause vcpe container |
| 921 | 6. From test container ping to destination route and verify ping success |
| 922 | """ |
| 923 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 924 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 925 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 926 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 927 | df = defer.Deferred() |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 928 | def test_external_connectivity(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 929 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 930 | df.callback(0) |
| 931 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 932 | host = '8.8.8.8' |
| 933 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 934 | try: |
| 935 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 936 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 937 | assert_equal(st, False) |
| 938 | st, _ = vsg.run_cmd('sudo docker pause {}'.format(vcpe_name)) |
| 939 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 940 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 941 | vsg.run_cmd('sudo docker unpause {}'.format(vcpe_name)) |
| 942 | except Exception as error: |
| 943 | log.info('Got Unexpected error %s'%error) |
| 944 | vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
| 945 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 946 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 947 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 948 | df.callback(0) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 949 | reactor.callLater(0, test_external_connectivity, df) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 950 | return df |
| 951 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 952 | @deferred(30) |
| 953 | def test_vsg_firewall_with_deny_destination_ip_set(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 954 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 955 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 956 | 1. Get vSG corresponding to vcpe |
| 957 | 2. Login to compute node |
| 958 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 959 | 4. From cord-tester ping to the denied IP address |
| 960 | 5. Verifying that ping should not be successful |
| 961 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 962 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 963 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 964 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 965 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 966 | df = defer.Deferred() |
| 967 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 968 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 969 | df.callback(0) |
| 970 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 971 | host = '8.8.8.8' |
| 972 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 973 | try: |
| 974 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 975 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 976 | assert_equal(st, False) |
| 977 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 978 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 979 | assert_equal(st, True) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 980 | except Exception as error: |
| 981 | log.info('Got Unexpected error %s'%error) |
| 982 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 983 | finally: |
| 984 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 985 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 986 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 987 | df.callback(0) |
| 988 | reactor.callLater(0, vcpe_firewall, df) |
| 989 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 990 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 991 | @deferred(60) |
| 992 | def test_vsg_firewall_with_rule_to_add_and_delete_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 993 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 994 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 995 | 1. Get vSG corresponding to vcpe |
| 996 | 2. Login to compute node |
| 997 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 998 | 4. From cord-tester ping to the denied IP address |
| 999 | 5. Verifying that ping should not be successful |
| 1000 | 6. Delete the iptable rule in vcpe |
| 1001 | 7. From cord-tester ping to the denied IP address |
| 1002 | 8. Verifying the ping should success |
| 1003 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1004 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1005 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1006 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1007 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1008 | df = defer.Deferred() |
| 1009 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1010 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1011 | df.callback(0) |
| 1012 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1013 | host = '8.8.8.8' |
| 1014 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1015 | try: |
| 1016 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 1017 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1018 | assert_equal(st, False) |
| 1019 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1020 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1021 | assert_equal(st, True) |
| 1022 | st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1023 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1024 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1025 | except Exception as error: |
| 1026 | log.info('Got Unexpected error %s'%error) |
| 1027 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1028 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1029 | finally: |
| 1030 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1031 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1032 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1033 | df.callback(0) |
| 1034 | reactor.callLater(0, vcpe_firewall, df) |
| 1035 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1036 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1037 | @deferred(40) |
| 1038 | def test_vsg_firewall_verifying_reachability_for_non_blocked_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1039 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1040 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1041 | 1. Get vSG corresponding to vcpe |
| 1042 | 2. Login to compute node |
| 1043 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 1044 | 4. From cord-tester ping to the denied IP address |
| 1045 | 5. Verifying that ping should not be successful |
| 1046 | 6. From cord-tester ping to the denied IP address other than the denied one |
| 1047 | 7. Verifying the ping should success |
| 1048 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1049 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1050 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1051 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1052 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1053 | df = defer.Deferred() |
| 1054 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1055 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1056 | df.callback(0) |
| 1057 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1058 | host1 = '8.8.8.8' |
| 1059 | host2 = '204.79.197.203' |
| 1060 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1061 | try: |
| 1062 | self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
| 1063 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1064 | assert_equal(st, False) |
| 1065 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1066 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1067 | assert_equal(st, True) |
| 1068 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1069 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1070 | except Exception as error: |
| 1071 | log.info('Got Unexpected error %s'%error) |
| 1072 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1073 | finally: |
| 1074 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1075 | self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1076 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1077 | df.callback(0) |
| 1078 | reactor.callLater(0, vcpe_firewall, df) |
| 1079 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1080 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1081 | @deferred(60) |
| 1082 | def test_vsg_firewall_appending_rules_with_deny_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1083 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1084 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1085 | 1. Get vSG corresponding to vcpe |
| 1086 | 2. Login to compute node |
| 1087 | 3. Execute iptable command on vcpe from compute node to deny a destination IP1 |
| 1088 | 4. From cord-tester ping to the denied IP address IP1 |
| 1089 | 5. Verifying that ping should not be successful |
| 1090 | 6. Execute iptable command on vcpe from compute node to deny a destination IP2 |
| 1091 | 6. From cord-tester ping to the denied IP address IP2 |
| 1092 | 7. Verifying that ping should not be successful |
| 1093 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1094 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1095 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1096 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1097 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1098 | df = defer.Deferred() |
| 1099 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1100 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1101 | df.callback(0) |
| 1102 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1103 | host1 = '8.8.8.8' |
| 1104 | host2 = '204.79.197.203' |
| 1105 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1106 | try: |
| 1107 | self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
| 1108 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1109 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1110 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1111 | assert_equal(st, False) |
| 1112 | st,_ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1113 | time.sleep(1) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1114 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1115 | assert_equal(st, True) |
| 1116 | st, out = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1117 | log.info('host2 ping output is %s'%out) |
| 1118 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1119 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,host2)) |
| 1120 | time.sleep(1) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1121 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1122 | assert_equal(st,True) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1123 | except Exception as error: |
| 1124 | log.info('Got Unexpected error %s'%error) |
| 1125 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1126 | finally: |
| 1127 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1128 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2)) |
| 1129 | self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1130 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1131 | df.callback(0) |
| 1132 | reactor.callLater(0, vcpe_firewall, df) |
| 1133 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1134 | |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1135 | @deferred(TIMEOUT) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1136 | def test_vsg_firewall_removing_one_rule_denying_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1137 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1138 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1139 | 1. Get vSG corresponding to vcpe |
| 1140 | 2. Login to compute node |
| 1141 | 3. Execute iptable command on vcpe from compute node to deny a destination IP1 |
| 1142 | 4. Execute iptable command on vcpe from compute node to deny a destination IP2 |
| 1143 | 5. From cord-tester ping to the denied IP address IP1 |
| 1144 | 6. Verifying that ping should not be successful |
| 1145 | 7. From cord-tester ping to the denied IP address IP2 |
| 1146 | 8. Verifying that ping should not be successful |
| 1147 | 9. Execute iptable command on vcpe from compute node to remove deny a destination IP2 rule |
| 1148 | 10. From cord-tester ping to the denied IP address IP2 |
| 1149 | 11. Verifying the ping should success |
| 1150 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1151 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1152 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1153 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1154 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1155 | df = defer.Deferred() |
| 1156 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1157 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1158 | df.callback(0) |
| 1159 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1160 | host1 = '8.8.8.8' |
| 1161 | host2 = '204.79.197.203' |
| 1162 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1163 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1164 | self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1165 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1166 | assert_equal(st, False) |
| 1167 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1168 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host2)) |
| 1169 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1170 | assert_equal(st, True) |
| 1171 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1172 | assert_equal(st,True) |
| 1173 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2)) |
| 1174 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1175 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1176 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1177 | assert_equal(st, True) |
| 1178 | except Exception as error: |
| 1179 | log.info('Got Unexpected error %s'%error) |
| 1180 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1181 | finally: |
| 1182 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host1)) |
| 1183 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host2)) |
| 1184 | self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1185 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1186 | df.callback(0) |
| 1187 | reactor.callLater(0, vcpe_firewall, df) |
| 1188 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1189 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1190 | @deferred(60) |
| 1191 | def test_vsg_firewall_changing_rule_id_deny_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1192 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1193 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1194 | 1. Get vSG corresponding to vcpe |
| 1195 | 2. Login to compute node |
| 1196 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 1197 | 5. From cord-tester ping to the denied IP address IP1 |
| 1198 | 6. Verifying that ping should not be successful |
| 1199 | 9. Execute iptable command on vcpe from compute node to change the rule ID to 2 to deny the same destination IP |
| 1200 | 10. From cord-tester ping to the denied IP address IP |
| 1201 | 11. Verifying that ping should not be successful |
| 1202 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1203 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1204 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1205 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1206 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1207 | df = defer.Deferred() |
| 1208 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1209 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1210 | df.callback(0) |
| 1211 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1212 | host = '8.8.8.8' |
| 1213 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1214 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1215 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1216 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1217 | assert_equal(st, False) |
| 1218 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1219 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1220 | assert_equal(st, True) |
| 1221 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP '.format(vcpe_name,host)) |
| 1222 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1223 | assert_equal(st,True) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1224 | except Exception as error: |
| 1225 | log.info('Got Unexpected error %s'%error) |
| 1226 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1227 | finally: |
| 1228 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1229 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1230 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1231 | df.callback(0) |
| 1232 | reactor.callLater(0, vcpe_firewall, df) |
| 1233 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1234 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1235 | @deferred(50) |
| 1236 | def test_vsg_firewall_changing_deny_rule_to_accept_dest_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1237 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1238 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1239 | 1. Get vSG corresponding to vcpe |
| 1240 | 2. Login to compute node |
| 1241 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 1242 | 5. From cord-tester ping to the denied IP address IP1 |
| 1243 | 6. Verifying that ping should not be successful |
| 1244 | 9. Execute iptable command on vcpe from compute node to accept the same destination IP |
| 1245 | 10. From cord-tester ping to the accepted IP |
| 1246 | 11. Verifying the ping should success |
| 1247 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1248 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1249 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1250 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1251 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1252 | df = defer.Deferred() |
| 1253 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1254 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1255 | df.callback(0) |
| 1256 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1257 | host = '8.8.8.8' |
| 1258 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1259 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1260 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1261 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1262 | assert_equal(st, False) |
| 1263 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1264 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1265 | assert_equal(st, True) |
| 1266 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -d {} -j ACCEPT'.format(vcpe_name,host)) |
| 1267 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1268 | assert_equal(st,False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1269 | except Exception as error: |
| 1270 | log.info('Got Unexpected error %s'%error) |
| 1271 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1272 | finally: |
| 1273 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1274 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j ACCEPT'.format(vcpe_name,host)) |
| 1275 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1276 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1277 | df.callback(0) |
| 1278 | reactor.callLater(0, vcpe_firewall, df) |
| 1279 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1280 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1281 | @deferred(60) |
| 1282 | def test_vsg_firewall_denying_destination_network(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1283 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1284 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1285 | 1. Get vSG corresponding to vcpe |
| 1286 | 2. Login to compute node |
| 1287 | 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet |
| 1288 | 4. From cord-tester ping to the denied IP address IP1 in the denied subnet |
| 1289 | 5. Verifying that ping should not be successful |
| 1290 | 6. From cord-tester ping to the denied IP address IP2 in the denied subnet |
| 1291 | 7. Verifying that ping should not be successful |
| 1292 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1293 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1294 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1295 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1296 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1297 | df = defer.Deferred() |
| 1298 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1299 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1300 | df.callback(0) |
| 1301 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1302 | network = '204.79.197.192/28' |
| 1303 | host1 = '204.79.197.203' |
| 1304 | host2 = '204.79.197.210' |
| 1305 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1306 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1307 | self.add_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1308 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1309 | assert_equal(st, False) |
| 1310 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network)) |
| 1311 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1312 | assert_equal(st, True) |
| 1313 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1314 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1315 | except Exception as error: |
| 1316 | log.info('Got Unexpected error %s'%error) |
| 1317 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1318 | finally: |
| 1319 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network)) |
| 1320 | self.del_static_route_via_vcpe_interface([host1,host2],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1321 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1322 | df.callback(0) |
| 1323 | reactor.callLater(0, vcpe_firewall, df) |
| 1324 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1325 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1326 | @deferred(60) |
| 1327 | def test_vsg_firewall_denying_destination_network_subnet_modification(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1328 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1329 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1330 | 1. Get vSG corresponding to vcpe |
| 1331 | 2. Login to compute node |
| 1332 | 3. Execute iptable command on vcpe from compute node to deny a destination IP subnet |
| 1333 | 4. From cord-tester ping to the denied IP address IP1 in the denied subnet |
| 1334 | 5. Verifying that ping should not be successful |
| 1335 | 6. From cord-tester ping to the denied IP address IP2 in the denied subnet |
| 1336 | 7. Verifying that ping should not be successful |
| 1337 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1338 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1339 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1340 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1341 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1342 | df = defer.Deferred() |
| 1343 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1344 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1345 | df.callback(0) |
| 1346 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1347 | network1 = '204.79.197.192/28' |
| 1348 | network2 = '204.79.197.192/27' |
| 1349 | host1 = '204.79.197.203' |
| 1350 | host2 = '204.79.197.210' |
| 1351 | host3 = '204.79.197.224' |
| 1352 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1353 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1354 | self.add_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1355 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1356 | assert_equal(st, False) |
| 1357 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,network1)) |
| 1358 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1359 | assert_equal(st, True) |
| 1360 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1361 | assert_equal(st,False) |
| 1362 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD 2 -d {} -j DROP'.format(vcpe_name,network2)) |
| 1363 | st, _ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 1364 | assert_equal(st, True) |
| 1365 | st, _ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 1366 | assert_equal(st, True) |
| 1367 | st, _ = getstatusoutput('ping -c 1 {}'.format(host3)) |
| 1368 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1369 | except Exception as error: |
| 1370 | log.info('Got Unexpected error %s'%error) |
| 1371 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1372 | finally: |
| 1373 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network1)) |
| 1374 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,network2)) |
| 1375 | self.del_static_route_via_vcpe_interface([host1,host2,host3],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1376 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1377 | df.callback(0) |
| 1378 | reactor.callLater(0, vcpe_firewall, df) |
| 1379 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1380 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1381 | @deferred(40) |
| 1382 | def test_vsg_firewall_with_deny_source_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1383 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1384 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1385 | 1. Get vSG corresponding to vcpe |
| 1386 | 2. Login to compute node |
| 1387 | 3. Execute iptable command on vcpe from compute node to deny a source IP |
| 1388 | 4. From cord-tester ping to 8.8.8.8 from the denied IP |
| 1389 | 5. Verifying that ping should not be successful |
| 1390 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1391 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1392 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1393 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1394 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1395 | df = defer.Deferred() |
| 1396 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1397 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1398 | df.callback(0) |
| 1399 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1400 | host = '8.8.8.8' |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1401 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1402 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1403 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 1404 | source_ip = get_ip(vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1405 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1406 | assert_equal(st, False) |
| 1407 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1408 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1409 | assert_equal(st, True) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1410 | except Exception as error: |
| 1411 | log.info('Got Unexpected error %s'%error) |
| 1412 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1413 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1414 | finally: |
| 1415 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1416 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1417 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1418 | df.callback(0) |
| 1419 | reactor.callLater(0, vcpe_firewall, df) |
| 1420 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1421 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1422 | @deferred(40) |
| 1423 | def test_vsg_firewall_rule_with_add_and_delete_deny_source_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1424 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1425 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1426 | 1. Get vSG corresponding to vcpe |
| 1427 | 2. Login to compute node |
| 1428 | 3. Execute iptable command on vcpe from compute node to deny a source IP |
| 1429 | 4. From cord-tester ping to 8.8.8.8 from the denied IP |
| 1430 | 5. Verifying that ping should not be successful |
| 1431 | 6. Delete the iptable rule in vcpe |
| 1432 | 7. From cord-tester ping to 8.8.8.8 from the denied IP |
| 1433 | 8. Verifying the ping should success |
| 1434 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1435 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1436 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1437 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1438 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1439 | df = defer.Deferred() |
| 1440 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1441 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1442 | df.callback(0) |
| 1443 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1444 | host = '8.8.8.8' |
| 1445 | source_ip = get_ip(self.vcpe_dhcp) |
| 1446 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1447 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1448 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 1449 | source_ip = get_ip(vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1450 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1451 | assert_equal(st, False) |
| 1452 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1453 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1454 | assert_equal(st, True) |
| 1455 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1456 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1457 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1458 | except Exception as error: |
| 1459 | log.info('Got Unexpected error %s'%error) |
| 1460 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1461 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1462 | finally: |
| 1463 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -s {} -j DROP'.format(vcpe_name,source_ip)) |
| 1464 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1465 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1466 | df.callback(0) |
| 1467 | reactor.callLater(0, vcpe_firewall, df) |
| 1468 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1469 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1470 | @deferred(40) |
| 1471 | def test_vsg_firewall_rule_with_deny_icmp_protocol_echo_requests_type(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1472 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1473 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1474 | 1. Get vSG corresponding to vcpe |
| 1475 | 2. Login to compute node |
| 1476 | 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets |
| 1477 | 4. From cord-tester ping to 8.8.8.8 |
| 1478 | 5. Verifying that ping should not be successful |
| 1479 | 6. Delete the iptable rule |
| 1480 | 7. From cord-tester ping to 8.8.8.8 |
| 1481 | 8. Verifying the ping should success |
| 1482 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1483 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1484 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1485 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1486 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1487 | df = defer.Deferred() |
| 1488 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1489 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1490 | df.callback(0) |
| 1491 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1492 | host = '8.8.8.8' |
| 1493 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1494 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1495 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1496 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1497 | assert_equal(st, False) |
| 1498 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1499 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1500 | assert_equal(st, True) |
| 1501 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1502 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1503 | assert_equal(st, False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1504 | except Exception as error: |
| 1505 | log.info('Got Unexpected error %s'%error) |
| 1506 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1507 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1508 | finally: |
| 1509 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1510 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1511 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1512 | df.callback(0) |
| 1513 | reactor.callLater(0, vcpe_firewall, df) |
| 1514 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1515 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1516 | @deferred(40) |
| 1517 | def test_vsg_firewall_rule_with_deny_icmp_protocol_echo_reply_type(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1518 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1519 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1520 | 1. Get vSG corresponding to vcpe |
| 1521 | 2. Login to compute node |
| 1522 | 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets |
| 1523 | 4. From cord-tester ping to 8.8.8.8 |
| 1524 | 5. Verifying that ping should not be successful |
| 1525 | 6. Delete the iptable rule |
| 1526 | 7. From cord-tester ping to 8.8.8.8 |
| 1527 | 8. Verifying the ping should success |
| 1528 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1529 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1530 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1531 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1532 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1533 | df = defer.Deferred() |
| 1534 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1535 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1536 | df.callback(0) |
| 1537 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1538 | host = '8.8.8.8' |
| 1539 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1540 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1541 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1542 | st, _ = getstatusoutput('ping -c 1 {}'.format('8.8.8.8')) |
| 1543 | assert_equal(st, False) |
| 1544 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1545 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1546 | assert_equal(st, True) |
| 1547 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1548 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1549 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1550 | except Exception as error: |
| 1551 | log.info('Got Unexpected error %s'%error) |
| 1552 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1553 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1554 | finally: |
| 1555 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1556 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1557 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1558 | df.callback(0) |
| 1559 | reactor.callLater(0, vcpe_firewall, df) |
| 1560 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1561 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1562 | @deferred(40) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 1563 | def test_vsg_firewall_changing_deny_rule_to_accept_rule_with_icmp_protocol_echo_requests_type(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1564 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1565 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1566 | 1. Get vSG corresponding to vcpe |
| 1567 | 2. Login to compute node |
| 1568 | 3. Execute iptable command on vcpe from compute node to deny icmp echo-requests type protocol packets |
| 1569 | 4. From cord-tester ping to 8.8.8.8 |
| 1570 | 5. Verifying that ping should not be successful |
| 1571 | 6. Insert another rule to accept the icmp-echo requests protocol packets |
| 1572 | 7. From cord-tester ping to 8.8.8.8 |
| 1573 | 8. Verifying the ping should success |
| 1574 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1575 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1576 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1577 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1578 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1579 | df = defer.Deferred() |
| 1580 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1581 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1582 | df.callback(0) |
| 1583 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1584 | host = '8.8.8.8' |
| 1585 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1586 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1587 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1588 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1589 | assert_equal(st, False) |
| 1590 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1591 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1592 | assert_equal(st, True) |
| 1593 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name)) |
| 1594 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1595 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1596 | except Exception as error: |
| 1597 | log.info('Got Unexpected error %s'%error) |
| 1598 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1599 | finally: |
| 1600 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j DROP'.format(vcpe_name)) |
| 1601 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-request -j ACCEPT'.format(vcpe_name)) |
| 1602 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1603 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1604 | df.callback(0) |
| 1605 | reactor.callLater(0, vcpe_firewall, df) |
| 1606 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1607 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1608 | @deferred(40) |
| 1609 | def test_vsg_firewall_changing_deny_rule_to_accept_rule_with_icmp_protocol_echo_reply_type(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1610 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1611 | Test Method: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1612 | 1. Get vSG corresponding to vcpe |
| 1613 | 2. Login to compute node |
| 1614 | 3. Execute iptable command on vcpe from compute node to deny icmp echo-reply type protocol packets |
| 1615 | 4. From cord-tester ping to 8.8.8.8 |
| 1616 | 5. Verifying the ping should not success |
| 1617 | 6. Insert another rule to accept the icmp-echo requests protocol packets |
| 1618 | 7. From cord-tester ping to 8.8.8.8 |
| 1619 | 8. Verifying the ping should success |
| 1620 | """ |
| 1621 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1622 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1623 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1624 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1625 | df = defer.Deferred() |
| 1626 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1627 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1628 | df.callback(0) |
| 1629 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1630 | host = '8.8.8.8' |
| 1631 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1632 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1633 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1634 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1635 | assert_equal(st, False) |
| 1636 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1637 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1638 | assert_equal(st, True) |
| 1639 | st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name)) |
| 1640 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1641 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1642 | except Exception as error: |
| 1643 | log.info('Got Unexpected error %s'%error) |
| 1644 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1645 | finally: |
| 1646 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j DROP'.format(vcpe_name)) |
| 1647 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp --icmp-type echo-reply -j ACCEPT'.format(vcpe_name)) |
| 1648 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1649 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1650 | df.callback(0) |
| 1651 | reactor.callLater(0, vcpe_firewall, df) |
| 1652 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1653 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1654 | @deferred(40) |
| 1655 | def test_vsg_firewall_for_deny_icmp_protocol(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1656 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1657 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1658 | 1. Get vSG corresponding to vcpe |
| 1659 | 2. Login to compute node |
| 1660 | 3. Execute iptable command on vcpe from compute node to deny icmp protocol packets |
| 1661 | 4. From cord-tester ping to 8.8.8.8 |
| 1662 | 5. Verifying that ping should not be successful |
| 1663 | 6. Delete the iptable rule |
| 1664 | 7. From cord-tester ping to 8.8.8.8 |
| 1665 | 8. Verifying the ping should success |
| 1666 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1667 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1668 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1669 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1670 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1671 | df = defer.Deferred() |
| 1672 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1673 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1674 | df.callback(0) |
| 1675 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1676 | host = '8.8.8.8' |
| 1677 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1678 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1679 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1680 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1681 | assert_equal(st, False) |
| 1682 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1683 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1684 | assert_equal(st, True) |
| 1685 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1686 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1687 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1688 | except Exception as error: |
| 1689 | log.info('Got Unexpected error %s'%error) |
| 1690 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1691 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1692 | finally: |
| 1693 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1694 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1695 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1696 | df.callback(0) |
| 1697 | reactor.callLater(0, vcpe_firewall, df) |
| 1698 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1699 | |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1700 | @deferred(60) |
| 1701 | def test_vsg_firewall_rule_deny_icmp_protocol_and_destination_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1702 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1703 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1704 | 1. Get vSG corresponding to vcpe |
| 1705 | 2. Login to compute node |
| 1706 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 1707 | 4. From cord-tester ping to 8.8.8.8 |
| 1708 | 5. Verifying that ping should not be successful |
| 1709 | 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets |
| 1710 | 7. From cord-tester ping to 8.8.8.8 |
| 1711 | 8. Verifying the ping should success |
| 1712 | 9. Delete the rule added in step 3 |
| 1713 | 10. From cord-tester ping to 8.8.8.8 |
| 1714 | 11. Verifying that ping should not be successful |
| 1715 | 12. Delete the rule added in step 6 |
| 1716 | 13. From cord-tester ping to 8.8.8.8 |
| 1717 | 14. Verifying the ping should success |
| 1718 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1719 | if not vcpe_name: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1720 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1721 | if not vcpe_intf: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1722 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1723 | df = defer.Deferred() |
| 1724 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1725 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1726 | df.callback(0) |
| 1727 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1728 | host = '8.8.8.8' |
| 1729 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1730 | try: |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1731 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1732 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1733 | assert_equal(st, False) |
| 1734 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1735 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1736 | assert_equal(st, True) |
| 1737 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1738 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1739 | assert_equal(st, True) |
| 1740 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1741 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1742 | assert_equal(st, True) |
| 1743 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1744 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1745 | assert_equal(st,False) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1746 | except Exception as error: |
| 1747 | log.info('Got Unexpected error %s'%error) |
| 1748 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1749 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1750 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1751 | finally: |
| 1752 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1753 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1754 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1755 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1756 | df.callback(0) |
| 1757 | reactor.callLater(0, vcpe_firewall, df) |
| 1758 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1759 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1760 | @deferred(100) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1761 | def test_vsg_firewall_flushing_all_configured_rules(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1762 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1763 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1764 | 1. Get vSG corresponding to vcpe |
| 1765 | 2. Login to compute node |
| 1766 | 3. Execute iptable command on vcpe from compute node to deny a destination IP |
| 1767 | 4. From cord-tester ping to 8.8.8.8 |
| 1768 | 5. Verifying that ping should not be successful |
| 1769 | 6. Execute iptable command on vcpe from compute node to deny icmp protocol packets |
| 1770 | 7. From cord-tester ping to 8.8.8.8 |
| 1771 | 8. Verifying the ping should success |
| 1772 | 9. Flush all the iptable rules configuraed in vcpe |
| 1773 | 10. Delete the rule added in step 6 |
| 1774 | 11. From cord-tester ping to 8.8.8.8 |
| 1775 | 12. Verifying the ping should success |
| 1776 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1777 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1778 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1779 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1780 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1781 | df = defer.Deferred() |
| 1782 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1783 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1784 | df.callback(0) |
| 1785 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1786 | host = '8.8.8.8' |
| 1787 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1788 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1789 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1790 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1791 | assert_equal(st, False) |
| 1792 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 1793 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1794 | assert_equal(st, True) |
| 1795 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1796 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1797 | assert_equal(st, True) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1798 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -F FORWARD'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1799 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1800 | assert_equal(st, True) |
| 1801 | vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
| 1802 | status = False |
| 1803 | clock = 0 |
| 1804 | while(clock <= 30): |
| 1805 | time.sleep(5) |
| 1806 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1807 | if st == False: |
| 1808 | status = True |
| 1809 | break |
| 1810 | clock += 5 |
| 1811 | assert_equal(status, True) |
| 1812 | except Exception as error: |
| 1813 | log.info('Got Unexpected error %s'%error) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1814 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1815 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p icmp -j DROP'.format(vcpe_name)) |
| 1816 | raise |
| 1817 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1818 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1819 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1820 | df.callback(0) |
| 1821 | reactor.callLater(0, vcpe_firewall, df) |
| 1822 | return df |
Anil Kumar Sanka | d47023a | 2017-03-29 21:11:09 +0000 | [diff] [blame] | 1823 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1824 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1825 | def test_vsg_firewall_deny_all_ipv4_traffic(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1826 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1827 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1828 | 1. Get vSG corresponding to vcpe |
| 1829 | 2. Login to compute node |
| 1830 | 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic |
| 1831 | 4. From cord-tester ping to 8.8.8.8 |
| 1832 | 5. Verifying that ping should not be successful |
| 1833 | 6. Delete the iptable rule added |
| 1834 | 7. From cord-tester ping to 8.8.8.8 |
| 1835 | 8. Verifying the ping should success |
| 1836 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1837 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1838 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1839 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1840 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1841 | df = defer.Deferred() |
| 1842 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1843 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1844 | df.callback(0) |
| 1845 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1846 | host = '8.8.8.8' |
| 1847 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1848 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1849 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1850 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1851 | assert_equal(st, False) |
| 1852 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name)) |
| 1853 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1854 | assert_equal(st, True) |
| 1855 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name)) |
| 1856 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1857 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1858 | except Exception as error: |
| 1859 | log.info('Got Unexpected error %s'%error) |
| 1860 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name)) |
| 1861 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1862 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1863 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1864 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1865 | df.callback(0) |
| 1866 | reactor.callLater(0, vcpe_firewall, df) |
| 1867 | return df |
Anil Kumar Sanka | 966c193 | 2017-03-31 00:48:31 +0000 | [diff] [blame] | 1868 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1869 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1870 | def test_vsg_firewall_replacing_deny_rule_to_accept_rule_ipv4_traffic(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1871 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1872 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 1873 | 1. Get vSG corresponding to vcpe |
| 1874 | 2. Login to compute node |
| 1875 | 3. Execute iptable command on vcpe from compute node to deny all ipv4 Traffic |
| 1876 | 4. From cord-tester ping to 8.8.8.8 |
| 1877 | 5. Verifying that ping should not be successful |
| 1878 | 6. Replace the deny rule added in step 3 with accept rule |
| 1879 | 7. From cord-tester ping to 8.8.8.8 |
| 1880 | 8. Verifying the ping should success |
| 1881 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1882 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1883 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1884 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1885 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1886 | df = defer.Deferred() |
| 1887 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1888 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1889 | df.callback(0) |
| 1890 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1891 | host = '8.8.8.8' |
| 1892 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1893 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1894 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1895 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1896 | assert_equal(st, False) |
| 1897 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name)) |
| 1898 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1899 | assert_equal(st, True) |
| 1900 | st,output = vsg.run_cmd('sudo docker exec {} iptables -R FORWARD 1 -4 -j ACCEPT'.format(vcpe_name)) |
| 1901 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1902 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1903 | except Exception as error: |
| 1904 | log.info('Got Unexpected error %s'%error) |
| 1905 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1906 | finally: |
| 1907 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name)) |
| 1908 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1909 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1910 | df.callback(0) |
| 1911 | reactor.callLater(0, vcpe_firewall, df) |
| 1912 | return df |
Anil Kumar Sanka | 966c193 | 2017-03-31 00:48:31 +0000 | [diff] [blame] | 1913 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1914 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1915 | def test_vsg_firewall_deny_all_traffic_coming_on_lan_interface_in_vcpe(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1916 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1917 | Test Method: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1918 | 1. Get vSG corresponding to vcpe |
| 1919 | 2. Login to compute node |
| 1920 | 3. Execute iptable command on vcpe from compute node to deny all the traffic coming on lan interface inside vcpe container |
| 1921 | 4. From cord-tester ping to 8.8.8.8 |
| 1922 | 5. Verifying the ping should not success |
| 1923 | 6. Delete the iptable rule added |
| 1924 | 7. From cord-tester ping to 8.8.8.8 |
| 1925 | 8. Verifying the ping should success |
| 1926 | """ |
| 1927 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1928 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1929 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1930 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1931 | df = defer.Deferred() |
| 1932 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1933 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1934 | df.callback(0) |
| 1935 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1936 | host = '8.8.8.8' |
| 1937 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1938 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1939 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1940 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1941 | assert_equal(st, False) |
| 1942 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -j DROP'.format(vcpe_name)) |
| 1943 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1944 | assert_equal(st, True) |
| 1945 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name)) |
| 1946 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1947 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1948 | except Exception as error: |
| 1949 | log.info('Got Unexpected error %s'%error) |
| 1950 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -j DROP'.format(vcpe_name)) |
| 1951 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1952 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1953 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1954 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1955 | df.callback(0) |
| 1956 | reactor.callLater(0, vcpe_firewall, df) |
| 1957 | return df |
| 1958 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1959 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 1960 | def test_vsg_firewall_deny_all_traffic_going_out_of_wan_interface_in_vcpe(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1961 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 1962 | Test Method: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1963 | 1. Get vSG corresponding to vcpe |
| 1964 | 2. Login to compute node |
| 1965 | 3. Execute iptable command on vcpe from compute node to deny all the traffic going out of wan interface inside vcpe container |
| 1966 | 4. From cord-tester ping to 8.8.8.8 |
| 1967 | 5. Verifying the ping should not success |
| 1968 | 6. Delete the iptable rule added |
| 1969 | 7. From cord-tester ping to 8.8.8.8 |
| 1970 | 8. Verifying the ping should success |
| 1971 | """ |
| 1972 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1973 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1974 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1975 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1976 | df = defer.Deferred() |
| 1977 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 1978 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 1979 | df.callback(0) |
| 1980 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1981 | host = '8.8.8.8' |
| 1982 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 1983 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1984 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1985 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1986 | assert_equal(st, False) |
| 1987 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -o eth0 -j DROP'.format(vcpe_name)) |
| 1988 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1989 | assert_equal(st, True) |
| 1990 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name)) |
| 1991 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 1992 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1993 | except Exception as error: |
| 1994 | log.info('Got Unexpected error %s'%error) |
| 1995 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -o eth0 -j DROP'.format(vcpe_name)) |
| 1996 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1997 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 1998 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 1999 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2000 | df.callback(0) |
| 2001 | reactor.callLater(0, vcpe_firewall, df) |
| 2002 | return df |
| 2003 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2004 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2005 | def test_vsg_firewall_deny_all_traffic_from_lan_to_wan_in_vcpe(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 2006 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2007 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 2008 | 1. Get vSG corresponding to vcpe |
| 2009 | 2. Login to compute node |
| 2010 | 3. Execute iptable command on vcpe from compute node to deny all the traffic from lan to wan interface in vcpe |
| 2011 | 4. From cord-tester ping to 8.8.8.8 |
| 2012 | 5. Verifying that ping should not be successful |
| 2013 | 6. Delete the iptable rule added |
| 2014 | 7. From cord-tester ping to 8.8.8.8 |
| 2015 | 8. Verifying the ping should success |
| 2016 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2017 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2018 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2019 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2020 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2021 | df = defer.Deferred() |
| 2022 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 2023 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 2024 | df.callback(0) |
| 2025 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2026 | host = '8.8.8.8' |
| 2027 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2028 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2029 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2030 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2031 | assert_equal(st, False) |
| 2032 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name)) |
| 2033 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2034 | assert_equal(st, True) |
| 2035 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name)) |
| 2036 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2037 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2038 | except Exception as error: |
| 2039 | log.info('Got Unexpected error %s'%error) |
| 2040 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -i eth1 -o eth0 -j DROP'.format(vcpe_name)) |
| 2041 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2042 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2043 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2044 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2045 | df.callback(0) |
| 2046 | reactor.callLater(0, vcpe_firewall, df) |
| 2047 | return df |
Anil Kumar Sanka | 966c193 | 2017-03-31 00:48:31 +0000 | [diff] [blame] | 2048 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2049 | @deferred(60) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2050 | def test_vsg_firewall_deny_all_dns_traffic(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2051 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2052 | Test Method: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2053 | 1. Get vSG corresponding to vcpe |
| 2054 | 2. Login to compute node |
| 2055 | 3. Execute iptable command on vcpe from compute node to deny all dns Traffic |
| 2056 | 4. From cord-tester ping to www.google.com |
| 2057 | 5. Verifying the ping should not success |
| 2058 | 6. Delete the iptable rule added |
| 2059 | 7. From cord-tester ping to www.google.com |
| 2060 | 8. Verifying the ping should success |
| 2061 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2062 | mgmt = 'eth0' |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2063 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2064 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2065 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2066 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2067 | df = defer.Deferred() |
| 2068 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 2069 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 2070 | df.callback(0) |
| 2071 | return |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2072 | host = 'google-public-dns-a.google.com' |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2073 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2074 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2075 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name)) |
| 2076 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2077 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2078 | assert_not_equal(st, False) |
| 2079 | VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf) |
| 2080 | st,output = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name)) |
| 2081 | vcpe_ip = VSGAccess.vcpe_get_dhcp(vcpe_intf, mgmt = mgmt) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2082 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2083 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2084 | VSGAccess.restore_interface_config(mgmt, vcpe=vcpe_intf) |
| 2085 | except Exception as error: |
| 2086 | log.info('Got Unexpected error %s'%error) |
| 2087 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -p udp --dport 53 -j DROP'.format(vcpe_name)) |
| 2088 | VSGAccess.restore_interface_config(mgmt,vcpe=vcpe_intf) |
| 2089 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2090 | df.callback(0) |
| 2091 | reactor.callLater(0, vcpe_firewall, df) |
| 2092 | return df |
| 2093 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2094 | @deferred(60) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2095 | def test_vsg_firewall_deny_all_ipv4_traffic_vcpe_container_restart(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 2096 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2097 | Test Method: |
Anil Kumar Sanka | 72755c9 | 2017-04-06 17:19:02 +0000 | [diff] [blame] | 2098 | 1. Get vSG corresponding to vcpe |
| 2099 | 2. Login to compute node |
| 2100 | 3. Execute iptable command on vcpe from compute node to deny all dns Traffic |
| 2101 | 4. From cord-tester ping to www.google.com |
| 2102 | 5. Verifying that ping should not be successful |
| 2103 | 6. Delete the iptable rule added |
| 2104 | 7. From cord-tester ping to www.google.com |
| 2105 | 8. Verifying the ping should success |
| 2106 | """ |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2107 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2108 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2109 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2110 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2111 | df = defer.Deferred() |
| 2112 | def vcpe_firewall(df): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 2113 | if self.on_pod is False: |
A R Karthick | 93ba8d0 | 2017-04-13 11:59:58 -0700 | [diff] [blame] | 2114 | df.callback(0) |
| 2115 | return |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2116 | host = '8.8.8.8' |
| 2117 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2118 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2119 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2120 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2121 | assert_equal(st, False) |
| 2122 | st,output = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -4 -j DROP'.format(vcpe_name)) |
| 2123 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2124 | assert_equal(st, True) |
| 2125 | st,output = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2126 | clock = 0 |
| 2127 | status = False |
| 2128 | while(clock <= 20 ): |
| 2129 | time.sleep(5) |
| 2130 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2131 | if st == False: |
| 2132 | status = True |
| 2133 | break |
| 2134 | clock += 5 |
| 2135 | assert_equal(status, True) |
| 2136 | except Exception as error: |
| 2137 | log.info('Got Unexpected error %s'%error) |
| 2138 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -4 -j DROP'.format(vcpe_name)) |
| 2139 | raise |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2140 | finally: |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2141 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2142 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | a357c6a | 2017-04-12 17:52:24 +0000 | [diff] [blame] | 2143 | df.callback(0) |
| 2144 | reactor.callLater(0, vcpe_firewall, df) |
| 2145 | return df |
Anil Kumar Sanka | 966c193 | 2017-03-31 00:48:31 +0000 | [diff] [blame] | 2146 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2147 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2148 | def test_vsg_nat_dnat_modifying_destination_ip(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2149 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2150 | Test Method: |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2151 | 1. Get vSG corresponding to vcpe |
| 2152 | 2. Login to compute node |
| 2153 | 3. Execute iptable command on vcpe from compute node to deny all dns Traffic |
| 2154 | 4. From cord-tester ping to www.google.com |
| 2155 | 5. Verifying the ping should not success |
| 2156 | 6. Delete the iptable rule added |
| 2157 | 7. From cord-tester ping to www.google.com |
| 2158 | 8. Verifying the ping should success |
| 2159 | """ |
| 2160 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2161 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2162 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2163 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2164 | df = defer.Deferred() |
| 2165 | def vcpe_firewall(df): |
| 2166 | host = '8.8.8.8' |
| 2167 | dst_ip = '123.123.123.123' |
| 2168 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2169 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2170 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2171 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2172 | assert_equal(st, False) |
| 2173 | st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
| 2174 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2175 | assert_equal(st, True) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2176 | except Exception as error: |
| 2177 | log.info('Got Unexpected error %s'%error) |
| 2178 | raise |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2179 | finally: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2180 | |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2181 | vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
| 2182 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2183 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2184 | df.callback(0) |
| 2185 | reactor.callLater(0,vcpe_firewall,df) |
| 2186 | return df |
| 2187 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2188 | @deferred(40) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2189 | def test_vsg_nat_dnat_modifying_destination_ip_and_delete(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2190 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2191 | Test Method: |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2192 | 1. Get vSG corresponding to vcpe |
| 2193 | 2. Login to compute node |
| 2194 | 3. Execute iptable command on vcpe from compute node to deny all dns Traffic |
| 2195 | 4. From cord-tester ping to www.google.com |
| 2196 | 5. Verifying the ping should not success |
| 2197 | 6. Delete the iptable rule added |
| 2198 | 7. From cord-tester ping to www.google.com |
| 2199 | 8. Verifying the ping should success |
| 2200 | """ |
| 2201 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2202 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2203 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2204 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2205 | df = defer.Deferred() |
| 2206 | def vcpe_firewall(df): |
| 2207 | host = '8.8.8.8' |
| 2208 | dst_ip = '123.123.123.123' |
| 2209 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2210 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2211 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2212 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2213 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2214 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2215 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2216 | assert_equal(st, True) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2217 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2218 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2219 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2220 | except Exception as error: |
| 2221 | log.info('Got Unexpected error %s'%error) |
| 2222 | vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
| 2223 | raise |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2224 | finally: |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2225 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2226 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2227 | df.callback(0) |
| 2228 | reactor.callLater(0,vcpe_firewall,df) |
| 2229 | return df |
| 2230 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2231 | @deferred(50) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2232 | def test_vsg_dnat_change_modifying_destination_ip_address(self, vcpe_name=None, vcpe_intf=None): |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2233 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 2234 | Test Method: |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2235 | 1. Get vSG corresponding to vcpe |
| 2236 | 2. Login to compute node |
| 2237 | 3. Execute iptable command on vcpe from compute node to deny all dns Traffic |
| 2238 | 4. From cord-tester ping to www.google.com |
| 2239 | 5. Verifying the ping should not success |
| 2240 | 6. Delete the iptable rule added |
| 2241 | 7. From cord-tester ping to www.google.com |
| 2242 | 8. Verifying the ping should success |
| 2243 | """ |
| 2244 | if not vcpe_name: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2245 | vcpe_name = self.container_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2246 | if not vcpe_intf: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2247 | vcpe_intf = self.dhcp_vcpes_reserved[0] |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2248 | df = defer.Deferred() |
| 2249 | def vcpe_firewall(df): |
| 2250 | host = '8.8.8.8' |
| 2251 | dst_ip = '123.123.123.123' |
| 2252 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2253 | try: |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2254 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2255 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2256 | assert_equal(st, False) |
| 2257 | st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -A PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
| 2258 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2259 | assert_equal(st, True) |
| 2260 | st,output = vsg.run_cmd('sudo docker exec {} iptables -t nat -R PREROUTING 1 -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,host)) |
| 2261 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2262 | assert_equal(st, False) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2263 | except Exception as error: |
| 2264 | log.info('Got Unexpected error %s'%error) |
| 2265 | raise |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2266 | finally: |
| 2267 | vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,dst_ip)) |
| 2268 | vsg.run_cmd('sudo docker exec {} iptables -t nat -D PREROUTING -s 192.168.0.0/16 -i eth1 -j DNAT --to-destination {}'.format(vcpe_name,host)) |
| 2269 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2270 | #vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
Anil Kumar Sanka | 5fa8d8b | 2017-04-18 22:01:48 +0000 | [diff] [blame] | 2271 | df.callback(0) |
| 2272 | reactor.callLater(0,vcpe_firewall,df) |
| 2273 | return df |
| 2274 | |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2275 | def vsg_xos_subscriber_create(self, index, subscriber_info = None, volt_subscriber_info = None): |
A R Karthick | 1977119 | 2017-04-25 14:57:05 -0700 | [diff] [blame] | 2276 | if self.on_pod is False: |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2277 | return '' |
| 2278 | if subscriber_info is None: |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2279 | subscriber_info = self.cord_subscriber.subscriber_info[index] |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2280 | if volt_subscriber_info is None: |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2281 | volt_subscriber_info = self.cord_subscriber.volt_subscriber_info[index] |
A R Karthick | d0b0679 | 2017-04-25 15:11:23 -0700 | [diff] [blame] | 2282 | s_tag = int(volt_subscriber_info['voltTenant']['s_tag']) |
| 2283 | c_tag = int(volt_subscriber_info['voltTenant']['c_tag']) |
| 2284 | vcpe = 'vcpe-{}-{}'.format(s_tag, c_tag) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2285 | subId = self.cord_subscriber.subscriberCreate(index, subscriber_info, volt_subscriber_info) |
| 2286 | if subId: |
A R Karthick | 97e0885 | 2017-04-26 10:06:38 -0700 | [diff] [blame] | 2287 | #if the vsg instance was already instantiated, then reduce delay |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2288 | if c_tag % self.SUBSCRIBERS_PER_S_TAG == 0: |
A R Karthick | 97e0885 | 2017-04-26 10:06:38 -0700 | [diff] [blame] | 2289 | delay = 350 |
| 2290 | else: |
| 2291 | delay = 90 |
| 2292 | log.info('Delaying %d seconds for the VCPE to be provisioned' %(delay)) |
| 2293 | time.sleep(delay) |
| 2294 | log.info('Testing for external connectivity to VCPE %s' %(vcpe)) |
| 2295 | self.vsg_for_external_connectivity(index) |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2296 | |
| 2297 | return subId |
A R Karthick | 97e0885 | 2017-04-26 10:06:38 -0700 | [diff] [blame] | 2298 | |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2299 | def vsg_xos_subscriber_delete(self, index, subId = '', voltId = '', subscriber_info = None, volt_subscriber_info = None): |
A R Karthick | 97e0885 | 2017-04-26 10:06:38 -0700 | [diff] [blame] | 2300 | if self.on_pod is False: |
| 2301 | return |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2302 | self.cord_subscriber.subscriberDelete(index, subId = subId, voltId = voltId, |
| 2303 | subscriber_info = subscriber_info, |
| 2304 | volt_subscriber_info = volt_subscriber_info) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 2305 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2306 | def vsg_xos_subscriber_id(self, index): |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2307 | if self.on_pod is False: |
| 2308 | return '' |
| 2309 | return self.cord_subscriber.subscriberId(index) |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2310 | |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2311 | def test_vsg_xos_subscriber_create_reserved(self): |
A.R Karthick | a296091 | 2017-05-18 18:52:55 -0700 | [diff] [blame] | 2312 | if self.on_pod is False: |
| 2313 | return |
A.R Karthick | a3fa2f9 | 2017-05-18 18:51:36 -0700 | [diff] [blame] | 2314 | tags_reserved = [ (int(vcpe['s_tag']), int(vcpe['c_tag'])) for vcpe in self.vcpes_reserved ] |
| 2315 | volt_tenants = self.restApiXos.ApiGet('TENANT_VOLT') |
| 2316 | subscribers = self.restApiXos.ApiGet('TENANT_SUBSCRIBER') |
| 2317 | reserved_tenants = filter(lambda tenant: (int(tenant['s_tag']), int(tenant['c_tag'])) in tags_reserved, volt_tenants) |
| 2318 | reserved_config = [] |
| 2319 | for tenant in reserved_tenants: |
| 2320 | for subscriber in subscribers: |
| 2321 | if int(subscriber['id']) == int(tenant['subscriber']): |
| 2322 | volt_subscriber_info = {} |
| 2323 | volt_subscriber_info['voltTenant'] = dict(s_tag = tenant['s_tag'], |
| 2324 | c_tag = tenant['c_tag'], |
| 2325 | subscriber = tenant['subscriber']) |
| 2326 | volt_subscriber_info['volt_id'] = tenant['id'] |
| 2327 | volt_subscriber_info['account_num'] = subscriber['identity']['account_num'] |
| 2328 | reserved_config.append( (subscriber, volt_subscriber_info) ) |
| 2329 | break |
| 2330 | else: |
| 2331 | log.info('Subscriber not found for tenant %s, s_tag: %s, c_tag: %s' %(str(tenant['subscriber']), |
| 2332 | str(tenant['s_tag']), |
| 2333 | str(tenant['c_tag']))) |
| 2334 | |
| 2335 | for subscriber_info, volt_subscriber_info in reserved_config: |
| 2336 | self.vsg_xos_subscriber_delete(0, |
| 2337 | subId = str(subscriber_info['id']), |
| 2338 | voltId = str(volt_subscriber_info['volt_id']), |
| 2339 | subscriber_info = subscriber_info, |
| 2340 | volt_subscriber_info = volt_subscriber_info) |
| 2341 | subId = self.vsg_xos_subscriber_create(0, |
| 2342 | subscriber_info = subscriber_info, |
| 2343 | volt_subscriber_info = volt_subscriber_info) |
| 2344 | log.info('Created reserved subscriber %s' %(subId)) |
| 2345 | |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 2346 | def vsg_create(self, num_subscribers): |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2347 | if self.on_pod is False: |
| 2348 | return |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 2349 | num_subscribers = min(num_subscribers, len(self.cord_subscriber.subscriber_info)) |
| 2350 | for index in xrange(num_subscribers): |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2351 | #check if the index exists |
| 2352 | subId = self.vsg_xos_subscriber_id(index) |
| 2353 | if subId and subId != '0': |
| 2354 | self.vsg_xos_subscriber_delete(index, subId = subId) |
| 2355 | subId = self.vsg_xos_subscriber_create(index) |
| 2356 | log.info('Created Subscriber %s' %(subId)) |
| 2357 | |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 2358 | def test_vsg_xos_subscriber_create_all(self): |
| 2359 | self.vsg_create(len(self.cord_subscriber.subscriber_info)) |
| 2360 | |
| 2361 | def vsg_delete(self, num_subscribers): |
A R Karthick | ed3a2ca | 2017-07-06 15:50:03 -0700 | [diff] [blame] | 2362 | if self.on_pod is False: |
| 2363 | return |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 2364 | num_subscribers = min(num_subscribers, len(self.cord_subscriber.subscriber_info)) |
| 2365 | for index in xrange(num_subscribers): |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2366 | subId = self.vsg_xos_subscriber_id(index) |
| 2367 | if subId and subId != '0': |
| 2368 | self.vsg_xos_subscriber_delete(index, subId = subId) |
| 2369 | |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 2370 | def test_vsg_xos_subscriber_delete_all(self): |
| 2371 | self.vsg_delete(len(self.cord_subscriber.subscriber_info)) |
| 2372 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2373 | def test_vsg_xos_subscriber_create_and_delete(self): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 2374 | subId = self.vsg_xos_subscriber_create(0) |
| 2375 | if subId and subId != '0': |
| 2376 | self.vsg_xos_subscriber_delete(0, subId) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 2377 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2378 | def test_vsg_xos_subscriber_2_create_and_delete(self): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 2379 | subId = self.vsg_xos_subscriber_create(1) |
| 2380 | if subId and subId != '0': |
| 2381 | self.vsg_xos_subscriber_delete(1, subId) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 2382 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2383 | def test_vsg_xos_subscriber_3_create_and_delete(self): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 2384 | subId = self.vsg_xos_subscriber_create(2) |
| 2385 | if subId and subId != '0': |
| 2386 | self.vsg_xos_subscriber_delete(2, subId) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 2387 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2388 | def test_vsg_xos_subscriber_4_create_and_delete(self): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 2389 | subId = self.vsg_xos_subscriber_create(3) |
| 2390 | if subId and subId != '0': |
| 2391 | self.vsg_xos_subscriber_delete(3, subId) |
A R Karthick | 035d2e2 | 2017-04-25 13:53:00 -0700 | [diff] [blame] | 2392 | |
A R Karthick | e29c8d4 | 2017-04-27 11:38:52 -0700 | [diff] [blame] | 2393 | def test_vsg_xos_subscriber_5_create_and_delete(self): |
A R Karthick | 5d30b3c | 2017-04-27 10:25:40 -0700 | [diff] [blame] | 2394 | subId = self.vsg_xos_subscriber_create(4) |
| 2395 | if subId and subId != '0': |
| 2396 | self.vsg_xos_subscriber_delete(4, subId) |
A.R Karthick | 282f0d3 | 2017-03-28 16:43:59 -0700 | [diff] [blame] | 2397 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2398 | @deferred(400) |
| 2399 | def test_vsg_xos_subscriber_external_connectivity_through_vcpe_instance(self, index=0): |
| 2400 | df = defer.Deferred() |
| 2401 | status = False |
| 2402 | def test_xos_subscriber(df): |
| 2403 | subId = self.vsg_xos_subscriber_id(index) |
| 2404 | if subId == '0': |
| 2405 | log.info('Creating vcpe instance ') |
| 2406 | subId = self.vsg_xos_subscriber_create(index) |
| 2407 | assert_not_equal(subId,'0') |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 2408 | vcpe = self.dhcp_vcpes[index] |
| 2409 | host = '8.8.8.8' |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2410 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2411 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2412 | assert_equal(st, False) |
| 2413 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2414 | df.callback(0) |
| 2415 | reactor.callLater(0,test_xos_subscriber,df) |
| 2416 | return df |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 2417 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2418 | #pass |
| 2419 | @deferred(50) |
| 2420 | def test_vsg_xos_subscriber_external_connectivity_without_creating_vcpe_instance(self, index=0): |
| 2421 | df = defer.Deferred() |
| 2422 | def test_xos_subscriber(df): |
| 2423 | subId = self.vsg_xos_subscriber_id(index) |
| 2424 | if subId != '0': |
| 2425 | log.info('deleting already existing vcpe instance ') |
| 2426 | self.vsg_xos_subscriber_delete(index, subId) |
| 2427 | vcpe = self.dhcp_vcpes[index] |
| 2428 | host = '8.8.8.8' |
| 2429 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2430 | st, out = getstatusoutput('route -n') |
| 2431 | log.info('route -n outpu-1-1-1--1-1-1-1-1-1-1 is %s'%out) |
| 2432 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2433 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2434 | assert_equal(st, True) |
| 2435 | df.callback(0) |
| 2436 | reactor.callLater(0,test_xos_subscriber,df) |
| 2437 | return df |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 2438 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2439 | @deferred(400) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2440 | def test_vsg_xos_subscriber_external_connectivity_after_removing_vcpe_instance_from_xos(self,index=0,host = '8.8.8.8'): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2441 | df = defer.Deferred() |
| 2442 | def test_xos_subscriber(df): |
| 2443 | subId = self.vsg_xos_subscriber_id(index) |
| 2444 | if subId == '0': |
| 2445 | subId = self.vsg_xos_subscriber_create(index) |
| 2446 | assert_not_equal(subId,'0') |
| 2447 | vcpe = self.dhcp_vcpes[index] |
| 2448 | if subId and subId != '0': |
| 2449 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2450 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2451 | assert_equal(st, False) |
| 2452 | self.vsg_xos_subscriber_delete(index, subId) |
| 2453 | time.sleep(2) |
| 2454 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2455 | assert_equal(st, True) |
| 2456 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe) |
| 2457 | df.callback(0) |
| 2458 | reactor.callLater(0,test_xos_subscriber,df) |
| 2459 | return df |
| 2460 | |
| 2461 | @deferred(400) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2462 | def test_vsg_xos_subscriber_external_connectivity_after_restarting_vcpe_instance(self, index=0, host = '8.8.8.8'): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2463 | df = defer.Deferred() |
| 2464 | def test_xos_subscriber(df): |
| 2465 | subId = self.vsg_xos_subscriber_id(index) |
| 2466 | if subId == '0': |
| 2467 | subId = self.vsg_xos_subscriber_create(index) |
| 2468 | assert_not_equal(subId,'0') |
| 2469 | vcpe_intf = self.dhcp_vcpes[index] |
| 2470 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2471 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2472 | assert_equal(st, False) |
| 2473 | vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2]) |
| 2474 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2475 | st, _ = vsg.run_cmd('sudo docker restart {}'.format(vcpe_name)) |
| 2476 | assert_equal(st, True) |
| 2477 | time.sleep(5) |
| 2478 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2479 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2480 | assert_equal(st, False) |
| 2481 | df.callback(0) |
| 2482 | reactor.callLater(0,test_xos_subscriber,df) |
| 2483 | return df |
| 2484 | |
| 2485 | @deferred(400) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2486 | def test_vsg_xos_subscriber_external_connectivity_toggling_vcpe_instance(self, index=0, host = '8.8.8.8'): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2487 | df = defer.Deferred() |
| 2488 | def test_xos_subscriber(df): |
| 2489 | subId = self.vsg_xos_subscriber_id(index) |
| 2490 | if subId == '0': |
| 2491 | subId = self.vsg_xos_subscriber_create(index) |
| 2492 | assert_not_equal(subId,'0') |
| 2493 | vcpe_intf = self.dhcp_vcpes[index] |
| 2494 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2495 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2496 | assert_equal(st, False) |
| 2497 | vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2]) |
| 2498 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2499 | st, _ = vsg.run_cmd('sudo docker stop {}'.format(vcpe_name)) |
| 2500 | assert_equal(st, True) |
| 2501 | time.sleep(3) |
| 2502 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2503 | assert_equal(st, True) |
| 2504 | st, _ = vsg.run_cmd('sudo docker start {}'.format(vcpe_name)) |
| 2505 | assert_equal(st, True) |
| 2506 | time.sleep(5) |
| 2507 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2508 | assert_equal(st, False) |
| 2509 | df.callback(0) |
| 2510 | reactor.callLater(0,test_xos_subscriber,df) |
| 2511 | return df |
| 2512 | |
| 2513 | #getting list out of range error while creating vcpe of index 6 |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2514 | def test_vsg_create_xos_subscribers_in_different_vsg_vm(self, index1=4, index2=6): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2515 | indexes = list(index1,index2) |
| 2516 | subids = [] |
| 2517 | for index in indexes: |
| 2518 | subId = self.vsg_xos_subscriber_id(index) |
| 2519 | if not subId: |
| 2520 | subId = self.vsg_xos_subscriber_create(index) |
| 2521 | assert_not_equal(subId,'0') |
| 2522 | subids.append(subId) |
| 2523 | log.info('succesfully created two vcpe instances in two different vSG VMs') |
| 2524 | self.vsg_xos_subscriber_delete(index1, subid[0]) |
| 2525 | self.vsg_xos_subscriber_delete(index2, subid[1]) |
| 2526 | |
| 2527 | #Unable to reach external network via vcpes created by XOS |
| 2528 | @deferred(TIMEOUT+400) |
| 2529 | def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_goes_down(self): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2530 | """ |
| 2531 | Test Method: |
| 2532 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2533 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2534 | 3.Kill first vcpe instance |
| 2535 | 4.Verify external network cant be reachable form first vcpe interface |
| 2536 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2537 | df = defer.Deferred() |
| 2538 | def test_xos_subscriber(df): |
| 2539 | host1 = '8.8.8.8' |
| 2540 | host2 = '4.2.2.2' |
| 2541 | vcpe_intf1 = self.dhcp_vcpes[0] |
| 2542 | vcpe_intf2 = self.dhcp_vcpes[1] |
| 2543 | vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2]) |
| 2544 | vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2]) |
| 2545 | subId1 = self.vsg_xos_subscriber_id(0) |
| 2546 | log.info('already existing subid of index 0 is %s'%subId1) |
| 2547 | if subId1 == '0': |
| 2548 | log.info('creating vcpe instance of index 0') |
| 2549 | subId1 = self.vsg_xos_subscriber_create(0) |
| 2550 | assert_not_equal(subId1,'0') |
| 2551 | subId2 = self.vsg_xos_subscriber_id(1) |
| 2552 | log.info('already existing subid of index 1 is %s'%subId2) |
| 2553 | if subId2 == '0': |
| 2554 | log.info('creating vcpe instance of index 1') |
| 2555 | subId2 = self.vsg_xos_subscriber_create(1) |
| 2556 | assert_not_equal(subId2,'0') |
| 2557 | vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1) |
| 2558 | vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2) |
| 2559 | try: |
| 2560 | for intf in [vcpe_intf1,vcpe_intf2]: |
| 2561 | host = host1 if intf is vcpe_intf1 else host2 |
| 2562 | self.add_static_route_via_vcpe_interface([host],vcpe=intf) |
| 2563 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2564 | assert_equal(st, False) |
| 2565 | if intf is vcpe_intf2: |
| 2566 | self.vsg_xos_subscriber_delete(1, subId2) |
| 2567 | st, _ = vsg2.run_cmd('sudo docker kill {}'.format(vcpe_name2)) |
| 2568 | time.sleep(2) |
| 2569 | self.add_static_route_via_vcpe_interface([host],vcpe=intf) |
| 2570 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2571 | assert_equal(st, False) |
| 2572 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2573 | assert_equal(st, True) |
| 2574 | except Exception as error: |
| 2575 | log.info('Got Unexpected error %s'%error) |
| 2576 | raise |
| 2577 | finally: |
| 2578 | self.vsg_xos_subscriber_delete(0, subId1) |
| 2579 | self.vsg_xos_subscriber_delete(1, subId2) |
| 2580 | self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2581 | self.del_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2582 | df.callback(0) |
| 2583 | reactor.callLater(0,test_xos_subscriber,df) |
| 2584 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2585 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2586 | @deferred(TIMEOUT+400) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2587 | def test_vsg_xos_subscriber_external_connectivity_after_vcpe_is_removed_and_added_again(self,index=0): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2588 | """ |
| 2589 | Test Method: |
| 2590 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2591 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2592 | 3.Remove first vcpe instance |
| 2593 | 4.Verify external network cant be reachable form first vcpe interface |
| 2594 | 5.Add back the removed vcpe instance |
| 2595 | 6.Verify external connectivity through vcpe instances from cord-tester |
| 2596 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2597 | df = defer.Deferred() |
| 2598 | def test_xos_subscriber(df,index=index): |
| 2599 | host = '8.8.8.8' |
| 2600 | subId = self.vsg_xos_subscriber_id(index) |
| 2601 | log.info('already existing subid of index 0 is %s'%subId) |
| 2602 | if subId == '0': |
| 2603 | log.info('creating vcpe instance of index %s'%index) |
| 2604 | subId = self.vsg_xos_subscriber_create(index) |
| 2605 | assert_not_equal(subId,'0') |
| 2606 | vcpe_intf = self.dhcp_vcpes[0] |
| 2607 | vcpe_name = 'vcpe-{}-{}'.format(vcpe_intf.split('.')[1],vcpe_intf.split('.')[2]) |
| 2608 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2609 | try: |
| 2610 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2611 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2612 | assert_equal(st, False) |
| 2613 | log.info('Deleting vcpe Instance of index %s'%index) |
| 2614 | self.vsg_xos_subscriber_delete(0, subId) |
| 2615 | st, _ = vsg.run_cmd('sudo docker kill {}'.format(vcpe_name)) |
| 2616 | time.sleep(1) |
| 2617 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2618 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2619 | assert_equal(st, True) |
| 2620 | subId = self.vsg_xos_subscriber_create(index) |
| 2621 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2622 | st,_ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2623 | assert_equal(st, False) |
| 2624 | except Exception as error: |
| 2625 | log.info('Got Unexpected error %s'%error) |
| 2626 | raise |
| 2627 | finally: |
| 2628 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2629 | self.vsg_xos_subscriber_delete(0, subId) |
| 2630 | df.callback(0) |
| 2631 | reactor.callLater(0,test_xos_subscriber,df) |
| 2632 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2633 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2634 | @deferred(TIMEOUT+400) |
| 2635 | def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_restarts(self): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2636 | """ |
| 2637 | Test Method: |
| 2638 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2639 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2640 | 3.Restart first vcpe instance |
| 2641 | 4.Verify external network cant be reachable form first vcpe interface |
| 2642 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2643 | df = defer.Deferred() |
| 2644 | def test_xos_subscriber(df): |
| 2645 | host1 = '8.8.8.8' |
| 2646 | host2 = '4.2.2.2' |
| 2647 | subId1 = self.vsg_xos_subscriber_id(0) |
| 2648 | log.info('already existing subid of index 0 is %s'%subId1) |
| 2649 | if subId1 == '0': |
| 2650 | log.info('creating vcpe instance of index 0') |
| 2651 | subId1 = self.vsg_xos_subscriber_create(0) |
| 2652 | assert_not_equal(subId1,'0') |
| 2653 | subId2 = self.vsg_xos_subscriber_id(1) |
| 2654 | log.info('already existing subid of index 1 is %s'%subId2) |
| 2655 | if subId2 == '0': |
| 2656 | log.info('creating vcpe instance of index 1') |
| 2657 | subId2 = self.vsg_xos_subscriber_create(1) |
| 2658 | vcpe_intf1 = self.dhcp_vcpes[0] |
| 2659 | vcpe_intf2 = self.dhcp_vcpes[1] |
| 2660 | vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2]) |
| 2661 | vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2]) |
| 2662 | vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1) |
| 2663 | vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2) |
| 2664 | try: |
| 2665 | #checking external connectivity from vcpe interface 1 before vcpe 2 restart |
| 2666 | self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2667 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2668 | assert_equal(st, False) |
| 2669 | #checking external connectivity from vcpe interface 2 before vcpe 2 restart |
| 2670 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2671 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2672 | assert_equal(st, False) |
| 2673 | st, _ = vsg2.run_cmd('sudo docker restart {}'.format(vcpe_name2)) |
| 2674 | time.sleep(10) |
| 2675 | #checking external connectivity from vcpe interface 1 after vcpe 2 restart |
| 2676 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2677 | assert_equal(st, False) |
| 2678 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2679 | time = 0 |
| 2680 | status = False |
| 2681 | while(time <= 100): |
| 2682 | time.sleep(10) |
| 2683 | st,_ = getstatusoutput('ping -c 1 {}'.format(hos2)) |
| 2684 | if st is False: |
| 2685 | status = True |
| 2686 | break |
| 2687 | time += 10 |
| 2688 | assert_equal(status, True) |
| 2689 | except Exception as error: |
| 2690 | log.info('Got Unexpected error %s'%error) |
| 2691 | raise |
| 2692 | finally: |
| 2693 | self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2694 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2695 | self.vsg_xos_subscriber_delete(0, subId1) |
| 2696 | self.vsg_xos_subscriber_delete(1, subId2) |
| 2697 | df.callback(0) |
| 2698 | reactor.callLater(0,test_xos_subscriber,df) |
| 2699 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2700 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2701 | @deferred(500) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2702 | def test_vsg_xos_multiple_subscribers_external_connectivity_if_one_vcpe_is_paused(self): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2703 | """ |
| 2704 | Test Method: |
| 2705 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2706 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2707 | 3.Pause running first vcpe instance |
| 2708 | 4.Verify external network cant be reachable form first vcpe interface |
| 2709 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2710 | df = defer.Deferred() |
| 2711 | def test_xos_subscriber(df): |
| 2712 | host1 = '8.8.8.8' |
| 2713 | host2 = '4.2.2.2' |
| 2714 | subId1 = self.vsg_xos_subscriber_id(0) |
| 2715 | log.info('already existing subid of index 0 is %s'%subId1) |
| 2716 | if subId1 == '0': |
| 2717 | log.info('creating vcpe instance of index 0') |
| 2718 | subId1 = self.vsg_xos_subscriber_create(0) |
| 2719 | assert_not_equal(subId1,'0') |
| 2720 | subId2 = self.vsg_xos_subscriber_id(1) |
| 2721 | log.info('already existing subid of index 1 is %s'%subId2) |
| 2722 | if subId2 == '0': |
| 2723 | log.info('creating vcpe instance of index 1') |
| 2724 | subId2 = self.vsg_xos_subscriber_create(1) |
| 2725 | vcpe_intf1 = self.dhcp_vcpes[0] |
| 2726 | vcpe_intf2 = self.dhcp_vcpes[1] |
| 2727 | vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2]) |
| 2728 | vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2]) |
| 2729 | vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1) |
| 2730 | vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2) |
| 2731 | try: |
| 2732 | #checking external connectivity from vcpe interface 1 before vcpe 2 pause |
| 2733 | self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2734 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2735 | assert_equal(st, False) |
| 2736 | #checking external connectivity from vcpe interface 2 before vcpe 2 pause |
| 2737 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2738 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2739 | assert_equal(st, False) |
| 2740 | st, _ = vsg2.run_cmd('sudo docker pause {}'.format(vcpe_name2)) |
| 2741 | time.sleep(1) |
| 2742 | #checking external connectivity from vcpe interface 1 after vcpe 2 pause |
| 2743 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2744 | assert_equal(st, False) |
| 2745 | #checking external connectivity from vcpe interface 2 after vcpe 2 pause |
| 2746 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2747 | assert_equal(st, True) |
| 2748 | except Exception as error: |
| 2749 | log.info('Got Unexpected error %s'%error) |
| 2750 | raise |
| 2751 | finally: |
| 2752 | log.info('In Finally block 3333333333333333') |
| 2753 | st, _ = vsg2.run_cmd('sudo docker unpause {}'.format(vcpe_name2)) |
| 2754 | self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2755 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2756 | self.vsg_xos_subscriber_delete(0, subId1) |
| 2757 | self.vsg_xos_subscriber_delete(1, subId2) |
| 2758 | df.callback(0) |
| 2759 | reactor.callLater(0,test_xos_subscriber,df) |
| 2760 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2761 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2762 | @deferred(500) |
| 2763 | def test_vsg_xos_subscriber_external_connectivity_if_one_vcpe_stops(self): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2764 | """ |
| 2765 | Test Method: |
| 2766 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2767 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2768 | 3.Stop running first vcpe instance |
| 2769 | 4.Verify external network cant be reachable form first vcpe interface |
| 2770 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2771 | df = defer.Deferred() |
| 2772 | def test_xos_subscriber(df): |
| 2773 | host1 = '8.8.8.8' |
| 2774 | host2 = '4.2.2.2' |
| 2775 | subId1 = self.vsg_xos_subscriber_id(0) |
| 2776 | log.info('already existing subid of index 0 is %s'%subId1) |
| 2777 | if subId1 == '0': |
| 2778 | log.info('creating vcpe instance of index 0') |
| 2779 | subId1 = self.vsg_xos_subscriber_create(0) |
| 2780 | assert_not_equal(subId1,'0') |
| 2781 | subId2 = self.vsg_xos_subscriber_id(1) |
| 2782 | log.info('already existing subid of index 1 is %s'%subId2) |
| 2783 | if subId2 == '0': |
| 2784 | log.info('creating vcpe instance of index 1') |
| 2785 | subId2 = self.vsg_xos_subscriber_create(1) |
| 2786 | vcpe_intf1 = self.dhcp_vcpes[0] |
| 2787 | vcpe_intf2 = self.dhcp_vcpes[1] |
| 2788 | vcpe_name1 = 'vcpe-{}-{}'.format(vcpe_intf1.split('.')[1],vcpe_intf1.split('.')[2]) |
| 2789 | vcpe_name2 = 'vcpe-{}-{}'.format(vcpe_intf2.split('.')[1],vcpe_intf2.split('.')[2]) |
| 2790 | vsg1 = VSGAccess.get_vcpe_vsg(vcpe_name1) |
| 2791 | vsg2 = VSGAccess.get_vcpe_vsg(vcpe_name2) |
| 2792 | try: |
| 2793 | #checking external connectivity from vcpe interface 1 before vcpe 2 stop |
| 2794 | self.add_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2795 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2796 | assert_equal(st, False) |
| 2797 | #checking external connectivity from vcpe interface 2 before vcpe 2 stop |
| 2798 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2799 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2800 | assert_equal(st, False) |
| 2801 | st, _ = vsg2.run_cmd('sudo docker stop {}'.format(vcpe_name2)) |
| 2802 | time.sleep(5) |
| 2803 | #checking external connectivity from vcpe interface 1 after vcpe 2 stop |
| 2804 | st,_ = getstatusoutput('ping -c 1 {}'.format(host1)) |
| 2805 | assert_equal(st, False) |
| 2806 | #checking external connectivity from vcpe interface 1 after vcpe 2 stop |
| 2807 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2808 | st,_ = getstatusoutput('ping -c 1 {}'.format(host2)) |
| 2809 | assert_equal(st, True) |
| 2810 | except Exception as error: |
| 2811 | log.info('Got Unexpected error %s'%error) |
| 2812 | raise |
| 2813 | finally: |
| 2814 | st, _ = vsg2.run_cmd('sudo docker start {}'.format(vcpe_name2)) |
| 2815 | time.sleep(10) |
| 2816 | self.del_static_route_via_vcpe_interface([host1],vcpe=vcpe_intf1) |
| 2817 | self.add_static_route_via_vcpe_interface([host2],vcpe=vcpe_intf2) |
| 2818 | self.vsg_xos_subscriber_delete(0, subId1) |
| 2819 | self.vsg_xos_subscriber_delete(1, subId2) |
| 2820 | df.callback(0) |
| 2821 | reactor.callLater(0,test_xos_subscriber,df) |
| 2822 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2823 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2824 | @deferred(420) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2825 | def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_stopped(self, index=0): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2826 | """ |
| 2827 | Test Method: |
| 2828 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2829 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2830 | 3.Bring down first vSG vm |
| 2831 | 4.Verify external network cant be reachable form first vcpe interface |
| 2832 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2833 | df = defer.Deferred() |
| 2834 | def test_xos_subscriber(df,index=index): |
| 2835 | host = '8.8.8.8' |
| 2836 | subId = self.vsg_xos_subscriber_id(index) |
| 2837 | if subId == '0': |
| 2838 | log.info('creating vcpe instance of index 0') |
| 2839 | subId = self.vsg_xos_subscriber_create(index) |
| 2840 | assert_not_equal(subId,'0') |
| 2841 | vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag) |
| 2842 | vcpe_name = self.container_vcpes[index] |
| 2843 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2844 | try: |
| 2845 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2846 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2847 | assert_equal(st, False) |
| 2848 | log.info('Stopping vsg instance') |
| 2849 | vsg.stop() |
| 2850 | time.sleep(5) |
| 2851 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2852 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2853 | assert_equal(st, True) |
| 2854 | except Exception as error: |
| 2855 | log.info('Got Unexpected error %s'%error) |
| 2856 | raise |
| 2857 | finally: |
| 2858 | vsg.start() |
| 2859 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2860 | self.vsg_xos_subscriber_delete(index, subId) |
| 2861 | df.callback(0) |
| 2862 | reactor.callLater(0,test_xos_subscriber,df) |
| 2863 | return df |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2864 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2865 | @deferred(420) |
Chetan Gaonker | e1f6638 | 2017-06-02 21:34:07 +0000 | [diff] [blame] | 2866 | def test_vsg_xos_subscriber_external_connectivity_after_vsg_vm_is_restarted(self, index=0): |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2867 | """ |
| 2868 | Test Method: |
Chetan Gaonker | fe1048f | 2017-06-13 20:16:25 +0000 | [diff] [blame] | 2869 | 1.Create subscriber |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2870 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2871 | 3.Bring down first vSG vm |
| 2872 | 4.Verify external network cant be reachable form first vcpe interface |
| 2873 | """ |
| 2874 | df = defer.Deferred() |
| 2875 | def test_xos_subscriber(df,index=index): |
| 2876 | host = '8.8.8.8' |
| 2877 | subId = self.vsg_xos_subscriber_id(index) |
| 2878 | if subId == '0': |
| 2879 | log.info('creating vcpe instance of index 0') |
| 2880 | subId = self.vsg_xos_subscriber_create(index) |
| 2881 | assert_not_equal(subId,'0') |
| 2882 | vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag) |
| 2883 | vcpe_name = self.container_vcpes[index] |
| 2884 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2885 | try: |
| 2886 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2887 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2888 | assert_equal(st, False) |
| 2889 | log.info('Restarting vsg instance') |
| 2890 | vsg.reboot() |
| 2891 | time.sleep(10) |
| 2892 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2893 | time = 0 |
| 2894 | status = False |
| 2895 | while(time <= 100): |
| 2896 | time.sleep(10) |
| 2897 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2898 | if st is False: |
| 2899 | status = True |
| 2900 | break |
| 2901 | time += 10 |
| 2902 | assert_equal(status, True) |
| 2903 | except Exception as error: |
| 2904 | log.info('Got Unexpected error %s'%error) |
| 2905 | raise |
| 2906 | finally: |
| 2907 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2908 | self.vsg_xos_subscriber_delete(index, subId) |
| 2909 | df.callback(0) |
| 2910 | reactor.callLater(0,test_xos_subscriber,df) |
| 2911 | return df |
| 2912 | |
| 2913 | @deferred(780) |
Chetan Gaonker | fe1048f | 2017-06-13 20:16:25 +0000 | [diff] [blame] | 2914 | def test_vsg_xos_multiple_subscribers_external_connectivity_if_two_vsgs_stop_and_start(self, index1=4, index2=6): |
Anil Kumar Sanka | 5bb352a | 2017-05-16 22:24:01 +0000 | [diff] [blame] | 2915 | """ |
| 2916 | Test Method: |
| 2917 | 1.Create two vcpe instances in two different vsg vms using XOS |
| 2918 | 2.Verify external connectivity through vcpe instances from cord-tester |
| 2919 | 3.Bring down first vSG vm |
| 2920 | 4.Verify external network cant be reachable form first vcpe interface |
| 2921 | 5.Bring down second vSG vm also |
| 2922 | 6.Verify external network cant be reachable form first vcpe interface also |
| 2923 | """ |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2924 | df = defer.Deferred(df,index1=index1,index2=index2) |
| 2925 | def test_xos_subscriber(df,index=index): |
| 2926 | subId1 = self.vsg_xos_subscriber_create(index1) |
| 2927 | subId2 = self.vsg_xos_subscriber_create(index2) |
| 2928 | if subId1 == '0': |
| 2929 | self.vsg_xos_subscriber_delete(index1, subId1) |
| 2930 | assert_not_equal(subId1, '0') |
| 2931 | if subId2 == '0': |
| 2932 | self.vsg_xos_subscriber_delete(index2, subId2) |
| 2933 | assert_not_equal(subId2, '0') |
| 2934 | for index in [index1,index2]: |
| 2935 | vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag) |
| 2936 | vcpe_name = self.container_vcpes[index] |
| 2937 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
| 2938 | try: |
| 2939 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2940 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2941 | assert_equal(st, False) |
| 2942 | log.info('Stopping vsg instance of index %s'%index) |
| 2943 | vsg.stop() |
| 2944 | time.sleep(5) |
| 2945 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2946 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2947 | assert_equal(st, True) |
| 2948 | except Exception as error: |
| 2949 | log.info('Got Unexpected error %s'%error) |
| 2950 | raise |
| 2951 | finally: |
| 2952 | vsg.start() |
| 2953 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2954 | df.callback(0) |
| 2955 | reactor.callLater(0,test_xos_subscriber,df) |
| 2956 | return df |
Anil Kumar Sanka | 52a39f8 | 2017-05-10 17:39:31 +0000 | [diff] [blame] | 2957 | |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2958 | @deferred(420) |
| 2959 | def test_vsg_xos_subscriber_external_connectivity_with_creating_firewall_rule(self,index=0): |
| 2960 | """ |
| 2961 | Alog: |
| 2962 | 1.Cretae a vcpe instance using XOS |
| 2963 | 2.Get dhcp IP to vcpe interface in cord-tester |
| 2964 | 3.Verify external network can be reachable from cord-tester |
| 2965 | 4.Add an iptable rule to drop packets destined to external network in vcpe |
| 2966 | 5.Verify now external network cant be reachable |
Chetan Gaonker | fe1048f | 2017-06-13 20:16:25 +0000 | [diff] [blame] | 2967 | 6.Delele the iptable in vcpe instance |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2968 | 7.Verify external network can be reachable from cord-tester |
| 2969 | """ |
| 2970 | df = defer.Deferred() |
| 2971 | def test_xos_subscriber(df,index=index): |
| 2972 | log.info('cls.dhcp_vcpes is %s'%self.dhcp_vcpes) |
| 2973 | host = '8.8.8.8' |
| 2974 | subId = self.vsg_xos_subscriber_create(index) |
| 2975 | if subId == '0': |
| 2976 | subId = self.vsg_xos_subscriber_create(index) |
| 2977 | assert_not_equal(subId, '0') |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 2978 | vcpe_intf = self.dhcp_vcpes[index] #'vcpe{}.{}.{}'.format(s_tag, c_tag) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2979 | vcpe_name = self.container_vcpes[index] |
| 2980 | vsg = VSGAccess.get_vcpe_vsg(vcpe_name) |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 2981 | try: |
| 2982 | self.add_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
| 2983 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2984 | #ssert_equal(st, False) |
| 2985 | st, _ = vsg.run_cmd('sudo docker exec {} iptables -I FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 2986 | st, _ = getstatusoutput('ping -c 1 {}'.format(host)) |
| 2987 | assert_equal(st, True) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2988 | st,_ = vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
| 2989 | self.vsg_xos_subscriber_delete(index, subId) |
| 2990 | except Exception as error: |
| 2991 | log.info('Got Unexpected error %s'%error) |
| 2992 | raise |
| 2993 | finally: |
| 2994 | vsg.run_cmd('sudo docker exec {} iptables -D FORWARD -d {} -j DROP'.format(vcpe_name,host)) |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 2995 | self.del_static_route_via_vcpe_interface([host],vcpe=vcpe_intf) |
Anil Kumar Sanka | 5db80d0 | 2017-06-02 21:10:19 +0000 | [diff] [blame] | 2996 | self.vsg_xos_subscriber_delete(index, subId) |
| 2997 | df.callback(0) |
| 2998 | reactor.callLater(0,test_xos_subscriber,df) |
| 2999 | return df |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3000 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3001 | def test_vsg_for_packet_received_with_invalid_ip_fields(self): |
| 3002 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3003 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3004 | 1.Create a vSG VM in compute node |
| 3005 | 2.Create a vCPE container in vSG VM |
| 3006 | 3.Ensure vSG VM and vCPE container created properly |
| 3007 | 4.From subscriber, send a ping packet with invalid ip fields |
| 3008 | 5.Verify that vSG drops the packet |
| 3009 | 6.Verify ping fails |
| 3010 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3011 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3012 | def test_vsg_for_packet_received_with_invalid_mac_fields(self): |
| 3013 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3014 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3015 | 1.Create a vSG VM in compute node |
| 3016 | 2.Create a vCPE container in vSG VM |
| 3017 | 3.Ensure vSG VM and vCPE container created properly |
| 3018 | 4.From subscriber, send a ping packet with invalid mac fields |
| 3019 | 5.Verify that vSG drops the packet |
| 3020 | 6.Verify ping fails |
| 3021 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3022 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3023 | def test_vsg_for_vlan_id_mismatch_in_stag(self): |
| 3024 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3025 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3026 | 1.Create a vSG VM in compute Node |
| 3027 | 2.Create a vCPE container in vSG VM |
| 3028 | 3.Ensure vSG VM and vCPE container created properly |
| 3029 | 4.Send a ping request to external valid IP from subscriber, with incorrect vlan id in s-tag and valid c-tag |
| 3030 | 5.Verify that ping fails as the packet drops at VM entry |
| 3031 | 6.Repeat step 4 with correct s-tag |
| 3032 | 7.Verify that ping success |
| 3033 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3034 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3035 | def test_vsg_for_vlan_id_mismatch_in_ctag(self): |
| 3036 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3037 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3038 | 1.Create a vSG VM in compute node |
| 3039 | 2.Create a vCPE container in vSG VM |
| 3040 | 3.Ensure vSG VM and vCPE container created properly |
| 3041 | 4.Send a ping request to external valid IP from subscriber, with valid s-tag and incorrect vlan id in c-tag |
| 3042 | 5.Verify that ping fails as the packet drops at vCPE container entry |
| 3043 | 6.Repeat step 4 with valid s-tag and c-tag |
| 3044 | 7.Verify that ping success |
| 3045 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3046 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3047 | def test_vsg_for_matching_and_mismatching_vlan_id_in_stag(self): |
| 3048 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3049 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3050 | 1.Create two vSG VMs in compute node |
| 3051 | 2.Create a vCPE container in each vSG VM |
| 3052 | 3.Ensure vSG VM and vCPE container created properly |
| 3053 | 4.From subscriber one, send ping request with valid s and c tags |
| 3054 | 5.From subscriber two, send ping request with vlan id mismatch in s-tag and valid c tags |
| 3055 | 6.Verify that ping success for only subscriber one and fails for two. |
| 3056 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3057 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3058 | def test_vsg_for_matching_and_mismatching_vlan_id_in_ctag(self): |
| 3059 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3060 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3061 | 1.Create a vSG VM in compute node |
| 3062 | 2.Create two vCPE containers in vSG VM |
| 3063 | 3.Ensure vSG VM and vCPE container created properly |
| 3064 | 4.From subscriber one, send ping request with valid s and c tags |
| 3065 | 5.From subscriber two, send ping request with valid s-tag and vlan id mismatch in c-tag |
| 3066 | 6.Verify that ping success for only subscriber one and fails for two |
| 3067 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3068 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3069 | def test_vsg_for_out_of_range_vlanid_in_ctag(self): |
| 3070 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3071 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3072 | 1.Create a vSG VM in compute node |
| 3073 | 2.Create a vCPE container in vSG VM |
| 3074 | 3.Ensure vSG VM and vCPE container created properly |
| 3075 | 4.From subscriber, send ping request with valid stag and vlan id in c-tag is an out of range value ( like 0,4097 ) |
| 3076 | 4.Verify that ping fails as the ping packets drops at vCPE container entry |
| 3077 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3078 | |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3079 | def test_vsg_for_out_of_range_vlanid_in_stag(self): |
| 3080 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3081 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3082 | 1.Create a vSG VM in compute node |
| 3083 | 2.Create a vCPE container in vSG VM |
| 3084 | 3.Ensure vSG VM and vCPE container created properly |
| 3085 | 2.From subscriber, send ping request with vlan id in s-tag is an out of range value ( like 0,4097 ), with valid c-tag |
| 3086 | 4.Verify that ping fails as the ping packets drops at vSG VM entry |
| 3087 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3088 | |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 3089 | def test_vsg_for_extracting_all_compute_stats_from_all_vcpe_containers(self): |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3090 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3091 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3092 | 1.Create a vSG VM in compute node |
| 3093 | 2.Create 10 vCPE containers in VM |
| 3094 | 3.Ensure vSG VM and vCPE containers created properly |
| 3095 | 4.Login to all vCPE containers |
| 3096 | 4.Get all compute stats from all vCPE containers |
| 3097 | 5.Verify the stats # verification method need to add |
| 3098 | """ |
A R Karthick | 6375149 | 2017-03-22 09:28:01 -0700 | [diff] [blame] | 3099 | |
Anil Kumar Sanka | f6a9f39 | 2017-05-06 00:18:31 +0000 | [diff] [blame] | 3100 | def test_vsg_for_extracting_dns_stats_from_all_vcpe_containers(self): |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3101 | """ |
Chetan Gaonker | 72f3c4e | 2017-05-10 18:16:49 +0000 | [diff] [blame] | 3102 | Test Method: |
Anil Kumar Sanka | 1213d4c | 2017-02-23 22:50:48 +0000 | [diff] [blame] | 3103 | 1.Create a vSG VM in compute node |
| 3104 | 2.Create 10 vCPE containers in VM |
| 3105 | 3.Ensure vSG VM and vCPE containers created properly |
| 3106 | 4.From 10 subscribers, send ping to valid and invalid dns hosts |
| 3107 | 5.Verify dns resolves and ping success for valid dns hosts |
| 3108 | 6.Verify ping fails for invalid dns hosts |
| 3109 | 7.Verify dns host name resolve flows in OvS |
| 3110 | 8.Login to all 10 vCPE containers |
| 3111 | 9.Extract all dns stats |
| 3112 | 10.Verify dns stats for queries sent, queries received for dns host resolve success and failed scenarios |
| 3113 | """ |
A R Karthick | 037cb98 | 2017-07-07 17:35:30 -0700 | [diff] [blame] | 3114 | pass |