Skip to content

Commit d82b8c6

Browse files
committed
Perform manual error checks instead of set -e
When using set -e, if you have a command fail, even when setting a variable, it causes the node to fail. I have removed set -e and checked error state where unexpected everywhere. I also added additional logging. Closes-Bug: #1326326 Change-Id: I7d2568c3693b9c486672e4322c7f01622aeba875
1 parent e6d9aaf commit d82b8c6

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

ironic_python_agent/shell/copy_configdrive_to_disk.sh

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,15 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616

17-
set -e
18-
1917
log() {
2018
echo "`basename $0`: $@"
2119
}
2220

21+
fail() {
22+
log "Error $@"
23+
exit 1
24+
}
25+
2326
usage() {
2427
[[ -z "$1" ]] || echo -e "USAGE ERROR: $@\n"
2528
echo "`basename $0`: CONFIGDRIVE DEVICE"
@@ -37,19 +40,20 @@ DEVICE="$2"
3740
# Check for preexisting partition for configdrive
3841
EXISTING_PARTITION=`/sbin/blkid -l -o device $DEVICE -t LABEL=config-2`
3942
if [[ $? == 0 ]]; then
43+
log "Existing configdrive found on ${DEVICE} at ${EXISTING_PARTITION}"
4044
ISO_PARTITION=$EXISTING_PARTITION
4145
else
4246
# Create small partition at the end of the device
4347
log "Adding configdrive partition to $DEVICE"
44-
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0
48+
parted -a optimal -s -- $DEVICE mkpart primary ext2 -64MiB -0 || fail "creating configdrive on ${DEVICE}"
4549

4650
# Find partition we just created
4751
# Dump all partitions, ignore empty ones, then get the last partition ID
48-
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'`
52+
ISO_PARTITION=`sfdisk --dump $DEVICE | grep -v ' 0,' | tail -n1 | awk '{print $1}'` || fail "finding ISO partition created on ${DEVICE}"
4953
fi
5054

5155
# This writes the ISO image to the config drive.
5256
log "Writing Configdrive contents in $CONFIGDRIVE to $ISO_PARTITION"
53-
dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct
57+
dd if=$CONFIGDRIVE of=$ISO_PARTITION bs=64K oflag=direct || fail "writing Configdrive to ${ISO_PARTITION}"
5458

5559
log "${DEVICE} imaged successfully!"

0 commit comments

Comments
 (0)