Fix Python code checkstyle execute by "systemvm\test\runtests.sh" (#2576)

* dependencies update

* Add extra blank line required by ...!?

* fix W605 invalid escape sequence and more blank lines

* print all installed python packages versions
This commit is contained in:
Rafael Weingärtner 2018-04-18 13:07:37 -03:00 committed by GitHub
parent 392f62dae0
commit bfe4cb0c41
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
23 changed files with 35 additions and 12 deletions

View File

@ -196,7 +196,7 @@ class CsAcl(CsDataBag):
egressIpsetStr = ''
if sflag and dflag:
egressIpsetStr = " -m set --match-set %s src " % sourceIpsetName + \
" -m set --match-set %s dst " % destIpsetName
" -m set --match-set %s dst " % destIpsetName
elif sflag:
egressIpsetStr = " -m set --match-set %s src " % sourceIpsetName
elif dflag:
@ -204,10 +204,10 @@ class CsAcl(CsDataBag):
if rule['protocol'] == "icmp":
fwr += egressIpsetStr + " -p %s " % rule['protocol'] + " -m %s " % rule['protocol'] + \
" --icmp-type %s" % icmp_type
" --icmp-type %s" % icmp_type
elif rule['protocol'] != "all":
fwr += egressIpsetStr + " -p %s " % rule['protocol'] + " -m %s " % rule['protocol'] + \
" %s" % rnge
" %s" % rnge
elif rule['protocol'] == "all":
fwr += egressIpsetStr
@ -1052,5 +1052,6 @@ def main(argv):
red.set()
return 0
if __name__ == "__main__":
main(sys.argv)

View File

@ -42,10 +42,10 @@ class CsProcess(object):
self.pid = []
for i in CsHelper.execute("ps aux"):
items = len(self.search)
proc = re.split("\s+", i)[items*-1:]
proc = re.split(r"\s+", i)[items*-1:]
matches = len([m for m in proc if m in self.search])
if matches == items:
self.pid.append(re.split("\s+", i)[1])
self.pid.append(re.split(r"\s+", i)[1])
logging.debug("CsProcess:: Searching for process ==> %s and found PIDs ==> %s", self.search, self.pid)
return self.pid
@ -61,5 +61,5 @@ class CsProcess(object):
def grep(self, str):
for i in CsHelper.execute("ps aux"):
if i.find(str) != -1:
return re.split("\s+", i)[1]
return re.split(r"\s+", i)[1]
return -1

View File

@ -127,7 +127,7 @@ class CsRedundant(object):
"%s/%s" % (self.CS_TEMPLATES_DIR, "checkrouter.sh.templ"), "/opt/cloud/bin/checkrouter.sh")
CsHelper.execute(
'sed -i "s/--exec\ \$DAEMON;/--exec\ \$DAEMON\ --\ --vrrp;/g" /etc/init.d/keepalived')
'sed -i "s/--exec $DAEMON;/--exec $DAEMON -- --vrrp;/g" /etc/init.d/keepalived')
# checkrouter.sh configuration
check_router = CsFile("/opt/cloud/bin/checkrouter.sh")
check_router.greplace("[RROUTER_LOG]", self.RROUTER_LOG)
@ -319,7 +319,7 @@ class CsRedundant(object):
logging.info("Adding gateway ==> %s to device ==> %s" % (gateway, dev))
if dev == CsHelper.PUBLIC_INTERFACES[self.cl.get_type()]:
route.add_defaultroute(gateway)
except:
except Exception:
logging.error("ERROR getting gateway from device %s" % dev)
else:
logging.error("Device %s was not ready could not bring it up" % dev)

View File

@ -193,6 +193,7 @@ class LineEditingFile(object):
os.unlink(changed_filename)
return changes
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
import doctest

View File

@ -112,6 +112,7 @@ def is_guestnet_configured(guestnet_dict, keys):
return exists
# If the command line json file is unprocessed process it
# This is important or, the control interfaces will get deleted!
if jsonFilename != "cmd_line.json" and os.path.isfile(jsonPath % "cmd_line.json"):

View File

@ -164,5 +164,6 @@ def unflock(file):
sys.exit(1)
return True
if __name__ == "__main__":
main(sys.argv[1:])

View File

@ -38,5 +38,6 @@ class TestCsAddress(unittest.TestCase):
def test_get_guest_netmask(self):
self.assertTrue(self.csaddress.get_guest_netmask() == "255.255.255.0")
if __name__ == '__main__':
unittest.main()

View File

@ -34,5 +34,6 @@ class TestCsApp(unittest.TestCase):
csapp = CsApp(csip)
self.assertTrue(csapp is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -42,5 +42,6 @@ class TestCsCmdLine(unittest.TestCase):
self.cscmdline.set_guest_gw(tval)
self.assertTrue(self.cscmdline.get_guest_gw() == tval)
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsConfig(unittest.TestCase):
csconfig = CsConfig()
self.assertTrue(csconfig is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsDatabag(unittest.TestCase):
csdatabag = CsDataBag("koffie")
self.assertTrue(csdatabag is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -33,5 +33,6 @@ class TestCsDhcp(unittest.TestCase):
csdhcp = CsDhcp("dhcpentry", {})
self.assertTrue(csdhcp is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsFile(unittest.TestCase):
csfile = CsFile("testfile")
self.assertTrue(csfile is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -41,5 +41,6 @@ class TestCsGuestNetwork(unittest.TestCase):
dns = csguestnetwork.get_dns()
self.assertTrue(len(dns) == 2)
if __name__ == '__main__':
unittest.main()

View File

@ -31,5 +31,6 @@ class TestCsHelper(unittest.TestCase):
result = CsHelper.execute("/bin/false")
self.assertTrue(result is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -34,5 +34,6 @@ class TestCsInterface(unittest.TestCase):
def test_is_public(self):
self.assertTrue(self.csinterface.is_public() is False)
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsNetfilter(unittest.TestCase):
csnetfilter = CsNetfilter()
self.assertTrue(csnetfilter is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsProcess(unittest.TestCase):
csprocess = CsProcess({})
self.assertTrue(csprocess is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -36,5 +36,6 @@ class TestCsRedundant(unittest.TestCase):
csredundant = CsRedundant(csconfig)
self.assertTrue(csredundant is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -43,5 +43,6 @@ class TestCsRoute(unittest.TestCase):
name = "eth1"
self.assertEqual("Table_eth1", csroute.get_tablename(name))
if __name__ == '__main__':
unittest.main()

View File

@ -29,5 +29,6 @@ class TestCsRule(unittest.TestCase):
csrule = CsRule("eth1")
self.assertTrue(csrule is not None)
if __name__ == '__main__':
unittest.main()

View File

@ -21,9 +21,9 @@
export PYTHONPATH="../debian/opt/cloud/bin/"
export PYTHONDONTWRITEBYTECODE=False
echo "Running pep8 to check systemvm/python code for errors"
pep8 --max-line-length=179 *py
pep8 --max-line-length=179 --exclude=monitorServices.py,baremetal-vr.py,passwd_server_ip.py `find ../debian -name \*.py`
echo "Running pycodestyle to check systemvm/python code for errors"
pycodestyle --max-line-length=179 *py
pycodestyle --max-line-length=179 --exclude=monitorServices.py,baremetal-vr.py,passwd_server_ip.py `find ../debian -name \*.py`
if [ $? -gt 0 ]
then
echo "Pylint failed, please check your code"

View File

@ -22,6 +22,8 @@
#
echo -e "#### System Information ####"
echo -e "\nO.S. information:"
echo $(uname -a)
echo -e "\nWho am I:"
whoami
@ -100,7 +102,7 @@ pip install --user --upgrade pip
for ((i=0;i<$RETRY_COUNT;i++))
do
pip install --user --upgrade lxml paramiko nose texttable ipmisim pyopenssl mock flask netaddr pylint pep8 > /tmp/piplog
pip install --user --upgrade lxml paramiko nose texttable ipmisim pyopenssl mock flask netaddr pylint pycodestyle six astroid > /tmp/piplog
if [[ $? -eq 0 ]]; then
echo -e "\npython packages installed successfully"
break;
@ -109,3 +111,5 @@ do
cat /tmp/piplog
done
echo -e "\nVersion of pip packages:\n"
echo $(pip freeze)