@@ -386,9 +386,10 @@ def check_interface_status_of_up_ports(self):
386386 host = hostname , source = 'running' , namespace = 'asic{}' .format (asic_id )
387387 )['ansible_facts' ]
388388
389+ ports = list (cfg_facts_of_asic .get ('PORT' , {}).items ())
390+
389391 up_ports = [
390- p for p , v in list (cfg_facts_of_asic ['PORT' ].items ())
391- if v .get ('admin_status' , None ) == 'up'
392+ p for p , v in ports if v .get ('admin_status' , None ) == 'up'
392393 ]
393394
394395 logger .info ('up_ports: {}' .format (up_ports ))
@@ -414,9 +415,15 @@ def check_interface_status_of_up_ports(self):
414415 # Add errlog to check result errmsg
415416 self .check_result .errmsg .append (errlog )
416417
418+ if not ports :
419+ failed = True
420+ self .check_result .errmsg .append (f"Device has no ports on asic{ asic_id } ."
421+ f"Please check 'show int status -n asic{ asic_id } ' " )
417422 else :
418423 cfg_facts = sonichost .config_facts (host = hostname , source = 'running' )['ansible_facts' ]
419- up_ports = [p for p , v in list (cfg_facts ['PORT' ].items ()) if v .get ('admin_status' , None ) == 'up' ]
424+ ports = list (cfg_facts .get ('PORT' , {}).items ())
425+
426+ up_ports = [p for p , v in ports if v .get ('admin_status' , None ) == 'up' ]
420427 logger .info ('up_ports: {}' .format (up_ports ))
421428 interface_facts = sonichost .interface_facts (up_ports = up_ports )['ansible_facts' ]
422429 interface_facts_on_hosts [hostname ] = interface_facts
@@ -432,6 +439,10 @@ def check_interface_status_of_up_ports(self):
432439 # Add errlog to check result errmsg
433440 self .check_result .errmsg .append (errlog )
434441
442+ if not ports :
443+ failed = True
444+ self .check_result .errmsg .append ("Device has no ports. Please check 'show int status' result" )
445+
435446 # Set the check result
436447 self .check_result .data ["interface_facts_on_hosts" ] = interface_facts_on_hosts
437448
0 commit comments