diff mbox series

[ovs-dev] ovs-dpctl-top: Fix Python3.12 invalid syntax warning

Message ID 20240829160433.1915883-1-msantana@redhat.com
State Accepted
Commit 0051785f00c52cbbc2897989a454a5512e82dce0
Delegated to: Simon Horman
Headers show
Series [ovs-dev] ovs-dpctl-top: Fix Python3.12 invalid syntax warning | expand

Checks

Context Check Description
ovsrobot/apply-robot warning apply and check: warning
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

Michael Santana Aug. 29, 2024, 4:04 p.m. UTC
Python3.12 is throwing syntax warnings in ovs-dpctl-top

[root@localhost ~]# python --version
Python 3.12.5
[root@localhost ~]# ovs-dpctl-top --help > /dev/null
/usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
/usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
/usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
  FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")


The warning seems to be new to python3.12

Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>> import re
>>> re.compile("([\w]+)\((.+)\)")
<stdin>:1: SyntaxWarning: invalid escape sequence '\w'
re.compile('([\\w]+)\\((.+)\\)')
>>> re.compile(r"([\w]+)\((.+)\)")
re.compile('([\\w]+)\\((.+)\\)')

Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>> import re
>>> re.compile("([\w]+)\((.+)\)")
re.compile('([\\w]+)\\((.+)\\)')


Prepending the string with r tells python treat the string as a raw string
literal and to not try to scape \w, \(, etc, and gets rid of the warning

Signed-off-by: Michael Santana <msantana@redhat.com>
---
 utilities/ovs-dpctl-top.in | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Simon Horman Aug. 30, 2024, 9:15 a.m. UTC | #1
On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
> Python3.12 is throwing syntax warnings in ovs-dpctl-top
> 
> [root@localhost ~]# python --version
> Python 3.12.5
> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
> 
> 
> The warning seems to be new to python3.12
> 
> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
> >>> import re
> >>> re.compile("([\w]+)\((.+)\)")
> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
> re.compile('([\\w]+)\\((.+)\\)')
> >>> re.compile(r"([\w]+)\((.+)\)")
> re.compile('([\\w]+)\\((.+)\\)')

Thanks Michael,

I also see this.

> 
> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
> >>> import re
> >>> re.compile("([\w]+)\((.+)\)")
> re.compile('([\\w]+)\\((.+)\\)')
> 
> 
> Prepending the string with r tells python treat the string as a raw string
> literal and to not try to scape \w, \(, etc, and gets rid of the warning
> 
> Signed-off-by: Michael Santana <msantana@redhat.com>

The checkpatch warning flagged by the robot aside, which I think can be
addressed when the patch is applied, this looks good to me.

Acked-by: Simon Horman <horms@ovn.org>
Eelco Chaudron Aug. 30, 2024, 10:23 a.m. UTC | #2
On 30 Aug 2024, at 11:15, Simon Horman wrote:

> On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
>> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>>
>> [root@localhost ~]# python --version
>> Python 3.12.5
>> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
>> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
>> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
>> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>>
>>
>> The warning seems to be new to python3.12
>>
>> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>>>> import re
>>>>> re.compile("([\w]+)\((.+)\)")
>> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
>> re.compile('([\\w]+)\\((.+)\\)')
>>>>> re.compile(r"([\w]+)\((.+)\)")
>> re.compile('([\\w]+)\\((.+)\\)')
>
> Thanks Michael,
>
> I also see this.
>
>>
>> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>>>> import re
>>>>> re.compile("([\w]+)\((.+)\)")
>> re.compile('([\\w]+)\\((.+)\\)')
>>
>>
>> Prepending the string with r tells python treat the string as a raw string
>> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>>
>> Signed-off-by: Michael Santana <msantana@redhat.com>
>
> The checkpatch warning flagged by the robot aside, which I think can be
> addressed when the patch is applied, this looks good to me.
>
> Acked-by: Simon Horman <horms@ovn.org>

Tested the change, and it looks good to me.

Acked-by: Eelco Chaudron <echaudro@redhat.com>
Eelco Chaudron Aug. 30, 2024, 10:32 a.m. UTC | #3
On 30 Aug 2024, at 12:23, Eelco Chaudron wrote:

> On 30 Aug 2024, at 11:15, Simon Horman wrote:
>
>> On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
>>> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>>>
>>> [root@localhost ~]# python --version
>>> Python 3.12.5
>>> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
>>> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>>>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
>>> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>>>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
>>> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>>>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>>>
>>>
>>> The warning seems to be new to python3.12
>>>
>>> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>>>>> import re
>>>>>> re.compile("([\w]+)\((.+)\)")
>>> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>>> re.compile(r"([\w]+)\((.+)\)")
>>> re.compile('([\\w]+)\\((.+)\\)')
>>
>> Thanks Michael,
>>
>> I also see this.
>>
>>>
>>> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>>>>> import re
>>>>>> re.compile("([\w]+)\((.+)\)")
>>> re.compile('([\\w]+)\\((.+)\\)')
>>>
>>>
>>> Prepending the string with r tells python treat the string as a raw string
>>> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>>>
>>> Signed-off-by: Michael Santana <msantana@redhat.com>
>>
>> The checkpatch warning flagged by the robot aside, which I think can be
>> addressed when the patch is applied, this looks good to me.
>>
>> Acked-by: Simon Horman <horms@ovn.org>
>
> Tested the change, and it looks good to me.
>
> Acked-by: Eelco Chaudron <echaudro@redhat.com>

I wanted to add that I have a general problem with the tool, I assume it’s related to my machine, but it might not be.
I get these errors for flows added:

in_port(2)in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib64/python3.9/threading.py", line 980, in _bootstrap_inner
self.run()
File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1126, in run
 self._flow_db.decay(self._interval)
File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1010, in decay
 for (key, value) in self._flows.items():
  RuntimeError: dictionary changed size during iteration

Can you confirm the tool works for you with active traffic?

//Eelco
Aaron Conole Aug. 30, 2024, 1:04 p.m. UTC | #4
Michael Santana <msantana@redhat.com> writes:

> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>
> [root@localhost ~]# python --version
> Python 3.12.5
> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>
>
> The warning seems to be new to python3.12
>
> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>>> import re
>>>> re.compile("([\w]+)\((.+)\)")
> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
> re.compile('([\\w]+)\\((.+)\\)')
>>>> re.compile(r"([\w]+)\((.+)\)")
> re.compile('([\\w]+)\\((.+)\\)')
>
> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>>> import re
>>>> re.compile("([\w]+)\((.+)\)")
> re.compile('([\\w]+)\\((.+)\\)')
>
>
> Prepending the string with r tells python treat the string as a raw string
> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>
> Signed-off-by: Michael Santana <msantana@redhat.com>
> ---

Thanks Michael, Simon, and Eelco.  Applied.
Aaron Conole Aug. 30, 2024, 1:04 p.m. UTC | #5
Simon Horman <horms@ovn.org> writes:

> On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
>> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>> 
>> [root@localhost ~]# python --version
>> Python 3.12.5
>> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
>> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
>> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
>> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>> 
>> 
>> The warning seems to be new to python3.12
>> 
>> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>> >>> import re
>> >>> re.compile("([\w]+)\((.+)\)")
>> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
>> re.compile('([\\w]+)\\((.+)\\)')
>> >>> re.compile(r"([\w]+)\((.+)\)")
>> re.compile('([\\w]+)\\((.+)\\)')
>
> Thanks Michael,
>
> I also see this.
>
>> 
>> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>> >>> import re
>> >>> re.compile("([\w]+)\((.+)\)")
>> re.compile('([\\w]+)\\((.+)\\)')
>> 
>> 
>> Prepending the string with r tells python treat the string as a raw string
>> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>> 
>> Signed-off-by: Michael Santana <msantana@redhat.com>
>
> The checkpatch warning flagged by the robot aside, which I think can be
> addressed when the patch is applied, this looks good to me.

I fixed that and the spelling mistake in the commit message (scape => escape)

> Acked-by: Simon Horman <horms@ovn.org>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Aaron Conole Aug. 30, 2024, 1:07 p.m. UTC | #6
Eelco Chaudron <echaudro@redhat.com> writes:

> On 30 Aug 2024, at 12:23, Eelco Chaudron wrote:
>
>> On 30 Aug 2024, at 11:15, Simon Horman wrote:
>>
>>> On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
>>>> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>>>>
>>>> [root@localhost ~]# python --version
>>>> Python 3.12.5
>>>> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
>>>> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>>>>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
>>>> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>>>>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
>>>> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>>>>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>>>>
>>>>
>>>> The warning seems to be new to python3.12
>>>>
>>>> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>>>>>> import re
>>>>>>> re.compile("([\w]+)\((.+)\)")
>>>> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>>>> re.compile(r"([\w]+)\((.+)\)")
>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>
>>> Thanks Michael,
>>>
>>> I also see this.
>>>
>>>>
>>>> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>>>>>> import re
>>>>>>> re.compile("([\w]+)\((.+)\)")
>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>
>>>>
>>>> Prepending the string with r tells python treat the string as a raw string
>>>> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>>>>
>>>> Signed-off-by: Michael Santana <msantana@redhat.com>
>>>
>>> The checkpatch warning flagged by the robot aside, which I think can be
>>> addressed when the patch is applied, this looks good to me.
>>>
>>> Acked-by: Simon Horman <horms@ovn.org>
>>
>> Tested the change, and it looks good to me.
>>
>> Acked-by: Eelco Chaudron <echaudro@redhat.com>
>
> I wanted to add that I have a general problem with the tool, I assume it’s related to my machine, but it might not be.
> I get these errors for flows added:
>
> in_port(2)in thread Thread-1:
> Traceback (most recent call last):
> File "/usr/lib64/python3.9/threading.py", line 980, in _bootstrap_inner
> self.run()
> File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1126, in run
>  self._flow_db.decay(self._interval)
> File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1010, in decay
>  for (key, value) in self._flows.items():
>   RuntimeError: dictionary changed size during iteration
>
> Can you confirm the tool works for you with active traffic?

I think this is an issue in the tool.  Can you try the following
snippet and see if it resolves your issue?

diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index 1708c2f374..f2d5bae6a6 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -1007,7 +1007,7 @@ class FlowDB:
     def decay(self, decayTimeInSeconds):
         """ Decay content. """
         now = datetime.datetime.now()
-        for (key, value) in self._flows.items():
+        for (key, value) in list(self._flows.items()):
             (stats_dict, updateTime) = value
             delta = now - updateTime
 


> //Eelco
>
> _______________________________________________
> dev mailing list
> dev@openvswitch.org
> https://mail.openvswitch.org/mailman/listinfo/ovs-dev
Eelco Chaudron Aug. 30, 2024, 1:35 p.m. UTC | #7
On 30 Aug 2024, at 15:07, Aaron Conole wrote:

> Eelco Chaudron <echaudro@redhat.com> writes:
>
>> On 30 Aug 2024, at 12:23, Eelco Chaudron wrote:
>>
>>> On 30 Aug 2024, at 11:15, Simon Horman wrote:
>>>
>>>> On Thu, Aug 29, 2024 at 12:04:33PM -0400, Michael Santana wrote:
>>>>> Python3.12 is throwing syntax warnings in ovs-dpctl-top
>>>>>
>>>>> [root@localhost ~]# python --version
>>>>> Python 3.12.5
>>>>> [root@localhost ~]# ovs-dpctl-top --help > /dev/null
>>>>> /usr/bin/ovs-dpctl-top:392: SyntaxWarning: invalid escape sequence '\w'
>>>>>   FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
>>>>> /usr/bin/ovs-dpctl-top:394: SyntaxWarning: invalid escape sequence '\w'
>>>>>   FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
>>>>> /usr/bin/ovs-dpctl-top:395: SyntaxWarning: invalid escape sequence '\w'
>>>>>   FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
>>>>>
>>>>>
>>>>> The warning seems to be new to python3.12
>>>>>
>>>>> Python 3.12.5 (main, Aug 23 2024, 00:00:00)
>>>>>>>> import re
>>>>>>>> re.compile("([\w]+)\((.+)\)")
>>>>> <stdin>:1: SyntaxWarning: invalid escape sequence '\w'
>>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>>>>> re.compile(r"([\w]+)\((.+)\)")
>>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>
>>>> Thanks Michael,
>>>>
>>>> I also see this.
>>>>
>>>>>
>>>>> Python 3.11.4 (main, Jun  7 2023, 00:00:00)
>>>>>>>> import re
>>>>>>>> re.compile("([\w]+)\((.+)\)")
>>>>> re.compile('([\\w]+)\\((.+)\\)')
>>>>>
>>>>>
>>>>> Prepending the string with r tells python treat the string as a raw string
>>>>> literal and to not try to scape \w, \(, etc, and gets rid of the warning
>>>>>
>>>>> Signed-off-by: Michael Santana <msantana@redhat.com>
>>>>
>>>> The checkpatch warning flagged by the robot aside, which I think can be
>>>> addressed when the patch is applied, this looks good to me.
>>>>
>>>> Acked-by: Simon Horman <horms@ovn.org>
>>>
>>> Tested the change, and it looks good to me.
>>>
>>> Acked-by: Eelco Chaudron <echaudro@redhat.com>
>>
>> I wanted to add that I have a general problem with the tool, I assume it’s related to my machine, but it might not be.
>> I get these errors for flows added:
>>
>> in_port(2)in thread Thread-1:
>> Traceback (most recent call last):
>> File "/usr/lib64/python3.9/threading.py", line 980, in _bootstrap_inner
>> self.run()
>> File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1126, in run
>>  self._flow_db.decay(self._interval)
>> File "/root/Documents/scratch/ovs/./utilities/ovs-dpctl-top", line 1010, in decay
>>  for (key, value) in self._flows.items():
>>   RuntimeError: dictionary changed size during iteration
>>
>> Can you confirm the tool works for you with active traffic?
>
> I think this is an issue in the tool.  Can you try the following
> snippet and see if it resolves your issue?
>
> diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
> index 1708c2f374..f2d5bae6a6 100755
> --- a/utilities/ovs-dpctl-top.in
> +++ b/utilities/ovs-dpctl-top.in
> @@ -1007,7 +1007,7 @@ class FlowDB:
>      def decay(self, decayTimeInSeconds):
>          """ Decay content. """
>          now = datetime.datetime.now()
> -        for (key, value) in self._flows.items():
> +        for (key, value) in list(self._flows.items()):
>              (stats_dict, updateTime) = value
>              delta = now - updateTime

Yes, that solved it for me. Gues we need another patch ;)

//Eelco
diff mbox series

Patch

diff --git a/utilities/ovs-dpctl-top.in b/utilities/ovs-dpctl-top.in
index ec57eccd6..1708c2f37 100755
--- a/utilities/ovs-dpctl-top.in
+++ b/utilities/ovs-dpctl-top.in
@@ -389,10 +389,10 @@  def args_get():
 # Code to parse a single line in dump-flow
 ###
 # key(values)
-FIELDS_CMPND = re.compile("([\w]+)\((.+)\)")
+FIELDS_CMPND = re.compile(r"([\w]+)\((.+)\)")
 # key:value
-FIELDS_CMPND_ELEMENT = re.compile("([\w:]+)=([/\.\w:]+)")
-FIELDS_ELEMENT = re.compile("([\w]+):([-\.\w]+)")
+FIELDS_CMPND_ELEMENT = re.compile(r"([\w:]+)=([/\.\w:]+)")
+FIELDS_ELEMENT = re.compile(r"([\w]+):([-\.\w]+)")
 
 
 def flow_line_iter(line):