Skip to content

Commit

Permalink
Merge pull request #975 from aginika/add-host-param-to-usb
Browse files Browse the repository at this point in the history
 add host option to USB Check
  • Loading branch information
k-okada committed Jun 3, 2015
2 parents 341c0e3 + cd8f3e5 commit da3555e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions jsk_tools/src/jsk_tools/sanity_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,27 +171,32 @@ def checkNodeState(target_node_name, needed, sub_success="", sub_fail=""):
if sub_success:
print Fore.GREEN+" "+sub_success+ Fore.RESET

def checkUSBExist(vendor_id, product_id, expect_usb_nums = 1, success_msg = "", error_msg = ""):
def checkUSBExist(vendor_id, product_id, expect_usb_nums = 1, host="", success_msg = "", error_msg = ""):
"""check USB Exists
vendor_string -- vendor string (e.g. if 8087:0024, 8087)
product_string -- product string (e.g. if 8087:0024, 0024)
expect_usb_nums -- number of usbs (default is 1)
"""
output_lines = subprocess.check_output("lsusb", shell=True).split("\n")
vendor_product = str(vendor_id) + ":" + str(product_id)
print Fore.LIGHTCYAN_EX + "Check USB Connect " + vendor_product + " x"+str(expect_usb_nums) + (" in "+str(host) if host else "")
output_lines = ""
if host:
output_lines = subprocess.check_output("ssh "+ host +" lsusb", shell=True).split("\n")
else:
output_lines = subprocess.check_output("lsusb", shell=True).split("\n")
usb_counter = 0
for output in output_lines:
if vendor_product in output:
usb_counter += 1
if usb_counter >= expect_usb_nums:
okMessage(vendor_product + " " + success_msg if success_msg else vendor_product + " Found enough ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
if usb_counter == expect_usb_nums:
okMessage(vendor_product + " ("+str(usb_counter)+"/"+str(expect_usb_nums)+"): " + success_msg if success_msg else vendor_product + " Found enough ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
return True
elif usb_counter == 0:
errorMessage(vendor_product + " " + error_msg if error_msg else vendor_product + " NOT Found !! ( 0 / " + str(expect_usb_nums) + " ) Detected")
errorMessage(vendor_product + " (0/" + str(expect_usb_nums) + ") " + error_msg if error_msg else vendor_product + " NOT Found !! ( 0 / " + str(expect_usb_nums) + " ) Detected")
return False
else:
errorMessage(vendor_product + " " + error_msg if error_msg else vendor_product + " IS FEW !! Only ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
errorMessage(vendor_product + " ("+str(usb_counter)+"/"+str(expect_usb_nums)+") " + error_msg if error_msg else vendor_product + " DOESN'T MATCH !! ( "+str(usb_counter)+"/"+str(expect_usb_nums)+" ) Detected")
return False

def checkROSMasterCLOSE_WAIT(host, username=""):
Expand Down

0 comments on commit da3555e

Please sign in to comment.