# Buggy code
def resolve_stack_topology(self, dps):
    """Resolve inter-DP config for stacking."""
    root_dp = None
    stack_dps = []
    for dp in dps:
        if dp.stack is not None:
            stack_dps.append(dp)
            if "priority" in dp.stack:
                test_config_condition(
                    dp.stack["priority"] <= 0, ("stack priority must be > 0")
                )
                test_config_condition(
                    root_dp is not None, "cannot have multiple stack roots"
                )
                root_dp = dp
                for vlan in dp.vlans.values():
                    test_config_condition(
                        vlan.faucet_vips, ("routing + stacking not supported")
                    )

    if root_dp is None:
        test_config_condition(stack_dps, "stacking enabled but no root_dp")
        return

    edge_count = Counter()

    graph = networkx.MultiGraph()
    for dp in dps:
        if dp.stack_ports:
            graph.add_node(dp.name)
            for port in dp.stack_ports:
                edge_name = self.add_stack_link(graph, dp, port)
                edge_count[edge_name] += 1
    if graph.size():
        for edge_name, count in edge_count.items():
            test_config_condition(
                count != 2, "%s defined only in one direction" % edge_name
            )
        if self.name in graph:
            if self.stack is None:
                self.stack = {}
            self.stack["root_dp"] = root_dp
            self.stack["graph"] = graph
            longest_path_to_root_len = 0
            for dp in graph.nodes():
                path_to_root_len = len(self.shortest_path(root_dp.name, src_dp=dp))
                test_config_condition(
                    path_to_root_len == 0, "%s not connected to stack" % dp
                )
                longest_path_to_root_len = max(
                    path_to_root_len, longest_path_to_root_len
                )
            self.stack["longest_path_to_root_len"] = longest_path_to_root_len


# Traceback (TypeError)
Oct 30 03:01:40 faucet.exception ERROR    Unhandled exception, killing RYU
Traceback (most recent call last):
File "/usr/lib/python3.6/site-packages/faucet/valve_util.py", line 34, in __koe
func(*args, **kwargs)
File "/usr/lib/python3.6/site-packages/faucet/faucet.py", line 156, in reload_config
time.time(), self.config_file, delete_dp=self._delete_deconfigured_dp)
File "/usr/lib/python3.6/site-packages/faucet/valves_manager.py", line 139, in request_reload_configs
self.load_configs(now, new_config_file, delete_dp=delete_dp)
File "/usr/lib/python3.6/site-packages/faucet/valves_manager.py", line 108, in load_configs
new_dps = self.parse_configs(new_config_file)
File "/usr/lib/python3.6/site-packages/faucet/valves_manager.py", line 88, in parse_configs
new_config_hashes, new_dps = dp_parser(new_config_file, self.logname)
File "/usr/lib/python3.6/site-packages/faucet/config_parser.py", line 51, in dp_parser
config_hashes, dps = _config_parser_v2(config_file, logname)
File "/usr/lib/python3.6/site-packages/faucet/config_parser.py", line 213, in _config_parser_v2
top_confs['vlans'])
File "/usr/lib/python3.6/site-packages/faucet/config_parser.py", line 181, in _dp_parser_v2
dp.resolve_stack_topology(dps)
File "/usr/lib/python3.6/site-packages/faucet/dp.py", line 614, in resolve_stack_topology
test_config_condition(dp.stack['priority'] <= 0, (
TypeError: '<=' not supported between instances of 'NoneType' and 'int'

# Fixed code
def resolve_stack_topology(self, dps):
    """Resolve inter-DP config for stacking."""
    root_dp = None
    stack_dps = []
    for dp in dps:
        if dp.stack is not None:
            stack_dps.append(dp)
            if "priority" in dp.stack:
                test_config_condition(
                    not isinstance(dp.stack["priority"], int),
                    (
                        "stack priority must be type %s not %s"
                        % (int, type(dp.stack["priority"]))
                    ),
                )
                test_config_condition(
                    dp.stack["priority"] <= 0, ("stack priority must be > 0")
                )
                test_config_condition(
                    root_dp is not None, "cannot have multiple stack roots"
                )
                root_dp = dp
                for vlan in dp.vlans.values():
                    test_config_condition(
                        vlan.faucet_vips, ("routing + stacking not supported")
                    )

    if root_dp is None:
        test_config_condition(stack_dps, "stacking enabled but no root_dp")
        return

    edge_count = Counter()

    graph = networkx.MultiGraph()
    for dp in dps:
        if dp.stack_ports:
            graph.add_node(dp.name)
            for port in dp.stack_ports:
                edge_name = self.add_stack_link(graph, dp, port)
                edge_count[edge_name] += 1
    if graph.size():
        for edge_name, count in edge_count.items():
            test_config_condition(
                count != 2, "%s defined only in one direction" % edge_name
            )
        if self.name in graph:
            if self.stack is None:
                self.stack = {}
            self.stack["root_dp"] = root_dp
            self.stack["graph"] = graph
            longest_path_to_root_len = 0
            for dp in graph.nodes():
                path_to_root_len = len(self.shortest_path(root_dp.name, src_dp=dp))
                test_config_condition(
                    path_to_root_len == 0, "%s not connected to stack" % dp
                )
                longest_path_to_root_len = max(
                    path_to_root_len, longest_path_to_root_len
                )
            self.stack["longest_path_to_root_len"] = longest_path_to_root_len