Exemplo n.º 1
0
 def eject(self):
     cmdline = "ip netns exec %s ip link set dev %s up"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s up in %s' \
               % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     time.sleep(self._wait)
Exemplo n.º 2
0
 def eject(self):
     cmdline = "ip netns exec %s iptables -i %s -D INPUT -j DROP"  \
         % (self._netns, self._interface)
     LOG.debug('take packets coming from %s in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     time.sleep(self._wait)
Exemplo n.º 3
0
 def eject(self):
     cmdline = "ip netns exec %s ip link set dev %s up"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s up in %s' \
               % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     time.sleep(self._wait)
Exemplo n.º 4
0
    def delete(self):
        """
        Delete the interface from bridge
        """
        LOG.debug("delete")

        brname = self._interface['bridge']['brname']
        ifname_peer = self._get_peer_ifname()
        cmdline = "brctl delif %s %s" % (brname, ifname_peer)
        LOG.debug('Trunk: deleting %s from %s' % (brname, ifname_peer))
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError:
            pass
        except OSError:
            pass

        cmdline = "ip link delete " + ifname_peer
        LOG.debug('Trunk: deleting the iface: ' + ifname_peer)
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError:
            pass
        except OSError:
            pass
Exemplo n.º 5
0
 def eject(self):
     cmdline = "ip netns exec %s iptables -i %s -D INPUT -j DROP"  \
         % (self._netns, self._interface)
     LOG.debug('take packets coming from %s in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     time.sleep(self._wait)
Exemplo n.º 6
0
    def delete(self):
        """
        Delete the interface from bridge
        """
        LOG.debug("delete")

        brname = self._interface['bridge']['brname']
        ifname_peer = self._get_peer_ifname()
        cmdline = "brctl delif %s %s" % (brname, ifname_peer)
        LOG.debug('Trunk: deleting %s from %s' % (brname, ifname_peer))
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError:
            pass
        except OSError:
            pass

        cmdline = "ip link delete " + ifname_peer
        LOG.debug('Trunk: deleting the iface: ' + ifname_peer)
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError:
            pass
        except OSError:
            pass
Exemplo n.º 7
0
 def inject(self):
     cmdline =  "ip netns exec %s ip link set dev %s down"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s down in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     # check the zk host actually went down
     check_zookeeper_host(self._ip, alive=False)
Exemplo n.º 8
0
 def eject(self):
     cmdline =  "ip netns exec %s ip link set dev %s up"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s up in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     # Check the zk host actually went up and in quorum
     check_zookeeper_host(self._ip, alive=True)
Exemplo n.º 9
0
 def inject(self):
     cmdline =  "ip netns exec %s ip link set dev %s down"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s down in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     # check the zk host actually went down
     check_zookeeper_host(self._ip, alive=False)
Exemplo n.º 10
0
 def eject(self):
     cmdline =  "ip netns exec %s ip link set dev %s up"  \
         % (self._netns, self._interface)
     LOG.debug('set dev %s up in %s' \
                   % (self._interface, self._netns))
     subprocess_compat.check_output(cmdline.split())
     # Check the zk host actually went up and in quorum
     check_zookeeper_host(self._ip, alive=True)
Exemplo n.º 11
0
            def put_veth_to_mm_ns(future):
                self._interface = future.result()
                ifname = self._interface['ifname']

                cmdline = 'ip link set %s netns %s' % (ifname, nsname)
                LOG.debug('VethNs: putting host veth to MM ns ' + cmdline)
                subprocess_compat.check_output(cmdline.split())

                cmdline = 'ip netns exec %s ip  link set %s up' % (nsname,
                                                                   ifname)
                LOG.debug('VethNs: setting IF up ' + cmdline)
                subprocess_compat.check_output(cmdline.split())
Exemplo n.º 12
0
    def delete(self):
        """
        Delete this veth + NS
        """

        cmdline = "ip netns del " + self._get_nsname()
        LOG.debug('VethNs: deleting the ns: ' + cmdline)
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError as e:
            LOG.exception(e)
        except OSError as e:
            LOG.exception(e)
Exemplo n.º 13
0
    def delete(self):

        """
        Delete this veth + NS
        """

        cmdline = "ip netns del " + self._get_nsname()
        LOG.debug('VethNs: deleting the ns: ' + cmdline)
        try:
            subprocess_compat.check_output(cmdline.split())
        except subprocess.CalledProcessError as e:
            LOG.exception(e)
        except OSError as e:
            LOG.exception(e)
Exemplo n.º 14
0
    def _clear():
        cmdline = ("for ns in `ip netns | grep -- ns-if-`; "
                   "do sudo -i ip netns delete $ns 2>/dev/null; done")
        logging.debug("cmdline: " + cmdline)
        try:
            subprocess_compat.check_output(cmdline, shell=True)
        except subprocess.CalledProcessError:
            pass

        cmdline = ("for iface in `ip link | grep -- if- | cut -d ':' -f 2`; "
                   "do sudo -i ip link delete $iface 2>/dev/null; done")
        logging.debug("cmdline: " + cmdline)
        try:
            subprocess_compat.check_output(cmdline, shell=True)
        except subprocess.CalledProcessError:
            pass
Exemplo n.º 15
0
    def execute(self, cmdline, timeout=None):
        """Executes cmdline inside the namespace

        Args:
            cmdline: command line string that'll be executed in the network
                      namespace.
            timeout: timeout in second

        Returns:
            output as a bytestring


        Raises:
            subprocess.CalledProcessError: when the command exists with non-zero
                                           value, including timeout.
            OSError: when the executable is not found or some other error
                     invoking
        """

        cmdline = self._process_cmdline(cmdline, timeout)
        LOG.debug('VethNs: executing command: %s', cmdline)
        #NOTE(tomoe): I know shell=True is insecure, but I trust people here :)
        result = subprocess_compat.check_output(cmdline, shell=True)
        LOG.debug('Result=%r', result)
        return result
Exemplo n.º 16
0
    def execute(self, cmdline, timeout=None):
        """Executes cmdline inside the namespace

        Args:
            cmdline: command line string that'll be executed in the network
                      namespace.
            timeout: timeout in second

        Returns:
            output as a bytestring


        Raises:
            subprocess.CalledProcessError: when the command exists with non-zero
                                           value, including timeout.
            OSError: when the executable is not found or some other error
                     invoking
        """

        cmdline = self._process_cmdline(cmdline, timeout)
        LOG.debug('VethNs: executing command: %s', cmdline)
        #NOTE(tomoe): I know shell=True is insecure, but I trust people here :)
        result = subprocess_compat.check_output(cmdline, shell=True)
        LOG.debug('Result=%r', result)
        return result
Exemplo n.º 17
0
    def _clear():
        cmdline = ("for ns in `ip netns | grep -- ns-if-`; "
                   "do sudo -i ip netns delete $ns 2>/dev/null; done")
        logging.debug("cmdline: " + cmdline)
        try:
            subprocess_compat.check_output(cmdline, shell=True)
        except subprocess.CalledProcessError:
            pass

        cmdline = ("for iface in `ip link | grep -- if- | cut -d ':' -f 2`; "
                   "do sudo -i ip link delete $iface 2>/dev/null; done")
        logging.debug("cmdline: " + cmdline)
        try:
            subprocess_compat.check_output(cmdline, shell=True)
        except subprocess.CalledProcessError:
            pass
Exemplo n.º 18
0
    def _get_midolman_logs_for_test(self, test_id):
        """Returns a string that contains midolman logs relevant
           to the test"""
        markers = self._get_markers_for_test(test_id)

        cmdline = self.tools_path + '/' +  \
            "dump_midolman_logs_for_test.sh '%s' '%s' '%s'" % (
            markers['start'], markers['end'], test_id)

        return subprocess_compat.check_output(cmdline, shell=True)
Exemplo n.º 19
0
    def _get_midolman_logs_for_test(self, test_id):
        """Returns a string that contains midolman logs relevant
           to the test"""
        markers = self._get_markers_for_test(test_id)

        cmdline = self.tools_path + '/' +  \
            "dump_midolman_logs_for_test.sh '%s' '%s' '%s'" % (
            markers['start'], markers['end'], test_id)

        return subprocess_compat.check_output(cmdline, shell=True)
Exemplo n.º 20
0
    def create(self):
        LOG.debug('create')
        brname = self._interface['bridge']['brname']
        ifname = self._get_ifname()
        ifname_peer = self._get_peer_ifname()

        #NOTE: may want to have idempotent version?
        try :
            # create a veth pair
            cmdline =  "ip link add dev %s type veth peer name %s" % (
                ifname, ifname_peer)
            LOG.debug('VethNs: creating a veth pair: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # add an end of the pair to bridge
            ifname_peer = self._get_peer_ifname()
            LOG.debug('Trunk: adding %s to %s' % (brname, ifname_peer))
            cmdline = "brctl addif %s %s" % (brname, ifname_peer)
            subprocess_compat.check_output(cmdline.split())
            cmdline = "ip link set dev %s up" % (ifname_peer,)
            subprocess_compat.check_output(cmdline.split())

            return self._interface

        except Exception as e:
            LOG.error('Either creating veth or namespace failed: ' + str(e))
            raise e
Exemplo n.º 21
0
    def create(self):
        LOG.debug('create')
        brname = self._interface['bridge']['brname']
        ifname = self._get_ifname()
        ifname_peer = self._get_peer_ifname()

        #NOTE: may want to have idempotent version?
        try:
            # create a veth pair
            cmdline = "ip link add dev %s type veth peer name %s" % (
                ifname, ifname_peer)
            LOG.debug('VethNs: creating a veth pair: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # add an end of the pair to bridge
            ifname_peer = self._get_peer_ifname()
            LOG.debug('Trunk: adding %s to %s' % (brname, ifname_peer))
            cmdline = "brctl addif %s %s" % (brname, ifname_peer)
            subprocess_compat.check_output(cmdline.split())
            cmdline = "ip link set dev %s up" % (ifname_peer, )
            subprocess_compat.check_output(cmdline.split())

            return self._interface

        except Exception as e:
            LOG.error('Either creating veth or namespace failed: ' + str(e))
            raise e
Exemplo n.º 22
0
    def report(self, stream):
        """Add per suite logs right at the end of a test run"""

        cmd = self.tools_path + '/' +  'dump_per_suite_logs.sh'
        out = subprocess_compat.check_output(cmd)
        stream.writeln(out)
Exemplo n.º 23
0
    def report(self, stream):
        """Add per suite logs right at the end of a test run"""

        cmd = self.tools_path + '/' + 'dump_per_suite_logs.sh'
        out = subprocess_compat.check_output(cmd)
        stream.writeln(out)
Exemplo n.º 24
0
 def _mark_mm_logs(self, marker_text):
     cmdline = self.tools_path + '/' +  'mark_mm_logs.sh ' + marker_text
     subprocess_compat.check_output(cmdline, shell=True)
Exemplo n.º 25
0
 def _get_per_test_logs(self, test):
     """Returns mmm log in string"""
     cmd = self.tools_path + '/' + 'dump_per_test_logs.sh'
     return subprocess_compat.check_output(cmd)
Exemplo n.º 26
0
def stop_midolman_agents():
    """Stops all Midolman agents."""
    subprocess_compat.check_output('cd %s; ./stop' % get_midolman_script_dir(),
                                   shell=True)
Exemplo n.º 27
0
 def _get_per_test_logs(self, test):
     """Returns mmm log in string"""
     cmd = self.tools_path + '/' +  'dump_per_test_logs.sh'
     return subprocess_compat.check_output(cmd)
Exemplo n.º 28
0
def stop_midolman_agents():
    """Stops all Midolman agents."""
    subprocess_compat.check_output(
        'cd %s; ./stop' % get_midolman_script_dir(), shell=True)
Exemplo n.º 29
0
 def _mark_mm_logs(self, marker_text):
     cmdline = self.tools_path + '/' + 'mark_mm_logs.sh ' + marker_text
     subprocess_compat.check_output(cmdline, shell=True)
Exemplo n.º 30
0
 def brctl(instr, trunk):
     cmd = 'brctl %s brv0 %s' % (instr, ifname(trunk))
     subprocess_compat.check_output(cmd.split())
Exemplo n.º 31
0
    def create(self):
        """Create a veth + network namespace.

        Args:
            N/A

        Returns:
           None

        Raises:
            subprocess.CalledProcessError: when one of the commands to set
                                           up the veth+ns environment fails
        """

        LOG.debug('create')
        ifname = self._get_ifname()
        ifname_peer = self._get_peer_ifname()

        #NOTE: may want to have idempotent version?
        try:
            # create a veth pair
            cmdline = "ip link add dev %s type veth peer name %s" % (
                ifname, ifname_peer)
            LOG.debug('VethNs: creating a veth pair: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # create a network namespace
            cmdline = "ip netns add " + self._get_nsname()
            LOG.debug('VethNs: creating a network namespace: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            if not self._interface.get('ipv6_addr'):
                # disable ipv6 if there's no address configured
                cmdline = 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'
                self.execute(cmdline)

        # configure hw address if any
            if self._interface.get('hw_addr'):
                cmdline = 'ip link set address %s dev %s' % (
                    self._interface['hw_addr'], ifname_peer)
                LOG.debug('VethNs: setting HW address: ' + cmdline)
                subprocess_compat.check_output(cmdline.split())

            # put the veth peer IF to the namespace that's just created.
            cmdline = "ip link set dev %s up netns %s" % (ifname_peer,
                                                          self._get_nsname())
            LOG.debug('VethNs: putting a veth to a ns: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # configure ipv4 address if any
            for addr in self._interface.get('ipv4_addr'):
                cmdline = 'ip addr add %s dev %s' % (addr, ifname_peer)
                LOG.debug('VethNs: adding ip address in the ns: ' + cmdline)
                self.execute(cmdline)

            # add default route if gateway is configured
            if self._interface.get('ipv4_gw'):
                cmdline = 'ip netns exec %s ip route add default via %s' %\
                          (self._get_nsname(), self._interface['ipv4_gw'])
                LOG.debug('VethNs: adding default route:' + cmdline)
                self.execute(cmdline)

            # takes care of ipv6 address
            if self._interface.get('ipv6_addr'):
                #TODO
                pass
            else:
                cmdline = 'ip -6 addr flush dev %s' % ifname_peer
                LOG.debug('VethNs: flushing ipv6 address: ' + cmdline)
                self.execute(cmdline)

            # set MTU if any
            if self._interface.get('mtu'):
                cmdline = "ip link set mtu %s dev %s" % (
                    self._interface['mtu'], ifname_peer)
                LOG.debug('VethNs: configuring mtu in the ns: ' + cmdline)
                self.execute(cmdline)

            return self._interface

        except Exception as e:
            LOG.error('Either creating veth or namespace failed: ' + str(e))
            raise e
Exemplo n.º 32
0
    def create(self):
        """Create a veth + network namespace.

        Args:
            N/A

        Returns:
           None

        Raises:
            subprocess.CalledProcessError: when one of the commands to set
                                           up the veth+ns environment fails
        """

        LOG.debug('create')
        ifname = self._get_ifname()
        ifname_peer = self._get_peer_ifname()

        #NOTE: may want to have idempotent version?
        try:
            # create a veth pair
            cmdline =  "ip link add dev %s type veth peer name %s" % (
                ifname, ifname_peer)
            LOG.debug('VethNs: creating a veth pair: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # create a network namespace
            cmdline =  "ip netns add " + self._get_nsname()
            LOG.debug('VethNs: creating a network namespace: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            if not self._interface.get('ipv6_addr'):
                # disable ipv6 if there's no address configured
                cmdline = 'sysctl -w net.ipv6.conf.default.disable_ipv6=1'
                self.execute(cmdline)

           # configure hw address if any
            if self._interface.get('hw_addr'):
                cmdline = 'ip link set address %s dev %s' % (
                    self._interface['hw_addr'],
                    ifname_peer)
                LOG.debug('VethNs: setting HW address: ' + cmdline)
                subprocess_compat.check_output(cmdline.split())

            # put the veth peer IF to the namespace that's just created.
            cmdline = "ip link set dev %s up netns %s" % (ifname_peer,
                                                          self._get_nsname())
            LOG.debug('VethNs: putting a veth to a ns: ' + cmdline)
            subprocess_compat.check_output(cmdline.split())

            # configure ipv4 address if any
            for addr in self._interface.get('ipv4_addr'):
                cmdline = 'ip addr add %s dev %s' % (addr, ifname_peer)
                LOG.debug('VethNs: adding ip address in the ns: ' + cmdline)
                self.execute(cmdline)

            # add default route if gateway is configured
            if self._interface.get('ipv4_gw'):
                cmdline = 'ip netns exec %s ip route add default via %s' %\
                          (self._get_nsname(), self._interface['ipv4_gw'])
                LOG.debug('VethNs: adding default route:' + cmdline)
                self.execute(cmdline)

            # takes care of ipv6 address
            if self._interface.get('ipv6_addr'):
                #TODO
                pass
            else:
                cmdline = 'ip -6 addr flush dev %s' % ifname_peer
                LOG.debug('VethNs: flushing ipv6 address: ' + cmdline)
                self.execute(cmdline)

             # set MTU if any
            if self._interface.get('mtu'):
                cmdline = "ip link set mtu %s dev %s" % (
                    self._interface['mtu'],
                    ifname_peer)
                LOG.debug('VethNs: configuring mtu in the ns: ' + cmdline)
                self.execute(cmdline)

            return self._interface

        except Exception as e:
            LOG.error('Either creating veth or namespace failed: ' + str(e))
            raise e