Skip to contentSkip to conversation

ltp: make copyFrom scp command non-fatal

PATCH Superseded Matthew 2 participants 4 messages Aug 5, 2020

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Matthew

author
#0 lore raw

PATCH v2 1/1 ltp: make copyFrom scp command non-fatal

[YOCTO #13802]

Make the scp failure non-fatal so the ltp tests continue to run and the rest of the logs will be available to see afterwards.

---
 meta/lib/oeqa/core/target/ssh.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/target/ssh.py +7 -4
index 090b40a814..e891a4bbfa 100644
@@ -50,7 +50,7 @@ class OESSHTarget(OETarget):
     def stop(self, **kwargs):
         pass
 
-    def _run(self, command, timeout=None, ignore_status=True):
+    def _run(self, command, timeout=None, ignore_status=True, ignore_error=False):
         """
             Runs command in target using SSHProcess.
         """
@@ -62,8 +62,11 @@ class OESSHTarget(OETarget):
                  "" % (status, time.time() - starttime))
 
         if status and not ignore_status:
-            raise AssertionError("Command '%s' returned non-zero exit "
-                                 "status %d:\n%s" % (command, status, output))
+            if ignore_error:
+                self.logger.warning("Command '%s' returned non-zero exit status %d:\n%s" % (command, status, output))
+            else:
+                raise AssertionError("Command '%s' returned non-zero exit "
+                                     "status %d:\n%s" % (command, status, output))
 
         return (status, output)
 
@@ -113,7 +116,7 @@ class OESSHTarget(OETarget):
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        return self._run(scpCmd, ignore_error=True)
 
     def copyDirTo(self, localSrc, remoteDst):
         """

--
2.27.0

#1 lore raw
Quoted 38 lines · Mingde (Matthew) Zeng

[YOCTO #13802]

Make the scp failure non-fatal so the ltp tests continue to run and the rest of the logs will be available to see afterwards.

---
 meta/lib/oeqa/core/target/ssh.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/target/ssh.py +6 -3
index 090b40a814..e891a4bbfa 100644
@@ -50,7 +50,7 @@ class OESSHTarget(OETarget):
     def stop(self, **kwargs):
         pass
 
-    def _run(self, command, timeout=None, ignore_status=True):
+    def _run(self, command, timeout=None, ignore_status=True, ignore_error=False):
         """
             Runs command in target using SSHProcess.
         """
@@ -62,8 +62,11 @@ class OESSHTarget(OETarget):
                  "" % (status, time.time() - starttime))
 
         if status and not ignore_status:
-            raise AssertionError("Command '%s' returned non-zero exit "
-                                 "status %d:\n%s" % (command, status, output))
+            if ignore_error:
+                self.logger.warning("Command '%s' returned non-zero exit status %d:\n%s" % (command, status, output))
+            else:
+                raise AssertionError("Command '%s' returned non-zero exit "
+                                     "status %d:\n%s" % (command, status, output))
 
         return (status, output)
 

meta/lib/oeqa/core/target/ssh.py class OESSHTarget(OETarget): · line 122

Quoted 8 lines
meta/lib/oeqa/core/target/ssh.py +1 -1
@@ -113,7 +116,7 @@ class OESSHTarget(OETarget):
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        return self._run(scpCmd, ignore_error=True)
 
     def copyDirTo(self, localSrc, remoteDst):
         """

That isn't what I meant, I mean something like:

meta/lib/oeqa/core/target/ssh.py +5 -2
index 090b40a8143..cbc56f2e0ad 100644
@@ -107,13 +107,16 @@ class OESSHTarget(OETarget):
             scpCmd = self.scp + [localSrc, remotePath]
             return self._run(scpCmd, ignore_status=False)
 
-    def copyFrom(self, remoteSrc, localDst):
+    def copyFrom(self, remoteSrc, localDst, warn_on_failure=False):
         """
             Copy file from target.
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        (status, output) = self._run(scpCmd, ignore_status=warn_on_failure)
+        if warn_on_failure and not status:
+            self.logger.warning("Copy X returned non-zero exit status %d:\n%s" % (XXX, status, output))
+        return (status, output)
 
     def copyDirTo(self, localSrc, remoteDst):
         """

so that we enable this in the specific case og the copy we might accept failure for.

Cheers,

Richard

author
#2 lore raw
Quoted 74 lines · Richard Purdie
Quoted 38 lines · Mingde (Matthew) Zeng

[YOCTO #13802]

Make the scp failure non-fatal so the ltp tests continue to run and the rest of the logs will be available to see afterwards.

---
 meta/lib/oeqa/core/target/ssh.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/target/ssh.py +6 -3
index 090b40a814..e891a4bbfa 100644
@@ -50,7 +50,7 @@ class OESSHTarget(OETarget):
     def stop(self, **kwargs):
         pass
 
-    def _run(self, command, timeout=None, ignore_status=True):
+    def _run(self, command, timeout=None, ignore_status=True, ignore_error=False):
         """
             Runs command in target using SSHProcess.
         """
@@ -62,8 +62,11 @@ class OESSHTarget(OETarget):
                  "" % (status, time.time() - starttime))
 
         if status and not ignore_status:
-            raise AssertionError("Command '%s' returned non-zero exit "
-                                 "status %d:\n%s" % (command, status, output))
+            if ignore_error:
+                self.logger.warning("Command '%s' returned non-zero exit status %d:\n%s" % (command, status, output))
+            else:
+                raise AssertionError("Command '%s' returned non-zero exit "
+                                     "status %d:\n%s" % (command, status, output))
 
         return (status, output)
 

meta/lib/oeqa/core/target/ssh.py class OESSHTarget(OETarget): · line 122

Quoted 8 lines
meta/lib/oeqa/core/target/ssh.py +1 -1
@@ -113,7 +116,7 @@ class OESSHTarget(OETarget):
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        return self._run(scpCmd, ignore_error=True)
 
     def copyDirTo(self, localSrc, remoteDst):
         """

That isn't what I meant, I mean something like:

meta/lib/oeqa/core/target/ssh.py +5 -2
index 090b40a8143..cbc56f2e0ad 100644
@@ -107,13 +107,16 @@ class OESSHTarget(OETarget):
             scpCmd = self.scp + [localSrc, remotePath]
             return self._run(scpCmd, ignore_status=False)
 
-    def copyFrom(self, remoteSrc, localDst):
+    def copyFrom(self, remoteSrc, localDst, warn_on_failure=False):
         """
             Copy file from target.
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        (status, output) = self._run(scpCmd, ignore_status=warn_on_failure)
+        if warn_on_failure and not status:
+            self.logger.warning("Copy X returned non-zero exit status %d:\n%s" % (XXX, status, output))
+        return (status, output)
 
     def copyDirTo(self, localSrc, remoteDst):
         """
Quoted 1 line

so that we enable this in the specific case og the copy we might accept failure for.

This works too, my implementation is not as specific as this but it still enables warning only when the optional parameter ignore_error=True, which is what I specified in the copyFrom function only.

I'll adjust my patch.

Quoted 4 lines

Cheers,

Richard

--
Mingde (Matthew) Zeng

author
#3 lore raw
In reply to Richard Purdie
Quoted 74 lines · Richard Purdie
Quoted 38 lines · Mingde (Matthew) Zeng

[YOCTO #13802]

Make the scp failure non-fatal so the ltp tests continue to run and the rest of the logs will be available to see afterwards.

---
 meta/lib/oeqa/core/target/ssh.py | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
meta/lib/oeqa/core/target/ssh.py +6 -3
index 090b40a814..e891a4bbfa 100644
@@ -50,7 +50,7 @@ class OESSHTarget(OETarget):
     def stop(self, **kwargs):
         pass
 
-    def _run(self, command, timeout=None, ignore_status=True):
+    def _run(self, command, timeout=None, ignore_status=True, ignore_error=False):
         """
             Runs command in target using SSHProcess.
         """
@@ -62,8 +62,11 @@ class OESSHTarget(OETarget):
                  "" % (status, time.time() - starttime))
 
         if status and not ignore_status:
-            raise AssertionError("Command '%s' returned non-zero exit "
-                                 "status %d:\n%s" % (command, status, output))
+            if ignore_error:
+                self.logger.warning("Command '%s' returned non-zero exit status %d:\n%s" % (command, status, output))
+            else:
+                raise AssertionError("Command '%s' returned non-zero exit "
+                                     "status %d:\n%s" % (command, status, output))
 
         return (status, output)
 

meta/lib/oeqa/core/target/ssh.py class OESSHTarget(OETarget): · line 122

Quoted 8 lines
meta/lib/oeqa/core/target/ssh.py +1 -1
@@ -113,7 +116,7 @@ class OESSHTarget(OETarget):
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        return self._run(scpCmd, ignore_error=True)
 
     def copyDirTo(self, localSrc, remoteDst):
         """

That isn't what I meant, I mean something like:

meta/lib/oeqa/core/target/ssh.py +5 -2
index 090b40a8143..cbc56f2e0ad 100644
@@ -107,13 +107,16 @@ class OESSHTarget(OETarget):
             scpCmd = self.scp + [localSrc, remotePath]
             return self._run(scpCmd, ignore_status=False)
 
-    def copyFrom(self, remoteSrc, localDst):
+    def copyFrom(self, remoteSrc, localDst, warn_on_failure=False):
         """
             Copy file from target.
         """
         remotePath = '%s@%s:%s' % (self.user, self.ip, remoteSrc)
         scpCmd = self.scp + [remotePath, localDst]
-        return self._run(scpCmd, ignore_status=False)
+        (status, output) = self._run(scpCmd, ignore_status=warn_on_failure)
+        if warn_on_failure and not status:
+            self.logger.warning("Copy X returned non-zero exit status %d:\n%s" % (XXX, status, output))
+        return (status, output)
 
     def copyDirTo(self, localSrc, remoteDst):
         """
Quoted 1 line

so that we enable this in the specific case og the copy we might accept failure for.

This works too, my implementation is not as specific as this, however it enables warning when the optional parameter ignore_error=True, which is only specified in the copyFrom function.

I'll adjust my patch.

Quoted 4 lines

Cheers,

Richard

--
Mingde (Matthew) Zeng