Skip to contentSkip to conversation

lib/oe/qa: handle missing data attribute in __exit__

PATCH In review Alex Kiernan 3 participants 3 messages Dec 29, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 lib/oe/qa: handle missing data attribute in __exit__

If mmap fails in open, we don't have a data attribute so when we execute as a context manager the call to self.data.close needs to handle the missing attribute:

File: '/home/akiernan/nanohub/build/../poky/meta/classes/chrpath.bbclass', lineno: 11, function: process_file_linux
0007: with oe.qa.ELFFile(fpath) as elf:
0008: try:
0009: elf.open()
0010: except oe.qa.NotELFFileError:
*** 0011: return

       0012:
       0013:    p = sub.Popen([cmd, '-l', fpath],stdout=sub.PIPE,stderr=sub.PIPE)
       0014:    out, err = p.communicate()
       0015:    # If returned successfully, process stdout for results
  File: '/home/akiernan/nanohub/build/../poky/meta/lib/oe/qa.py', lineno: 50, function: __exit__
       0046:    def __enter__(self):
       0047:        return self
       0048:
       0049:    def __exit__(self, exc_type, exc_value, traceback):
   *** 0050:        self.data.close()
       0051:
       0052:    def open(self):
       0053:        with open(self.name, "rb") as f:
       0054:            try:

Exception: AttributeError: 'ELFFile' object has no attribute 'data'

Fixes 7785c41d0b95 ("chrpath: do less work")

---

 meta/lib/oe/qa.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
meta/lib/oe/qa.py +5 -1
index 21066c4dc3b3..d85206f155f0 100644
@@ -47,7 +47,11 @@ class ELFFile:
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
-        self.data.close()
+        try:
+            self.data.close()
+        except AttributeError:
+            # If we failed to mmap in open then the data attribute won't exist
+            pass
 
     def open(self):
         with open(self.name, "rb") as f:
Signature · 1 line
2.17.1
#1 lore raw

✗ patchtest: failure for lib/oe/qa: handle missing data attribute in __exit__

== Series Details ==

Series: lib/oe/qa: handle missing data attribute in __exit__
Revision: 1
URL : https://patchwork.openembedded.org/series/21782/
State : failure

== Summary ==

Thank you for submitting this patch series to OpenEmbedded Core. This is an automated response. Several tests have been executed on the proposed series by patchtest resulting in the following failures:

* Issue Series does not apply on top of target branch [test_series_merge_on_head]
Suggested fix Rebase your series on top of targeted branch
Targeted branch master (currently at 39825cba47)

If you believe any of these test results are incorrect, please reply to the mailing list ([email protected]) raising your concerns. Otherwise we would appreciate you correcting the issues and submitting a new version of the patchset if applicable. Please ensure you add/increment the version number when sending the new version (i.e. [PATCH] -> [PATCH v2] -> [PATCH v3] -> ...).

---

Guidelines:     https://www.openembedded.org/wiki/Commit_Patch_Message_Guidelines
Test framework: http://git.yoctoproject.org/cgit/cgit.cgi/patchtest
Test suite:     http://git.yoctoproject.org/cgit/cgit.cgi/patchtest-oe
#2 lore raw
In reply to Alex Kiernan
Quoted 55 lines · Alex Kiernan

If mmap fails in open, we don't have a data attribute so when we execute
as a context manager the call to self.data.close needs to handle the missing attribute:

File:
'/home/akiernan/nanohub/build/../poky/meta/classes/chrpath.bbclass',
lineno: 11, function: process_file_linux
0007: with oe.qa.ELFFile(fpath) as elf:
0008: try:
0009: elf.open()
0010: except oe.qa.NotELFFileError:

   *** 0011:            return
       0012:
       0013:    p = sub.Popen([cmd, '-l',

fpath],stdout=sub.PIPE,stderr=sub.PIPE)
0014: out, err = p.communicate()
0015: # If returned successfully, process stdout for
results
File: '/home/akiernan/nanohub/build/../poky/meta/lib/oe/qa.py',
lineno: 50, function: __exit__

       0046:    def __enter__(self):
       0047:        return self
       0048:
       0049:    def __exit__(self, exc_type, exc_value, traceback):
   *** 0050:        self.data.close()
       0051:
       0052:    def open(self):
       0053:        with open(self.name, "rb") as f:
       0054:            try:

Exception: AttributeError: 'ELFFile' object has no attribute 'data'

Fixes 7785c41d0b95 ("chrpath: do less work")

---

 meta/lib/oe/qa.py | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
meta/lib/oe/qa.py +4 -1
index 21066c4dc3b3..d85206f155f0 100644
@@ -47,7 +47,11 @@ class ELFFile:
         return self
 
     def __exit__(self, exc_type, exc_value, traceback):
-        self.data.close()
+        try:
+            self.data.close()
+        except AttributeError:
+            # If we failed to mmap in open then the data attribute

won't exist
+ pass

Quoted 2 lines

def open(self):
with open(self.name, "rb") as f:

Thanks, there was a patch in master-next which was being held for various reasons but I fixed the commit message and I merged it early on to resolve this in master.

Cheers,

Richard