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.
Change-Id: I66c89f20acb2c266c15ad9987b5c2b7548f976bd
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
diff --git a/redfish-tests/redfish_requests.py b/redfish-tests/redfish_requests.py
index 28dee84..19c22e0 100644
--- a/redfish-tests/redfish_requests.py
+++ b/redfish-tests/redfish_requests.py
@@ -1,6 +1,7 @@
import enum
import math
import re
+
import requests
@@ -14,11 +15,12 @@
class RedfishRequest:
- telemetry_service_path = '/redfish/v1/TelemetryService'
- metric_definition_path = f'{telemetry_service_path}/MetricDefinitions'
- metric_report_definition_path = \
- f'{telemetry_service_path}/MetricReportDefinitions'
- metric_report_path = f'{telemetry_service_path}/MetricReports'
+ telemetry_service_path = "/redfish/v1/TelemetryService"
+ metric_definition_path = f"{telemetry_service_path}/MetricDefinitions"
+ metric_report_definition_path = (
+ f"{telemetry_service_path}/MetricReportDefinitions"
+ )
+ metric_report_path = f"{telemetry_service_path}/MetricReports"
def __init__(self, host_addr, username, password):
self.host_addr = host_addr
@@ -28,39 +30,44 @@
def get(self, path, code=RedfishHttpStatus.ok):
u = self.host_addr + path
r = requests.get(u, auth=(self.username, self.password), verify=False)
- assert r.status_code == code, \
- f'{r.status_code} == {code} on path {u}\n{r.text}'
+ assert (
+ r.status_code == code
+ ), f"{r.status_code} == {code} on path {u}\n{r.text}"
print(r.text)
return r.json()
def post(self, path, body, code=RedfishHttpStatus.created):
u = self.host_addr + path
- r = requests.post(u, auth=(self.username, self.password), verify=False,
- json=body)
- assert r.status_code == code, \
- f'{r.status_code} == {code} on path {u}\n{r.text}'
+ r = requests.post(
+ u, auth=(self.username, self.password), verify=False, json=body
+ )
+ assert (
+ r.status_code == code
+ ), f"{r.status_code} == {code} on path {u}\n{r.text}"
print(r.text)
return r.json()
def delete(self, path, code=RedfishHttpStatus.no_content):
u = self.host_addr + path
- r = requests.delete(u, auth=(self.username, self.password),
- verify=False)
- assert r.status_code == code, \
- f'{r.status_code} == {code} on path {u}\n{r.text}'
+ r = requests.delete(
+ u, auth=(self.username, self.password), verify=False
+ )
+ assert (
+ r.status_code == code
+ ), f"{r.status_code} == {code} on path {u}\n{r.text}"
class TelemetryService:
def __init__(self, redfish, metric_limit):
r = redfish.get(redfish.telemetry_service_path)
- self.min_interval = Duration.to_seconds(r['MinCollectionInterval'])
- self.max_reports = r['MaxReports']
+ self.min_interval = Duration.to_seconds(r["MinCollectionInterval"])
+ self.max_reports = r["MaxReports"]
self.metrics = []
r = redfish.get(redfish.metric_definition_path)
- for m in r['Members']:
- path = m['@odata.id']
+ for m in r["Members"]:
+ path = m["@odata.id"]
metricDef = redfish.get(path)
- self.metrics += [x for x in metricDef['MetricProperties']]
+ self.metrics += [x for x in metricDef["MetricProperties"]]
self.metrics = self.metrics[:metric_limit]
@@ -70,27 +77,35 @@
def get_collection(self):
r = self.redfish.get(self.redfish.metric_report_definition_path)
- return [x['@odata.id'] for x in r['Members']]
+ return [x["@odata.id"] for x in r["Members"]]
- def add_report(self, id, metrics=None, type='OnRequest', actions=None,
- interval=None, code=RedfishHttpStatus.created):
+ def add_report(
+ self,
+ id,
+ metrics=None,
+ type="OnRequest",
+ actions=None,
+ interval=None,
+ code=RedfishHttpStatus.created,
+ ):
body = {
- 'Id': id,
- 'Metrics': [],
- 'MetricReportDefinitionType': type,
- 'ReportActions': ['RedfishEvent', 'LogToMetricReportsCollection']
+ "Id": id,
+ "Metrics": [],
+ "MetricReportDefinitionType": type,
+ "ReportActions": ["RedfishEvent", "LogToMetricReportsCollection"],
}
if metrics is not None:
- body['Metrics'] = metrics
+ body["Metrics"] = metrics
if actions is not None:
- body['ReportActions'] = actions
+ body["ReportActions"] = actions
if interval is not None:
- body['Schedule'] = {'RecurrenceInterval': interval}
- return self.redfish.post(self.redfish.metric_report_definition_path,
- body, code)
+ body["Schedule"] = {"RecurrenceInterval": interval}
+ return self.redfish.post(
+ self.redfish.metric_report_definition_path, body, code
+ )
def delete_report(self, path):
- self.redfish.delete(f'{path}')
+ self.redfish.delete(f"{path}")
class Duration:
@@ -98,19 +113,20 @@
pass
def to_iso8061(time):
- assert time >= 0, 'Invalid argument, time is negative'
+ assert time >= 0, "Invalid argument, time is negative"
days = int(time / (24 * 60 * 60))
time = math.fmod(time, (24 * 60 * 60))
hours = int(time / (60 * 60))
time = math.fmod(time, (60 * 60))
minutes = int(time / 60)
time = round(math.fmod(time, 60), 3)
- return f'P{str(days)}DT{str(hours)}H{str(minutes)}M{str(time)}S'
+ return f"P{str(days)}DT{str(hours)}H{str(minutes)}M{str(time)}S"
def to_seconds(duration):
- r = re.fullmatch(r'-?P(\d+D)?(T(\d+H)?(\d+M)?(\d+(.\d+)?S)?)?',
- duration)
- assert r, 'Invalid argument, not match with regex'
+ r = re.fullmatch(
+ r"-?P(\d+D)?(T(\d+H)?(\d+M)?(\d+(.\d+)?S)?)?", duration
+ )
+ assert r, "Invalid argument, not match with regex"
days = r.group(1)
hours = r.group(3)
minutes = r.group(4)