mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-09-02 19:32:34 +01:00
push/pull commands always raise DeviceError + handle error on pulling a property file.
Previosuly, they raised CalledProcessError/DeviceError based on implementation. Making it consistent to facillitated handling in calling code.
This commit is contained in:
@@ -290,6 +290,7 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
try:
|
||||||
if not as_root:
|
if not as_root:
|
||||||
adb_command(self.adb_name, "push '{}' '{}'".format(source, dest), timeout=timeout)
|
adb_command(self.adb_name, "push '{}' '{}'".format(source, dest), timeout=timeout)
|
||||||
else:
|
else:
|
||||||
@@ -297,6 +298,8 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
|
|||||||
self.execute('mkdir -p {}'.format(self.path.dirname(device_tempfile)))
|
self.execute('mkdir -p {}'.format(self.path.dirname(device_tempfile)))
|
||||||
adb_command(self.adb_name, "push '{}' '{}'".format(source, device_tempfile), timeout=timeout)
|
adb_command(self.adb_name, "push '{}' '{}'".format(source, device_tempfile), timeout=timeout)
|
||||||
self.execute('cp {} {}'.format(device_tempfile, dest), as_root=True)
|
self.execute('cp {} {}'.format(device_tempfile, dest), as_root=True)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
raise DeviceError(e)
|
||||||
|
|
||||||
def pull_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
def pull_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
||||||
"""
|
"""
|
||||||
@@ -304,6 +307,7 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
try:
|
||||||
if not as_root:
|
if not as_root:
|
||||||
adb_command(self.adb_name, "pull '{}' '{}'".format(source, dest), timeout=timeout)
|
adb_command(self.adb_name, "pull '{}' '{}'".format(source, dest), timeout=timeout)
|
||||||
else:
|
else:
|
||||||
@@ -311,6 +315,8 @@ class AndroidDevice(BaseLinuxDevice): # pylint: disable=W0223
|
|||||||
self.execute('mkdir -p {}'.format(self.path.dirname(device_tempfile)))
|
self.execute('mkdir -p {}'.format(self.path.dirname(device_tempfile)))
|
||||||
self.execute('cp {} {}'.format(source, device_tempfile), as_root=True)
|
self.execute('cp {} {}'.format(source, device_tempfile), as_root=True)
|
||||||
adb_command(self.adb_name, "pull '{}' '{}'".format(device_tempfile, dest), timeout=timeout)
|
adb_command(self.adb_name, "pull '{}' '{}'".format(device_tempfile, dest), timeout=timeout)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
raise DeviceError(e)
|
||||||
|
|
||||||
def delete_file(self, filepath, as_root=False): # pylint: disable=W0221
|
def delete_file(self, filepath, as_root=False): # pylint: disable=W0221
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
@@ -179,9 +179,15 @@ class BaseLinuxDevice(Device): # pylint: disable=abstract-method
|
|||||||
for propfile in self.property_files:
|
for propfile in self.property_files:
|
||||||
if not self.file_exists(propfile):
|
if not self.file_exists(propfile):
|
||||||
continue
|
continue
|
||||||
|
try:
|
||||||
normname = propfile.lstrip(self.path.sep).replace(self.path.sep, '.')
|
normname = propfile.lstrip(self.path.sep).replace(self.path.sep, '.')
|
||||||
outfile = os.path.join(context.host_working_directory, normname)
|
outfile = os.path.join(context.host_working_directory, normname)
|
||||||
self.pull_file(propfile, outfile)
|
self.pull_file(propfile, outfile)
|
||||||
|
except DeviceError:
|
||||||
|
# We pull these files "opportunistically", so if a pull fails
|
||||||
|
# (e.g. we don't have permissions to read the file), just note
|
||||||
|
# it quietly (not as an error/warning) and move on.
|
||||||
|
self.logger.debug('Could not pull property file "{}"'.format(propfile))
|
||||||
return {}
|
return {}
|
||||||
|
|
||||||
def get_sysfile_value(self, sysfile, kind=None):
|
def get_sysfile_value(self, sysfile, kind=None):
|
||||||
@@ -972,6 +978,7 @@ class LinuxDevice(BaseLinuxDevice):
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
try:
|
||||||
if background:
|
if background:
|
||||||
if as_root and self.username != 'root':
|
if as_root and self.username != 'root':
|
||||||
raise DeviceError('Cannot execute in background with as_root=True unless user is root.')
|
raise DeviceError('Cannot execute in background with as_root=True unless user is root.')
|
||||||
@@ -981,6 +988,8 @@ class LinuxDevice(BaseLinuxDevice):
|
|||||||
if self._is_root_user:
|
if self._is_root_user:
|
||||||
as_root = False
|
as_root = False
|
||||||
return self.shell.execute(command, timeout, check_exit_code, as_root, strip_colors)
|
return self.shell.execute(command, timeout, check_exit_code, as_root, strip_colors)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
raise DeviceError(e)
|
||||||
|
|
||||||
def kick_off(self, command):
|
def kick_off(self, command):
|
||||||
"""
|
"""
|
||||||
@@ -1026,15 +1035,19 @@ class LinuxDevice(BaseLinuxDevice):
|
|||||||
|
|
||||||
def push_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
def push_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
try:
|
||||||
if not as_root or self.username == 'root':
|
if not as_root or self.username == 'root':
|
||||||
self.shell.push_file(source, dest, timeout=timeout)
|
self.shell.push_file(source, dest, timeout=timeout)
|
||||||
else:
|
else:
|
||||||
tempfile = self.path.join(self.working_directory, self.path.basename(dest))
|
tempfile = self.path.join(self.working_directory, self.path.basename(dest))
|
||||||
self.shell.push_file(source, tempfile, timeout=timeout)
|
self.shell.push_file(source, tempfile, timeout=timeout)
|
||||||
self.shell.execute('cp -r {} {}'.format(tempfile, dest), timeout=timeout, as_root=True)
|
self.shell.execute('cp -r {} {}'.format(tempfile, dest), timeout=timeout, as_root=True)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
raise DeviceError(e)
|
||||||
|
|
||||||
def pull_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
def pull_file(self, source, dest, as_root=False, timeout=default_timeout): # pylint: disable=W0221
|
||||||
self._check_ready()
|
self._check_ready()
|
||||||
|
try:
|
||||||
if not as_root or self.username == 'root':
|
if not as_root or self.username == 'root':
|
||||||
self.shell.pull_file(source, dest, timeout=timeout)
|
self.shell.pull_file(source, dest, timeout=timeout)
|
||||||
else:
|
else:
|
||||||
@@ -1042,6 +1055,8 @@ class LinuxDevice(BaseLinuxDevice):
|
|||||||
self.shell.execute('cp -r {} {}'.format(source, tempfile), timeout=timeout, as_root=True)
|
self.shell.execute('cp -r {} {}'.format(source, tempfile), timeout=timeout, as_root=True)
|
||||||
self.shell.execute('chown -R {} {}'.format(self.username, tempfile), timeout=timeout, as_root=True)
|
self.shell.execute('chown -R {} {}'.format(self.username, tempfile), timeout=timeout, as_root=True)
|
||||||
self.shell.pull_file(tempfile, dest, timeout=timeout)
|
self.shell.pull_file(tempfile, dest, timeout=timeout)
|
||||||
|
except CalledProcessError as e:
|
||||||
|
raise DeviceError(e)
|
||||||
|
|
||||||
def delete_file(self, filepath, as_root=False): # pylint: disable=W0221
|
def delete_file(self, filepath, as_root=False): # pylint: disable=W0221
|
||||||
self.execute('rm -rf {}'.format(filepath), as_root=as_root)
|
self.execute('rm -rf {}'.format(filepath), as_root=as_root)
|
||||||
|
Reference in New Issue
Block a user