ironic-python-agent 9.4.1__py3-none-any.whl → 9.4.3__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 +6 -0
- ironic_python_agent/config.py +67 -2
- ironic_python_agent/disk_partitioner.py +125 -0
- ironic_python_agent/disk_utils.py +788 -0
- ironic_python_agent/errors.py +9 -0
- ironic_python_agent/extensions/standby.py +64 -19
- ironic_python_agent/format_inspector.py +1044 -0
- ironic_python_agent/hardware.py +40 -27
- ironic_python_agent/partition_utils.py +8 -3
- ironic_python_agent/qemu_img.py +153 -0
- ironic_python_agent/tests/unit/base.py +3 -0
- ironic_python_agent/tests/unit/extensions/test_clean.py +13 -7
- ironic_python_agent/tests/unit/extensions/test_deploy.py +13 -7
- ironic_python_agent/tests/unit/extensions/test_standby.py +128 -69
- ironic_python_agent/tests/unit/test_disk_partitioner.py +202 -0
- ironic_python_agent/tests/unit/test_disk_utils.py +1066 -0
- ironic_python_agent/tests/unit/test_hardware.py +61 -10
- ironic_python_agent/tests/unit/test_partition_utils.py +42 -24
- ironic_python_agent/tests/unit/test_qemu_img.py +332 -0
- ironic_python_agent/tests/unit/test_utils.py +37 -6
- ironic_python_agent/utils.py +28 -0
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/METADATA +1 -1
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/RECORD +29 -22
- ironic_python_agent-9.4.3.dist-info/pbr.json +1 -0
- ironic_python_agent-9.4.1.dist-info/pbr.json +0 -1
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/AUTHORS +0 -0
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/LICENSE +0 -0
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/WHEEL +0 -0
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/entry_points.txt +0 -0
- {ironic_python_agent-9.4.1.dist-info → ironic_python_agent-9.4.3.dist-info}/top_level.txt +0 -0
ironic_python_agent/agent.py
CHANGED
|
@@ -408,6 +408,12 @@ class IronicPythonAgent(base.ExecuteCommandMixin):
|
|
|
408
408
|
if config.get('metrics_statsd'):
|
|
409
409
|
for opt, val in config.items():
|
|
410
410
|
setattr(cfg.CONF.metrics_statsd, opt, val)
|
|
411
|
+
if config.get('disable_deep_image_inspection') is not None:
|
|
412
|
+
cfg.CONF.set_override('disable_deep_image_inspection',
|
|
413
|
+
config['disable_deep_image_inspection'])
|
|
414
|
+
if config.get('permitted_image_formats') is not None:
|
|
415
|
+
cfg.CONF.set_override('permitted_image_formats',
|
|
416
|
+
config['permitted_image_formats'])
|
|
411
417
|
if config.get('agent_token_required'):
|
|
412
418
|
self.agent_token_required = True
|
|
413
419
|
token = config.get('agent_token')
|
ironic_python_agent/config.py
CHANGED
|
@@ -331,13 +331,75 @@ cli_opts = [
|
|
|
331
331
|
help='If the agent should rebuild the configuration drive '
|
|
332
332
|
'using a local filesystem, instead of letting Ironic '
|
|
333
333
|
'determine if this action is necessary.'),
|
|
334
|
+
cfg.BoolOpt('disable_deep_image_inspection',
|
|
335
|
+
default=False,
|
|
336
|
+
help='This disables the additional deep image inspection '
|
|
337
|
+
'the agent does before converting and writing an image. '
|
|
338
|
+
'Generally, this should remain enabled for maximum '
|
|
339
|
+
'security, but this option allows disabling it if there '
|
|
340
|
+
'is a compatability concern.'),
|
|
341
|
+
cfg.ListOpt('permitted_image_formats',
|
|
342
|
+
default='raw,qcow2',
|
|
343
|
+
help='The supported list of image formats which are '
|
|
344
|
+
'permitted for deployment with Ironic Python Agent. If '
|
|
345
|
+
'an image format outside of this list is detected, the '
|
|
346
|
+
'image validation logic will fail the deployment '
|
|
347
|
+
'process. This check is skipped if deep image '
|
|
348
|
+
'inspection is disabled.'),
|
|
334
349
|
]
|
|
335
350
|
|
|
336
|
-
|
|
351
|
+
disk_utils_opts = [
|
|
352
|
+
cfg.IntOpt('bios_boot_partition_size',
|
|
353
|
+
default=1,
|
|
354
|
+
help='Size of BIOS Boot partition in MiB when configuring '
|
|
355
|
+
'GPT partitioned systems for local boot in BIOS.'),
|
|
356
|
+
cfg.StrOpt('dd_block_size',
|
|
357
|
+
default='1M',
|
|
358
|
+
help='Block size to use when writing to the nodes disk.'),
|
|
359
|
+
cfg.IntOpt('partition_detection_attempts',
|
|
360
|
+
default=3,
|
|
361
|
+
min=1,
|
|
362
|
+
help='Maximum attempts to detect a newly created partition.'),
|
|
363
|
+
cfg.IntOpt('partprobe_attempts',
|
|
364
|
+
default=10,
|
|
365
|
+
help='Maximum number of attempts to try to read the '
|
|
366
|
+
'partition.'),
|
|
367
|
+
cfg.IntOpt('image_convert_memory_limit',
|
|
368
|
+
default=2048,
|
|
369
|
+
help='Memory limit for "qemu-img convert" in MiB. Implemented '
|
|
370
|
+
'via the address space resource limit.'),
|
|
371
|
+
cfg.IntOpt('image_convert_attempts',
|
|
372
|
+
default=3,
|
|
373
|
+
help='Number of attempts to convert an image.'),
|
|
374
|
+
]
|
|
375
|
+
|
|
376
|
+
disk_part_opts = [
|
|
377
|
+
cfg.IntOpt('check_device_interval',
|
|
378
|
+
default=1,
|
|
379
|
+
help='After Ironic has completed creating the partition table, '
|
|
380
|
+
'it continues to check for activity on the attached iSCSI '
|
|
381
|
+
'device status at this interval prior to copying the image'
|
|
382
|
+
' to the node, in seconds'),
|
|
383
|
+
cfg.IntOpt('check_device_max_retries',
|
|
384
|
+
default=20,
|
|
385
|
+
help='The maximum number of times to check that the device is '
|
|
386
|
+
'not accessed by another process. If the device is still '
|
|
387
|
+
'busy after that, the disk partitioning will be treated as'
|
|
388
|
+
' having failed.')
|
|
389
|
+
]
|
|
337
390
|
|
|
338
391
|
|
|
339
392
|
def list_opts():
|
|
340
|
-
return [('DEFAULT', cli_opts)
|
|
393
|
+
return [('DEFAULT', cli_opts),
|
|
394
|
+
('disk_utils', disk_utils_opts),
|
|
395
|
+
('disk_partitioner', disk_part_opts)]
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
def populate_config():
|
|
399
|
+
"""Populate configuration. In a method so tests can easily utilize it."""
|
|
400
|
+
CONF.register_cli_opts(cli_opts)
|
|
401
|
+
CONF.register_opts(disk_utils_opts, group='disk_utils')
|
|
402
|
+
CONF.register_opts(disk_part_opts, group='disk_partitioner')
|
|
341
403
|
|
|
342
404
|
|
|
343
405
|
def override(params):
|
|
@@ -364,3 +426,6 @@ def override(params):
|
|
|
364
426
|
LOG.warning('Unable to override configuration option %(key)s '
|
|
365
427
|
'with %(value)r: %(exc)s',
|
|
366
428
|
{'key': key, 'value': value, 'exc': exc})
|
|
429
|
+
|
|
430
|
+
|
|
431
|
+
populate_config()
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
# Copyright 2014 Red Hat, Inc.
|
|
2
|
+
# All Rights Reserved.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License"); you may
|
|
5
|
+
# not use this file except in compliance with the License. You may obtain
|
|
6
|
+
# a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
12
|
+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
13
|
+
# License for the specific language governing permissions and limitations
|
|
14
|
+
# under the License.
|
|
15
|
+
|
|
16
|
+
"""
|
|
17
|
+
Code for creating partitions on a disk.
|
|
18
|
+
|
|
19
|
+
Imported from ironic-lib's disk_utils as of the following commit:
|
|
20
|
+
https://opendev.org/openstack/ironic-lib/commit/42fa5d63861ba0f04b9a4f67212173d7013a1332
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
import logging
|
|
24
|
+
|
|
25
|
+
from ironic_lib.common.i18n import _
|
|
26
|
+
from ironic_lib import exception
|
|
27
|
+
from ironic_lib import utils
|
|
28
|
+
from oslo_config import cfg
|
|
29
|
+
|
|
30
|
+
CONF = cfg.CONF
|
|
31
|
+
|
|
32
|
+
LOG = logging.getLogger(__name__)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class DiskPartitioner(object):
|
|
36
|
+
|
|
37
|
+
def __init__(self, device, disk_label='msdos', alignment='optimal'):
|
|
38
|
+
"""A convenient wrapper around the parted tool.
|
|
39
|
+
|
|
40
|
+
:param device: The device path.
|
|
41
|
+
:param disk_label: The type of the partition table. Valid types are:
|
|
42
|
+
"bsd", "dvh", "gpt", "loop", "mac", "msdos",
|
|
43
|
+
"pc98", or "sun".
|
|
44
|
+
:param alignment: Set alignment for newly created partitions.
|
|
45
|
+
Valid types are: none, cylinder, minimal and
|
|
46
|
+
optimal.
|
|
47
|
+
|
|
48
|
+
"""
|
|
49
|
+
self._device = device
|
|
50
|
+
self._disk_label = disk_label
|
|
51
|
+
self._alignment = alignment
|
|
52
|
+
self._partitions = []
|
|
53
|
+
|
|
54
|
+
def _exec(self, *args):
|
|
55
|
+
# NOTE(lucasagomes): utils.execute() is already a wrapper on top
|
|
56
|
+
# of processutils.execute() which raises specific
|
|
57
|
+
# exceptions. It also logs any failure so we don't
|
|
58
|
+
# need to log it again here.
|
|
59
|
+
utils.execute('parted', '-a', self._alignment, '-s', self._device,
|
|
60
|
+
'--', 'unit', 'MiB', *args, use_standard_locale=True,
|
|
61
|
+
run_as_root=True)
|
|
62
|
+
|
|
63
|
+
def add_partition(self, size, part_type='primary', fs_type='',
|
|
64
|
+
boot_flag=None, extra_flags=None):
|
|
65
|
+
"""Add a partition.
|
|
66
|
+
|
|
67
|
+
:param size: The size of the partition in MiB.
|
|
68
|
+
:param part_type: The type of the partition. Valid values are:
|
|
69
|
+
primary, logical, or extended.
|
|
70
|
+
:param fs_type: The filesystem type. Valid types are: ext2, fat32,
|
|
71
|
+
fat16, HFS, linux-swap, NTFS, reiserfs, ufs.
|
|
72
|
+
If blank (''), it will create a Linux native
|
|
73
|
+
partition (83).
|
|
74
|
+
:param boot_flag: Boot flag that needs to be configured on the
|
|
75
|
+
partition. Ignored if None. It can take values
|
|
76
|
+
'bios_grub', 'boot'.
|
|
77
|
+
:param extra_flags: List of flags to set on the partition. Ignored
|
|
78
|
+
if None.
|
|
79
|
+
:returns: The partition number.
|
|
80
|
+
|
|
81
|
+
"""
|
|
82
|
+
self._partitions.append({'size': size,
|
|
83
|
+
'type': part_type,
|
|
84
|
+
'fs_type': fs_type,
|
|
85
|
+
'boot_flag': boot_flag,
|
|
86
|
+
'extra_flags': extra_flags})
|
|
87
|
+
return len(self._partitions)
|
|
88
|
+
|
|
89
|
+
def get_partitions(self):
|
|
90
|
+
"""Get the partitioning layout.
|
|
91
|
+
|
|
92
|
+
:returns: An iterator with the partition number and the
|
|
93
|
+
partition layout.
|
|
94
|
+
|
|
95
|
+
"""
|
|
96
|
+
return enumerate(self._partitions, 1)
|
|
97
|
+
|
|
98
|
+
def commit(self):
|
|
99
|
+
"""Write to the disk."""
|
|
100
|
+
LOG.debug("Committing partitions to disk.")
|
|
101
|
+
cmd_args = ['mklabel', self._disk_label]
|
|
102
|
+
# NOTE(lucasagomes): Lead in with 1MiB to allow room for the
|
|
103
|
+
# partition table itself.
|
|
104
|
+
start = 1
|
|
105
|
+
for num, part in self.get_partitions():
|
|
106
|
+
end = start + part['size']
|
|
107
|
+
cmd_args.extend(['mkpart', part['type'], part['fs_type'],
|
|
108
|
+
str(start), str(end)])
|
|
109
|
+
if part['boot_flag']:
|
|
110
|
+
cmd_args.extend(['set', str(num), part['boot_flag'], 'on'])
|
|
111
|
+
if part['extra_flags']:
|
|
112
|
+
for flag in part['extra_flags']:
|
|
113
|
+
cmd_args.extend(['set', str(num), flag, 'on'])
|
|
114
|
+
start = end
|
|
115
|
+
|
|
116
|
+
self._exec(*cmd_args)
|
|
117
|
+
|
|
118
|
+
try:
|
|
119
|
+
from ironic_python_agent import disk_utils # circular dependency
|
|
120
|
+
disk_utils.wait_for_disk_to_become_available(self._device)
|
|
121
|
+
except exception.IronicException as e:
|
|
122
|
+
raise exception.InstanceDeployFailure(
|
|
123
|
+
_('Disk partitioning failed on device %(device)s. '
|
|
124
|
+
'Error: %(error)s')
|
|
125
|
+
% {'device': self._device, 'error': e})
|