Skip to content
This repository was archived by the owner on Jul 21, 2026. It is now read-only.

Commit 3a3c87a

Browse files
committed
Reformat and fix linting errors
Correct all the errors reported by pre-commit.
1 parent afcea88 commit 3a3c87a

38 files changed

Lines changed: 3010 additions & 2676 deletions

conftest.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,24 +4,27 @@
44

55

66
def pytest_addoption(parser):
7-
parser.addoption('--run-slow',
8-
action='store_true',
9-
default=False,
10-
help='run tests marked as slow')
7+
parser.addoption(
8+
"--run-slow",
9+
action="store_true",
10+
default=False,
11+
help="run tests marked as slow",
12+
)
1113

1214

1315
def pytest_configure(config):
14-
slow_info = 'slow: mark test as slow to run'
15-
neg_info = 'negative: marks tests that test invalid input'
16-
config.addinivalue_line('markers', slow_info)
17-
config.addinivalue_line('markers', neg_info)
16+
slow_info = "slow: mark test as slow to run"
17+
neg_info = "negative: marks tests that test invalid input"
18+
config.addinivalue_line("markers", slow_info)
19+
config.addinivalue_line("markers", neg_info)
1820

1921

2022
def pytest_collection_modifyitems(config, items):
21-
if config.getoption('--run-slow'):
23+
if config.getoption("--run-slow"):
2224
return
23-
skipped = pytest.mark.skip(reason='slow tests are skipped by default; '
24-
'to run, call pytest with --run-slow.')
25+
skipped = pytest.mark.skip(
26+
reason="slow tests are skipped by default; to run, call pytest with --run-slow."
27+
)
2528
for item in items:
26-
if 'slow' in item.keywords:
29+
if "slow" in item.keywords:
2730
item.add_marker(skipped)

esileapclient/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
# Licensed under the Apache License, Version 2.0 (the "License"); you may
32
# not use this file except in compliance with the License. You may obtain
43
# a copy of the License at
@@ -14,4 +13,4 @@
1413
import pbr.version
1514

1615

17-
__version__ = pbr.version.VersionInfo('python-esileapclient').version_string()
16+
__version__ = pbr.version.VersionInfo("python-esileapclient").version_string()

esileapclient/common/base.py

Lines changed: 53 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,12 @@ class Manager(object):
3232
@property
3333
@abc.abstractmethod
3434
def resource_class(self):
35-
"""The resource class
36-
"""
35+
"""The resource class"""
3736

3837
@property
3938
@abc.abstractmethod
4039
def _resource_name(self):
41-
"""The resource name.
42-
"""
40+
"""The resource name."""
4341

4442
def __init__(self, api):
4543
self.api = api
@@ -50,17 +48,20 @@ def _path(self, resource_id=None):
5048
path.
5149
"""
5250

53-
return ('/v1/%s/%s' % (self._resource_name, resource_id)
54-
if resource_id else '/v1/%s' % self._resource_name)
51+
return (
52+
"/v1/%s/%s" % (self._resource_name, resource_id)
53+
if resource_id
54+
else "/v1/%s" % self._resource_name
55+
)
5556

5657
@staticmethod
5758
def _url_variables(variables):
5859
"""Returns a url with variables set"""
5960

60-
url_variables = '?'
61+
url_variables = "?"
6162
for k, v in variables.items():
6263
if v is not None:
63-
url_variables += k + '=' + v + '&'
64+
url_variables += k + "=" + v + "&"
6465
return url_variables[:-1]
6566

6667
def _create(self, os_esileap_api_version=None, **kwargs):
@@ -71,30 +72,32 @@ def _create(self, os_esileap_api_version=None, **kwargs):
7172

7273
new = {}
7374
invalid = []
74-
for (key, value) in kwargs.items():
75+
for key, value in kwargs.items():
7576
if key in self.resource_class._creation_attributes:
7677
new[key] = value
7778
else:
7879
invalid.append(key)
7980
if invalid:
80-
raise Exception('The attribute(s) "%(attrs)s" '
81-
'are invalid; they are not '
82-
'needed to create %(resource)s.' %
83-
{'resource': self._resource_name,
84-
'attrs': '","'.join(invalid)})
81+
raise Exception(
82+
'The attribute(s) "%(attrs)s" '
83+
"are invalid; they are not "
84+
"needed to create %(resource)s."
85+
% {"resource": self._resource_name, "attrs": '","'.join(invalid)}
86+
)
8587

8688
headers = {}
8789
if os_esileap_api_version is not None:
88-
headers['headers'] = {'X-OpenStack-ESI-Leap-API-Version':
89-
os_esileap_api_version}
90+
headers["headers"] = {
91+
"X-OpenStack-ESI-Leap-API-Version": os_esileap_api_version
92+
}
9093

9194
url = self._path()
92-
resp, body = self.api.json_request('POST', url, body=new, **headers)
95+
resp, body = self.api.json_request("POST", url, body=new, **headers)
9396

9497
if resp.status_code == 201:
9598
return self.resource_class(self, body)
9699
else:
97-
raise exceptions.CommandError(json.loads(resp.text)['faultstring'])
100+
raise exceptions.CommandError(json.loads(resp.text)["faultstring"])
98101

99102
def _update(self, resource_id, os_esileap_api_version=None, **kwargs):
100103
"""Update a resource based on a kwargs dictionary of attributes.
@@ -104,30 +107,32 @@ def _update(self, resource_id, os_esileap_api_version=None, **kwargs):
104107

105108
new = {}
106109
invalid = []
107-
for (key, value) in kwargs.items():
110+
for key, value in kwargs.items():
108111
if key in self.resource_class._update_attributes:
109112
new[key] = value
110113
else:
111114
invalid.append(key)
112115
if invalid:
113-
raise Exception('The attribute(s) "%(attrs)s" '
114-
'are invalid; they are not '
115-
'needed to update %(resource)s.' %
116-
{'resource': self._resource_name,
117-
'attrs': '","'.join(invalid)})
116+
raise Exception(
117+
'The attribute(s) "%(attrs)s" '
118+
"are invalid; they are not "
119+
"needed to update %(resource)s."
120+
% {"resource": self._resource_name, "attrs": '","'.join(invalid)}
121+
)
118122

119123
headers = {}
120124
if os_esileap_api_version is not None:
121-
headers['headers'] = {'X-OpenStack-ESI-Leap-API-Version':
122-
os_esileap_api_version}
125+
headers["headers"] = {
126+
"X-OpenStack-ESI-Leap-API-Version": os_esileap_api_version
127+
}
123128

124129
url = self._path(resource_id)
125-
resp, body = self.api.json_request('PATCH', url, body=new, **headers)
130+
resp, body = self.api.json_request("PATCH", url, body=new, **headers)
126131

127132
if resp.status_code == 200:
128133
return self.resource_class(self, body)
129134
else:
130-
raise exceptions.CommandError(json.loads(resp.text)['faultstring'])
135+
raise exceptions.CommandError(json.loads(resp.text)["faultstring"])
131136

132137
def _list(self, url, obj_class=None, os_esileap_api_version=None):
133138
if obj_class is None:
@@ -136,17 +141,18 @@ def _list(self, url, obj_class=None, os_esileap_api_version=None):
136141
kwargs = {}
137142

138143
if os_esileap_api_version is not None:
139-
kwargs['headers'] = {'X-OpenStack-ESI-Leap-API-Version':
140-
os_esileap_api_version}
144+
kwargs["headers"] = {
145+
"X-OpenStack-ESI-Leap-API-Version": os_esileap_api_version
146+
}
141147

142-
resp, body = self.api.json_request('GET', url, **kwargs)
148+
resp, body = self.api.json_request("GET", url, **kwargs)
143149

144150
if resp.status_code == 200:
145151
body = body[self._resource_name]
146152

147153
return [obj_class(self, res) for res in body if res]
148154
else:
149-
raise exceptions.CommandError(json.loads(resp.text)['faultstring'])
155+
raise exceptions.CommandError(json.loads(resp.text)["faultstring"])
150156

151157
def _get(self, resource_id, obj_class=None, os_esileap_api_version=None):
152158
"""Retrieve a resource.
@@ -162,16 +168,17 @@ def _get(self, resource_id, obj_class=None, os_esileap_api_version=None):
162168
kwargs = {}
163169

164170
if os_esileap_api_version is not None:
165-
kwargs['headers'] = {'X-OpenStack-ESI-Leap-API-Version':
166-
os_esileap_api_version}
171+
kwargs["headers"] = {
172+
"X-OpenStack-ESI-Leap-API-Version": os_esileap_api_version
173+
}
167174

168-
resp, body = self.api.json_request('GET', url, **kwargs)
175+
resp, body = self.api.json_request("GET", url, **kwargs)
169176

170177
if resp.status_code == 200:
171178
return obj_class(self, body)
172179

173180
else:
174-
raise exceptions.CommandError(json.loads(resp.text)['faultstring'])
181+
raise exceptions.CommandError(json.loads(resp.text)["faultstring"])
175182

176183
def _delete(self, resource_id, os_esileap_api_version=None):
177184
"""Delete a resource.
@@ -184,13 +191,14 @@ def _delete(self, resource_id, os_esileap_api_version=None):
184191
kwargs = {}
185192

186193
if os_esileap_api_version is not None:
187-
kwargs['headers'] = {'X-OpenStack-ESI-Leap-API-Version':
188-
os_esileap_api_version}
194+
kwargs["headers"] = {
195+
"X-OpenStack-ESI-Leap-API-Version": os_esileap_api_version
196+
}
189197

190-
resp, _ = self.api.json_request('DELETE', url, **kwargs)
198+
resp, _ = self.api.json_request("DELETE", url, **kwargs)
191199

192200
if resp.status_code != 200:
193-
raise exceptions.CommandError(json.loads(resp.text)['faultstring'])
201+
raise exceptions.CommandError(json.loads(resp.text)["faultstring"])
194202

195203

196204
@six.add_metaclass(abc.ABCMeta)
@@ -214,8 +222,7 @@ def detailed_fields(self):
214222
@property
215223
@abc.abstractmethod
216224
def _creation_attributes(self):
217-
"""A list of required creation attributes for a resource type.
218-
"""
225+
"""A list of required creation attributes for a resource type."""
219226

220227
def __init__(self, manager, info):
221228
"""Populate and bind to a manager.
@@ -224,12 +231,13 @@ def __init__(self, manager, info):
224231
"""
225232

226233
self.manager = manager
227-
self._info = {k: v for (k, v) in info.items() if k
228-
in self.detailed_fields.keys()}
234+
self._info = {
235+
k: v for (k, v) in info.items() if k in self.detailed_fields.keys()
236+
}
229237
self._add_details(self._info)
230238

231239
def _add_details(self, info):
232-
for (k, v) in info.items():
240+
for k, v in info.items():
233241
try:
234242
setattr(self, k, v)
235243
except AttributeError:

esileapclient/common/utils.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
# Define constants for operator pattern and filter pattern
1010
OPS = {
11-
'>=': operator.ge,
12-
'<=': operator.le,
13-
'>': operator.gt,
14-
'<': operator.lt,
15-
'=': operator.eq,
11+
">=": operator.ge,
12+
"<=": operator.le,
13+
">": operator.gt,
14+
"<": operator.lt,
15+
"=": operator.eq,
1616
}
1717

18-
OPERATOR_PATTERN = '|'.join(re.escape(op) for op in OPS.keys())
19-
FILTER_PATTERN = re.compile(rf'([^><=]+)({OPERATOR_PATTERN})(.+)')
18+
OPERATOR_PATTERN = "|".join(re.escape(op) for op in OPS.keys())
19+
FILTER_PATTERN = re.compile(rf"([^><=]+)({OPERATOR_PATTERN})(.+)")
2020

2121

2222
def convert_value(value_str):
@@ -44,11 +44,11 @@ def parse_property_filter(filter_str):
4444

4545
def node_matches_property_filters(node, property_filters):
4646
"""Check if a node matches all property filters."""
47-
properties = node.get('resource_properties', node.get('properties', {}))
47+
properties = node.get("resource_properties", node.get("properties", {}))
4848
for key, op, value in property_filters:
4949
if key not in properties:
5050
return False
51-
node_value = convert_value(properties.get(key, ''))
51+
node_value = convert_value(properties.get(key, ""))
5252
if not op(node_value, value):
5353
return False
5454
return True
@@ -67,8 +67,7 @@ def filter_nodes_by_properties(nodes, properties):
6767
raise
6868

6969
filtered_nodes = [
70-
node for node in nodes
71-
if node_matches_property_filters(node, property_filters)
70+
node for node in nodes if node_matches_property_filters(node, property_filters)
7271
]
7372

7473
return filtered_nodes

esileapclient/osc/plugin.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,18 @@
1515
from openstackclient.i18n import _
1616

1717

18-
DEFAULT_API_VERSION = '1'
18+
DEFAULT_API_VERSION = "1"
1919

2020
# Required by the OSC plugin interface
21-
API_NAME = 'lease'
22-
API_VERSION_OPTION = 'os_esileap_api_version'
21+
API_NAME = "lease"
22+
API_VERSION_OPTION = "os_esileap_api_version"
2323
API_VERSIONS = {
24-
'1': 'esi.connection.ESIConnection',
24+
"1": "esi.connection.ESIConnection",
2525
}
2626

2727
OS_LEASE_API_LATEST = True
28-
LAST_KNOWN_API_VERSION = '1'
29-
LATEST_VERSION = '1'
28+
LAST_KNOWN_API_VERSION = "1"
29+
LATEST_VERSION = "1"
3030

3131

3232
LOG = logging.getLogger(__name__)
@@ -44,7 +44,6 @@ def make_client(instance):
4444

4545

4646
def build_option_parser(parser):
47-
4847
"""Hook to add global options
4948
5049
Called from openstackclient.shell.OpenStackShell.__init__()
@@ -55,11 +54,10 @@ def build_option_parser(parser):
5554
initialized by OpenStackShell.
5655
"""
5756
parser.add_argument(
58-
'--os-esileap-api-version',
59-
metavar='<os_esileap_api_version>',
57+
"--os-esileap-api-version",
58+
metavar="<os_esileap_api_version>",
6059
default=DEFAULT_API_VERSION,
61-
help=_('ESI-LEAP API version, default=%s')
62-
% DEFAULT_API_VERSION,
60+
help=_("ESI-LEAP API version, default=%s") % DEFAULT_API_VERSION,
6361
)
6462

6563
return parser

0 commit comments

Comments
 (0)