def test_skip_alias(self, mock_get_active_interfaces):
     """Interface aliases are not reported by L{get_active_device_info}."""
     mock_get_active_interfaces.side_effect = lambda: (list(
         get_active_interfaces()) + [("eth0:foo", {})])
     device_info = get_active_device_info()
     interfaces = [i["interface"] for i in device_info]
     self.assertNotIn("eth0:foo", interfaces)
Exemple #2
0
 def test_skip_vlan(self, mock_get_active_interfaces):
     """VLAN interfaces are not reported by L{get_active_device_info}."""
     mock_get_active_interfaces.side_effect = lambda sock: (list(
         get_active_interfaces(sock)) + [b"eth0.1"])
     device_info = get_active_device_info()
     mock_get_active_interfaces.assert_called_with(ANY)
     interfaces = [i["interface"] for i in device_info]
     self.assertNotIn("eth0.1", interfaces)
 def test_skip_vlan(self, mock_get_active_interfaces):
     """VLAN interfaces are not reported by L{get_active_device_info}."""
     mock_get_active_interfaces.side_effect = lambda: (list(
         get_active_interfaces()) + [("eth0.1", {})])
     device_info = get_active_device_info()
     self.assertTrue(mock_get_active_interfaces.called)
     interfaces = [i["interface"] for i in device_info]
     self.assertNotIn("eth0.1", interfaces)
Exemple #4
0
    def test_duplicate_network_interfaces(self, mock_ioctl, mock_unpack):
        """
        L{get_active_interfaces} doesn't return duplicate network interfaces.
        The call to C{fcntl.ioctl} might return the same interface several
        times, so we make sure to clean it up.
        """
        import landscape.lib.network
        original_struct_size = landscape.lib.network.IF_STRUCT_SIZE
        landscape.lib.network.IF_STRUCT_SIZE = 40
        self.addCleanup(
            setattr, landscape.lib.network, "IF_STRUCT_SIZE",
            original_struct_size)
        # This is a fake response observed to return the same interface several
        # times (here, br1:priv)
        response = (
            b"lo\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02"
            b"\x00\x00\x00\x7f\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00eth1:pub\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x02\x00\x00\x00\xc8\xb4\xc4.\x00\x00\x00\x00\x00\x00\x00"
            b"\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00br1:metadata\x00\x00\x00\x00\x02"
            b"\x00\x00\x00\xa9\xfe\xa9\xfe\x00\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00br1:0\x00\x00\x00\x00\x00\x00\x00"
            b"\x00"
            b"\x00\x00\x00\x02\x00\x00\x00\xc9\x19\x1f\x1d\x00\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00br1\x00\x00\x00\x00"
            b"\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\xc0\xa8d"
            b"\x1d\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00br1:priv\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00\x00\xac"
            b"\x13\x02\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00"
            b"\x00\x00\x00br1:priv\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x00"
            b"\x00\xac\x13\x02A")

        fake_array = array.array("B", response + b"\0" * 4855)

        with patch("array.array") as mock_array:
            mock_array.return_value = fake_array
            mock_ioctl.return_value = 0
            mock_unpack.return_value = (280, 38643456)

            sock = socket.socket(
                socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_IP)
            interfaces = list(get_active_interfaces(sock))

        mock_array.assert_called_with("B", ANY)
        mock_ioctl.assert_called_with(ANY, ANY, ANY)
        mock_unpack.assert_called_with("iL", ANY)

        self.assertEqual(
            [b"lo", b"eth1:pub", b"br1:metadata",
             b"br1:0", b"br1", b"br1:priv"],
            interfaces)