ironic-python-agent 10.2.0__py3-none-any.whl → 11.0.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/__init__.py +0 -19
- ironic_python_agent/agent.py +15 -12
- ironic_python_agent/api/app.py +35 -17
- ironic_python_agent/config.py +31 -7
- ironic_python_agent/errors.py +9 -0
- ironic_python_agent/hardware.py +7 -0
- ironic_python_agent/hardware_managers/container.py +152 -0
- ironic_python_agent/netutils.py +41 -2
- ironic_python_agent/tests/unit/extensions/test_poll.py +2 -4
- ironic_python_agent/tests/unit/hardware_managers/test_container.py +115 -0
- ironic_python_agent/tests/unit/metrics_lib/__init__.py +0 -0
- ironic_python_agent/tests/unit/test_agent.py +99 -172
- ironic_python_agent/tests/unit/test_hardware.py +68 -12
- ironic_python_agent/tests/unit/test_inspector.py +7 -3
- ironic_python_agent/utils.py +1 -1
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/AUTHORS +4 -0
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/METADATA +7 -7
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/RECORD +23 -20
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/entry_points.txt +1 -0
- ironic_python_agent-11.0.0.dist-info/pbr.json +1 -0
- ironic_python_agent-10.2.0.dist-info/pbr.json +0 -1
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/LICENSE +0 -0
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/WHEEL +0 -0
- {ironic_python_agent-10.2.0.dist-info → ironic_python_agent-11.0.0.dist-info}/top_level.txt +0 -0
ironic_python_agent/__init__.py
CHANGED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
2
|
-
# you may not use this file except in compliance with the License.
|
|
3
|
-
# You may obtain a copy of the License at
|
|
4
|
-
#
|
|
5
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
#
|
|
7
|
-
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
-
# See the License for the specific language governing permissions and
|
|
11
|
-
# limitations under the License.
|
|
12
|
-
|
|
13
|
-
import eventlet
|
|
14
|
-
|
|
15
|
-
# NOTE(JayF) Without monkey_patching socket, API requests will hang with TLS
|
|
16
|
-
# enabled. Enabling more than just socket for monkey patching causes failures
|
|
17
|
-
# in image streaming. In an ideal world, we track down all those errors and
|
|
18
|
-
# monkey patch everything as suggested in eventlet documentation.
|
|
19
|
-
eventlet.monkey_patch(all=False, socket=True)
|
ironic_python_agent/agent.py
CHANGED
|
@@ -22,7 +22,6 @@ import threading
|
|
|
22
22
|
import time
|
|
23
23
|
from urllib import parse as urlparse
|
|
24
24
|
|
|
25
|
-
import eventlet
|
|
26
25
|
from oslo_concurrency import processutils
|
|
27
26
|
from oslo_config import cfg
|
|
28
27
|
from oslo_log import log
|
|
@@ -106,7 +105,7 @@ class IronicPythonAgentHeartbeater(threading.Thread):
|
|
|
106
105
|
self.agent.set_agent_advertise_addr()
|
|
107
106
|
|
|
108
107
|
while self._run_next():
|
|
109
|
-
|
|
108
|
+
time.sleep(0.1)
|
|
110
109
|
|
|
111
110
|
def _run_next(self):
|
|
112
111
|
# The logic here makes sure we don't wait exactly 5 seconds more or
|
|
@@ -253,7 +252,6 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
253
252
|
# Allows this to be turned on by the conductor while running,
|
|
254
253
|
# in the event of long running ramdisks where the conductor
|
|
255
254
|
# got upgraded somewhere along the way.
|
|
256
|
-
self.agent_token_required = cfg.CONF.agent_token_required
|
|
257
255
|
self.generated_cert = None
|
|
258
256
|
|
|
259
257
|
def get_status(self):
|
|
@@ -439,7 +437,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
439
437
|
self.heartbeater.start()
|
|
440
438
|
try:
|
|
441
439
|
while self.serve_api:
|
|
442
|
-
|
|
440
|
+
time.sleep(0.1)
|
|
443
441
|
except KeyboardInterrupt:
|
|
444
442
|
LOG.info('Caught keyboard interrupt, exiting')
|
|
445
443
|
self.api.stop()
|
|
@@ -455,6 +453,9 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
455
453
|
|
|
456
454
|
# Update config with values from Ironic
|
|
457
455
|
config = content.get('config', {})
|
|
456
|
+
if config.get('agent_containers'):
|
|
457
|
+
for opt, val in config['agent_containers'].items():
|
|
458
|
+
cfg.CONF.set_override(opt, val, group='container')
|
|
458
459
|
if config.get('metrics'):
|
|
459
460
|
for opt, val in config.items():
|
|
460
461
|
setattr(cfg.CONF.metrics, opt, val)
|
|
@@ -470,8 +471,6 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
470
471
|
md5_allowed = config.get('agent_md5_checksum_enable')
|
|
471
472
|
if md5_allowed is not None:
|
|
472
473
|
cfg.CONF.set_override('md5_enabled', md5_allowed)
|
|
473
|
-
if config.get('agent_token_required'):
|
|
474
|
-
self.agent_token_required = True
|
|
475
474
|
token = config.get('agent_token')
|
|
476
475
|
if token:
|
|
477
476
|
if len(token) >= 32:
|
|
@@ -487,11 +486,15 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
487
486
|
'intended and the deployment may fail '
|
|
488
487
|
'depending on settings in the ironic '
|
|
489
488
|
'deployment.')
|
|
490
|
-
if not self.agent_token
|
|
491
|
-
LOG.error('
|
|
492
|
-
'
|
|
493
|
-
'
|
|
494
|
-
'
|
|
489
|
+
if not self.agent_token:
|
|
490
|
+
LOG.error('We do not have a token on file '
|
|
491
|
+
'from the Ironic deployment, and '
|
|
492
|
+
'one should be on file. '
|
|
493
|
+
'Possible external agent restart '
|
|
494
|
+
'outside of Ironic\'s process. '
|
|
495
|
+
'This is **FATAL**.')
|
|
496
|
+
self.serve_api = False
|
|
497
|
+
self.lockdown = True
|
|
495
498
|
else:
|
|
496
499
|
LOG.info('An invalid token was received.')
|
|
497
500
|
if self.agent_token and not self.standalone:
|
|
@@ -558,7 +561,7 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
558
561
|
'found, please check your pxe append parameters.')
|
|
559
562
|
|
|
560
563
|
in_rescued_mode = os.path.exists('/etc/.rescued')
|
|
561
|
-
if not in_rescued_mode:
|
|
564
|
+
if not in_rescued_mode and self.serve_api:
|
|
562
565
|
self.serve_ipa_api()
|
|
563
566
|
else:
|
|
564
567
|
# NOTE(cid): In rescued state, we don't call _lockdown_system() as
|
ironic_python_agent/api/app.py
CHANGED
|
@@ -13,9 +13,11 @@
|
|
|
13
13
|
# limitations under the License.
|
|
14
14
|
|
|
15
15
|
import json
|
|
16
|
+
import threading
|
|
16
17
|
|
|
18
|
+
from cheroot.ssl import builtin
|
|
19
|
+
from cheroot import wsgi
|
|
17
20
|
from oslo_log import log
|
|
18
|
-
from oslo_service import wsgi
|
|
19
21
|
import werkzeug
|
|
20
22
|
from werkzeug import exceptions as http_exc
|
|
21
23
|
from werkzeug import routing
|
|
@@ -92,7 +94,7 @@ class Application(object):
|
|
|
92
94
|
:param conf: configuration object.
|
|
93
95
|
"""
|
|
94
96
|
self.agent = agent
|
|
95
|
-
self.
|
|
97
|
+
self.server = None
|
|
96
98
|
self._conf = conf
|
|
97
99
|
self.url_map = routing.Map([
|
|
98
100
|
routing.Rule('/', endpoint='root', methods=['GET']),
|
|
@@ -128,28 +130,44 @@ class Application(object):
|
|
|
128
130
|
|
|
129
131
|
def start(self, tls_cert_file=None, tls_key_file=None):
|
|
130
132
|
"""Start the API service in the background."""
|
|
131
|
-
if tls_cert_file and tls_key_file:
|
|
132
|
-
self._conf.set_override('cert_file', tls_cert_file, group='ssl')
|
|
133
|
-
self._conf.set_override('key_file', tls_key_file, group='ssl')
|
|
134
|
-
use_tls = True
|
|
135
|
-
else:
|
|
136
|
-
use_tls = self._conf.listen_tls
|
|
137
133
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
self.
|
|
134
|
+
ssl_group = getattr(self._conf, 'ssl', {})
|
|
135
|
+
|
|
136
|
+
self.tls_cert_file = tls_cert_file or getattr(
|
|
137
|
+
ssl_group, 'cert_file', None)
|
|
138
|
+
self.tls_key_file = tls_key_file or getattr(
|
|
139
|
+
ssl_group, 'key_file', None)
|
|
140
|
+
|
|
141
|
+
bind_addr = (self.agent.listen_address.hostname,
|
|
142
|
+
self.agent.listen_address.port)
|
|
143
|
+
|
|
144
|
+
server = wsgi.Server(bind_addr=bind_addr, wsgi_app=self,
|
|
145
|
+
server_name='ironic-python-agent')
|
|
146
|
+
|
|
147
|
+
if self.tls_cert_file and self.tls_key_file:
|
|
148
|
+
server.ssl_adapter = builtin.BuiltinSSLAdapter(
|
|
149
|
+
certificate=self.tls_cert_file,
|
|
150
|
+
private_key=self.tls_key_file
|
|
151
|
+
)
|
|
152
|
+
|
|
153
|
+
self.server = server
|
|
154
|
+
self.server.prepare()
|
|
155
|
+
self.server_thread = threading.Thread(target=self.server.serve)
|
|
156
|
+
self.server_thread.daemon = True
|
|
157
|
+
self.server_thread.start()
|
|
158
|
+
|
|
143
159
|
LOG.info('Started API service on port %s',
|
|
144
160
|
self.agent.listen_address.port)
|
|
145
161
|
|
|
146
162
|
def stop(self):
|
|
147
163
|
"""Stop the API service."""
|
|
148
164
|
LOG.debug("Stopping the API service.")
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
165
|
+
|
|
166
|
+
if self.server:
|
|
167
|
+
self.server.stop()
|
|
168
|
+
self.server_thread.join(timeout=2)
|
|
169
|
+
self.server = None
|
|
170
|
+
|
|
153
171
|
LOG.info('Stopped API service on port %s',
|
|
154
172
|
self.agent.listen_address.port)
|
|
155
173
|
|
ironic_python_agent/config.py
CHANGED
|
@@ -292,12 +292,6 @@ cli_opts = [
|
|
|
292
292
|
'This variable can be also configured via image_info.'
|
|
293
293
|
'Value coming from image_info takes precedence over'
|
|
294
294
|
'value coming from command line or configuration file.'),
|
|
295
|
-
cfg.BoolOpt('agent_token_required',
|
|
296
|
-
default=APARAMS.get('ipa-agent-token-required', False),
|
|
297
|
-
help='Control to enforce if API command requests should '
|
|
298
|
-
'enforce token validation. The configuration provided '
|
|
299
|
-
'by the conductor MAY override this and force this '
|
|
300
|
-
'setting to be changed to True in memory.'),
|
|
301
295
|
cfg.IntOpt('image_download_connection_timeout', min=1,
|
|
302
296
|
default=APARAMS.get(
|
|
303
297
|
'ipa-image-download-connection-timeout', 60),
|
|
@@ -442,13 +436,42 @@ disk_part_opts = [
|
|
|
442
436
|
' having failed.')
|
|
443
437
|
]
|
|
444
438
|
|
|
439
|
+
container_opts = [
|
|
440
|
+
cfg.BoolOpt('allow_arbitrary_containers',
|
|
441
|
+
default=False,
|
|
442
|
+
help='Allow arbitrary containers to be run'
|
|
443
|
+
'without restriction.'),
|
|
444
|
+
cfg.ListOpt('allowed_containers',
|
|
445
|
+
default=[],
|
|
446
|
+
help='List of allowed containers that can be run.'),
|
|
447
|
+
cfg.StrOpt('container_steps_file',
|
|
448
|
+
default='/etc/ironic-python-agent.d/mysteps.yaml',
|
|
449
|
+
help='Path to the YAML file containing container-based'
|
|
450
|
+
'cleaning steps.'),
|
|
451
|
+
cfg.StrOpt('runner',
|
|
452
|
+
default='podman',
|
|
453
|
+
choices=['podman', 'docker'],
|
|
454
|
+
help='Container runtime to use for cleaning steps.'),
|
|
455
|
+
cfg.ListOpt('pull_options',
|
|
456
|
+
default=['--tls-verify=false'],
|
|
457
|
+
help='Options to use when pulling container images.'),
|
|
458
|
+
cfg.ListOpt('run_options',
|
|
459
|
+
default=['--rm', '--network=host', '--tls-verify=false'],
|
|
460
|
+
help='Options to use when running containers.'),
|
|
461
|
+
cfg.StrOpt('container_conf_file',
|
|
462
|
+
default='/etc/containers/containers.conf',
|
|
463
|
+
help='Path to the container configuration file in the IPA RAM')
|
|
464
|
+
]
|
|
465
|
+
|
|
445
466
|
|
|
446
467
|
def list_opts():
|
|
447
468
|
return [('DEFAULT', cli_opts),
|
|
448
469
|
('disk_utils', disk_utils_opts),
|
|
449
470
|
('disk_partitioner', disk_part_opts),
|
|
450
471
|
('metrics', metrics_opts),
|
|
451
|
-
('metrics_statsd', statsd_opts)
|
|
472
|
+
('metrics_statsd', statsd_opts),
|
|
473
|
+
('container', container_opts)
|
|
474
|
+
]
|
|
452
475
|
|
|
453
476
|
|
|
454
477
|
def populate_config():
|
|
@@ -458,6 +481,7 @@ def populate_config():
|
|
|
458
481
|
CONF.register_opts(disk_part_opts, group='disk_partitioner')
|
|
459
482
|
CONF.register_opts(metrics_opts, group='metrics')
|
|
460
483
|
CONF.register_opts(statsd_opts, group='metrics_statsd')
|
|
484
|
+
CONF.register_opts(container_opts, group='container')
|
|
461
485
|
|
|
462
486
|
|
|
463
487
|
def override(params):
|
ironic_python_agent/errors.py
CHANGED
|
@@ -268,6 +268,15 @@ class HardwareManagerMethodNotFound(RESTError):
|
|
|
268
268
|
super(HardwareManagerMethodNotFound, self).__init__(details)
|
|
269
269
|
|
|
270
270
|
|
|
271
|
+
class HardwareManagerConfigurationError(RESTError):
|
|
272
|
+
"""Error raised when a hardware manager has invalid configuration."""
|
|
273
|
+
|
|
274
|
+
message = 'Hardware manager configuration error'
|
|
275
|
+
|
|
276
|
+
def __init__(self, details=None):
|
|
277
|
+
super(HardwareManagerConfigurationError, self).__init__(details)
|
|
278
|
+
|
|
279
|
+
|
|
271
280
|
class IncompatibleHardwareMethodError(RESTError):
|
|
272
281
|
"""Error raised when HardwareManager method incompatible with hardware."""
|
|
273
282
|
|
ironic_python_agent/hardware.py
CHANGED
|
@@ -3652,6 +3652,8 @@ def dispatch_to_managers(method, *args, **kwargs):
|
|
|
3652
3652
|
:param kwargs: keyword arguments to dispatched method
|
|
3653
3653
|
|
|
3654
3654
|
:returns: result of successful dispatch of method
|
|
3655
|
+
:raises HardwareManagerConfigurationError: if a hardware manager is
|
|
3656
|
+
misconfigured
|
|
3655
3657
|
:raises HardwareManagerMethodNotFound: if all managers failed the method
|
|
3656
3658
|
:raises HardwareManagerNotFound: if no valid hardware managers found
|
|
3657
3659
|
"""
|
|
@@ -3660,6 +3662,11 @@ def dispatch_to_managers(method, *args, **kwargs):
|
|
|
3660
3662
|
if getattr(manager, method, None):
|
|
3661
3663
|
try:
|
|
3662
3664
|
return getattr(manager, method)(*args, **kwargs)
|
|
3665
|
+
except errors.HardwareManagerConfigurationError as e:
|
|
3666
|
+
LOG.error('Configuration error in HardwareManager'
|
|
3667
|
+
' %(manager)s: %(e)s',
|
|
3668
|
+
{'manager': manager, 'e': e})
|
|
3669
|
+
raise
|
|
3663
3670
|
except errors.IncompatibleHardwareMethodError:
|
|
3664
3671
|
LOG.debug('HardwareManager %(manager)s does not '
|
|
3665
3672
|
'support %(method)s',
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
2
|
+
# you may not use this file except in compliance with the License.
|
|
3
|
+
# You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
from ironic_python_agent import errors
|
|
14
|
+
from ironic_python_agent import hardware
|
|
15
|
+
from ironic_python_agent import utils
|
|
16
|
+
from oslo_config import cfg
|
|
17
|
+
from oslo_log import log
|
|
18
|
+
|
|
19
|
+
from functools import partial
|
|
20
|
+
import yaml
|
|
21
|
+
|
|
22
|
+
CONF = cfg.CONF
|
|
23
|
+
LOG = log.getLogger()
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class ContainerHardwareManager(hardware.HardwareManager):
|
|
27
|
+
"""Hardware manager for container-based cleanup."""
|
|
28
|
+
|
|
29
|
+
HARDWARE_MANAGER_NAME = "ContainerHardwareManager"
|
|
30
|
+
HARDWARE_MANAGER_VERSION = "1"
|
|
31
|
+
|
|
32
|
+
def __init__(self):
|
|
33
|
+
self.STEPS = None
|
|
34
|
+
|
|
35
|
+
def _load_steps_from_yaml(self, file_path):
|
|
36
|
+
"""Load steps from YAML file."""
|
|
37
|
+
try:
|
|
38
|
+
with open(file_path, 'r') as file:
|
|
39
|
+
data = yaml.safe_load(file)
|
|
40
|
+
return data.get('steps', [])
|
|
41
|
+
except Exception as e:
|
|
42
|
+
LOG.debug("Error loading steps from YAML file: %s", e)
|
|
43
|
+
return []
|
|
44
|
+
|
|
45
|
+
def container_clean_step(self, node, ports, container_url,
|
|
46
|
+
pull_options=None, run_options=None):
|
|
47
|
+
try:
|
|
48
|
+
pull_options = pull_options or CONF.container.pull_options
|
|
49
|
+
run_options = run_options or CONF.container.run_options
|
|
50
|
+
utils.execute(CONF.container.runner, "pull",
|
|
51
|
+
*pull_options, container_url)
|
|
52
|
+
utils.execute(CONF.container.runner, "run",
|
|
53
|
+
*run_options, container_url)
|
|
54
|
+
LOG.info("Container step completed for image: %s", container_url)
|
|
55
|
+
except Exception as e:
|
|
56
|
+
LOG.exception("Error during container operation: %s", e)
|
|
57
|
+
raise
|
|
58
|
+
|
|
59
|
+
def _create_cleanup_method(self, container_url, pull_options=None,
|
|
60
|
+
run_options=None):
|
|
61
|
+
return partial(self.container_clean_step, container_url=container_url,
|
|
62
|
+
pull_options=pull_options, run_options=run_options)
|
|
63
|
+
|
|
64
|
+
def _create_container_step(self):
|
|
65
|
+
return {
|
|
66
|
+
"step": "container_clean_step",
|
|
67
|
+
"priority": 0, # run only manual cleaning
|
|
68
|
+
"interface": "deploy",
|
|
69
|
+
"reboot_requested": False,
|
|
70
|
+
"abortable": True,
|
|
71
|
+
"argsinfo": {
|
|
72
|
+
"container_url": {"description": "Container image URL"},
|
|
73
|
+
"pull_options": {"description": "Pull options",
|
|
74
|
+
"required": False},
|
|
75
|
+
"run_options": {"description": "Run options",
|
|
76
|
+
"required": False},
|
|
77
|
+
},
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
def evaluate_hardware_support(self):
|
|
81
|
+
"""Determine if container runner exists and return support level."""
|
|
82
|
+
containers_runners = ["podman", "docker"]
|
|
83
|
+
for runner in containers_runners:
|
|
84
|
+
try:
|
|
85
|
+
stdout, _ = utils.execute("which", runner)
|
|
86
|
+
LOG.debug("Found %s, returning MAINLINE",
|
|
87
|
+
runner)
|
|
88
|
+
return hardware.HardwareSupport.MAINLINE
|
|
89
|
+
except Exception as e:
|
|
90
|
+
LOG.debug("Error checking container runner: %s", e)
|
|
91
|
+
LOG.debug("No container runner found, returning NONE")
|
|
92
|
+
return hardware.HardwareSupport.NONE
|
|
93
|
+
|
|
94
|
+
def get_clean_steps(self, node, ports):
|
|
95
|
+
"""Dynamically generate cleaning steps."""
|
|
96
|
+
self.STEPS = self._load_steps_from_yaml(
|
|
97
|
+
CONF.container['container_steps_file'])
|
|
98
|
+
steps = [self._create_container_step()]
|
|
99
|
+
for step in self.STEPS:
|
|
100
|
+
try:
|
|
101
|
+
steps.append(
|
|
102
|
+
{
|
|
103
|
+
"step": step["name"],
|
|
104
|
+
"priority": step["priority"],
|
|
105
|
+
"interface": step['interface'],
|
|
106
|
+
"reboot_requested": step['reboot_requested'],
|
|
107
|
+
"abortable": step["abortable"],
|
|
108
|
+
}
|
|
109
|
+
)
|
|
110
|
+
except KeyError as e:
|
|
111
|
+
missing_key = str(e)
|
|
112
|
+
step_name = step.get("name", "unknown")
|
|
113
|
+
LOG.exception("Missing key '%s' in cleaning step: %s",
|
|
114
|
+
missing_key, step_name)
|
|
115
|
+
raise errors.HardwareManagerConfigurationError(
|
|
116
|
+
f"Missing required key '{missing_key}' in cleaning step:\
|
|
117
|
+
{step_name}"
|
|
118
|
+
)
|
|
119
|
+
return steps
|
|
120
|
+
|
|
121
|
+
def get_service_steps(self, node, ports):
|
|
122
|
+
return self.get_clean_steps(node, ports)
|
|
123
|
+
|
|
124
|
+
def get_deploy_steps(self, node, ports):
|
|
125
|
+
return self.get_clean_steps(node, ports)
|
|
126
|
+
|
|
127
|
+
def __getattr__(self, name):
|
|
128
|
+
ALLOW_ARBITRARY_CONTAINERS = CONF.container
|
|
129
|
+
['allow_arbitrary_containers']
|
|
130
|
+
ALLOWED_CONTAINERS = CONF.container['allowed_containers']
|
|
131
|
+
if self.STEPS is None:
|
|
132
|
+
self.STEPS = self._load_steps_from_yaml(
|
|
133
|
+
CONF.container['container_steps_file'])
|
|
134
|
+
|
|
135
|
+
for step in self.STEPS:
|
|
136
|
+
if step.get('name') == name:
|
|
137
|
+
if not ALLOW_ARBITRARY_CONTAINERS:
|
|
138
|
+
if step.get('image') not in ALLOWED_CONTAINERS:
|
|
139
|
+
LOG.debug(
|
|
140
|
+
"%s is not registered as ALLOWED_CONTAINERS "
|
|
141
|
+
"in ironic-python-agent.conf", step.get('image')
|
|
142
|
+
)
|
|
143
|
+
continue
|
|
144
|
+
|
|
145
|
+
return self._create_cleanup_method(
|
|
146
|
+
container_url=step.get('image'),
|
|
147
|
+
pull_options=step.get(
|
|
148
|
+
'pull_options'),
|
|
149
|
+
run_options=step
|
|
150
|
+
.get('run_options'))
|
|
151
|
+
raise AttributeError(
|
|
152
|
+
"%s object has no attribute %s", self.__class__.__name__, name)
|
ironic_python_agent/netutils.py
CHANGED
|
@@ -34,6 +34,13 @@ LLDP_ETHERTYPE = 0x88cc
|
|
|
34
34
|
IFF_PROMISC = 0x100
|
|
35
35
|
SIOCGIFFLAGS = 0x8913
|
|
36
36
|
SIOCSIFFLAGS = 0x8914
|
|
37
|
+
# SIOCETHTOOL from linux/sockios.h
|
|
38
|
+
SIOCETHTOOL = 0x8946
|
|
39
|
+
# ETHTOOL_GPERMADDR from linux/ethtool.h
|
|
40
|
+
ETHTOOL_GPERMADDR = 0x00000020
|
|
41
|
+
# MAX_ADDR_LEN from linux/netdevice.h
|
|
42
|
+
MAX_ADDR_LEN = 32
|
|
43
|
+
|
|
37
44
|
INFINIBAND_ADDR_LEN = 59
|
|
38
45
|
|
|
39
46
|
# LLDP definitions needed to extract vlan information
|
|
@@ -45,10 +52,25 @@ dot1_VLAN_NAME = "03"
|
|
|
45
52
|
VLAN_ID_LEN = len(LLDP_802dot1_OUI + dot1_VLAN_NAME)
|
|
46
53
|
|
|
47
54
|
|
|
55
|
+
class ethtoolPermAddr(ctypes.Structure):
|
|
56
|
+
"""Class for getting interface permanent MAC address"""
|
|
57
|
+
_fields_ = [("cmd", ctypes.c_uint32),
|
|
58
|
+
("size", ctypes.c_uint32),
|
|
59
|
+
("data", ctypes.c_uint8 * MAX_ADDR_LEN)]
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class ifreq_data(ctypes.Union):
|
|
63
|
+
_fields_ = [("ifr_flags", ctypes.c_short),
|
|
64
|
+
(
|
|
65
|
+
"ifr_data_ethtool_perm_addr",
|
|
66
|
+
ctypes.POINTER(ethtoolPermAddr))]
|
|
67
|
+
|
|
68
|
+
|
|
48
69
|
class ifreq(ctypes.Structure):
|
|
49
|
-
"""Class for
|
|
70
|
+
"""Class for ioctl on socket."""
|
|
71
|
+
_anonymous_ = ("ifr_data",)
|
|
50
72
|
_fields_ = [("ifr_ifrn", ctypes.c_char * 16),
|
|
51
|
-
("
|
|
73
|
+
("ifr_data", ifreq_data)]
|
|
52
74
|
|
|
53
75
|
|
|
54
76
|
class RawPromiscuousSockets(object):
|
|
@@ -236,6 +258,23 @@ def get_ipv6_addr(interface_id):
|
|
|
236
258
|
|
|
237
259
|
|
|
238
260
|
def get_mac_addr(interface_id):
|
|
261
|
+
"""Retrieve permanent mac address, if unable to fallback to default one"""
|
|
262
|
+
try:
|
|
263
|
+
data = ethtoolPermAddr(cmd=ETHTOOL_GPERMADDR, size=MAX_ADDR_LEN)
|
|
264
|
+
ifr = ifreq(ifr_ifrn=interface_id.encode())
|
|
265
|
+
ifr.ifr_data_ethtool_perm_addr = ctypes.pointer(data)
|
|
266
|
+
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0)
|
|
267
|
+
fcntl.ioctl(sock.fileno(), SIOCETHTOOL, ifr)
|
|
268
|
+
# if not full of zeros
|
|
269
|
+
if any(data.data[:data.size]):
|
|
270
|
+
# kernel updates size to actual address size during ioctl call
|
|
271
|
+
permaddr = [f'{b:02x}' for b in data.data[:data.size]]
|
|
272
|
+
return ':'.join(permaddr)
|
|
273
|
+
except OSError:
|
|
274
|
+
pass
|
|
275
|
+
LOG.warning("Failed to get permanent mac address for interface %s, "
|
|
276
|
+
"falling back to default mac address",
|
|
277
|
+
interface_id)
|
|
239
278
|
return get_default_ip_addr(socket.AF_PACKET, interface_id)
|
|
240
279
|
|
|
241
280
|
|
|
@@ -42,8 +42,7 @@ class TestPollExtension(base.IronicAgentTest):
|
|
|
42
42
|
def test_set_node_info_success(self):
|
|
43
43
|
self.mock_agent.standalone = True
|
|
44
44
|
node_info = {'node': {'uuid': 'fake-node', 'properties': {}},
|
|
45
|
-
'config': {'
|
|
46
|
-
'agent_token': 'blah' * 8}}
|
|
45
|
+
'config': {'agent_token': 'blah' * 8}}
|
|
47
46
|
result = self.agent_extension.set_node_info(node_info=node_info)
|
|
48
47
|
self.mock_agent.process_lookup_data.assert_called_once_with(node_info)
|
|
49
48
|
self.assertEqual('SUCCEEDED', result.command_status)
|
|
@@ -51,8 +50,7 @@ class TestPollExtension(base.IronicAgentTest):
|
|
|
51
50
|
def test_set_node_info_not_standalone(self):
|
|
52
51
|
self.mock_agent.standalone = False
|
|
53
52
|
node_info = {'node': {'uuid': 'fake-node', 'properties': {}},
|
|
54
|
-
'config': {'
|
|
55
|
-
'agent_token': 'blah' * 8}}
|
|
53
|
+
'config': {'agent_token': 'blah' * 8}}
|
|
56
54
|
self.assertRaises(errors.InvalidCommandError,
|
|
57
55
|
self.agent_extension.set_node_info,
|
|
58
56
|
node_info=node_info)
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
2
|
+
# you may not use this file except in compliance with the License.
|
|
3
|
+
# You may obtain a copy of the License at
|
|
4
|
+
#
|
|
5
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
+
#
|
|
7
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
8
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
9
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
10
|
+
# See the License for the specific language governing permissions and
|
|
11
|
+
# limitations under the License.
|
|
12
|
+
|
|
13
|
+
from unittest import mock
|
|
14
|
+
|
|
15
|
+
from oslo_config import cfg
|
|
16
|
+
|
|
17
|
+
from ironic_python_agent import hardware
|
|
18
|
+
from ironic_python_agent.hardware_managers import container
|
|
19
|
+
from ironic_python_agent.tests.unit import base
|
|
20
|
+
|
|
21
|
+
CONF = cfg.CONF
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class TestContainerHardwareManager(base.IronicAgentTest):
|
|
25
|
+
def setUp(self):
|
|
26
|
+
super(TestContainerHardwareManager, self).setUp()
|
|
27
|
+
self.hardware = container.ContainerHardwareManager()
|
|
28
|
+
self.config(
|
|
29
|
+
runner='podman',
|
|
30
|
+
pull_options=['--tls-verify=false'],
|
|
31
|
+
run_options=['--rm', '--network=host', '--tls-verify=false'],
|
|
32
|
+
container_steps_file='/tmp/steps.yaml',
|
|
33
|
+
allow_arbitrary_containers=False,
|
|
34
|
+
allowed_containers=[],
|
|
35
|
+
group='container'
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def test_evaluate_hardware_support_docker_available(self):
|
|
39
|
+
with mock.patch('ironic_python_agent.utils.execute',
|
|
40
|
+
autospec=True) as mock_execute:
|
|
41
|
+
mock_execute.side_effect = [
|
|
42
|
+
mock.Mock(side_effect=Exception('Podman not found')),
|
|
43
|
+
('/usr/bin/docker', '')
|
|
44
|
+
]
|
|
45
|
+
|
|
46
|
+
support_level = self.hardware.evaluate_hardware_support()
|
|
47
|
+
mock_execute.assert_called_with('which', 'docker')
|
|
48
|
+
self.assertEqual(support_level, hardware.HardwareSupport.MAINLINE)
|
|
49
|
+
|
|
50
|
+
def test_evaluate_hardware_support_podman_available(self):
|
|
51
|
+
with mock.patch('ironic_python_agent.utils.execute',
|
|
52
|
+
autospec=True) as mock_execute:
|
|
53
|
+
mock_execute.return_value = ('/usr/bin/podman', '')
|
|
54
|
+
support_level = self.hardware.evaluate_hardware_support()
|
|
55
|
+
mock_execute.assert_called_with('which', 'podman')
|
|
56
|
+
self.assertEqual(support_level, hardware.HardwareSupport.MAINLINE)
|
|
57
|
+
|
|
58
|
+
def test_evaluate_hardware_support_no_runners(self):
|
|
59
|
+
with mock.patch('ironic_python_agent.utils.execute',
|
|
60
|
+
autospec=True) as mock_execute:
|
|
61
|
+
mock_execute.side_effect = Exception('Runner not found')
|
|
62
|
+
support_level = self.hardware.evaluate_hardware_support()
|
|
63
|
+
expected_calls = [
|
|
64
|
+
mock.call('which', 'podman'),
|
|
65
|
+
mock.call('which', 'docker')
|
|
66
|
+
]
|
|
67
|
+
mock_execute.assert_has_calls(expected_calls, any_order=True)
|
|
68
|
+
self.assertEqual(support_level, hardware.HardwareSupport.NONE)
|
|
69
|
+
|
|
70
|
+
def test_container_runners_list(self):
|
|
71
|
+
expected_runners = ["podman", "docker"]
|
|
72
|
+
runners = getattr(self.hardware, 'CONTAINERS_RUNNERS',
|
|
73
|
+
["podman", "docker"])
|
|
74
|
+
self.assertEqual(runners, expected_runners)
|
|
75
|
+
|
|
76
|
+
@mock.patch('ironic_python_agent.utils.execute', autospec=True)
|
|
77
|
+
def test_container_clean_step_with_custom_options(self, mock_execute):
|
|
78
|
+
node = mock.MagicMock()
|
|
79
|
+
ports = mock.MagicMock()
|
|
80
|
+
container_url = 'test-image:latest'
|
|
81
|
+
pull_options = ['--tls-verify=false', '-q']
|
|
82
|
+
run_options = ['--rm', '--network=host', '--tls-verify=false', '-q']
|
|
83
|
+
|
|
84
|
+
self.hardware.container_clean_step(
|
|
85
|
+
node,
|
|
86
|
+
ports,
|
|
87
|
+
container_url,
|
|
88
|
+
pull_options=pull_options,
|
|
89
|
+
run_options=run_options
|
|
90
|
+
)
|
|
91
|
+
mock_execute.assert_any_call(
|
|
92
|
+
CONF.container.runner,
|
|
93
|
+
"pull",
|
|
94
|
+
*pull_options,
|
|
95
|
+
container_url
|
|
96
|
+
)
|
|
97
|
+
mock_execute.assert_any_call(
|
|
98
|
+
CONF.container.runner,
|
|
99
|
+
"run",
|
|
100
|
+
*run_options,
|
|
101
|
+
container_url
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
def test_create_container_step(self):
|
|
105
|
+
step = self.hardware._create_container_step()
|
|
106
|
+
|
|
107
|
+
self.assertEqual(step['step'], 'container_clean_step')
|
|
108
|
+
self.assertEqual(step['priority'], 0)
|
|
109
|
+
self.assertEqual(step['interface'], 'deploy')
|
|
110
|
+
self.assertFalse(step['reboot_requested'])
|
|
111
|
+
self.assertTrue(step['abortable'])
|
|
112
|
+
|
|
113
|
+
self.assertIn('container_url', step['argsinfo'])
|
|
114
|
+
self.assertIn('pull_options', step['argsinfo'])
|
|
115
|
+
self.assertIn('run_options', step['argsinfo'])
|
|
File without changes
|