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