Drop Ironic DB using non-default password 65/46065/1
authorVictor Morales <victor.morales@intel.com>
Fri, 20 Oct 2017 19:06:29 +0000 (12:06 -0700)
committerVictor Morales <victor.morales@intel.com>
Fri, 20 Oct 2017 19:06:29 +0000 (12:06 -0700)
The current implementation relays on the fact that the existing mysql
deployment the root user can remove has access to the root user
without its password. It's possible to drop the Ironic database using
the same credentials that were used during its creation.

Change-Id: I4b26455e06e5f024d2bd8c42065367838bb4aa0f
Signed-off-by: Victor Morales <victor.morales@intel.com>
bifrost/scripts/destroy-env.sh

index f6eca4e..45d2b72 100755 (executable)
@@ -44,7 +44,9 @@ rm -rf /tmp/baremetal.*
 
 echo "removing ironic database"
 if $(which mysql &> /dev/null); then
-    mysql -u root ironic --execute "drop database ironic;"
+    mysql_ironic_user=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 2 )
+    msyql_ironic_password=$(sudo grep "connection" /etc/ironic/ironic.conf | cut -d : -f 3)
+    mysql -u${mysql_ironic_user#*//} -p${msyql_ironic_password%%@*} --execute "drop database ironic;"
 fi
 echo "removing leases"
 [[ -e /var/lib/misc/dnsmasq/dnsmasq.leases ]] && > /var/lib/misc/dnsmasq/dnsmasq.leases