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