diff mbox series

[1/3] rteval: Only process warnings if dmidecode_loaded is True

Message ID 20210909130314.6109-1-jkacur@redhat.com
State New
Headers show
Series [1/3] rteval: Only process warnings if dmidecode_loaded is True | expand

Commit Message

John Kacur Sept. 9, 2021, 1:03 p.m. UTC
If python-dmidecode is not available, then you can't test hasattr
or you will get a NameError. Simply return instead.

Signed-off-by: John Kacur <jkacur@redhat.com>
---
 rteval/sysinfo/dmi.py | 3 +++
 1 file changed, 3 insertions(+)

Comments

Punit Agrawal Sept. 13, 2021, 5:39 a.m. UTC | #1
John Kacur <jkacur@redhat.com> writes:

> If python-dmidecode is not available, then you can't test hasattr

> or you will get a NameError. Simply return instead.

>

> Signed-off-by: John Kacur <jkacur@redhat.com>

> ---

>  rteval/sysinfo/dmi.py | 3 +++

>  1 file changed, 3 insertions(+)

>

> diff --git a/rteval/sysinfo/dmi.py b/rteval/sysinfo/dmi.py

> index bd397360096a..80cf3c723b36 100644

> --- a/rteval/sysinfo/dmi.py

> +++ b/rteval/sysinfo/dmi.py

> @@ -42,6 +42,9 @@ except ModuleNotFoundError:

>  def ProcessWarnings():

>      """ Process Warnings from dmidecode """

>  

> +    if not dmidecode_loaded:

> +        return

> +

>      if not hasattr(dmidecode, 'get_warnings'):

>          return


Tested after purging python3-dmidecode package on Debian.

Tested-by: Punit Agrawal <punit1.agrawal@toshiba.co.jp>


Thanks,
Punit
diff mbox series

Patch

diff --git a/rteval/sysinfo/dmi.py b/rteval/sysinfo/dmi.py
index bd397360096a..80cf3c723b36 100644
--- a/rteval/sysinfo/dmi.py
+++ b/rteval/sysinfo/dmi.py
@@ -42,6 +42,9 @@  except ModuleNotFoundError:
 def ProcessWarnings():
     """ Process Warnings from dmidecode """
 
+    if not dmidecode_loaded:
+        return
+
     if not hasattr(dmidecode, 'get_warnings'):
         return