1
0
mirror of https://github.com/ARM-software/devlib.git synced 2024-10-06 02:40:50 +01:00

LocalConnection: Implement connected_as_root parameter

As of commit 5601fdb108 the
`connected_as_root` status is tracked in the connection. Add missing
implementation to `LocalConnection`.
This commit is contained in:
Marc Bonnici 2019-09-11 16:47:07 +01:00 committed by setrofim
parent 5d4315c5d2
commit ed135febde

View File

@ -38,9 +38,21 @@ class LocalConnection(object):
name = 'local'
@property
def connected_as_root(self):
if self._connected_as_root is None:
result = self.execute('id', as_root=False)
self._connected_as_root = 'uid=0(' in result
return self._connected_as_root
@connected_as_root.setter
def connected_as_root(self, state):
self._connected_as_root = state
# pylint: disable=unused-argument
def __init__(self, platform=None, keep_password=True, unrooted=False,
password=None, timeout=None):
self._connected_as_root = None
self.logger = logging.getLogger('local_connection')
self.keep_password = keep_password
self.unrooted = unrooted
@ -67,7 +79,7 @@ class LocalConnection(object):
def execute(self, command, timeout=None, check_exit_code=True,
as_root=False, strip_colors=True, will_succeed=False):
self.logger.debug(command)
if as_root:
if as_root and not self.connected_as_root:
if self.unrooted:
raise TargetStableError('unrooted')
password = self._get_password()
@ -84,7 +96,7 @@ class LocalConnection(object):
raise TargetStableError(message)
def background(self, command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, as_root=False):
if as_root:
if as_root and not self.connected_as_root:
if self.unrooted:
raise TargetStableError('unrooted')
password = self._get_password()