ironic-python-agent 9.7.1__py3-none-any.whl → 9.7.2__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.
Files changed (31) hide show
  1. ironic_python_agent/agent.py +6 -0
  2. ironic_python_agent/config.py +67 -2
  3. ironic_python_agent/disk_partitioner.py +125 -0
  4. ironic_python_agent/disk_utils.py +788 -0
  5. ironic_python_agent/errors.py +9 -0
  6. ironic_python_agent/extensions/standby.py +67 -19
  7. ironic_python_agent/format_inspector.py +1044 -0
  8. ironic_python_agent/hardware.py +40 -27
  9. ironic_python_agent/partition_utils.py +8 -3
  10. ironic_python_agent/qemu_img.py +153 -0
  11. ironic_python_agent/tests/unit/base.py +3 -0
  12. ironic_python_agent/tests/unit/extensions/test_clean.py +13 -7
  13. ironic_python_agent/tests/unit/extensions/test_deploy.py +13 -7
  14. ironic_python_agent/tests/unit/extensions/test_service.py +13 -7
  15. ironic_python_agent/tests/unit/extensions/test_standby.py +124 -69
  16. ironic_python_agent/tests/unit/test_disk_partitioner.py +202 -0
  17. ironic_python_agent/tests/unit/test_disk_utils.py +1066 -0
  18. ironic_python_agent/tests/unit/test_hardware.py +61 -10
  19. ironic_python_agent/tests/unit/test_partition_utils.py +42 -24
  20. ironic_python_agent/tests/unit/test_qemu_img.py +332 -0
  21. ironic_python_agent/tests/unit/test_utils.py +37 -6
  22. ironic_python_agent/utils.py +28 -0
  23. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/METADATA +1 -1
  24. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/RECORD +30 -23
  25. ironic_python_agent-9.7.2.dist-info/pbr.json +1 -0
  26. ironic_python_agent-9.7.1.dist-info/pbr.json +0 -1
  27. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/AUTHORS +0 -0
  28. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/LICENSE +0 -0
  29. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/WHEEL +0 -0
  30. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/entry_points.txt +0 -0
  31. {ironic_python_agent-9.7.1.dist-info → ironic_python_agent-9.7.2.dist-info}/top_level.txt +0 -0
@@ -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
  md5_allowed = config.get('agent_md5_checksum_enable')
412
418
  if md5_allowed is not None:
413
419
  cfg.CONF.set_override('md5_enabled', md5_allowed)
@@ -343,13 +343,75 @@ cli_opts = [
343
343
  help='If the agent should rebuild the configuration drive '
344
344
  'using a local filesystem, instead of letting Ironic '
345
345
  'determine if this action is necessary.'),
346
+ cfg.BoolOpt('disable_deep_image_inspection',
347
+ default=False,
348
+ help='This disables the additional deep image inspection '
349
+ 'the agent does before converting and writing an image. '
350
+ 'Generally, this should remain enabled for maximum '
351
+ 'security, but this option allows disabling it if there '
352
+ 'is a compatability concern.'),
353
+ cfg.ListOpt('permitted_image_formats',
354
+ default='raw,qcow2',
355
+ help='The supported list of image formats which are '
356
+ 'permitted for deployment with Ironic Python Agent. If '
357
+ 'an image format outside of this list is detected, the '
358
+ 'image validation logic will fail the deployment '
359
+ 'process. This check is skipped if deep image '
360
+ 'inspection is disabled.'),
346
361
  ]
347
362
 
348
- CONF.register_cli_opts(cli_opts)
363
+ disk_utils_opts = [
364
+ cfg.IntOpt('bios_boot_partition_size',
365
+ default=1,
366
+ help='Size of BIOS Boot partition in MiB when configuring '
367
+ 'GPT partitioned systems for local boot in BIOS.'),
368
+ cfg.StrOpt('dd_block_size',
369
+ default='1M',
370
+ help='Block size to use when writing to the nodes disk.'),
371
+ cfg.IntOpt('partition_detection_attempts',
372
+ default=3,
373
+ min=1,
374
+ help='Maximum attempts to detect a newly created partition.'),
375
+ cfg.IntOpt('partprobe_attempts',
376
+ default=10,
377
+ help='Maximum number of attempts to try to read the '
378
+ 'partition.'),
379
+ cfg.IntOpt('image_convert_memory_limit',
380
+ default=2048,
381
+ help='Memory limit for "qemu-img convert" in MiB. Implemented '
382
+ 'via the address space resource limit.'),
383
+ cfg.IntOpt('image_convert_attempts',
384
+ default=3,
385
+ help='Number of attempts to convert an image.'),
386
+ ]
387
+
388
+ disk_part_opts = [
389
+ cfg.IntOpt('check_device_interval',
390
+ default=1,
391
+ help='After Ironic has completed creating the partition table, '
392
+ 'it continues to check for activity on the attached iSCSI '
393
+ 'device status at this interval prior to copying the image'
394
+ ' to the node, in seconds'),
395
+ cfg.IntOpt('check_device_max_retries',
396
+ default=20,
397
+ help='The maximum number of times to check that the device is '
398
+ 'not accessed by another process. If the device is still '
399
+ 'busy after that, the disk partitioning will be treated as'
400
+ ' having failed.')
401
+ ]
349
402
 
350
403
 
351
404
  def list_opts():
352
- return [('DEFAULT', cli_opts)]
405
+ return [('DEFAULT', cli_opts),
406
+ ('disk_utils', disk_utils_opts),
407
+ ('disk_partitioner', disk_part_opts)]
408
+
409
+
410
+ def populate_config():
411
+ """Populate configuration. In a method so tests can easily utilize it."""
412
+ CONF.register_cli_opts(cli_opts)
413
+ CONF.register_opts(disk_utils_opts, group='disk_utils')
414
+ CONF.register_opts(disk_part_opts, group='disk_partitioner')
353
415
 
354
416
 
355
417
  def override(params):
@@ -376,3 +438,6 @@ def override(params):
376
438
  LOG.warning('Unable to override configuration option %(key)s '
377
439
  'with %(value)r: %(exc)s',
378
440
  {'key': key, 'value': value, 'exc': exc})
441
+
442
+
443
+ 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})