Ensure local SSH key can login localhost

Change-Id: I03f7b9ec68c55f4819698775524ce4df6875d511
This commit is contained in:
Federico Ressi 2020-11-18 14:37:59 +01:00
parent 0d46934bb6
commit a2a8b4467d
5 changed files with 49 additions and 16 deletions

2
Vagrantfile vendored
View File

@ -39,7 +39,7 @@ TOX_ENVLIST = ENV.fetch('TOX_ENVLIST', '')
TOX_EXTRA_ARGS = ENV.fetch('TOX_EXTRA_ARGS', '--notest')
# Allow to switch configuration
DEVSTACK_CONF_NAME = ENV.fetch('DEVSTACK_CONF_NAME', 'ovn')
DEVSTACK_CONF_NAME = ENV.fetch('DEVSTACK_CONF_NAME', 'ovs')
DEVSTACK_LOCAL_CONF_FILE = ENV.fetch(
'DEVSTACK_LOCAL_CONF_FILE',

View File

@ -19,8 +19,8 @@ repository. See contrib/vagrant to create a vagrant VM.
3. Tobiko require Heat to be enabled, so heat should be also enabled::
[[local|localrc]]
enable_plugin heat https://opendev.org/openstack/heat
> cat local.conf
[[local|localrc]]
enable_plugin heat https://opendev.org/openstack/heat
3. Run ``stack.sh``

View File

@ -36,6 +36,7 @@ function configure_tobiko {
configure_tobiko_keystone "${tobiko_conf_file}"
configure_tobiko_nova "${tobiko_conf_file}"
configure_tobiko_neutron "${tobiko_conf_file}"
configure_tobiko_ssh "${tobiko_conf_file}"
echo_summary "Apply changes to actual ${TOBIKO_CONF_FILE} file."
sudo mkdir -p $(dirname "${TOBIKO_CONF_FILE}")
@ -151,17 +152,8 @@ function configure_tobiko_nova {
(
cd $(dirname "${tobiko_conf_file}")
local key_file=${TOBIKO_NOVA_KEY_FILE}
if [ "${key_file}" != "" ]; then
iniset "${tobiko_conf_file}" nova key_file "${key_file}"
else
# Use the default keyfile name
key_file=~/.ssh/id_rsa
fi
if ! [ -r "${key_file}" ]; then
mkdir -p $(dirname "${key_file}")
ssh-keygen -f "${key_file}" -N ""
fi
configure_key_file "${tobiko_conf_file}" nova key_file \
"${TOBIKO_NOVA_KEY_FILE}"
)
}
@ -179,6 +171,43 @@ function configure_tobiko_neutron {
}
function configure_tobiko_ssh {
echo_summary "Write [ssh] section to ${TOBIKO_CONF_FILE}"
local tobiko_conf_file=$1
(
cd $(dirname "${tobiko_conf_file}")
configure_key_file "${tobiko_conf_file}" ssh key_file \
"${TOBIKO_SSH_KEY_FILE}"
)
}
function configure_key_file {
local tobiko_conf_file=$1
ensure_key_file "${key_file}"
iniset_nonempty "$@"
}
function ensure_key_file {
local key_file=${1:-~/.ssh/id_rsa}
# Ensure key file exists
if ! [ -r "${key_file}" ]; then
mkdir -p $(dirname "${key_file}")
ssh-keygen -f "${key_file}" -N ""
fi
# Ensure Tobiko can SSH localhost using key file
local pub_key
pub_key=$(cat "${key_file}.pub")
if ! grep "${pub_key}" ~/.ssh/authorized_keys; then
cat "${key_file}.pub" >> ~/.ssh/authorized_keys
fi
chmod 600 "${key_file}" "${key_file}.pub" ~/.ssh/authorized_keys
}
function iniset_nonempty {
# Calls iniset only when option value is not an empty string
if [ -n "$4" ]; then

View File

@ -41,3 +41,6 @@ TOBIKO_NOVA_KEY_FILE=${TOBIKO_NOVA_KEY_FILE:-}
TOBIKO_NEUTRON_FLOATING_NETWORK=${TOBIKO_NEUTRON_FLOATING_NETWORK:-${PUBLIC_NETWORK_NAME}}
TOBIKO_NEUTRON_IPV4_DNS_NAMESERVERS=${TOBIKO_NEUTRON_IPV4_DNS_NAMESERVERS:-}
TOBIKO_NEUTRON_IPV6_DNS_NAMESERVERS=${TOBIKO_NEUTRON_IPV6_DNS_NAMESERVERS:-}
# --- SSH settings ---
TOBIKO_SSH_KEY_FILE=${TOBIKO_SSH_KEY_FILE:-}

View File

@ -7,7 +7,6 @@ SERVICE_PASSWORD=$ADMIN_PASSWORD
LOGFILE=/opt/stack/devstack/stack.log
LOG_COLOR=False
# Disable unrequired services -------------------------------------------------
disable_service horizon
@ -30,3 +29,5 @@ enable_plugin heat https://opendev.org/openstack/heat.git
# Configure Tobiko ------------------------------------------------------------
enable_plugin devstack-plugin-tobiko https://opendev.org/x/devstack-plugin-tobiko.git
TOBIKO_NEUTRON_IPV4_DNS_NAMESERVERS=1.1.1.1,8.8.8.8