Revert "black: re-format"
This reverts commit 5731818de0ce446ceaafc7e75ae39da1b69942ae.
Signed-off-by: George Keishing <gkeishin@in.ibm.com>
Change-Id: Ie61cdc8c7f2825b0d9d66be87a6a3a058de2b372
diff --git a/lib/openbmctool_utils.py b/lib/openbmctool_utils.py
index dfe84e7..a6c94e9 100755
--- a/lib/openbmctool_utils.py
+++ b/lib/openbmctool_utils.py
@@ -5,21 +5,22 @@
openbmctool_execute_command.
"""
-import collections
-import json
+import gen_print as gp
+import gen_cmd as gc
+import gen_valid as gv
+import gen_misc as gm
+import var_funcs as vf
+import utils as utils
+from robot.libraries.BuiltIn import BuiltIn
import re
import tempfile
-
-import gen_cmd as gc
-import gen_misc as gm
-import gen_print as gp
-import gen_valid as gv
-import utils as utils
-import var_funcs as vf
-from robot.libraries.BuiltIn import BuiltIn
+import collections
+import json
-def openbmctool_execute_command(command_string, *args, **kwargs):
+def openbmctool_execute_command(command_string,
+ *args,
+ **kwargs):
r"""
Run the command string as an argument to the openbmctool.py program and
return the stdout and the return code.
@@ -63,12 +64,10 @@
# Get global BMC variable values.
openbmc_host = BuiltIn().get_variable_value("${OPENBMC_HOST}", default="")
https_port = BuiltIn().get_variable_value("${HTTPS_PORT}", default="443")
- openbmc_username = BuiltIn().get_variable_value(
- "${OPENBMC_USERNAME}", default=""
- )
- openbmc_password = BuiltIn().get_variable_value(
- "${OPENBMC_PASSWORD}", default=""
- )
+ openbmc_username = BuiltIn().get_variable_value("${OPENBMC_USERNAME}",
+ default="")
+ openbmc_password = BuiltIn().get_variable_value("${OPENBMC_PASSWORD}",
+ default="")
if not gv.valid_value(openbmc_host):
return "", "", 1
if not gv.valid_value(openbmc_username):
@@ -82,35 +81,24 @@
# example, the user may have specified "fru status | head -n 2" which
# would be broken into 2 list elements. We will also break on ">"
# (re-direct).
- pipeline = list(
- map(str.strip, re.split(r" ([\|>]) ", str(command_string)))
- )
+ pipeline = list(map(str.strip, re.split(r' ([\|>]) ',
+ str(command_string))))
# The "tail" command below prevents a "egrep: write error: Broken pipe"
# error if the user is piping the output to a sub-process.
# Use "egrep -v" to get rid of editorial output from openbmctool.py.
- pipeline.insert(
- 1,
- "| tail -n +1 | egrep -v 'Attempting login|User [^ ]+"
- " has been logged out'",
- )
+ pipeline.insert(1, "| tail -n +1 | egrep -v 'Attempting login|User [^ ]+"
+ " has been logged out'")
- command_string = (
- "set -o pipefail ; python3 $(which openbmctool.py) -H "
- + openbmc_host
- + ":"
- + https_port
- + " -U "
- + openbmc_username
- + " -P "
- + openbmc_password
- + " "
- + " ".join(pipeline)
- )
+ command_string = "set -o pipefail ; python3 $(which openbmctool.py) -H "\
+ + openbmc_host + ":" + https_port + " -U " + openbmc_username + " -P " + openbmc_password\
+ + " " + " ".join(pipeline)
return gc.shell_cmd(command_string, *args, **kwargs)
-def openbmctool_execute_command_json(command_string, *args, **kwargs):
+def openbmctool_execute_command_json(command_string,
+ *args,
+ **kwargs):
r"""
Run the command string as an argument to the openbmctool.py program, parse
the JSON output into a dictionary and return the dictionary.
@@ -124,19 +112,21 @@
See openbmctool_execute_command (above) for all field descriptions.
"""
- rc, output = openbmctool_execute_command(command_string, *args, **kwargs)
+ rc, output = openbmctool_execute_command(command_string,
+ *args,
+ **kwargs)
try:
json_object = utils.to_json_ordered(output)
except json.JSONDecodeError:
BuiltIn().fail(gp.sprint_error(output))
- if json_object["status"] != "ok":
+ if json_object['status'] != "ok":
err_msg = "Error found in JSON data returned by the openbmctool.py "
err_msg += "command. Expected a 'status' field value of \"ok\":\n"
err_msg += gp.sprint_var(json_object, 1)
BuiltIn().fail(gp.sprint_error(err_msg))
- return json_object["data"]
+ return json_object['data']
def get_fru_status():
@@ -165,9 +155,8 @@
[functional]: No
...
"""
- rc, output = openbmctool_execute_command(
- "fru status", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("fru status", print_output=False,
+ ignore_err=False)
# Example value for output (partial):
# Component | Is a FRU | Present | Functional | Has Logs
# cpu0 | Yes | Yes | Yes | No
@@ -245,9 +234,8 @@
parsed into a list of dictionaries.
"""
- rc, output = openbmctool_execute_command(
- "fru print", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("fru print", print_output=False,
+ ignore_err=False)
if parse_json:
return gm.json_loads_multiple(output)
else:
@@ -317,9 +305,8 @@
parsed into a list of dictionaries.
"""
- rc, output = openbmctool_execute_command(
- "fru list", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("fru list", print_output=False,
+ ignore_err=False)
if parse_json:
return gm.json_loads_multiple(output)
else:
@@ -327,6 +314,7 @@
def get_sensors_print():
+
r"""
Get the output of the sensors print command and return as a list of
dictionaries.
@@ -353,9 +341,9 @@
[target]: Active
...
"""
- rc, output = openbmctool_execute_command(
- "sensors print", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("sensors print",
+ print_output=False,
+ ignore_err=False)
# Example value for output (partial):
# sensor | type | units | value | target
# OCC0 | Discrete | N/A | Active | Active
@@ -365,6 +353,7 @@
def get_sensors_list():
+
r"""
Get the output of the sensors list command and return as a list of
dictionaries.
@@ -391,9 +380,9 @@
[target]: Active
...
"""
- rc, output = openbmctool_execute_command(
- "sensors list", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("sensors list",
+ print_output=False,
+ ignore_err=False)
# Example value for output (partial):
# sensor | type | units | value | target
# OCC0 | Discrete | N/A | Active | Active
@@ -413,9 +402,9 @@
Example result (excerpt):
openbmctool_version: 1.06
"""
- rc, output = openbmctool_execute_command(
- "-V | cut -f 2 -d ' '", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("-V | cut -f 2 -d ' '",
+ print_output=False,
+ ignore_err=False)
return output
@@ -425,14 +414,15 @@
the collect_service_data command.
"""
- return [
- "inventory.txt",
- "sensorReadings.txt",
- "ledStatus.txt",
- "SELshortlist.txt",
- "parsedSELs.txt",
- "bmcFullRaw.txt",
- ]
+ return\
+ [
+ "inventory.txt",
+ "sensorReadings.txt",
+ "ledStatus.txt",
+ "SELshortlist.txt",
+ "parsedSELs.txt",
+ "bmcFullRaw.txt"
+ ]
def collect_service_data(verify=False):
@@ -449,41 +439,32 @@
# Route the output of collect_service_data to a file for easier parsing.
temp = tempfile.NamedTemporaryFile()
temp_file_path = temp.name
- openbmctool_execute_command(
- "collect_service_data > " + temp_file_path, ignore_err=False
- )
+ openbmctool_execute_command("collect_service_data > " + temp_file_path,
+ ignore_err=False)
# Isolate the file paths in the collect_service_data output. We're
# looking for output lines like this from which to extract the file paths:
# Inventory collected and stored in /tmp/dummy--2018-09-26_17.59.18/inventory.txt
- rc, file_paths = gc.shell_cmd(
- "egrep 'collected and' " + temp_file_path
- # + " | sed -re 's#.*/tmp#/tmp#g'",
- + " | sed -re 's#[^/]*/#/#'",
- quiet=1,
- print_output=0,
- )
+ rc, file_paths = gc.shell_cmd("egrep 'collected and' " + temp_file_path
+ # + " | sed -re 's#.*/tmp#/tmp#g'",
+ + " | sed -re 's#[^/]*/#/#'",
+ quiet=1, print_output=0)
# Example file_paths value:
# /tmp/dummy--2018-09-26_17.59.18/inventory.txt
# /tmp/dummy--2018-09-26_17.59.18/sensorReadings.txt
# etc.
# Convert from output to list.
- collect_service_data_file_paths = list(
- filter(None, file_paths.split("\n"))
- )
+ collect_service_data_file_paths =\
+ list(filter(None, file_paths.split("\n")))
if int(verify):
# Create a list of files by stripping the dir names from the elements
# of collect_service_data_file_paths.
- files_obtained = [
- re.sub(r".*/", "", file_path)
- for file_path in collect_service_data_file_paths
- ]
+ files_obtained = [re.sub(r".*/", "", file_path)
+ for file_path in collect_service_data_file_paths]
files_expected = service_data_files()
files_missing = list(set(files_expected) - set(files_obtained))
if len(files_missing) > 0:
- gp.printn(
- "collect_service_data output:\n"
- + gm.file_to_str(temp_file_path)
- )
+ gp.printn("collect_service_data output:\n"
+ + gm.file_to_str(temp_file_path))
err_msg = "The following files are missing from the list of files"
err_msg += " returned by collect_service_data:\n"
err_msg += gp.sprint_var(files_missing)
@@ -498,7 +479,11 @@
Return a complete list of field names returned by the health_check command.
"""
- return ["hardware_status", "performance"]
+ return\
+ [
+ "hardware_status",
+ "performance"
+ ]
def get_health_check(verify=False):
@@ -522,9 +507,9 @@
health_check command.
"""
- rc, output = openbmctool_execute_command(
- "health_check", print_output=False, ignore_err=False
- )
+ rc, output = openbmctool_execute_command("health_check",
+ print_output=False,
+ ignore_err=False)
health_check = vf.key_value_outbuf_to_dict(output, delim=":")
if int(verify):
err_msg = gv.valid_dict(health_check, health_check_fields())
@@ -540,7 +525,11 @@
remote_logging view command.
"""
- return ["Address", "Port"]
+ return\
+ [
+ "Address",
+ "Port"
+ ]
def get_remote_logging_view(verify=False):
@@ -565,14 +554,14 @@
remote_logging view' command.
"""
- remote_logging_view = openbmctool_execute_command_json(
- "logging remote_logging view", print_output=False, ignore_err=False
- )
+ remote_logging_view =\
+ openbmctool_execute_command_json("logging remote_logging view",
+ print_output=False,
+ ignore_err=False)
if int(verify):
- err_msg = gv.valid_dict(
- remote_logging_view, remote_logging_view_fields()
- )
+ err_msg = gv.valid_dict(remote_logging_view,
+ remote_logging_view_fields())
if err_msg != "":
BuiltIn().fail(gp.sprint_error(err_msg))
@@ -615,9 +604,8 @@
else:
new_options = options
- command_string = gc.create_command_string(
- "network " + sub_command, new_options
- )
- return openbmctool_execute_command_json(
- command_string, print_output=False, ignore_err=False
- )
+ command_string = gc.create_command_string('network ' + sub_command,
+ new_options)
+ return openbmctool_execute_command_json(command_string,
+ print_output=False,
+ ignore_err=False)