#!/bin/bash

set -o xtrace

echo "Running local.sh"

openrc=/home/stack/devstack/openrc
source $openrc

if is_service_enabled n-api; then
    for user in admin demo; do
        source $openrc $user $user
        nova keypair-add --pub-key /home/stack/.ssh/authorized_keys default
        nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
        nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
    done
fi

#!/bin/bash

echo "Running local.sh"

set -o xtrace

openrc=/home/stack/devstack/openrc
authorized_keys_file=/home/stack/.ssh/authorized_keys

source "$openrc"

if is_service_enabled n-api; then
    # Extract valid public key into tmp file to work around the issue,
    # introduced by puppet adding comments in the beginning of authorized_keys
    pubkey_file=`mktemp`
    grep -vE '^\s*#' "$authorized_keys_file" | head -n 1 > "$pubkey_file"

    for user in admin demo; do
        source "$openrc" "$user" "$user"
        nova keypair-add --pub-key "$pubkey_file" default
        nova secgroup-add-rule default icmp -1 -1 0.0.0.0/0
        nova secgroup-add-rule default tcp 22 22 0.0.0.0/0
    done

    # Tmp file cleanup
    rm -f "$pubkey_file"
fi

Work around invalid public key issue
Work around invalid public key issue

I've faced with inability of keystone to recognize a public key
inside of `~stack/.ssh/autorized_keys` file. This happened because
of puppet writing three-line comment stating it was generated
automatically. With this fix it works fine.

Changes, I've done:
- Move public key path into separate variable
- Write public key into tmp file and pass it to `nova keypair-add`

Change-Id: I827b7e1695f61ef2742137195866cb2deb4a390f
