def file_status_snapshot(network):
    bf_set_network(network)
    name = uuid.uuid4().hex
    bf_init_snapshot(join(_this_dir, 'snapshot_file_status'), name)
    yield name
    # cleanup
    bf_delete_snapshot(name)
def roles_snapshot(network):
    bf_set_network(network)
    name = uuid.uuid4().hex
    bf_init_snapshot(join(_this_dir, 'roles_snapshot'), name)
    yield name
    # cleanup
    bf_delete_snapshot(name)
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 example_snapshot(network):
    bf_set_network(network)
    name = uuid.uuid4().hex
    bf_init_snapshot(join(_this_dir, "snapshot"), name)
    yield name
    # cleanup
    bf_delete_snapshot(name)
示例#5
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")

    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 check_interfaces(self, node_and_interfaces: [str]) -> List[int]:
     case_base = tempfile.TemporaryDirectory()
     shutil.copytree(self.base, case_base.name + "/", dirs_exist_ok=True)
     remove_interface_in_config(case_base.name, node_and_interfaces)
     case_base_snapshot = self.new_snapshot_name(case_base.name)
     violated_policies = self.get_violated_policies(case_base_snapshot)
     bf_delete_snapshot(case_base_snapshot)
     return violated_policies
def test_init_snapshot_no_crash(network):
    """Run some init snapshot commands. The goal is not to crash."""
    bf_set_network(network)
    uid = uuid.uuid4().hex
    try:
        bf_init_snapshot(join(_this_dir, 'snapshot'), uid)
        bf_generate_dataplane()
    finally:
        # cleanup
        bf_delete_snapshot(uid)
def test_fork_snapshot_add_files(network, example_snapshot):
    """Run fork snapshot command that adds files."""
    name = uuid.uuid4().hex

    bf_set_network(network)
    try:
        # Should succeed uploading a zip with a new file
        bf_fork_snapshot(base_name=example_snapshot,
                         name=name,
                         add_files=join(_this_dir, 'fork'))

    finally:
        bf_delete_snapshot(name)
def test_fork_snapshot(network, example_snapshot):
    """Run fork snapshot command with valid and invalid inputs."""
    name = uuid.uuid4().hex

    bf_set_network(network)
    try:
        # Should succeed with existent base snapshot and valid name
        bf_fork_snapshot(base_name=example_snapshot, name=name)

        # Fail using existing snapshot name without specifying overwrite
        with pytest.raises(ValueError):
            bf_fork_snapshot(base_name=example_snapshot, name=name)
    finally:
        bf_delete_snapshot(name)
示例#10
0
 def run(self):
     output_path = os.path.join(self.base, "raw.json")
     results = json.load(open(output_path))
     idx = 0
     for interface, affected_nodes, snapshot, selection_type, config_path in self.generate_test_case(results):
         print(f"Interface {interface} is down.")
         if interface not in results:
             results[interface] = {}
         if selection_type not in results[interface]:
             results[interface][selection_type] = {
                 "affected_nodes": list(affected_nodes),
                 "solutions": {}
             }
         for solution, name in self.solutions:
             if name not in results[interface][selection_type]['solutions']:
                 s = solution(snapshot, config_path, list(affected_nodes))
                 internal_nodes = s.get_internal_nodes()
                 results[interface][selection_type]['solutions'][name] = list(internal_nodes)
         json.dump(results, open(output_path, "w"), indent=2)
         bf_delete_snapshot(snapshot)
         idx += 10
         if idx == 15:
             idx = 0
             reset()
示例#11
0
def interfaces_from_snapshot(snapshot: str, nodes: str = None) -> Set[str]:
    cache_path = os.path.join(snapshot, "interface_from_snapshot.json")
    found = False
    if os.path.exists(cache_path):
        found = True
        caches = json.load(open(cache_path))
    else:
        bf_init_snapshot(snapshot, "interface_from_snapshot", overwrite=True)
        caches = {}
    if len(caches) == 0:
        results = bfq.interfaceProperties().answer(
            snapshot="interface_from_snapshot").frame()
        for _, result in results.iterrows():
            if result.Interface.hostname not in caches:
                caches[result.Interface.hostname] = []
            caches[result.Interface.hostname].append(
                interface_to_str(result.Interface))
    json.dump(caches, open(cache_path, "w"))
    if not found:
        bf_delete_snapshot("interface_from_snapshot")
    if nodes:
        return set(caches[nodes])
    else:
        return set([y for x in caches.values() for y in x])
示例#12
0
 def delete_snapshot(self, snapshot):
     bf_delete_snapshot(snapshot)