Esempio n. 1
0
    def test_list_ips_by_iface_v6_mainline(self):
        retval = futils.CommandOutput(
            "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 \n"
            "    inet6 ::1/128 scope host \n"
            "       valid_lft forever preferred_lft forever\n"
            "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000\n"
            "    inet6 fe80::20c:29ff:fecb:c819/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n"
            "4: mgmt0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 \n"
            "    inet6 fe80::1/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n"
            "    inet6 fe80::8872:90ff:fec4:f79e/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n",
            ""
        )

        with mock.patch('calico.felix.futils.check_call',
                        return_value=retval) as m_check_call:
            ips = devices.list_ips_by_iface(futils.IPV6)
        self.assertEqual(
            ips,
            {
                "lo": {IPAddress("::1")},
                "eth0": {IPAddress("fe80::20c:29ff:fecb:c819")},
                "mgmt0": {IPAddress("fe80::1"),
                          IPAddress("fe80::8872:90ff:fec4:f79e")},
            }
        )
Esempio n. 2
0
    def test_list_ips_by_iface_v4_mainline(self):
        retval = futils.CommandOutput(
            "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default \n"
            "    inet 127.0.0.1/8 scope host lo\n"
            "       valid_lft forever preferred_lft forever\n"
            "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"
            "    inet 192.168.171.128/24 brd 192.168.171.255 scope global eth0\n"
            "       valid_lft forever preferred_lft forever\n"
            "3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"
            "    inet 172.16.171.5/24 brd 172.16.171.255 scope global eth1\n"
            "       valid_lft forever preferred_lft forever\n"
            "5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default \n"
            "    inet 172.17.0.1/16 scope global docker0\n"
            "       valid_lft forever preferred_lft forever\n"
            "6: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default \n"
            "    inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0\n"
            "       valid_lft forever preferred_lft forever\n"
            "    inet 10.0.3.2/24 brd 10.0.3.255 scope global lxcbr0\n"
            "       valid_lft forever preferred_lft forever\n",
            ""
        )

        with mock.patch('calico.felix.futils.check_call',
                        return_value=retval) as m_check_call:
            ips = devices.list_ips_by_iface(futils.IPV4)
        self.assertEqual(
            ips,
            {
                "lo": {IPAddress("127.0.0.1")},
                "eth0": {IPAddress("192.168.171.128")},
                "eth1": {IPAddress("172.16.171.5")},
                "docker0": {IPAddress("172.17.0.1")},
                "lxcbr0": {IPAddress("10.0.3.1"), IPAddress("10.0.3.2")},
            }
        )
Esempio n. 3
0
    def _poll_interfaces(self, known_interfaces):
        """Does a single poll of the host interfaces, looking for IP changes.

        Sends updates to the EndpointManager via the _on_iface_ips_update()
        message.

        This is broken out form the loop above to make it easier to test.

        :param known_interfaces:
        :return:
        """
        # We only care about host interfaces, not workload ones.
        exclude_prefixes = self.config.IFACE_PREFIX
        # Get the IPs for each interface.
        ips_by_iface = devices.list_ips_by_iface(self.ip_type)
        for iface, ips in ips_by_iface.items():
            ignore_iface = any(
                iface.startswith(prefix) for prefix in exclude_prefixes)
            if ignore_iface:
                # Ignore non-host interfaces.
                ips_by_iface.pop(iface)
            else:
                # Compare with the set of IPs that were there before.
                # We pop interfaces that we see so that we can clean up
                # deletions below.
                old_ips = known_interfaces.pop(iface, None)
                if old_ips != ips:
                    _log.debug("IPs of interface %s changed to %s", iface, ips)
                    self._on_iface_ips_update(iface, ips, async=True)
        # Clean up deletions.  Anything left in known_interfaces has
        # been deleted.
        for iface, ips in known_interfaces.iteritems():
            self._on_iface_ips_update(iface, None, async=True)
        # Update our cache of known interfaces for the next loop.
        return ips_by_iface
Esempio n. 4
0
    def test_list_ips_by_iface_v6_mainline(self):
        retval = futils.CommandOutput(
            "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 \n"
            "    inet6 ::1/128 scope host \n"
            "       valid_lft forever preferred_lft forever\n"
            "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qlen 1000\n"
            "    inet6 fe80::20c:29ff:fecb:c819/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n"
            "4: mgmt0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 \n"
            "    inet6 fe80::1/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n"
            "    inet6 fe80::8872:90ff:fec4:f79e/64 scope link \n"
            "       valid_lft forever preferred_lft forever\n",
            ""
        )

        with mock.patch('calico.felix.futils.check_call',
                        return_value=retval) as m_check_call:
            ips = devices.list_ips_by_iface(futils.IPV6)
        self.assertEqual(
            ips,
            {
                "lo": {IPAddress("::1")},
                "eth0": {IPAddress("fe80::20c:29ff:fecb:c819")},
                "mgmt0": {IPAddress("fe80::1"),
                          IPAddress("fe80::8872:90ff:fec4:f79e")},
            }
        )
Esempio n. 5
0
    def test_list_ips_by_iface_v4_mainline(self):
        retval = futils.CommandOutput(
            "1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default \n"
            "    inet 127.0.0.1/8 scope host lo\n"
            "       valid_lft forever preferred_lft forever\n"
            "2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"
            "    inet 192.168.171.128/24 brd 192.168.171.255 scope global eth0\n"
            "       valid_lft forever preferred_lft forever\n"
            "3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000\n"
            "    inet 172.16.171.5/24 brd 172.16.171.255 scope global eth1\n"
            "       valid_lft forever preferred_lft forever\n"
            "5: docker0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default \n"
            "    inet 172.17.0.1/16 scope global docker0\n"
            "       valid_lft forever preferred_lft forever\n"
            "6: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default \n"
            "    inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0\n"
            "       valid_lft forever preferred_lft forever\n"
            "    inet 10.0.3.2/24 brd 10.0.3.255 scope global lxcbr0\n"
            "       valid_lft forever preferred_lft forever\n",
            ""
        )

        with mock.patch('calico.felix.futils.check_call',
                        return_value=retval) as m_check_call:
            ips = devices.list_ips_by_iface(futils.IPV4)
        self.assertEqual(
            ips,
            {
                "lo": {IPAddress("127.0.0.1")},
                "eth0": {IPAddress("192.168.171.128")},
                "eth1": {IPAddress("172.16.171.5")},
                "docker0": {IPAddress("172.17.0.1")},
                "lxcbr0": {IPAddress("10.0.3.1"), IPAddress("10.0.3.2")},
            }
        )
Esempio n. 6
0
    def _poll_interfaces(self, known_interfaces):
        """Does a single poll of the host interfaces, looking for IP changes.

        Sends updates to the EndpointManager via the _on_iface_ips_update()
        message.

        This is broken out form the loop above to make it easier to test.

        :param known_interfaces:
        :return:
        """
        # We only care about host interfaces, not workload ones.
        exclude_prefix = self.config.IFACE_PREFIX
        # Get the IPs for each interface.
        ips_by_iface = devices.list_ips_by_iface(self.ip_type)
        for iface, ips in ips_by_iface.items():
            if iface.startswith(exclude_prefix):
                # Ignore non-host interfaces.
                ips_by_iface.pop(iface)
            else:
                # Compare with the set of IPs that were there before.
                # We pop interfaces that we see so that we can clean up
                # deletions below.
                old_ips = known_interfaces.pop(iface, None)
                if old_ips != ips:
                    _log.debug("IPs of interface %s changed to %s",
                               iface, ips)
                    self._on_iface_ips_update(iface, ips, async=True)
        # Clean up deletions.  Anything left in known_interfaces has
        # been deleted.
        for iface, ips in known_interfaces.iteritems():
            self._on_iface_ips_update(iface, None, async=True)
        # Update our cache of known interfaces for the next loop.
        return ips_by_iface