misc: fix python sonarcloud BLOCKER level issues

Fix of the top 11 python issues flagged as BLOCKER.

Ticket: VPP-1856
Type: fix

Change-Id: Icf4691e62f4a69d6ee196b6d6e2ab52d961b5c76
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
This commit is contained in:
Paul Vinciguerra
2020-04-03 12:18:40 -04:00
committed by Neale Ranns
parent c17d6cfaf4
commit 582eac5c30
9 changed files with 66 additions and 60 deletions

View File

@ -82,6 +82,7 @@ class Siphon(object):
self._tplenv = jinja2.Environment(
loader=loader,
trim_blocks=True,
autoescape=True,
keep_trailing_newline=True)
# Convenience, get a reference to the internal escape and

View File

@ -122,7 +122,7 @@ class AutoConfig(object):
answer = input("Please enter the netmask [n.n.n.n]: ")
plen = ip_address(answer).netmask_bits()
return '{}/{}'.format(ipaddr, plen)
except None:
except ValueError:
print("Please enter a valid IPv4 address.")
@staticmethod

View File

@ -164,9 +164,7 @@ class VppGrubUtil(object):
"""
vpp_cmdline = self.create_cmdline(isolated_cpus)
if vpp_cmdline == '':
return vpp_cmdline
if len(vpp_cmdline):
# Update grub
# Save the original file
rootdir = node['rootdir']
@ -176,14 +174,16 @@ class VppGrubUtil(object):
# Write the output file
# Does a copy of the original file exist, if not create one
(ret, stdout, stderr) = VPPUtil.exec_command('ls {}'.format(ofilename))
(ret, stdout, stderr) = VPPUtil.exec_command(
'ls {}'.format(ofilename))
if ret != 0:
if stdout.strip('\n') != ofilename:
cmd = 'sudo cp {} {}'.format(filename, ofilename)
(ret, stdout, stderr) = VPPUtil.exec_command(cmd)
if ret != 0:
raise RuntimeError('{} failed on node {} {}'.
format(cmd, self._node['host'], stderr))
format(cmd, self._node['host'],
stderr))
# Get the contents of the current grub config file
cmd = 'cat {}'.format(filename)

View File

@ -248,6 +248,7 @@ class Containers(object):
def build(self, path, vpp_path):
env = Environment(loader=FileSystemLoader(path),
autoescape=True,
trim_blocks=True)
self.tmp_render(join(vpp_path, "Dockerfile"),
@ -264,6 +265,7 @@ class Containers(object):
def release(self, path, vpp_path):
env = Environment(loader=FileSystemLoader(path),
autoescape=True,
trim_blocks=True)
self.tmp_render(join(vpp_path, "Dockerfile"),

View File

@ -8,12 +8,13 @@
import unittest
import time
from socket import inet_pton, inet_ntop, AF_INET6
import socket
from socket import inet_pton, inet_ntop
from vpp_object import VppObject
from vpp_papi import VppEnum
from scapy.packet import Raw
from scapy.packet import raw
from scapy.layers.l2 import Ether, ARP
from scapy.layers.inet import IP, ICMP, icmptypes
from scapy.layers.inet6 import IPv6, ipv6nh, IPv6ExtHdrHopByHop, \
@ -833,8 +834,8 @@ class TestVRRP6(VppTestCase):
self.assertEqual(pkt[IPv6].dst, "ff02::1")
# convert addrs to packed format since string versions could differ
src_addr = inet_pton(AF_INET6, pkt[IPv6].src)
vr_ll_addr = inet_pton(AF_INET6, vr.interface().local_ip6_ll)
src_addr = inet_pton(socket.AF_INET6, pkt[IPv6].src)
vr_ll_addr = inet_pton(socket.AF_INET6, vr.interface().local_ip6_ll)
self.assertEqual(src_addr, vr_ll_addr)
self.assertTrue(pkt[ICMPv6ND_NA].tgt in vr.virtual_ips())

View File

@ -648,7 +648,7 @@ class VPPAPIParser(object):
elif len(p) == 4:
p[0] = Field(p[1], p[2])
else:
self._parse_error('ERROR')
self._parse_error('ERROR', self._token_coord(p, 1))
self.fields.append(p[2])
def p_declaration_array_vla(self, p):

View File

@ -5,7 +5,7 @@ import struct
from scapy.layers.inet import IP, ICMP, TCP, UDP
from scapy.layers.ipsec import SecurityAssociation, ESP
from scapy.layers.l2 import Ether
from scapy.packet import Raw
from scapy.packet import raw, Raw
from scapy.layers.inet6 import IPv6, ICMPv6EchoRequest, IPv6ExtHdrHopByHop, \
IPv6ExtHdrFragment, IPv6ExtHdrDestOpt

View File

@ -1,5 +1,6 @@
#!/usr/bin/env python3
import socket
from socket import inet_pton, inet_ntop
import unittest

View File

@ -1,7 +1,8 @@
import os
import time
import socket
from socket import inet_pton, inet_ntop
import struct
import time
from traceback import format_exc, format_stack
import scapy.compat