diff options
| author | Zuul <zuul@review.opendev.org> | 2021-05-26 17:17:02 +0000 |
|---|---|---|
| committer | Gerrit Code Review <review@openstack.org> | 2021-05-26 17:17:02 +0000 |
| commit | 2172122b879dc4eddff34d97a686e3d23f4fae23 (patch) | |
| tree | 89a257dc4399a39ec0da66cb2762c7ff4ac447d0 /ironic_python_agent/extensions | |
| parent | b4dd03168e631baeb0edd2c4269e1258a8fed839 (diff) | |
| parent | 606e50031240e3f5bc29aa04e77e2c2f718667ee (diff) | |
| download | ironic-python-agent-2172122b879dc4eddff34d97a686e3d23f4fae23.tar.gz | |
Merge "Rewrite write_image.sh in Python"
Diffstat (limited to 'ironic_python_agent/extensions')
| -rw-r--r-- | ironic_python_agent/extensions/standby.py | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/ironic_python_agent/extensions/standby.py b/ironic_python_agent/extensions/standby.py index ab1414df..74f244e0 100644 --- a/ironic_python_agent/extensions/standby.py +++ b/ironic_python_agent/extensions/standby.py @@ -23,6 +23,7 @@ from ironic_lib import exception from oslo_concurrency import processutils from oslo_config import cfg from oslo_log import log +from oslo_utils import units import requests from ironic_python_agent import errors @@ -46,16 +47,6 @@ def _image_location(image_info): return os.path.join(tempfile.gettempdir(), image_info['id']) -def _path_to_script(script): - """Get the location of a script which ships with ironic-python-agent. - - :param script: The script name as a string. - :returns: The relative path to the script. - """ - cwd = os.path.dirname(os.path.realpath(__file__)) - return os.path.join(cwd, '..', script) - - def _download_with_proxy(image_info, url, image_id): """Opens a download stream for the given URL. @@ -203,14 +194,24 @@ def _write_whole_disk_image(image, image_info, device): :raises: ImageWriteError if the command to write the image encounters an error. """ - script = _path_to_script('shell/write_image.sh') - command = ['/bin/bash', script, image, device] + # FIXME(dtantsur): pass the real node UUID for logging + disk_utils.destroy_disk_metadata(device, '') + disk_utils.udev_settle() + + command = ['qemu-img', 'convert', + '-t', 'directsync', '-O', 'host_device', '-W', + image, device] LOG.info('Writing image with command: {}'.format(' '.join(command))) try: - stdout, stderr = utils.execute(*command) + # TODO(dtantsur): switch to disk_utils.convert_image when it supports + # -t and -W flags and defaults to 2 GiB memory limit. + limits = processutils.ProcessLimits(address_space=2048 * units.Mi) + utils.execute(*command, prlimit=limits) except processutils.ProcessExecutionError as e: raise errors.ImageWriteError(device, e.exit_code, e.stdout, e.stderr) + disk_utils.trigger_device_rescan(device) + def _write_image(image_info, device): """Writes an image to the specified device. |
