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