From d10abd26f171a484194128494c4c430c1db0ba1e Mon Sep 17 00:00:00 2001 From: Markos Chandras Date: Fri, 3 Feb 2017 12:38:02 +0000 Subject: [PATCH] roles: bifrost-create-vm-nodes: Randomize VM XML file /tmp/vm.xml is not that uncommon to exist outside of bifrost and to hold user's temporary VM definitions so make sure we don't wipe it and use a random file instead. Change-Id: I70088df744011b391a66ab2f98b67583c43dd0b2 --- .../files/create_vm_nodes-for-role.sh | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh b/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh index 3a57876c5..e4e9ec386 100755 --- a/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh +++ b/playbooks/roles/bifrost-create-vm-nodes/files/create_vm_nodes-for-role.sh @@ -218,17 +218,23 @@ function create_node { " - echo ${vm_xml} > /tmp/vm.xml + local vm_tmpfile=$(mktemp -p /tmp vm.XXXX.xml) + # This is very unlikely to happen but still better safe than sorry + if [ $? != 0 ]; then + echo "Failed to create the temporary VM XML file" + exit 1 + fi + echo ${vm_xml} > ${vm_tmpfile} # NOTE(TheJulia): the create command powers on a VM that has been defined, # where as define creates the VM, but does not change the power state. - virsh define /tmp/vm.xml 2>&1 >/dev/null + virsh define ${vm_tmpfile} &>/dev/null if [ $? != 0 ] then echo "failed to create VM $NAME" >&2 - rm -f /tmp/vm.xml + rm -f ${vm_tmpfile} exit 1 fi - rm -f /tmp/vm.xml + rm -f ${vm_tmpfile} fi