ironic-python-agent 11.2.0__py3-none-any.whl → 11.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ironic_python_agent/agent.py +69 -12
- ironic_python_agent/device_hints.py +53 -10
- ironic_python_agent/hardware.py +569 -242
- ironic_python_agent/raid_utils.py +10 -3
- ironic_python_agent/tests/unit/samples/hardware_samples.py +1 -1
- ironic_python_agent/tests/unit/test_agent.py +217 -10
- ironic_python_agent/tests/unit/test_device_hints.py +35 -3
- ironic_python_agent/tests/unit/test_hardware.py +1567 -120
- ironic_python_agent/tests/unit/test_raid_utils.py +7 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/AUTHORS +1 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/METADATA +2 -3
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/RECORD +17 -17
- ironic_python_agent-11.3.0.dist-info/pbr.json +1 -0
- ironic_python_agent-11.2.0.dist-info/pbr.json +0 -1
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/LICENSE +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/WHEEL +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/entry_points.txt +0 -0
- {ironic_python_agent-11.2.0.dist-info → ironic_python_agent-11.3.0.dist-info}/top_level.txt +0 -0
ironic_python_agent/agent.py
CHANGED
|
@@ -22,6 +22,8 @@ import threading
|
|
|
22
22
|
import time
|
|
23
23
|
from urllib import parse as urlparse
|
|
24
24
|
|
|
25
|
+
import requests
|
|
26
|
+
|
|
25
27
|
from oslo_concurrency import processutils
|
|
26
28
|
from oslo_config import cfg
|
|
27
29
|
from oslo_log import log
|
|
@@ -38,6 +40,7 @@ from ironic_python_agent import mdns
|
|
|
38
40
|
from ironic_python_agent import netutils
|
|
39
41
|
from ironic_python_agent import utils
|
|
40
42
|
|
|
43
|
+
CONF = cfg.CONF
|
|
41
44
|
LOG = log.getLogger(__name__)
|
|
42
45
|
|
|
43
46
|
# Time(in seconds) to wait for any of the interfaces to be up
|
|
@@ -174,7 +177,10 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|
|
174
177
|
"""Stop the heartbeat thread."""
|
|
175
178
|
LOG.info('stopping heartbeater')
|
|
176
179
|
self.stop_event.set()
|
|
177
|
-
|
|
180
|
+
# Only join if the thread was actually started
|
|
181
|
+
if self.is_alive():
|
|
182
|
+
return self.join()
|
|
183
|
+
return None
|
|
178
184
|
|
|
179
185
|
|
|
180
186
|
class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
@@ -302,19 +308,59 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
302
308
|
|
|
303
309
|
return source
|
|
304
310
|
|
|
311
|
+
def _test_ip_reachability(self, api_url):
|
|
312
|
+
"""Test if an API URL is reachable via HTTP GET request.
|
|
313
|
+
|
|
314
|
+
:param api_url: The full API URL to test (including protocol and port)
|
|
315
|
+
:returns: True if the URL is reachable, False otherwise
|
|
316
|
+
"""
|
|
317
|
+
try:
|
|
318
|
+
# Disable SSL verification for reachability testing only
|
|
319
|
+
response = requests.get(
|
|
320
|
+
api_url, timeout=CONF.http_request_timeout, verify=False
|
|
321
|
+
) # nosec
|
|
322
|
+
# Any HTTP response (even 404, 500, etc.) indicates reachability
|
|
323
|
+
LOG.debug('API URL %s is reachable (status: %s)',
|
|
324
|
+
api_url, response.status_code)
|
|
325
|
+
return True
|
|
326
|
+
except requests.exceptions.RequestException as e:
|
|
327
|
+
LOG.debug('API URL %s not reachable: %s', api_url, e)
|
|
328
|
+
return False
|
|
329
|
+
|
|
305
330
|
def _find_routable_addr(self):
|
|
331
|
+
# Process API URLs: check reachability and collect IPs in one pass
|
|
332
|
+
reachable_api_urls = []
|
|
306
333
|
ips = set()
|
|
334
|
+
|
|
307
335
|
for api_url in self.api_urls:
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
try:
|
|
311
|
-
addrs = socket.getaddrinfo(ironic_host, 0)
|
|
312
|
-
except socket.gaierror:
|
|
313
|
-
LOG.debug('Could not resolve %s, maybe no DNS', ironic_host)
|
|
314
|
-
ips.add(ironic_host)
|
|
315
|
-
continue
|
|
316
|
-
ips.update(addr for _, _, _, _, (addr, *_) in addrs)
|
|
336
|
+
parsed = urlparse.urlparse(api_url)
|
|
337
|
+
ironic_host = parsed.hostname
|
|
317
338
|
|
|
339
|
+
# Test reachability using the full URL (including port)
|
|
340
|
+
if self._test_ip_reachability(api_url):
|
|
341
|
+
reachable_api_urls.append(api_url)
|
|
342
|
+
LOG.debug('API URL %s is reachable', api_url)
|
|
343
|
+
|
|
344
|
+
# Collect IPs for reachable hosts
|
|
345
|
+
try:
|
|
346
|
+
addrs = socket.getaddrinfo(ironic_host, 0)
|
|
347
|
+
ips.update(addr for _, _, _, _, (addr, *_) in addrs)
|
|
348
|
+
except socket.gaierror:
|
|
349
|
+
LOG.debug('Could not resolve %s, maybe no DNS',
|
|
350
|
+
ironic_host)
|
|
351
|
+
ips.add(ironic_host)
|
|
352
|
+
else:
|
|
353
|
+
LOG.debug('API URL %s is not reachable, skipping', api_url)
|
|
354
|
+
|
|
355
|
+
# Update api_urls configuration to only include reachable endpoints
|
|
356
|
+
if reachable_api_urls:
|
|
357
|
+
LOG.info('Filtered API URLs from %d to %d reachable endpoints',
|
|
358
|
+
len(self.api_urls), len(reachable_api_urls))
|
|
359
|
+
self.api_urls = reachable_api_urls
|
|
360
|
+
else:
|
|
361
|
+
LOG.warning('No reachable Ironic API URLs found, keeping all URLs')
|
|
362
|
+
|
|
363
|
+
# Find routable address using collected IPs
|
|
318
364
|
for attempt in range(self.ip_lookup_attempts):
|
|
319
365
|
for ironic_host in ips:
|
|
320
366
|
found_ip = self._get_route_source(ironic_host)
|
|
@@ -448,6 +494,15 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
448
494
|
self.node = content['node']
|
|
449
495
|
LOG.info('Lookup succeeded, node UUID is %s',
|
|
450
496
|
self.node['uuid'])
|
|
497
|
+
|
|
498
|
+
# Store skip_bmc_detect flag in the node before caching
|
|
499
|
+
# This allows hardware managers to check if BMC detection is needed
|
|
500
|
+
skip_bmc = content.get('config', {}).get('agent_skip_bmc_detect',
|
|
501
|
+
False)
|
|
502
|
+
if skip_bmc:
|
|
503
|
+
LOG.info('Ironic has indicated BMC detection should be skipped')
|
|
504
|
+
self.node['skip_bmc_detect'] = True
|
|
505
|
+
|
|
451
506
|
hardware.cache_node(self.node)
|
|
452
507
|
self.heartbeat_timeout = content['config']['heartbeat_timeout']
|
|
453
508
|
|
|
@@ -569,13 +624,15 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
569
624
|
# rescue operations.
|
|
570
625
|
LOG.info('Found rescue state marker file, locking down IPA '
|
|
571
626
|
'in disabled mode')
|
|
572
|
-
self.heartbeater.
|
|
627
|
+
if hasattr(self, 'heartbeater') and self.heartbeater.is_alive():
|
|
628
|
+
self.heartbeater.stop()
|
|
573
629
|
self.serve_api = False
|
|
574
630
|
while True:
|
|
575
631
|
time.sleep(100)
|
|
576
632
|
|
|
577
633
|
if not self.standalone and self.api_urls:
|
|
578
|
-
self.heartbeater.
|
|
634
|
+
if hasattr(self, 'heartbeater') and self.heartbeater.is_alive():
|
|
635
|
+
self.heartbeater.stop()
|
|
579
636
|
|
|
580
637
|
if self.lockdown:
|
|
581
638
|
self._lockdown_system()
|
|
@@ -191,11 +191,12 @@ def find_devices_by_hints(devices, root_device_hints):
|
|
|
191
191
|
:size: (Integer) Size of the device in *bytes*
|
|
192
192
|
:model: (String) Device model
|
|
193
193
|
:vendor: (String) Device vendor name
|
|
194
|
-
:serial: (String) Device serial number
|
|
195
|
-
:wwn: (String) Unique storage identifier
|
|
196
|
-
:wwn_with_extension: (String): Unique storage
|
|
197
|
-
the vendor extension appended
|
|
198
|
-
:wwn_vendor_extension: (String): United vendor
|
|
194
|
+
:serial: (String or List[String]) Device serial number(s)
|
|
195
|
+
:wwn: (String or List[String]) Unique storage identifier(s)
|
|
196
|
+
:wwn_with_extension: (String or List[String]): Unique storage
|
|
197
|
+
identifier(s) with the vendor extension appended
|
|
198
|
+
:wwn_vendor_extension: (String or List[String]): United vendor
|
|
199
|
+
storage identifier(s)
|
|
199
200
|
:rotational: (Boolean) Whether it's a rotational device or
|
|
200
201
|
not. Useful to distinguish HDDs (rotational) and SSDs
|
|
201
202
|
(not rotational).
|
|
@@ -221,6 +222,47 @@ def find_devices_by_hints(devices, root_device_hints):
|
|
|
221
222
|
device_value = dev.get(hint)
|
|
222
223
|
hint_value = parsed_hints[hint]
|
|
223
224
|
|
|
225
|
+
# Handle device attributes that are a list of strings
|
|
226
|
+
# (serial, wwn, wwn_with_extension, and wwn_vendor_extension).
|
|
227
|
+
if hint_type is str and isinstance(device_value, list):
|
|
228
|
+
# NOTE(mostepha): Device value is a list. Consider it matched
|
|
229
|
+
# if any value in the list matches the hint.
|
|
230
|
+
device_values = [v for v in device_value if v is not None]
|
|
231
|
+
if not device_values:
|
|
232
|
+
LOG.warning(
|
|
233
|
+
'The attribute "%(attr)s" of the device "%(dev)s" '
|
|
234
|
+
'has an empty value. Skipping device.',
|
|
235
|
+
{'attr': hint, 'dev': device_name})
|
|
236
|
+
break
|
|
237
|
+
|
|
238
|
+
matched = False
|
|
239
|
+
for val in device_values:
|
|
240
|
+
try:
|
|
241
|
+
normalized_val = _normalize_hint_expression(val, hint)
|
|
242
|
+
if specs_matcher.match(normalized_val, hint_value):
|
|
243
|
+
LOG.info('The attribute "%(attr)s" of device '
|
|
244
|
+
'"%(dev)s" matched hint %(hint)s with '
|
|
245
|
+
'value "%(value)s"',
|
|
246
|
+
{'attr': hint, 'dev': device_name,
|
|
247
|
+
'hint': hint_value, 'value': val})
|
|
248
|
+
matched = True
|
|
249
|
+
break
|
|
250
|
+
except ValueError:
|
|
251
|
+
# Skip invalid/empty values in the list
|
|
252
|
+
continue
|
|
253
|
+
|
|
254
|
+
# Continue to next hint if any value matched. Otherwise, break
|
|
255
|
+
# and try the next device.
|
|
256
|
+
if matched:
|
|
257
|
+
continue
|
|
258
|
+
else:
|
|
259
|
+
LOG.info('None of the values %(values)s for attribute '
|
|
260
|
+
'"%(attr)s" of device "%(dev)s" match the hint '
|
|
261
|
+
'%(hint)s',
|
|
262
|
+
{'values': device_values, 'attr': hint,
|
|
263
|
+
'dev': device_name, 'hint': hint_value})
|
|
264
|
+
break
|
|
265
|
+
|
|
224
266
|
if hint_type is str:
|
|
225
267
|
try:
|
|
226
268
|
device_value = _normalize_hint_expression(device_value,
|
|
@@ -286,11 +328,12 @@ def match_root_device_hints(devices, root_device_hints):
|
|
|
286
328
|
:size: (Integer) Size of the device in *bytes*
|
|
287
329
|
:model: (String) Device model
|
|
288
330
|
:vendor: (String) Device vendor name
|
|
289
|
-
:serial: (String) Device serial number
|
|
290
|
-
:wwn: (String) Unique storage identifier
|
|
291
|
-
:wwn_with_extension: (String): Unique storage
|
|
292
|
-
the vendor extension appended
|
|
293
|
-
:wwn_vendor_extension: (String): United vendor
|
|
331
|
+
:serial: (String or List[String]) Device serial number(s)
|
|
332
|
+
:wwn: (String or List[String]) Unique storage identifier(s)
|
|
333
|
+
:wwn_with_extension: (String or List[String]): Unique storage
|
|
334
|
+
identifier(s) with the vendor extension appended
|
|
335
|
+
:wwn_vendor_extension: (String or List[String]): United vendor
|
|
336
|
+
storage identifier(s)
|
|
294
337
|
:rotational: (Boolean) Whether it's a rotational device or
|
|
295
338
|
not. Useful to distinguish HDDs (rotational) and SSDs
|
|
296
339
|
(not rotational).
|