@@ -6062,81 +6062,76 @@ def n9300_switch_memory_check(tversion, fabric_nodes, **kwargs):
60626062 recommended_action = 'Increase the switch memory to at least 24GB on affected N9300-series switches.'
60636063 doc_url = 'https://datacenter.github.io/ACI-Pre-Upgrade-Validation-Script/validations/#n9300-switch-memory'
60646064 min_memory_kb = 24 * 1024 * 1024
6065+ msg = ''
60656066
60666067 affected_nodes = [
60676068 node for node in fabric_nodes
60686069 if node .get ('fabricNode' , {}).get ('attributes' , {}).get ('model' , '' ).startswith ('N9K-C93' )
60696070 ]
60706071
60716072 if not affected_nodes :
6072- return Result (result = NA , msg = 'No N9300 switches found. Skipping.' )
6073-
6074- proc_mem_mos = icurl ('class' , 'procMemUsage.json' )
6075- node_total_kb = {}
6076- parse_errors = []
6077-
6078- for memory_mo in proc_mem_mos :
6079- attrs = memory_mo .get ('procMemUsage' , {}).get ('attributes' , {})
6080- total = attrs .get ('Total' )
6081- mem_dn = attrs .get ('dn' , '' )
6082- if not total or '/memusage-sup' not in mem_dn :
6083- continue
6084- dn_match = re .search (node_regex , mem_dn )
6085- if not dn_match :
6086- continue
6087- try :
6088- total_kb = int (total )
6089- except (TypeError , ValueError ):
6090- parse_errors .append ([mem_dn , total ])
6091- continue
6092-
6093- node_id = dn_match .group ('node' )
6094- if node_id not in node_total_kb :
6095- node_total_kb [node_id ] = total_kb
6096-
6097- if parse_errors :
6098- return Result (
6099- result = ERROR ,
6100- msg = 'Failed to parse procMemUsage Total for one or more nodes.' ,
6101- headers = ['DN' , 'Total' ],
6102- data = parse_errors ,
6103- )
6104-
6105- missing_nodes = []
6073+ result = NA
6074+ msg = 'No N9300 switches found. Skipping.'
6075+ else :
6076+ proc_mem_mos = icurl ('class' , 'procMemUsage.json' )
6077+ node_total_kb = {}
6078+ parse_errors = []
6079+
6080+ for memory_mo in proc_mem_mos :
6081+ attrs = memory_mo .get ('procMemUsage' , {}).get ('attributes' , {})
6082+ total = attrs .get ('Total' )
6083+ mem_dn = attrs .get ('dn' , '' )
6084+ if not total or '/memusage-sup' not in mem_dn :
6085+ continue
6086+ dn_match = re .search (node_regex , mem_dn )
6087+ if not dn_match :
6088+ continue
6089+ try :
6090+ total_kb = int (total )
6091+ except (TypeError , ValueError ):
6092+ parse_errors .append ([mem_dn , total ])
6093+ continue
61066094
6107- for node in affected_nodes :
6108- node_id = node ['fabricNode' ]['attributes' ]['id' ]
6109- total_kb = node_total_kb .get (node_id )
6110- if total_kb is None :
6111- missing_nodes .append ([
6112- node_id ,
6113- node ['fabricNode' ]['attributes' ].get ('name' , '' ),
6114- node ['fabricNode' ]['attributes' ].get ('model' , '' ),
6115- ])
6116- continue
6095+ node_id = dn_match .group ('node' )
6096+ if node_id not in node_total_kb :
6097+ node_total_kb [node_id ] = total_kb
61176098
6118- memory_in_gb = round (total_kb / 1048576 , 2 )
6119- if total_kb < min_memory_kb :
6120- result = FAIL_O
6121- data .append ([
6122- node_id ,
6123- node ['fabricNode' ]['attributes' ].get ('name' , '' ),
6124- node ['fabricNode' ]['attributes' ].get ('model' , '' ),
6125- memory_in_gb ,
6126- ])
6099+ if parse_errors :
6100+ result = ERROR
6101+ msg = 'Failed to parse procMemUsage Total for one or more nodes.'
6102+ headers = ['DN' , 'Total' ]
6103+ data = parse_errors
6104+ else :
6105+ missing_nodes = []
6106+
6107+ for node in affected_nodes :
6108+ node_id = node ['fabricNode' ]['attributes' ]['id' ]
6109+ total_kb = node_total_kb .get (node_id )
6110+ if total_kb is None :
6111+ missing_nodes .append ([
6112+ node_id ,
6113+ node ['fabricNode' ]['attributes' ].get ('name' , '' ),
6114+ node ['fabricNode' ]['attributes' ].get ('model' , '' ),
6115+ ])
6116+ continue
61276117
6128- if missing_nodes :
6129- return Result (
6130- result = ERROR ,
6131- msg = 'Missing procMemUsage data for one or more affected N9300 nodes.' ,
6132- headers = ['NodeId' , 'Name' , 'Model' ],
6133- data = missing_nodes ,
6134- )
6118+ if total_kb < min_memory_kb :
6119+ memory_in_gb = round (total_kb / 1048576 , 2 )
6120+ result = FAIL_O
6121+ data .append ([
6122+ node_id ,
6123+ node ['fabricNode' ]['attributes' ].get ('name' , '' ),
6124+ node ['fabricNode' ]['attributes' ].get ('model' , '' ),
6125+ memory_in_gb ,
6126+ ])
61356127
6136- if result == FAIL_O :
6137- return Result (result = result , headers = headers , data = data , recommended_action = recommended_action , doc_url = doc_url )
6128+ if missing_nodes :
6129+ result = ERROR
6130+ msg = 'Missing procMemUsage data for one or more affected N9300 nodes.'
6131+ headers = ['NodeId' , 'Name' , 'Model' ]
6132+ data = missing_nodes
61386133
6139- return Result (result = result )
6134+ return Result (result = result , msg = msg , headers = headers , data = data , recommended_action = recommended_action , doc_url = doc_url )
61406135
61416136# ---- Script Execution ----
61426137
0 commit comments