-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixup perfmon.11 #11
base: master
Are you sure you want to change the base?
Fixup perfmon.11 #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
[MAIN] | ||
|
||
# Use multiple processes to speed up Pylint. Specifying 0 will auto-detect the | ||
# number of processors available to use, and will cap the count on Windows to | ||
# avoid hangs. | ||
jobs=2 | ||
|
||
# Pickle collected data for later comparisons. | ||
persistent=yes | ||
|
||
# Discover python modules and packages in the file system subtree. | ||
recursive=yes | ||
|
||
# Add paths to the list of the source roots. Supports globbing patterns. The | ||
# source root is an absolute path or a path relative to the current working | ||
# directory used to determine a package namespace for modules located under the | ||
# source root. | ||
source-roots= | ||
ocaml/xapi-storage/python, | ||
scripts, | ||
scripts/examples/python, | ||
|
||
# When enabled, pylint would attempt to guess common misconfiguration and emit | ||
# user-friendly hints instead of false-positive error messages. | ||
suggestion-mode=yes | ||
|
||
# In verbose mode, extra non-checker-related info will be displayed. | ||
verbose=yes | ||
|
||
[MESSAGES CONTROL] | ||
|
||
# Disable the message, report, category or checker with the given id(s). You | ||
# can either give multiple identifiers separated by comma (,) or put this | ||
# option multiple times (only on the command line, not in the configuration | ||
# file where it should appear only once). You can also use "--disable=all" to | ||
# disable everything first and then re-enable specific checks. For example, if | ||
# you want to run only the similarities checker, you can use "--disable=all | ||
# --enable=similarities". If you want to run only the classes checker, but have | ||
# no Warning level messages displayed, use "--disable=all --enable=classes | ||
# --disable=W". | ||
disable= | ||
bad-option-value, # old pylint for py2: ignore newer (unknown) pylint options | ||
bad-continuation, # old pylint warns about some modern black formatting | ||
bad-indentation, | ||
consider-using-dict-comprehension, | ||
consider-using-f-string, | ||
consider-using-with, | ||
import-error, | ||
import-outside-toplevel, | ||
invalid-name, | ||
missing-final-newline, | ||
missing-function-docstring, | ||
multiple-imports, | ||
redefined-outer-name, | ||
trailing-whitespace, # enable this soon, after citical PRs are merged | ||
useless-option-value, # new pylint has abaondoned these old options | ||
|
||
[FORMAT] | ||
|
||
# Maximum number of characters on a single line. | ||
max-line-length=98 | ||
|
||
[BASIC] | ||
|
||
# Good variable names which should always be accepted, separated by a comma. | ||
good-names=a, | ||
b, | ||
c, | ||
f, | ||
i, | ||
j, | ||
k, | ||
ex, | ||
Run, | ||
_ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
rule_settings: | ||
disable: | ||
- replace-interpolation-with-fstring | ||
- use-fstring-for-concatenation | ||
- use-fstring-for-formatting |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Used for importing a non-".py" file as a module | ||
|
||
import sys | ||
import os | ||
|
||
def import_from_file(module_name, file_path): | ||
"""Import a file as a module""" | ||
# Only for python3, but CI has python2 pytest check, so add this line | ||
if sys.version_info.major == 2: | ||
return None | ||
from importlib import machinery, util | ||
loader = machinery.SourceFileLoader(module_name, file_path) | ||
spec = util.spec_from_loader(module_name, loader) | ||
assert spec | ||
assert spec.loader | ||
module = util.module_from_spec(spec) | ||
# Probably a good idea to add manually imported module stored in sys.modules | ||
sys.modules[module_name] = module | ||
spec.loader.exec_module(module) | ||
return module | ||
|
||
def get_module(module_name, file_path): | ||
testdir = os.path.dirname(__file__) | ||
return import_from_file(module_name, testdir + file_path) |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -313,7 +313,7 @@ class RRDUpdates: | |
print_debug("Calling http://localhost/rrd_updates?%s" % paramstr) | ||
|
||
sock = urllib.request.urlopen("http://localhost/rrd_updates?%s" % paramstr) | ||
xmlsource = sock.read() | ||
xmlsource = sock.read().decode('utf-8') | ||
sock.close() | ||
|
||
# Use sax rather than minidom and save Vvvast amounts of time and memory. | ||
|
@@ -380,7 +380,7 @@ def get_percent_mem_usage(ignored): | |
memlist = memfd.readlines() | ||
memfd.close() | ||
memdict = [ m.split(':', 1) for m in memlist ] | ||
memdict = dict([(k.strip(), float(re.search('\d+', v.strip()).group(0))) for (k,v) in memdict]) | ||
memdict = dict([(k.strip(), float(re.search(r'\d+', v.strip()).group(0))) for (k,v) in memdict]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [mypy] reported by reviewdog 🐶 |
||
# We consider the sum of res memory and swap in use as the hard demand | ||
# of mem usage, it is bad if this number is beyond the physical mem, as | ||
# in such case swapping is obligatory rather than voluntary, hence | ||
|
@@ -481,8 +481,12 @@ class VariableState: | |
""" | ||
def __init__(self): | ||
self.value = None | ||
# pytype: disable=attribute-error | ||
# pylint: disable-next=no-member | ||
self.timeof_last_alarm = time.time() - self.alarm_auto_inhibit_period | ||
# pylint: disable-next=no-member | ||
self.trigger_down_counter = self.alarm_trigger_period | ||
# pytype: enable=attribute-error | ||
|
||
class Variable(VariableConfig, VariableState): | ||
""" Variable() is used by ObjectMonitor to create one Variable object for each | ||
|
@@ -1067,7 +1071,8 @@ def main(): | |
vm_uuid_list = rrd_updates.get_uuid_list_by_objtype('vm') | ||
|
||
# Remove any monitors for VMs no longer listed in rrd_updates page | ||
for uuid in vm_mon_lookup: | ||
# We use .pop() inside the loop, use list(dict_var.keys()): | ||
for uuid in list(vm_mon_lookup.keys()): | ||
if uuid not in vm_uuid_list: | ||
vm_mon_lookup.pop(uuid) | ||
|
||
|
@@ -1103,7 +1108,8 @@ def main(): | |
print_debug("sr_uuid_list = %s" % sr_uuid_list) | ||
|
||
# Remove monitors for SRs no longer listed in the rrd_updates page | ||
for uuid in sr_mon_lookup: | ||
# We use .pop() inside the loop, use list(dict_var.keys()): | ||
for uuid in list(sr_mon_lookup.keys()): | ||
if uuid not in sr_uuid_list: | ||
sr_mon_lookup.pop(uuid) | ||
# Create monitors for SRs that have just appeared in rrd_updates page | ||
|
@@ -1231,25 +1237,22 @@ if __name__ == "__main__": | |
# we caught a signal which we have already logged | ||
pass | ||
|
||
except Exception as e: | ||
except Exception as e: # pylint: disable=broad-exception-caught | ||
rc = 2 | ||
log_err("FATAL ERROR: perfmon will exit") | ||
log_err("Exception is of class %s" % e.__class__) | ||
ex = sys.exc_info() | ||
err = traceback.format_exception(*ex) | ||
|
||
# Python built-in Exception has args, | ||
# but XenAPI.Failure has details instead. Sigh. | ||
try: | ||
errmsg = "\n".join([ str(x) for x in e.args ]) | ||
# print the exception args nicely | ||
log_err(errmsg) | ||
except Exception as ignored: | ||
log_err("\n".join([ str(x) for x in e.args ])) | ||
except AttributeError: | ||
try: | ||
errmsg = "\n".join([ str(x) for x in e.details ]) | ||
# print the exception args nicely | ||
log_err(errmsg) | ||
except Exception as ignored: | ||
assert isinstance(e, XenAPI.Failure) | ||
log_err("\n".join([ str(x) for x in e.details ])) | ||
except AttributeError: | ||
pass | ||
|
||
# now log the traceback to syslog | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[pylint] reported by reviewdog 🐶
C0114: Missing module docstring (missing-module-docstring)