[ovs-dev] [PATCH v1] tests: fix python2 module not find error

Ilya Maximets i.maximets at ovn.org
Mon Jul 19 11:21:11 UTC 2021


On 7/19/21 1:03 PM, Amber, Kumar wrote:
> Hi llya,
> 
> Pls find the comments inline.
> 
>> -----Original Message-----
>> From: Ilya Maximets <i.maximets at ovn.org>
>> Sent: Monday, July 19, 2021 4:07 PM
>> To: Ilya Maximets <i.maximets at ovn.org>; Amber, Kumar
>> <kumar.amber at intel.com>; ovs-dev at openvswitch.org
>> Cc: Stokes, Ian <ian.stokes at intel.com>
>> Subject: Re: [PATCH v1] tests: fix python2 module not find error
>>
>> On 7/19/21 12:35 PM, Ilya Maximets wrote:
>>> On 7/17/21 5:21 AM, Amber, Kumar wrote:
>>>> Hi llya,
>>>>
>>>> This is what I get after a minor tweek :
>>>> "except ImportError as err:
>>>>      print(err)"
>>>>
>>>> when Scapy is not present :
>>>>
>>>> No module named 'scapy'
>>>> Traceback (most recent call last):
>>>>   File "./../mfex_fuzzy.py", line 10, in <module>
>>>>     pktdump = PcapWriter(path, append=False, sync=True)
>>>> NameError: name 'PcapWriter' is not defined
>>>>
>>>> Is this ohk ?
>>>
>>> I don't understand why we're catching this exception.
>>> Even with your changes if the package is not available, we will catch
>>> the ImportError, print it and go further, later while trying to use
>>> modules that wasn't imported we will get another more vague exception.
>>> So what is the port catching ImportError in the first place?
>>
>> s/port/point/
>>
>>>
>>> If we'll exit after printing... well, but doesn't python print
>>> exception trace by itself?
>>>
>>> BTW, the title of this patch is incorrect.  We do not support python2,
>>> this problem is with python3 < 3.6.
> 
> Yes makes sense now logs are very clear we don’t need the try and catch block  at all removed in the patch
> And fixed the heading .
> 
> Traceback (most recent call last):
>   File "./mfex_fuzzy.py", line 2, in <module>
>     from scapy.all import RandMAC, RandIP, PcapWriter, RandIP6, RandShort, fuzz
> ModuleNotFoundError: No module named 'scapy

OK.  And since we're here, the pip3 might not be available
on a system, so checking for 'pip3 list' is not reliable.
Please, replace it with the import attempt. See how idl tests
are checking for SSL support for example:
  https://github.com/openvswitch/ovs/blob/master/tests/ovsdb-idl.at#L228-L230


>>>
>>> Best regards, Ilya Maximets.
>>>
>>>>
>>>> Regards
>>>> Amber
>>>>
>>>>
>>>>> -----Original Message-----
>>>>> From: Ilya Maximets <i.maximets at ovn.org>
>>>>> Sent: Saturday, July 17, 2021 12:21 AM
>>>>> To: Amber, Kumar <kumar.amber at intel.com>; ovs-dev at openvswitch.org
>>>>> Cc: i.maximets at ovn.org; Stokes, Ian <ian.stokes at intel.com>
>>>>> Subject: Re: [PATCH v1] tests: fix python2 module not find error
>>>>>
>>>>> On 7/16/21 8:15 PM, kumar Amber wrote:
>>>>>> This fixes the flake8 error on pyhton version older than 3.6 as
>>>>>> ModuleNotFoundError in not available before 3.6 and that is now
>>>>>> replaced to ImportError which is present in earlier versions.
>>>>>>
>>>>>> ../../tests/mfex_fuzzy.py:5:8: F821 undefined name
>> 'ModuleNotFoundError'
>>>>>> 2653Makefile:5826: recipe for target 'flake8-check' failed
>>>>>>
>>>>>> Fixes: 50be6715c0 ("test/sytem-dpdk: Add unit test for mfex
>>>>>> autovalidator")
>>>>>> Signed-off-by: kumar Amber <kumar.amber at intel.com>
>>>>>> ---
>>>>>>  tests/mfex_fuzzy.py | 2 +-
>>>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>>>
>>>>>> diff --git a/tests/mfex_fuzzy.py b/tests/mfex_fuzzy.py index
>>>>>> 5b056bb48..fd257ffb6 100755
>>>>>> --- a/tests/mfex_fuzzy.py
>>>>>> +++ b/tests/mfex_fuzzy.py
>>>>>> @@ -2,7 +2,7 @@
>>>>>>  try:
>>>>>>      from scapy.all import RandMAC, RandIP, PcapWriter, RandIP6,
>>>>>> RandShort,
>>>>> fuzz
>>>>>>      from scapy.all import IPv6, Dot1Q, IP, Ether, UDP, TCP -except
>>>>>> ModuleNotFoundError as err:
>>>>>> +except ImportError as err:
>>>>>>      print(err + ": Scapy")
>>>>>>  import sys
>>>>>>
>>>>>>
>>>>>
>>>>> I can confirm that this fixes the flake8 issue.
>>>>>
>>>>> But I'm not sure how that is supposed to work at all.
>>>>> Here is what I get in a plain python console:
>>>>>
>>>>> Python 3.6.8 (default, Mar 18 2021, 08:58:41) [GCC 8.4.1 20200928
>>>>> (Red Hat 8.4.1-1)] on linux Type "help", "copyright", "credits" or
>>>>> "license" for more information.
>>>>>>>> try:
>>>>> ...     from scapy.all import RandMAC
>>>>> ... except ImportError as err:
>>>>> ...     print(err + ": Scapy")
>>>>> ...
>>>>> Traceback (most recent call last):
>>>>>   File "<stdin>", line 2, in <module>
>>>>> ModuleNotFoundError: No module named 'scapy'
>>>>>
>>>>> During handling of the above exception, another exception occurred:
>>>>>
>>>>> Traceback (most recent call last):
>>>>>   File "<stdin>", line 4, in <module>
>>>>> TypeError: unsupported operand type(s) for +: 'ModuleNotFoundError' and
>> 'str'
>>>>>
>>>>>
>>>>> Best regards, Ilya Maximets.
>>>
> 



More information about the dev mailing list