Browse Source

Enable Unused Variable

Flake8 currently ignores:
F841: local variable is assigned to but never used

Pylint currently ignores:
W0612: Unused variable warning

Enable them for more thorough testing of code

Change-Id: I4c55186f939675cc2c3dc871ad03699d95c6091b
Story: 2004515
Task: 29303
Signed-off-by: Eric Barrett <eric.barrett@windriver.com>
changes/67/664267/3 v2.0.0.rc0
Eric Barrett 2 years ago
parent
commit
0805514d60
13 changed files with 30 additions and 57 deletions
  1. +8
    -25
      cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py
  2. +1
    -1
      cgcs-patch/cgcs-patch/cgcs_patch/api/controllers/root.py
  3. +1
    -1
      cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py
  4. +0
    -2
      cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py
  5. +2
    -11
      cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py
  6. +3
    -3
      cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py
  7. +5
    -5
      cgcs-patch/cgcs-patch/cgcs_patch/patch_verify.py
  8. +2
    -1
      cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py
  9. +2
    -1
      cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py
  10. +1
    -1
      cgcs-patch/cgcs-patch/pylint.rc
  11. +1
    -1
      cgcs-patch/cgcs-patch/tox.ini
  12. +1
    -2
      pylint.rc
  13. +3
    -3
      tsconfig/tsconfig/tsconfig/tests/test_basics.py

+ 8
- 25
cgcs-patch/cgcs-patch/cgcs_make_patch/make_patch_functions.py View File

@ -471,7 +471,6 @@ class PatchList(object):
sys.exit(2)
if fix and (rc2 > MINOR_DIFF):
new_status = self.get_status()
old_status = prd.get_status()
# TODO should we update status
prd.set_status(new_status)
rc2 = prd.compare(self.patch_data[prd.patch_id])
@ -897,7 +896,7 @@ class RecipeData(object):
extra_arg = "--prebuilt"
if os.path.isfile(path):
rc = issue_cmd_rc("%s %s %s >> %s/%s.log" % (path, self.name, extra_arg, os.environ['DEST'], os.environ['PREFIX']))
issue_cmd_rc("%s %s %s >> %s/%s.log" % (path, self.name, extra_arg, os.environ['DEST'], os.environ['PREFIX']))
def build_patch(self, pf, fatal=True):
for package in self.packages:
@ -1265,13 +1264,11 @@ class PatchRecipeData(object):
def _read_rpm_db(self, patch_id):
release_map = {}
rpm_db_dir = "export/patch_data"
rpm_db = self._get_rpm_db_path(patch_id)
with open(rpm_db) as f:
for line in f:
words = line.split()
if len(words) == 3:
arch = words[0]
rpm = words[1]
release = words[2]
release_map[rpm] = release[1:]
@ -1933,45 +1930,31 @@ def make_patch():
print("invalid patch file path: '%s'" % patch)
make_patch_usage()
if 'MY_REPO' in os.environ:
MY_REPO = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_REPO'])))
else:
if 'MY_REPO' not in os.environ:
print("ERROR: environment variable 'MY_REPO' is not defined")
sys.exit(1)
if 'MY_WORKSPACE' in os.environ:
MY_WORKSPACE = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_WORKSPACE'])))
else:
if 'MY_WORKSPACE' not in os.environ:
print("ERROR: environment variable 'MY_REPO' is not defined")
sys.exit(1)
if 'PROJECT' in os.environ:
PROJECT = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['PROJECT'])))
else:
if 'PROJECT' not in os.environ:
print("ERROR: environment variable 'PROJECT' is not defined")
sys.exit(1)
if 'SRC_BUILD_ENVIRONMENT' in os.environ:
SRC_BUILD_ENVIRONMENT = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['SRC_BUILD_ENVIRONMENT'])))
else:
if 'SRC_BUILD_ENVIRONMENT' not in os.environ:
print("ERROR: environment variable 'SRC_BUILD_ENVIRONMENT' is not defined")
sys.exit(1)
if 'MY_SRC_RPM_BUILD_DIR' in os.environ:
MY_SRC_RPM_BUILD_DIR = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_SRC_RPM_BUILD_DIR'])))
else:
if 'MY_SRC_RPM_BUILD_DIR' not in os.environ:
print("ERROR: environment variable 'MY_SRC_RPM_BUILD_DIR' is not defined")
sys.exit(1)
if 'MY_BUILD_CFG' in os.environ:
MY_BUILD_CFG = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_BUILD_CFG'])))
else:
if 'MY_BUILD_CFG' not in os.environ:
print("ERROR: environment variable 'MY_BUILD_CFG' is not defined")
sys.exit(1)
if 'MY_BUILD_DIR' in os.environ:
MY_BUILD_DIR = os.path.normpath(os.path.join(cwd, os.path.expanduser(os.environ['MY_BUILD_DIR'])))
else:
if 'MY_BUILD_DIR' not in os.environ:
print("ERROR: environment variable 'MY_BUILD_DIR' is not defined")
sys.exit(1)


+ 1
- 1
cgcs-patch/cgcs-patch/cgcs_patch/api/controllers/root.py View File

@ -134,7 +134,7 @@ class PatchAPIController(object):
@expose('json')
def upload_dir(self, **kwargs):
files = []
for key, path in kwargs.items():
for path in kwargs.values():
LOG.info("upload-dir: Retrieving patches from %s" % path)
for f in glob.glob(path + '/*.patch'):
if os.path.isfile(f):


+ 1
- 1
cgcs-patch/cgcs-patch/cgcs_patch/patch_agent.py View File

@ -993,7 +993,7 @@ class PatchAgent(PatchService):
break
try:
datachk = json.loads(data)
json.loads(data)
break
except ValueError:
# Message is incomplete


+ 0
- 2
cgcs-patch/cgcs-patch/cgcs_patch/patch_client.py View File

@ -994,8 +994,6 @@ def host_install_async(debug, args):
def drop_host(debug, args):
force = False
if len(args) != 1:
print_help()


+ 2
- 11
cgcs-patch/cgcs-patch/cgcs_patch/patch_controller.py View File

@ -743,13 +743,10 @@ class PatchController(PatchService):
self.patch_data.metadata[patch_id]["patchstate"] = \
self.patch_data.metadata[patch_id]["repostate"]
any_out_of_date = False
for ip in self.hosts.keys():
if not self.hosts[ip].out_of_date:
continue
any_out_of_date = True
for pkg in self.hosts[ip].installed.keys():
for patch_id in self.patch_data.content_versions.keys():
if pkg not in self.patch_data.content_versions[patch_id]:
@ -920,8 +917,6 @@ class PatchController(PatchService):
LOG.info(msg)
audit_log_info(msg)
repo_changed = False
for patch in patch_list:
msg = "Importing patch: %s" % patch
LOG.info(msg)
@ -978,8 +973,6 @@ class PatchController(PatchService):
msg_error += msg + "\n"
continue
repo_changed = True
try:
thispatch = PatchFile.extract_patch(patch,
metadata_dir=avail_dir,
@ -1804,8 +1797,6 @@ class PatchController(PatchService):
LOG.exception(msg)
raise PatchFail(msg)
release = None
patch_added = False
failure = False
recursive = True
@ -2007,7 +1998,7 @@ class PatchController(PatchService):
rc = False
self.hosts_lock.acquire()
for ip, host in self.hosts.items():
for host in self.hosts.values():
if host.state == constants.PATCH_AGENT_STATE_INSTALLING:
rc = True
break
@ -2467,7 +2458,7 @@ class PatchControllerMainThread(threading.Thread):
if data == '':
break
try:
datachk = json.loads(data)
json.loads(data)
break
except ValueError:
# Message is incomplete


+ 3
- 3
cgcs-patch/cgcs-patch/cgcs_patch/patch_functions.py View File

@ -154,7 +154,7 @@ def write_xml_file(top,
def parse_rpm_filename(filename):
# Drop the extension
(basename, ext) = os.path.splitext(os.path.basename(filename))
basename = os.path.splitext(os.path.basename(filename))[0]
# RPM name format is:
# [<epoch>:]<pkgname>-<version>-<release>.<arch>
@ -244,7 +244,7 @@ class BasePackageData(object):
continue
self.pkgs[sw_rel] = {}
for root, dirs, files in os.walk("%s/Packages" % reldir):
for root, dirs, files in os.walk("%s/Packages" % reldir): # pylint: disable=unused-variable
for name in files:
if name.endswith(".rpm"):
try:
@ -612,7 +612,7 @@ class PatchData(object):
write_xml_file(top, fname)
def gen_groups_xml(self):
for ver, rdir in repo_dir.items():
for ver in repo_dir:
self.gen_release_groups_xml(ver)
def query_line(self,


+ 5
- 5
cgcs-patch/cgcs-patch/cgcs_patch/patch_verify.py View File

@ -33,12 +33,12 @@ cert_type_all = [cert_type_dev_str, cert_type_formal_str]
def verify_hash(data_hash, signature_bytes, certificate_list):
"""
Checkes that a hash's signature can be validates against an approved
Checks that a hash's signature can be validated against an approved
certificate
:param data_hash: A hash of the data to be validated
:param signature_bytes: A pre-generated signature (typically, the hash
encrypted with a private key)
:param certifcate_list: A list of approved certificates or public keys
:param certificate_list: A list of approved certificates or public keys
which the signature is validated against
:return: True if the signature was validated against a certificate
"""
@ -47,7 +47,7 @@ def verify_hash(data_hash, signature_bytes, certificate_list):
if verified:
break
pub_key = read_RSA_key(cert)
x = pub_key.exportKey()
pub_key.exportKey()
# PSS is the recommended signature scheme, but some tools (like OpenSSL)
# use the older v1_5 scheme. We try to validate against both.
@ -58,14 +58,14 @@ def verify_hash(data_hash, signature_bytes, certificate_list):
verifier = PKCS1_PSS.new(pub_key)
try:
verified = verifier.verify(data_hash, signature_bytes) # pylint: disable=not-callable
except ValueError as e:
except ValueError:
verified = False
if not verified:
verifier = PKCS1_v1_5.new(pub_key)
try:
verified = verifier.verify(data_hash, signature_bytes)
except ValueError as e:
except ValueError:
verified = False
return verified


+ 2
- 1
cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_agent.py View File

@ -19,4 +19,5 @@ import cgcs_patch.patch_agent # noqa: E402
class CgcsPatchAgentTestCase(testtools.TestCase):
def test_cgcs_patch_agent_instantiate(self):
pc = cgcs_patch.patch_agent.PatchAgent()
# pylint: disable=unused-variable
pc = cgcs_patch.patch_agent.PatchAgent() # noqa: F841

+ 2
- 1
cgcs-patch/cgcs-patch/cgcs_patch/tests/test_patch_controller.py View File

@ -20,4 +20,5 @@ class CgcsPatchControllerTestCase(testtools.TestCase):
@mock.patch('six.moves.builtins.open')
def test_cgcs_patch_controller_instantiate(self, mock_open):
pc = cgcs_patch.patch_controller.PatchController()
# pylint: disable=unused-variable
pc = cgcs_patch.patch_controller.PatchController() # noqa: F841

+ 1
- 1
cgcs-patch/cgcs-patch/pylint.rc View File

@ -45,7 +45,7 @@ symbols=no
# no Warning level messages displayed, use"--disable=all --enable=classes
# --disable=W"
#disable=
disable=C, R, W0603, W0612, W0613, W0702, W0703, W1201
disable=C, R, W0603, W0613, W0702, W0703, W1201
[REPORTS]


+ 1
- 1
cgcs-patch/cgcs-patch/tox.ini View File

@ -67,7 +67,7 @@ commands = {[testenv:stestr]commands}
# F841 local variable 'XXXXXX' is assigned to but never used
show-source = True
#ignore = H101,H102,H105,H306,H401,H404,H405,E501,F401,F841
ignore = H101,H102,H105,H306,H401,H404,H405,E501,F401,F841
ignore = H101,H102,H105,H306,H401,H404,H405,E501,F401
exclude = .venv,.git,.tox,dist,doc,*lib/python*,*egg,build,release-tag-*
# H106: Don't put vim configuration in source files (off by default).
# H203: Use assertIs(Not)None to check for None (off by default).


+ 1
- 2
pylint.rc View File

@ -27,12 +27,11 @@ load-plugins=
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
# W0603 Using the global statement warning
# W0612 Unused variable warning
# W0613 Unused argument warning
# W0702 bare-except
# W0703 broad except warning
# W1201 logging-not-lazy
disable=C, R, W0603, W0612, W0613, W0702, W0703, W1201
disable=C, R, W0603, W0613, W0702, W0703, W1201
[REPORTS]


+ 3
- 3
tsconfig/tsconfig/tsconfig/tests/test_basics.py View File

@ -114,7 +114,7 @@ vswitch_type=ovs-dpdk
# 1st: /etc/build.info
# 2nd: /etc/platform/platform.conf
mock_open.return_value = io.StringIO(self.mock_malformed_build)
from tsconfig import tsconfig
from tsconfig import tsconfig # pylint: disable=unused-variable
mock_logging_exception.assert_called_once()
# This tests the behaviour when the platform.conf is missing
@ -129,7 +129,7 @@ vswitch_type=ovs-dpdk
# 1st: /etc/build.info
# 2nd: /etc/platform/platform.conf
mock_open.return_value = io.StringIO(self.mock_19_01_build)
from tsconfig import tsconfig
from tsconfig import tsconfig # pylint: disable=unused-variable
mock_logging_exception.assert_called_once()
# This tests the behaviour when the platform.conf is empty
@ -145,7 +145,7 @@ vswitch_type=ovs-dpdk
# 2nd: /etc/platform/platform.conf
mock_open.side_effect = [io.StringIO(self.mock_19_01_build),
io.StringIO(self.mock_platform_conf_empty)]
from tsconfig import tsconfig
from tsconfig import tsconfig # pylint: disable=unused-variable
mock_logging_exception.assert_called_once()
# This tests the behaviour when the platform.conf has the minimal entries


Loading…
Cancel
Save