<commit_before>import os
import subprocess
import sys
import time

import argparse
import paramiko

import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_utils as os_utils

parser = argparse.ArgumentParser()

parser.add_argument("-r", "--report",
                    help="Create json result file",
                    action="store_true")

args = parser.parse_args()

""" logging configuration """
logger = ft_logger.Logger("ODL_SFC").getLogger()

FUNCTEST_REPO = ft_utils.FUNCTEST_REPO

HOME = os.environ['HOME'] + "/"

VM_BOOT_TIMEOUT = 180
INSTANCE_NAME = "client"
FLAVOR = "m1.small"
IMAGE_NAME = "sf_nsh_colorado"
IMAGE_FILENAME = "sf_nsh_colorado.qcow2"
IMAGE_FORMAT = "qcow2"
IMAGE_PATH = "/home/opnfv/functest/data" + "/" + IMAGE_FILENAME

# NEUTRON Private Network parameters

NET_NAME = "example-net"
SUBNET_NAME = "example-subnet"
SUBNET_CIDR = "172.16.31.10/24"
ROUTER_NAME = "example-router"

SECGROUP_NAME = "example-sg"
SECGROUP_DESCR = "Example Security group"

INSTANCE_NAME_2 = "server"

# TEST_DB = ft_utils.get_parameter_from_yaml("results.test_db_url")

PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
TACKER_SCRIPT = 'sfc_tacker.bash'
TEARDOWN_SCRIPT = "sfc_teardown.bash"
TACKER_CHANGECLASSI = "sfc_change_classi.bash"


def main():

    # Allow any port so that tacker commands reaches the server.
    # This will be deleted when tacker is included in OPNFV installation

    status = "PASS"
    failures = 0
    start_time = time.time()
    json_results = {}

    ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
    contr_cmd = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                 " 'fuel node'|grep controller|awk '{print $10}'")
    logger.info("Executing script to get ip_server: '%s'" % contr_cmd)
    process = subprocess.Popen(contr_cmd,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    ip_server = process.stdout.readline().rstrip()

    contr_cmd2 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                  " 'fuel node'|grep compute|awk '{print $10}'")
    logger.info("Executing script to get ip_compute: '%s'" % contr_cmd2)
    process = subprocess.Popen(contr_cmd2,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    ip_compute = process.stdout.readline().rstrip()

    iptable_cmd1 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                    " ssh " + ip_server + " iptables -P INPUT ACCEPT ")
    iptable_cmd2 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                    " ssh " + ip_server + " iptables -t nat -P INPUT ACCEPT ")

    logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd1)
    subprocess.call(iptable_cmd1, shell=True, stderr=subprocess.PIPE)

    logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd2)
    subprocess.call(iptable_cmd2, shell=True, stderr=subprocess.PIPE)

# Getting the different clients

    nova_client = os_utils.get_nova_client()
    neutron_client = os_utils.get_neutron_client()<commit_msg>SFC testcase IP tables policy<commit_after>import os
import subprocess
import sys
import time

import argparse
import paramiko

import functest.utils.functest_logger as ft_logger
import functest.utils.functest_utils as ft_utils
import functest.utils.openstack_utils as os_utils

parser = argparse.ArgumentParser()

parser.add_argument("-r", "--report",
                    help="Create json result file",
                    action="store_true")

args = parser.parse_args()

""" logging configuration """
logger = ft_logger.Logger("ODL_SFC").getLogger()

FUNCTEST_REPO = ft_utils.FUNCTEST_REPO

HOME = os.environ['HOME'] + "/"

VM_BOOT_TIMEOUT = 180
INSTANCE_NAME = "client"
FLAVOR = "m1.small"
IMAGE_NAME = "sf_nsh_colorado"
IMAGE_FILENAME = "sf_nsh_colorado.qcow2"
IMAGE_FORMAT = "qcow2"
IMAGE_PATH = "/home/opnfv/functest/data" + "/" + IMAGE_FILENAME

# NEUTRON Private Network parameters

NET_NAME = "example-net"
SUBNET_NAME = "example-subnet"
SUBNET_CIDR = "172.16.31.10/24"
ROUTER_NAME = "example-router"

SECGROUP_NAME = "example-sg"
SECGROUP_DESCR = "Example Security group"

INSTANCE_NAME_2 = "server"

# TEST_DB = ft_utils.get_parameter_from_yaml("results.test_db_url")

PRE_SETUP_SCRIPT = 'sfc_pre_setup.bash'
TACKER_SCRIPT = 'sfc_tacker.bash'
TEARDOWN_SCRIPT = "sfc_teardown.bash"
TACKER_CHANGECLASSI = "sfc_change_classi.bash"


def main():

    # Allow any port so that tacker commands reaches the server.
    # This will be deleted when tacker is included in OPNFV installation

    status = "PASS"
    failures = 0
    start_time = time.time()
    json_results = {}

    ssh_options = '-o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no'
    contr_cmd = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                 " 'fuel node'|grep controller|awk '{print $10}'")
    logger.info("Executing script to get ip_server: '%s'" % contr_cmd)
    process = subprocess.Popen(contr_cmd,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    ip_server = process.stdout.readline().rstrip()

    contr_cmd2 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                  " 'fuel node'|grep compute|awk '{print $10}'")
    logger.info("Executing script to get ip_compute: '%s'" % contr_cmd2)
    process = subprocess.Popen(contr_cmd2,
                               shell=True,
                               stdout=subprocess.PIPE,
                               stderr=subprocess.PIPE)
    ip_compute = process.stdout.readline().rstrip()

    iptable_cmd1 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                    " ssh " + ip_server + " iptables -P INPUT ACCEPT ")
    iptable_cmd2 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                    " ssh " + ip_server + " iptables -t nat -P INPUT ACCEPT ")
    iptable_cmd3 = ("sshpass -p r00tme ssh " + ssh_options + " root@10.20.0.2"
                    " ssh " + ssh_options + " " + ip_server +
                    " iptables -A INPUT -m state"
                    " --state NEW,ESTABLISHED,RELATED -j ACCEPT")

    logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd1)
    subprocess.call(iptable_cmd1, shell=True, stderr=subprocess.PIPE)

    logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd2)
    subprocess.call(iptable_cmd2, shell=True, stderr=subprocess.PIPE)

    logger.info("Changing firewall policy in controller: '%s'" % iptable_cmd3)
    subprocess.call(iptable_cmd2, shell=True, stderr=subprocess.PIPE)

# Getting the different clients

    nova_client = os_utils.get_nova_client()
    neutron_client = os_utils.get_neutron_client()
{'fraction_non_alphanumeric': 0.11256210078069553, 'fraction_numerical': 0.01973030518097942, 'mean_word_length': 2.9695774647887325, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 11, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3491627', 'n_tokens_mistral': 2527, 'n_tokens_neox': 2378, 'n_words': 494}