コード例 #1
0
ファイル: test_util.py プロジェクト: sysbot/pybatfish
def test_encoder_with_datamodel_element():
    encoder = BfJsonEncoder()

    iface = Interface(hostname='node', interface="iface")
    assert encoder.default(iface) == iface.dict()

    assert json.loads(
        json.dumps({"name": {"nested": iface}},
                   cls=BfJsonEncoder)) == {"name": {"nested": iface.dict()}}
コード例 #2
0
def test_as_dict():
    assert Interface(hostname='host', interface='iface').dict() == {
        'hostname': 'host', 'interface': 'iface'}
    assert IssueType(major='lazer', minor='coal').dict() == {'major': 'lazer',
                                                             'minor': 'coal'}

    # Make sure Edge dict is right if either string or Interface is passed in
    assert Edge(
        node1='r1',
        node1interface='iface1',
        node2='r2',
        node2interface=Interface(hostname='r2', interface='iface2')
    ).dict() == {'node1': 'r1', 'node1interface': 'iface1',
                 'node2': 'r2', 'node2interface': 'iface2'}
コード例 #3
0
def test_fork_snapshot_deactivate(network, example_snapshot):
    """Use fork snapshot to deactivate and restore items."""
    deactivate_name = uuid.uuid4().hex
    restore_name = uuid.uuid4().hex
    node = 'as2border1'
    interface = Interface(hostname='as1border1',
                          interface='GigabitEthernet1/0')
    link = Edge(node1='as2core1',
                node1interface='GigabitEthernet1/0',
                node2='as2border2',
                node2interface='GigabitEthernet2/0')

    bf_set_network(network)
    try:
        # Should succeed with deactivations
        bf_fork_snapshot(base_name=example_snapshot,
                         name=deactivate_name,
                         deactivate_interfaces=[interface],
                         deactivate_links=[link],
                         deactivate_nodes=[node])

        # Should succeed with valid restorations from snapshot with deactivation
        bf_fork_snapshot(base_name=deactivate_name,
                         name=restore_name,
                         restore_interfaces=[interface],
                         restore_links=[link],
                         restore_nodes=[node])
    finally:
        bf_delete_snapshot(deactivate_name)
        bf_delete_snapshot(restore_name)
コード例 #4
0
def test_interfacegroup_construction_list():
    """Check that we construct interface groups where sub-props are lists."""
    interface = Interface(hostname="h1", interface="i1")
    group = InterfaceGroup("g1", interfaces=[interface])

    assert group.name == "g1"
    assert group.interfaces == [interface]
コード例 #5
0
ファイル: test_snapshot_funcs.py プロジェクト: yrll/pybatfish
def test_fork_snapshot_deactivate(network, example_snapshot):
    """Use fork snapshot to deactivate and restore items."""
    deactivate_name = uuid.uuid4().hex
    restore_name = uuid.uuid4().hex
    node = "as2border1"
    interface = Interface(hostname="as1border1",
                          interface="GigabitEthernet1/0")

    bf_set_network(network)
    try:
        # Should succeed with deactivations
        bf_fork_snapshot(
            base_name=example_snapshot,
            name=deactivate_name,
            deactivate_interfaces=[interface],
            deactivate_nodes=[node],
        )

        # Should succeed with valid restorations from snapshot with deactivation
        bf_fork_snapshot(
            base_name=deactivate_name,
            name=restore_name,
            restore_interfaces=[interface],
            restore_nodes=[node],
        )
    finally:
        bf_delete_snapshot(deactivate_name)
        bf_delete_snapshot(restore_name)
コード例 #6
0
def test_interfacegroup_construction_badtype():
    """Check that we throw an error when interface group is built with wrong type."""
    with pytest.raises(ValueError):
        InterfaceGroup("g1", interfaces="i1")
    with pytest.raises(ValueError):
        InterfaceGroup(
            "book1",
            interfaces=["ag", Interface(hostname="h1", interface="i1")])
コード例 #7
0
def test_as_dict():
    assert Interface(hostname='host', interface='iface').dict() == {
        'hostname': 'host',
        'interface': 'iface'
    }
    assert IssueType(major='lazer', minor='coal').dict() == {
        'major': 'lazer',
        'minor': 'coal'
    }
コード例 #8
0
def test_as_dict():
    assert Interface(hostname="host", interface="iface").dict() == {
        "hostname": "host",
        "interface": "iface",
    }
    assert IssueType(major="lazer", minor="coal").dict() == {
        "major": "lazer",
        "minor": "coal",
    }

    # Make sure Edge dict is right if either string or Interface is passed in
    assert Edge(
        node1="r1",
        node1interface="iface1",
        node2="r2",
        node2interface=Interface(hostname="r2", interface="iface2"),
    ).dict() == {
        "node1": "r1",
        "node1interface": "iface1",
        "node2": "r2",
        "node2interface": "iface2",
    }
コード例 #9
0
 def network_failure(self,
                     base_snapshot,
                     reference_snapshot,
                     deactivate_node,
                     deactivated_int,
                     overwrite=True):
     if not deactivated_int:
         bf_fork_snapshot(base_snapshot,
                          reference_snapshot,
                          deactivate_nodes=deactivate_node,
                          overwrite=overwrite)
     else:
         bf_fork_snapshot(base_snapshot,
                          reference_snapshot,
                          deactivate_interfaces=[
                              Interface(deactivate_node[0],
                                        deactivated_int[0])
                          ],
                          overwrite=overwrite)
コード例 #10
0
def test_interfacegroup_construction_item():
    """Check that we construct address groups when sub-props are not a list."""
    interface = Interface(hostname="h1", interface="i1")
    interface_group = InterfaceGroup("g1", interfaces=[interface])
    assert InterfaceGroup("g1", interfaces=interface) == interface_group
コード例 #11
0
def test_html_interface():
    i = Interface(hostname='host', interface='special&')
    assert i._repr_html_() == "host:special&"
    i = Interface(hostname='host', interface='normal:0/0.0')
    assert i._repr_html_() == "host:normal:0/0.0"
コード例 #12
0
def test_json_serialization():
    i = Interface(hostname='host', interface='iface')
    # Load into dict from json to ignore key ordering
    assert json.loads(BfJsonEncoder().encode(i)) == json.loads(
        json.dumps(i.dict()))
コード例 #13
0
def test_json_serialization():
    i = Interface(hostname='host', interface='iface')
    assert BfJsonEncoder().encode(i) == json.dumps(i.dict())