Skip to content

Commit

Permalink
Improve error reporting and logging
Browse files Browse the repository at this point in the history
  • Loading branch information
russss committed Aug 6, 2023
1 parent f40ec41 commit e62e716
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 18 deletions.
21 changes: 13 additions & 8 deletions buildmap/plugins/noc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def __init__(self, buildmap, _config, opts, db):
self.opts = opts
self.buildmap = buildmap
self.location_layer = None
self.link_layers = {}
self.link_layers: dict[str, LinkType] = {}
self.locations = {}
self.links: list[Link] = []
self.processed_links = set()
Expand Down Expand Up @@ -117,6 +117,7 @@ def get_locations(self):
name = row["entityhandle"]
yield Location(
name,
row["entityhandle"],
int(get_col(row, "cores_required", 1)),
get_col(row, "deployed") == "true",
)
Expand Down Expand Up @@ -193,6 +194,7 @@ def get_links(self) -> Iterator[Link]:
# self.log.info("Link from %s to %s" % (from_switch, to_switch))

type = self.link_layers[row["layer"]]

self.log.info(
"Link from %s to %s %s meter"
% (from_location, to_location, row["length"])
Expand All @@ -207,14 +209,15 @@ def get_links(self) -> Iterator[Link]:
else:
self._warning(
"%s link from %s to %s had no cores, assuming 2"
% (type.title(), from_location, to_location)
% (type.value.title(), from_location, to_location)
)
cores = 2

yield Link(
from_location=from_location,
to_location=to_location,
type=type,
handle=row["entityhandle"],
link_type=type,
length=length,
cores=cores,
deployed=get_col(row, "deployed") == "true",
Expand Down Expand Up @@ -515,11 +518,13 @@ def create_physical_dot(self):
sg.add_node(node)

for link in self.links:
# if link.to_switch.name == "NOC DC2":
if not link.from_location:
self._warning(f"Link {link} has no from_location")
continue
if not link.to_location:
self._warning(f"Link {link} has no to_location")
continue
edge = pydot.Edge(link.to_location.name, link.from_location.name)
# else:
# edge = pydot.Edge(link.to_switch.name, link.from_location.name)

colour, label = self._physical_link_label_and_colour(link)
if label is None:
return None
Expand Down Expand Up @@ -562,7 +567,7 @@ def create_logical_dot(self):
return dot

def get_link_medium(self, link: Link):
return link.type.title()
return link.type.value.title()

def _write_stats(self, stats_file):
# Physical links
Expand Down
27 changes: 17 additions & 10 deletions buildmap/plugins/noc/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
CONNECTOR_LOSS = Decimal("0.1")


class LinkType():
class LinkType(Enum):
Copper = "copper"
Fibre = "fibre"

Expand All @@ -21,13 +21,20 @@ class Location:
"""The `cores_required` attribute indicates how many uplink
cores this switch requires - usually 1 bidi link in our case."""

def __init__(self, name: str, cores_required: int = 1, deployed: bool = False):
def __init__(
self,
name: str,
handle: str,
cores_required: int = 1,
deployed: bool = False,
):
self.name = name
self.handle = handle
self.cores_required = cores_required
self.deployed = deployed

def __repr__(self) -> str:
return "<Switch {}>".format(self.name)
return f"<Switch {self.name} (0x{self.handle})>"

def __eq__(self, other):
if type(other) != type(self):
Expand All @@ -51,16 +58,20 @@ def __init__(
self,
from_location: Location,
to_location: Location,
type: LinkType,
handle: str,
link_type: LinkType,
length: int,
cores: int,
aggregated: bool,
deployed: bool,
fibre_name: Optional[str],
):
if type(link_type) != LinkType:
raise ValueError(f"Link type must be a LinkType enum, got {link_type}")
self.from_location = from_location
self.to_location = to_location
self.type = type
self.handle = handle
self.type = link_type
self.length = length
self.cores = cores
self.cores_used = 0
Expand All @@ -69,11 +80,7 @@ def __init__(
self.deployed = deployed

def __repr__(self) -> str:
return "<Link {from_switch} -> {to_switch} ({type})>".format(
from_switch=self.from_location,
to_switch=self.to_location,
type=self.type.value,
)
return f"<Link {self.from_location} -> {self.to_location} ({self.type.value}, handle 0x{self.handle})>"


class LogicalLink:
Expand Down

0 comments on commit e62e716

Please sign in to comment.