Beispiel #1
0
def test_ttp_parse_no_ttp(monkeypatch):
    def mock_import_module(name):
        raise ModuleNotFoundError

    monkeypatch.setattr(importlib, "import_module", mock_import_module)

    with pytest.warns(UserWarning) as warning_msg:
        ttp_parse(template="blah", output="blah")
    assert (
        str(warning_msg._list[0].message) ==
        "\n***** Module 'None' not installed! ****************************************************\nTo resolve this issue, install 'None'. You can do this in one of the following ways:\n1: 'pip install -r requirements-ttp.txt'\n2: 'pip install scrapli[ttp]'\n***** Module 'None' not installed! ****************************************************"
    )
Beispiel #2
0
def test_ttp_no_ttp_installed(monkeypatch):
    def _import_module(name):
        raise ModuleNotFoundError

    monkeypatch.setattr("importlib.import_module", _import_module)

    with pytest.warns(UserWarning) as exc:
        output = ttp_parse("cisco_nxos", "show racecar")

    assert "Optional Extra Not Installed!" in str(exc.list[0].message)
    assert output == []
Beispiel #3
0
    def ttp_parse_output(
        self,
        template: Union[str,
                        TextIOWrapper]) -> Union[Dict[str, Any], List[Any]]:
        """
        Parse results with ttp, always return structured data

        Returns an empty list if parsing fails!

        Args:
            template: string path to ttp template or opened ttp template file

        Returns:
            structured_result: empty list or parsed data from ttp

        Raises:
            N/A

        """
        return ttp_parse(template=template, output=self.result) or []
Beispiel #4
0
def test_ttp_parse():
    # example data lifted straight out of ttp docs
    data_to_parse = """
    interface Loopback0
     description Router-id-loopback
     ip address 192.168.0.113/24
    !
    interface Vlan778
     description CPE_Acces_Vlan
     ip address 2002::fd37/124
     ip vrf CPE1
    !
    """

    ttp_template = """
    interface {{ interface }}
     ip address {{ ip }}/{{ mask }}
     description {{ description }}
     ip vrf {{ vrf }}
    """

    expected = [
        [
            {
                "ip": "192.168.0.113",
                "mask": "24",
                "description": "Router-id-loopback",
                "interface": "Loopback0",
            },
            {
                "vrf": "CPE1",
                "ip": "2002::fd37",
                "mask": "124",
                "description": "CPE_Acces_Vlan",
                "interface": "Vlan778",
            },
        ]
    ]
    result = ttp_parse(template=ttp_template, output=data_to_parse)
    assert result == expected
Beispiel #5
0
def test_ttp_parse_failed_to_parse():
    result = ttp_parse(template="mytemplateisneat", output="blah")
    assert result == [{}]
Beispiel #6
0
def test_ttp_parse_invalid_template():
    result = ttp_parse(template=None, output="blah")
    assert result == []