eCTS: Run openocd and lsusb as a root

Running lsusb (to get iSerial) and openocd requires a privilege.
This patch makes cts.py run these commands as a root. Opening
ttyACM0 requires a privilege as well but it'll be done by asking
a user to add themselves to dialout group.

BUG=chromium:664309
BRANCH=none
TEST=Run cts.py on a freshly set up cros_sdk chroot.

Change-Id: Ib9d007459c4b1322b15f521a5253d833e2304c3c
Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/558804
Reviewed-by: Randall Spangler <rspangler@chromium.org>
This commit is contained in:
Daisuke Nojiri 2017-07-02 12:28:31 -07:00 committed by chrome-bot
parent 74d09422e9
commit b20a873d0f
1 changed files with 4 additions and 3 deletions

View File

@ -79,7 +79,7 @@ class Board(object):
Returns:
List of serials
"""
usb_args = ['lsusb', '-v', '-d', '0x0483:0x374b']
usb_args = ['sudo', 'lsusb', '-v', '-d', '0x0483:0x374b']
st_link_info = sp.check_output(usb_args)
st_serials = []
for line in st_link_info.split('\n'):
@ -105,7 +105,7 @@ class Board(object):
Returns:
True if execution is successful or False otherwise.
"""
args = ['openocd', '-s', OCD_SCRIPT_DIR,
args = ['sudo', 'openocd', '-s', OCD_SCRIPT_DIR,
'-f', self.openocd_config, '-c', 'hla_serial ' + self.hla_serial]
for cmd in commands:
@ -194,7 +194,8 @@ class Board(object):
except serial.SerialException:
raise ValueError('Failed to open ' + self.tty_port + ' of ' + self.board +
'. Please make sure the port is available and you have' +
' permission to read it.')
' permission to read it. Create dialout group and run:' +
' sudo usermod -a -G dialout <username>.')
self.tty = tty
def read_tty(self, max_boot_count=1):