black: re-format
black and isort are enabled in the openbmc-build-scripts on Python files
to have a consistent formatting. Re-run the formatter on the whole
repository.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I944f1915ece753f72a3fa654902d445a9749d0f9
diff --git a/bin/websocket_monitor.py b/bin/websocket_monitor.py
index 3425057..0f0a5a4 100755
--- a/bin/websocket_monitor.py
+++ b/bin/websocket_monitor.py
@@ -5,18 +5,19 @@
"""
import json
-import sys
-import websocket
import ssl
+import sys
+
import requests
+import websocket
from retrying import retry
save_path_0 = sys.path[0]
del sys.path[0]
-from gen_print import * # NOQA
-from gen_arg import * # NOQA
-from gen_valid import * # NOQA
+from gen_arg import * # NOQA
+from gen_print import * # NOQA
+from gen_valid import * # NOQA
# Restore sys.path[0].
sys.path.insert(0, save_path_0)
@@ -26,37 +27,39 @@
parser = argparse.ArgumentParser(
- usage='%(prog)s [OPTIONS]',
+ usage="%(prog)s [OPTIONS]",
description="%(prog)s will open a websocket session on a remote OpenBMC. "
- + "When an eSEL is created on that BMC, the monitor will receive "
- + "notice over websocket that the eSEL was created "
- + "and it will print a message.",
+ + "When an eSEL is created on that BMC, the monitor will receive "
+ + "notice over websocket that the eSEL was created "
+ + "and it will print a message.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
- prefix_chars='-+')
+ prefix_chars="-+",
+)
parser.add_argument(
- 'openbmc_host',
- default='',
- help='The BMC host name or IP address.')
+ "openbmc_host", default="", help="The BMC host name or IP address."
+)
parser.add_argument(
- '--openbmc_username',
- default='root',
- help='The userid for the open BMC system.')
+ "--openbmc_username",
+ default="root",
+ help="The userid for the open BMC system.",
+)
parser.add_argument(
- '--openbmc_password',
- default='',
- help='The password for the open BMC system.')
+ "--openbmc_password",
+ default="",
+ help="The password for the open BMC system.",
+)
parser.add_argument(
- '--monitor_type',
- choices=['logging', 'dump'],
- default='logging',
- help='The type of notifications from websocket to monitor.')
+ "--monitor_type",
+ choices=["logging", "dump"],
+ default="logging",
+ help="The type of notifications from websocket to monitor.",
+)
stock_list = [("test_mode", 0), ("quiet", 0), ("debug", 0)]
-def exit_function(signal_number=0,
- frame=None):
+def exit_function(signal_number=0, frame=None):
r"""
Execute whenever the program ends normally or with the signals that we
catch (i.e. TERM, INT).
@@ -67,8 +70,7 @@
qprint_pgm_footer()
-def signal_handler(signal_number,
- frame):
+def signal_handler(signal_number, frame):
r"""
Handle signals. Without a function to catch a SIGTERM or SIGINT, the
program would terminate immediately with return code 143 and without
@@ -95,14 +97,12 @@
valid_value(openbmc_username)
valid_value(openbmc_password)
global monitoring_uri
- monitoring_uri = '/xyz/openbmc_project/' + monitor_type
+ monitoring_uri = "/xyz/openbmc_project/" + monitor_type
gen_post_validation(exit_function, signal_handler)
@retry(stop_max_attempt_number=3, wait_fixed=1000)
-def login(openbmc_host,
- openbmc_username,
- openbmc_password):
+def login(openbmc_host, openbmc_username, openbmc_password):
r"""
Log into the BMC and return the session object.
@@ -114,15 +114,19 @@
qprint_executing()
- http_header = {'Content-Type': 'application/json'}
+ http_header = {"Content-Type": "application/json"}
session = requests.session()
- response = session.post('https://' + openbmc_host + '/login', headers=http_header,
- json={"data": [openbmc_username, openbmc_password]},
- verify=False, timeout=30)
+ response = session.post(
+ "https://" + openbmc_host + "/login",
+ headers=http_header,
+ json={"data": [openbmc_username, openbmc_password]},
+ verify=False,
+ timeout=30,
+ )
valid_value(response.status_code, valid_values=[200])
login_response = json.loads(response.text)
qprint_var(login_response)
- valid_value(login_response['status'], valid_values=['ok'])
+ valid_value(login_response["status"], valid_values=["ok"])
return session
@@ -145,12 +149,14 @@
# or
# /xyz/openbmc_project/dump/entry/1","properties":{"Size":186180}}').
- if monitoring_uri + '/entry' in message:
- if 'Id' in message:
- qprint_timen('eSEL received over websocket interface.')
+ if monitoring_uri + "/entry" in message:
+ if "Id" in message:
+ qprint_timen("eSEL received over websocket interface.")
websocket_obj.close()
- elif 'Size' in message:
- qprint_timen('Dump notification received over websocket interface.')
+ elif "Size" in message:
+ qprint_timen(
+ "Dump notification received over websocket interface."
+ )
websocket_obj.close()
@@ -212,17 +218,23 @@
session = login(openbmc_host, openbmc_username, openbmc_password)
qprint_timen("Registering websocket handlers.")
cookies = session.cookies.get_dict()
- cookies = sprint_var(cookies, fmt=no_header() | strip_brackets(),
- col1_width=0, trailing_char="",
- delim="=").replace("\n", ";")
+ cookies = sprint_var(
+ cookies,
+ fmt=no_header() | strip_brackets(),
+ col1_width=0,
+ trailing_char="",
+ delim="=",
+ ).replace("\n", ";")
# Register the event handlers. When an ESEL is created by the system
# under test, the on_message() handler will be called.
- websocket_obj = websocket.WebSocketApp("wss://" + openbmc_host + "/subscribe",
- on_message=on_message,
- on_error=on_error,
- on_close=on_close,
- on_open=on_open,
- cookie=cookies)
+ websocket_obj = websocket.WebSocketApp(
+ "wss://" + openbmc_host + "/subscribe",
+ on_message=on_message,
+ on_error=on_error,
+ on_close=on_close,
+ on_open=on_open,
+ cookie=cookies,
+ )
qprint_timen("Completed registering of websocket handlers.")
websocket_obj.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})