From 0dc40d33e4f9e019429d2e3daf248a6a85d35c54 Mon Sep 17 00:00:00 2001 From: Tobias Henkel Date: Tue, 13 Aug 2019 21:05:11 +0200 Subject: [PATCH] Support optional post upload hooks There are several scenarios where it can be useful hook into nodepool after an image got uploaded but before it is taken into use by the launchers. One use case is to be able to run validations on the image (e.g. image size, boot test, etc.) before nodepool tries to use that image and causing potentially node_failures. Another more advanced use case is to be able to pre-distribute an image to all compute nodes in a cloud before an image is used at scale. To facilitate these use cases this adds a new config option post-upload-hook to the provider config. This takes a path to a user defined executable script which then can perform various tasks. If the process fails with an rc != 0 the image gets deleted again and the upload fails. Change-Id: I099cf1243b1bd262b8ee96ab323dbd34c7578c10 --- doc/source/configuration.rst | 15 +++++++ nodepool/builder.py | 36 +++++++++++++++ nodepool/driver/openstack/config.py | 6 ++- .../tests/fixtures/config_validate/good.yaml | 1 + nodepool/tests/fixtures/node_upload_hook.yaml | 45 +++++++++++++++++++ nodepool/tests/post-upload-hook | 20 +++++++++ nodepool/tests/unit/test_builder.py | 10 +++++ 7 files changed, 132 insertions(+), 1 deletion(-) create mode 100644 nodepool/tests/fixtures/node_upload_hook.yaml create mode 100755 nodepool/tests/post-upload-hook diff --git a/doc/source/configuration.rst b/doc/source/configuration.rst index 00d17a34b..96be0e9f6 100644 --- a/doc/source/configuration.rst +++ b/doc/source/configuration.rst @@ -446,6 +446,7 @@ Selecting the OpenStack driver adds the following options to the launch-retries: 3 image-name-format: '{image_name}-{timestamp}' hostname-format: '{label.name}-{provider.name}-{node.id}' + post-upload-hook: /usr/bin/custom-hook diskimages: - name: trusty meta: @@ -567,6 +568,20 @@ Selecting the OpenStack driver adds the following options to the Format for image names that are uploaded to providers. + .. attr:: post-upload-hook + :type: string + :default: None + + Filename of an optional script that can be called after an image has + been uploaded to a provider but before it is taken into use. This is + useful to perform last minute validation tests before an image is + really used for build nodes. The script will be called as follows: + + ``