Faster nova fixed key generation

Using bc 64 times in loop is too verbose and slow,
replacing the echo/bc loop with hexdump and urandom.

The hexdump approach is 75 times faster and
does not floods the debug logs.

Using the common function for generating,
this kind of string with lib/heat and by the read_password.

Change-Id: If6a86dfaf0c21e2635c6de0a7b96a8ed7ec5b507
This commit is contained in:
Attila Fazekas 2014-05-28 09:52:22 +02:00
parent a7a2b883b2
commit f71b500bea
3 changed files with 10 additions and 7 deletions

View File

@ -695,6 +695,13 @@ function get_default_host_ip {
echo $host_ip
}
# Generates hex string from ``size`` byte of pseudo random data
# generate_hex_string size
function generate_hex_string {
local size=$1
hexdump -n "$size" -v -e '/1 "%02x"' /dev/urandom
}
# Grab a numbered field from python prettytable output
# Fields are numbered starting with 1
# Reverse syntax is supported: -1 is the last field, -2 is second to last, etc.

View File

@ -98,7 +98,7 @@ function configure_heat {
iniset $HEAT_CONF DEFAULT heat_waitcondition_server_url http://$HEAT_API_CFN_HOST:$HEAT_API_CFN_PORT/v1/waitcondition
iniset $HEAT_CONF DEFAULT heat_watch_server_url http://$HEAT_API_CW_HOST:$HEAT_API_CW_PORT
iniset $HEAT_CONF database connection `database_connection_url heat`
iniset $HEAT_CONF DEFAULT auth_encryption_key `hexdump -n 16 -v -e '/1 "%02x"' /dev/urandom`
iniset $HEAT_CONF DEFAULT auth_encryption_key $(generate_hex_string 16)
iniset $HEAT_CONF DEFAULT region_name_for_services "$REGION_NAME"

View File

@ -426,7 +426,7 @@ function read_password {
echo "Invalid chars in password. Try again:"
done
if [ ! $pw ]; then
pw=$(cat /dev/urandom | tr -cd 'a-f0-9' | head -c 20)
pw=$(generate_hex_string 10)
fi
eval "$var=$pw"
echo "$var=$pw" >> $localrc
@ -1211,11 +1211,7 @@ fi
# Create a randomized default value for the keymgr's fixed_key
if is_service_enabled nova; then
FIXED_KEY=""
for i in $(seq 1 64); do
FIXED_KEY+=$(echo "obase=16; $(($RANDOM % 16))" | bc);
done;
iniset $NOVA_CONF keymgr fixed_key "$FIXED_KEY"
iniset $NOVA_CONF keymgr fixed_key $(generate_hex_string 32)
fi
if is_service_enabled zeromq; then