Update controllerconfig testenv to use python3 by default

Change pylint, flake and cover testenvs from python2.7 to python3.
Change installed version of pylint and isort for tests to be the
same as the ones used in sysinv. Previously no version was pinned
when using python3.
Add pylint to deps.

Part of this was work was neccessary to fix flake8 and pylint errors:
- Add inline pylint suppressions.
- The Request object add_data method doesn't exist anymore. Use direct
access to data field instead.
- Remove whitespace between print function and '('.

Story: 2008454
Task: 42675
Task: 42617
Signed-off-by: Dan Voiculeasa <dan.voiculeasa@windriver.com>
Change-Id: Icfae48dbbcd8efa4abb1a557a91bf1c58c5cb5bc
This commit is contained in:
Dan Voiculeasa 2021-06-22 20:35:51 +03:00
parent 1fda925b50
commit ac389b4b2b
16 changed files with 27 additions and 23 deletions

View File

@ -22,19 +22,19 @@ class ConfigError(Exception):
class ValidateFail(ConfigError): class ValidateFail(ConfigError):
"""Validation of data failed.""" """Validation of data failed."""
pass pass # pylint: disable=unnecessary-pass
class UpgradeFail(ConfigError): class UpgradeFail(ConfigError):
"""Upgrade error.""" """Upgrade error."""
pass pass # pylint: disable=unnecessary-pass
class KeystoneFail(ConfigError): class KeystoneFail(ConfigError):
"""Keystone error.""" """Keystone error."""
pass pass # pylint: disable=unnecessary-pass
class TidyStorageFail(ConfigError): class TidyStorageFail(ConfigError):
"""Tidy storage error.""" """Tidy storage error."""
pass pass # pylint: disable=unnecessary-pass

View File

@ -35,7 +35,7 @@ def rest_api_request(token, method, api_cmd, api_cmd_headers=None,
if api_cmd_payload is not None: if api_cmd_payload is not None:
request_info.add_header("Content-type", "application/json") request_info.add_header("Content-type", "application/json")
request_info.add_data(api_cmd_payload) request_info.data = api_cmd_payload
request = urlrequest.urlopen(request_info) request = urlrequest.urlopen(request_info)
response = request.read() response = request.read()
@ -94,7 +94,7 @@ def get_token(auth_url, auth_project, auth_user, auth_password,
"domain": {"name": project_domain} "domain": {"name": project_domain}
}}}}) }}}})
request_info.add_data(payload) request_info.data = payload
request = urlrequest.urlopen(request_info) request = urlrequest.urlopen(request_info)
# Identity API v3 returns token id in X-Subject-Token # Identity API v3 returns token id in X-Subject-Token

View File

@ -62,7 +62,7 @@ def check_sm_service(service, state):
try: try:
output = subprocess.check_output(["sm-query", "service", service], output = subprocess.check_output(["sm-query", "service", service],
universal_newlines=True) universal_newlines=True)
return state in output return state in output # pylint: disable=unsupported-membership-test
except subprocess.CalledProcessError: except subprocess.CalledProcessError:
return False return False
@ -324,7 +324,7 @@ def is_ssh_parent():
try: try:
cmd_output = subprocess.check_output(command, shell=True, cmd_output = subprocess.check_output(command, shell=True,
universal_newlines=True) universal_newlines=True)
if "ssh" in cmd_output: if "ssh" in cmd_output: # pylint: disable=unsupported-membership-test
return True return True
else: else:
return False return False

View File

@ -1,5 +1,4 @@
hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0 hacking!=0.13.0,<0.14,>=0.12.0 # Apache-2.0
pylint <=1.9.3;python_version<'3.0'
pytest pytest
mockproc>= 0.3.1 # BSD mockproc>= 0.3.1 # BSD
coverage>=3.6 coverage>=3.6
@ -8,3 +7,6 @@ os-testr>=0.8.0 # Apache-2.0
stestr>=1.0.0 # Apache-2.0 stestr>=1.0.0 # Apache-2.0
testresources>=0.2.4 # Apache-2.0/BSD testresources>=0.2.4 # Apache-2.0/BSD
testrepository>=0.0.18 # Apache-2.0/BSD testrepository>=0.0.18 # Apache-2.0/BSD
isort<5;python_version>="3.0"
pylint<2.1.0;python_version<"3.0" # GPLv2
pylint<2.4.0;python_version>="3.0" # GPLv2

View File

@ -45,12 +45,14 @@ commands =
stestr slowest stestr slowest
[testenv:pylint] [testenv:pylint]
basepython = python2.7 basepython = python3
deps = {[testenv]deps} deps = {[testenv]deps}
pylint
commands = pylint {posargs} controllerconfig --rcfile=./pylint.rc --extension-pkg-whitelist=netifaces commands = pylint {posargs} controllerconfig --rcfile=./pylint.rc --extension-pkg-whitelist=netifaces
[testenv:flake8] [testenv:flake8]
basepython = python2.7 basepython = python3
deps = -r{toxinidir}/test-requirements.txt deps = -r{toxinidir}/test-requirements.txt
commands = flake8 {posargs} commands = flake8 {posargs}
@ -67,7 +69,7 @@ ignore = H101,H102,H104,H306,H401,H404,H405
exclude = build exclude = build
[testenv:cover] [testenv:cover]
basepython = python2.7 basepython = python3
deps = {[testenv]deps} deps = {[testenv]deps}
commands = commands =

View File

@ -34,7 +34,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -35,7 +35,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -41,7 +41,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -31,7 +31,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -40,7 +40,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -30,7 +30,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -31,7 +31,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -51,7 +51,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -28,7 +28,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -30,7 +30,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1

View File

@ -31,7 +31,7 @@ def main():
elif arg == 3: elif arg == 3:
action = sys.argv[arg] action = sys.argv[arg]
else: else:
print ("Invalid option %s." % sys.argv[arg]) print("Invalid option %s." % sys.argv[arg])
return 1 return 1
arg += 1 arg += 1