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/conftest.py b/redfish-tests/conftest.py
index d5ed4ae..b0d5ad1 100644
--- a/redfish-tests/conftest.py
+++ b/redfish-tests/conftest.py
@@ -3,34 +3,35 @@
def pytest_addoption(parser):
- parser.addoption('--host_addr', action='store',
- default='https://localhost:4443')
- parser.addoption('--username', action='store', default='root')
- parser.addoption('--password', action='store', default='0penBmc')
- parser.addoption('--metric_limit', action='store', default=200)
+ parser.addoption(
+ "--host_addr", action="store", default="https://localhost:4443"
+ )
+ parser.addoption("--username", action="store", default="root")
+ parser.addoption("--password", action="store", default="0penBmc")
+ parser.addoption("--metric_limit", action="store", default=200)
-@pytest.fixture(scope='session')
+@pytest.fixture(scope="session")
def redfish(request):
- host_addr = request.config.getoption('--host_addr')
- username = request.config.getoption('--username')
- password = request.config.getoption('--password')
+ host_addr = request.config.getoption("--host_addr")
+ username = request.config.getoption("--username")
+ password = request.config.getoption("--password")
return redfish_requests.RedfishRequest(host_addr, username, password)
-@pytest.fixture(scope='session')
+@pytest.fixture(scope="session")
def telemetry(request, redfish):
- metric_limit = request.config.getoption('--metric_limit')
+ metric_limit = request.config.getoption("--metric_limit")
return redfish_requests.TelemetryService(redfish, metric_limit)
-@pytest.fixture(scope='function')
+@pytest.fixture(scope="function")
def report_definitions(redfish):
report_definitions = redfish_requests.ReportDef(redfish)
- print('Cleaning reports before test')
+ print("Cleaning reports before test")
for report in report_definitions.get_collection():
report_definitions.delete_report(report)
yield report_definitions
- print('Cleaning reports after test')
+ print("Cleaning reports after test")
for report in report_definitions.get_collection():
report_definitions.delete_report(report)
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)
diff --git a/redfish-tests/test_telemetry.py b/redfish-tests/test_telemetry.py
index 36eb770..921737b 100644
--- a/redfish-tests/test_telemetry.py
+++ b/redfish-tests/test_telemetry.py
@@ -261,7 +261,7 @@
@pytest.mark.parametrize(
- "invalid", ["50000", "P12ST", "PT12S12", "PPP" "PD222T222H222M222.222S"]
+ "invalid", ["50000", "P12ST", "PT12S12", "PPPPD222T222H222M222.222S"]
)
def test_add_report_with_invalid_duration_response_bad_request(
invalid, report_definitions