<commit_before>#!/usr/bin/env python

"""
Network Test Cases modules for unittest

"""

import commands
import time
import unittest

from igep_qa.helpers import common

class TestNetwork(unittest.TestCase):
    """Generic tests for network interfaces.

    .. warning::

        The interface is set up when the test start and set down when finishes.

    Keyword arguments:
        - testname : The name of the test to be executed.
        - ipaddr : The local IP address.
        - serverip : The remote IP address.
        - interface : The interface to be used, e.g. eth0, wlan0.
        - min_throughput : The minimum throughput required (in MBits)

    Prerequisite commands:
        - ifconfig
        - iperf
        - ping

    """
    def __init__(self, testname, ipaddr, serverip, interface, min_throughput = 90):
        super(TestNetwork, self).__init__(testname)
        self.ipaddr = ipaddr
        self.serverip = serverip
        self.interface = interface
        self.min_throughput = min_throughput

    def setUp(self):
        # NOT deconfiguring network interfaces in follwing cases 
        # - If / is an NFS mount
        # - Pinging local address 127.0.0.1
        # Instead of, use an ethernet alias.
        if common.is_nfsroot() or self.serverip == "127.0.0.1" :
            self.interface = "%s:0" % self.interface
        commands.getstatusoutput("ifconfig %s down" % self.interface)
        commands.getstatusoutput("ifconfig %s %s"
                                "" % (self.interface, self.ipaddr))
        # Use a small delay to be sure the interface is up
        time.sleep(1)
<commit_msg>tests/qnetwork: Avoid false positives pinging the serverip before test.<commit_after>#!/usr/bin/env python

"""
Network Test Cases modules for unittest

"""

import commands
import time
import unittest

from igep_qa.helpers import common

class TestNetwork(unittest.TestCase):
    """Generic tests for network interfaces.

    .. warning::

        The interface is set up when the test start and set down when finishes.

    Keyword arguments:
        - testname : The name of the test to be executed.
        - ipaddr : The local IP address.
        - serverip : The remote IP address.
        - interface : The interface to be used, e.g. eth0, wlan0.
        - min_throughput : The minimum throughput required (in MBits)

    Prerequisite commands:
        - ifconfig
        - iperf
        - ping

    """
    def __init__(self, testname, ipaddr, serverip, interface, min_throughput = 90):
        super(TestNetwork, self).__init__(testname)
        self.ipaddr = ipaddr
        self.serverip = serverip
        self.interface = interface
        self.min_throughput = min_throughput

    def setUp(self):
        # NOT deconfiguring network interfaces in follwing cases 
        # - If / is an NFS mount
        # - Pinging local address 127.0.0.1
        # Instead of, use an ethernet alias.
        if common.is_nfsroot() or self.serverip == "127.0.0.1" :
            self.interface = "%s:0" % self.interface
        # Force to down the interface
        commands.getstatusoutput("ifconfig %s down" % self.interface)
        # Use a small delay to be sure the interface is down
        time.sleep(1)
        # Verify that we're not able to ping the server when interface is down,
        # this check is useful to avoid false positives.
        retval = commands.getstatusoutput("ping -c 1 %s" % self.serverip)
        self.failIf(retval[0] == 0, "failed: Pinging to %s %s" % (self.serverip, retval[1]))
        # Set up the interface
        commands.getstatusoutput("ifconfig %s %s"
                                "" % (self.interface, self.ipaddr))
        # Use a small delay to be sure the interface is up
        time.sleep(1)

{'fraction_non_alphanumeric': 0.08647214854111406, 'fraction_numerical': 0.010875331564986738, 'mean_word_length': 2.2508620689655174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1519879', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1042, 'n_words': 371}