Skip to content

Commit

Permalink
[fwutil]: Fix component table layout. (sonic-net#831)
Browse files Browse the repository at this point in the history
Signed-off-by: Nazarii Hnydyn <nazariig@mellanox.com>
  • Loading branch information
nazariig authored Mar 24, 2020
1 parent 6e3679b commit 30adcbd
Showing 1 changed file with 55 additions and 78 deletions.
133 changes: 55 additions & 78 deletions fwutil/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,7 @@ def get_status(self, force):

append_chassis_name = self.is_chassis_has_components()
append_module_na = not self.is_modular_chassis()
module_name = NA

for chassis_name, chassis_component_map in self.chassis_component_map.items():
for chassis_component_name, chassis_component in chassis_component_map.items():
Expand All @@ -565,17 +566,6 @@ def get_status(self, force):
status = self.FW_STATUS_UP_TO_DATE
info = NA

if append_chassis_name:
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_na:
module_name = NA
append_module_na = False
else:
module_name = EMPTY

if component:
firmware_path = component[self.__pcp.FIRMWARE_KEY]
firmware_version_available = component[self.__pcp.VERSION_KEY]
Expand All @@ -590,8 +580,8 @@ def get_status(self, force):

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_na else EMPTY,
chassis_component_name,
firmware_path,
firmware_version,
Expand All @@ -600,11 +590,19 @@ def get_status(self, force):
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_na:
append_module_na = False

append_chassis_name = not self.is_chassis_has_components()
chassis_name = self.chassis.get_name()

if self.is_modular_chassis():
for module_name, module_component_map in self.module_component_map.items():
append_module_name = True

for module_component_name, module_component in module_component_map.items():
component = self.__pcp.module_component_map[module_name][module_component_name]

Expand All @@ -616,17 +614,6 @@ def get_status(self, force):
status = self.FW_STATUS_UP_TO_DATE
info = NA

if append_chassis_name:
chassis_name = self.chassis.get_name()
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_name:
append_module_name = False
else:
module_name = EMPTY

if component:
firmware_path = component[self.__pcp.FIRMWARE_KEY]
firmware_version_available = component[self.__pcp.VERSION_KEY]
Expand All @@ -641,8 +628,8 @@ def get_status(self, force):

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_name else EMPTY,
module_component_name,
firmware_path,
firmware_version,
Expand All @@ -651,13 +638,20 @@ def get_status(self, force):
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_name:
append_module_name = False

return tabulate(status_table, self.STATUS_HEADER, tablefmt=self.FORMAT)

def update_firmware(self, force):
status_table = [ ]

append_chassis_name = self.is_chassis_has_components()
append_module_na = not self.is_modular_chassis()
module_name = NA

for chassis_name, chassis_component_map in self.chassis_component_map.items():
for chassis_component_name, chassis_component in chassis_component_map.items():
Expand All @@ -672,17 +666,6 @@ def update_firmware(self, force):

status = self.FW_STATUS_UP_TO_DATE

if append_chassis_name:
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_na:
module_name = NA
append_module_na = False
else:
module_name = EMPTY

if component:
firmware_path = component[self.__pcp.FIRMWARE_KEY]
firmware_version_available = component[self.__pcp.VERSION_KEY]
Expand Down Expand Up @@ -712,14 +695,21 @@ def update_firmware(self, force):

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_na else EMPTY,
chassis_component_name,
status,
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_na:
append_module_na = False

append_chassis_name = not self.is_chassis_has_components()
chassis_name = self.chassis.get_name()

if self.is_modular_chassis():
for module_name, module_component_map in self.module_component_map.items():
Expand All @@ -738,17 +728,6 @@ def update_firmware(self, force):

status = self.FW_STATUS_UP_TO_DATE

if append_chassis_name:
chassis_name = self.chassis.get_name()
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_name:
append_module_name = False
else:
module_name = EMPTY

if component:
firmware_path = component[self.__pcp.FIRMWARE_KEY]
firmware_version_available = component[self.__pcp.VERSION_KEY]
Expand Down Expand Up @@ -778,13 +757,19 @@ def update_firmware(self, force):

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_name else EMPTY,
module_component_name,
status,
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_name:
append_module_name = False

return tabulate(status_table, self.RESULT_HEADER, tablefmt=self.FORMAT)


Expand All @@ -803,34 +788,31 @@ def get_status(self):

append_chassis_name = self.is_chassis_has_components()
append_module_na = not self.is_modular_chassis()
module_name = NA

for chassis_name, chassis_component_map in self.chassis_component_map.items():
for chassis_component_name, chassis_component in chassis_component_map.items():
firmware_version = chassis_component.get_firmware_version()
description = chassis_component.get_description()

if append_chassis_name:
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_na:
module_name = NA
append_module_na = False
else:
module_name = EMPTY

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_na else EMPTY,
chassis_component_name,
firmware_version,
description
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_na:
append_module_na = False

append_chassis_name = not self.is_chassis_has_components()
chassis_name = self.chassis.get_name()

if self.is_modular_chassis():
for module_name, module_component_map in self.module_component_map.items():
Expand All @@ -840,25 +822,20 @@ def get_status(self):
firmware_version = module_component.get_firmware_version()
description = module_component.get_description()

if append_chassis_name:
chassis_name = self.chassis.get_name()
append_chassis_name = False
else:
chassis_name = EMPTY

if append_module_name:
append_module_name = False
else:
module_name = EMPTY

status_table.append(
[
chassis_name,
module_name,
chassis_name if append_chassis_name else EMPTY,
module_name if append_module_name else EMPTY,
module_component_name,
firmware_version,
description
]
)

if append_chassis_name:
append_chassis_name = False

if append_module_name:
append_module_name = False

return tabulate(status_table, self.HEADER, tablefmt=self.FORMAT)

0 comments on commit 30adcbd

Please sign in to comment.