Skip to content

Commit c7e46c9

Browse files
authored
Fix deprecation warnings (sonic-net#1423)
#### What I did Fix Python deprecation warnings as reported by pytest #### How I did it Convert strings which include escape sequences into raw strings
1 parent 73e28b9 commit c7e46c9

File tree

4 files changed

+6
-7
lines changed

4 files changed

+6
-7
lines changed

config/config_mgmt.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -582,8 +582,7 @@ def _searchKeysInConfig(self, In, Out, skeys):
582582
for skey in skeys:
583583
# pattern is very specific to current primary keys in
584584
# config DB, may need to be updated later.
585-
pattern = '^' + skey + '\|' + '|' + skey + '$' + \
586-
'|' + '^' + skey + '$'
585+
pattern = r'^{0}\||{0}$|^{0}$'.format(skey)
587586
reg = re.compile(pattern)
588587
if reg.search(key):
589588
# In primary key, only 1 match can be found, so return

config/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,7 @@ def _change_hostname(hostname):
640640
if current_hostname != hostname:
641641
clicommon.run_command('echo {} > /etc/hostname'.format(hostname), display_cmd=True)
642642
clicommon.run_command('hostname -F /etc/hostname', display_cmd=True)
643-
clicommon.run_command('sed -i "/\s{}$/d" /etc/hosts'.format(current_hostname), display_cmd=True)
643+
clicommon.run_command(r'sed -i "/\s{}$/d" /etc/hosts'.format(current_hostname), display_cmd=True)
644644
clicommon.run_command('echo "127.0.0.1 {}" >> /etc/hosts'.format(hostname), display_cmd=True)
645645

646646
def _clear_qos():
@@ -1990,7 +1990,7 @@ def vrf_add_management_vrf(config_db):
19901990
Iface Destination Gateway Flags RefCnt Use Metric Mask MTU Window IRTT
19911991
eth0 00000000 01803B0A 0003 0 0 202 00000000 0 0 0
19921992
"""
1993-
cmd = "cat /proc/net/route | grep -E \"eth0\s+00000000\s+[0-9A-Z]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+202\" | wc -l"
1993+
cmd = r"cat /proc/net/route | grep -E \"eth0\s+00000000\s+[0-9A-Z]+\s+[0-9]+\s+[0-9]+\s+[0-9]+\s+202\" | wc -l"
19941994
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
19951995
output = proc.communicate()
19961996
if int(output[0]) >= 1:

scripts/route_check.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ def filter_out_local_interfaces(keys):
320320
:return keys filtered out of local
321321
"""
322322
rt = []
323-
local_if_re = ['eth0', 'lo', 'docker0', 'tun0', 'Loopback\d+']
323+
local_if_re = [r'eth0', r'lo', r'docker0', r'tun0', r'Loopback\d+']
324324

325325
db = swsscommon.DBConnector(APPL_DB_NAME, 0)
326326
tbl = swsscommon.Table(db, 'ROUTE_TABLE')

tests/sku_create_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def are_file_contents_same(self,fname1,fname2):
3636

3737
#Loop if either fname1 or fname2 has not reached EOF
3838
while f1_line!='' or f2_line!='':
39-
f1_line = re.sub('[\s+]','',f1_line)
40-
f2_line = re.sub('[\s+]','',f2_line)
39+
f1_line = re.sub(r'[\s+]', '', f1_line)
40+
f2_line = re.sub(r'[\s+]', '', f2_line)
4141

4242
if f1_line!=f2_line:
4343
f1.close()

0 commit comments

Comments
 (0)