Exemplo n.º 1
0
def _validate_miimon_conf(kwargs, required=True):
    """
    Validate miimon configuration
    """
    # Make copy of kwargs so we don't modify what was passed in
    kwargs = copy.copy(kwargs)

    # Remove miimon and downdelay (if present) to test invalid input
    for key in ("miimon", "downdelay"):
        kwargs.pop(key, None)

    if required:
        # Leaving out miimon should raise an error
        try:
            suse_ip.build_interface(
                "bond0",
                "bond",
                enabled=True,
                **kwargs,
            )
        except AttributeError as exc:
            assert "miimon" in str(exc)
        else:
            raise Exception("AttributeError was not raised")

    _validate_miimon_downdelay(kwargs)
Exemplo n.º 2
0
def _get_bonding_opts(kwargs):
    results = suse_ip.build_interface(
        "bond0",
        "bond",
        enabled=True,
        **kwargs,
    )
    _check_common_opts_bond(results)

    for line in results:
        if line.startswith("BONDING_MODULE_OPTS="):
            return sorted(line.split("=", 1)[-1].strip("'").split())
    raise Exception("BONDING_MODULE_OPTS not found")
Exemplo n.º 3
0
def _validate_miimon_downdelay(kwargs):
    """
    Validate that downdelay that is not a multiple of miimon raises an error
    """
    # Make copy of kwargs so we don't modify what was passed in
    kwargs = copy.copy(kwargs)

    # Remove miimon and downdelay (if present) to test invalid input
    for key in ("miimon", "downdelay"):
        kwargs.pop(key, None)

    kwargs["miimon"] = 100
    kwargs["downdelay"] = 201
    try:
        suse_ip.build_interface(
            "bond0",
            "bond",
            enabled=True,
            **kwargs,
        )
    except AttributeError as exc:
        assert "multiple of miimon" in str(exc)
    else:
        raise Exception("AttributeError was not raised")
Exemplo n.º 4
0
def test_build_interface_bond_slave():
    """
    Test that bond slave interfaces are properly built
    """
    results = sorted(
        suse_ip.build_interface(
            "eth1",
            "slave",
            enabled=True,
            test=True,
            master="bond0",
        ))
    expected = [
        "BOOTPROTO='none'",
        "STARTMODE='auto'",
    ]
    assert results == expected, results
Exemplo n.º 5
0
def test_build_interface():
    """
    Test to build an interface script for a network interface.
    """
    with patch.object(suse_ip, "_raise_error_iface", return_value=None):
        with pytest.raises(AttributeError):
            suse_ip.build_interface("iface", "slave", True)

        with patch.dict(suse_ip.__salt__,
                        {"network.interfaces": lambda: {
                            "eth": True
                        }}):
            with pytest.raises(AttributeError):
                suse_ip.build_interface(
                    "iface",
                    "eth",
                    True,
                    netmask="255.255.255.255",
                    prefix=32,
                    test=True,
                )
            with pytest.raises(AttributeError):
                suse_ip.build_interface(
                    "iface",
                    "eth",
                    True,
                    ipaddrs=["A"],
                    test=True,
                )
            with pytest.raises(AttributeError):
                suse_ip.build_interface(
                    "iface",
                    "eth",
                    True,
                    ipv6addrs=["A"],
                    test=True,
                )

    with patch.object(suse_ip, "_raise_error_iface",
                      return_value=None), patch.object(suse_ip,
                                                       "_parse_settings_bond",
                                                       MagicMock()):
        mock = jinja2.exceptions.TemplateNotFound("foo")
        with patch.object(
                jinja2.Environment,
                "get_template",
                MagicMock(side_effect=mock),
        ):
            assert suse_ip.build_interface("iface", "vlan", True) == ""

        with patch.object(suse_ip, "_get_non_blank_lines",
                          return_value="A"), patch.object(
                              jinja2.Environment, "get_template", MagicMock()):
            assert suse_ip.build_interface("iface", "vlan", True,
                                           test="A") == "A"

            with patch.object(suse_ip, "_write_file_iface",
                              return_value=None), patch.object(
                                  os.path, "join",
                                  return_value="A"), patch.object(
                                      suse_ip, "_read_file", return_value="A"):
                assert suse_ip.build_interface("iface", "vlan", True) == "A"
                with patch.dict(
                        suse_ip.__salt__,
                    {"network.interfaces": lambda: {
                        "eth": True
                    }},
                ):
                    assert (suse_ip.build_interface(
                        "iface",
                        "eth",
                        True,
                        ipaddrs=["127.0.0.1/8"],
                    ) == "A")
                    assert (suse_ip.build_interface(
                        "iface",
                        "eth",
                        True,
                        ipv6addrs=["fc00::1/128"],
                    ) == "A")