Addition of (nova ssh) key_pair_fixture with cmdline,heat template,

and a stacks fixture class to be used in test_floating_ip scenarios.

Change-Id: I87c61e16b97527688e8a02277a7c6693e887692e
This commit is contained in:
pkomarov 2019-04-21 09:17:27 +03:00 committed by Pini Komarov
parent f301597e87
commit 579b0beb83
6 changed files with 58 additions and 5 deletions

View File

@ -10,6 +10,11 @@ function install_tobiko {
function configure_tobiko { function configure_tobiko {
#Setup an ssh key
local nova_key_file=${TOBIKO_NOVA_KEY_FILE:-~/.ssh/id_rsa}
if ! [ -r "${nova_key_file}" ]; then
ssh-keygen -t rsa -q -P "" -f "${nova_key_file}"
fi
# Write configuration to a new temporary file # Write configuration to a new temporary file
local tobiko_conf=$(mktemp) local tobiko_conf=$(mktemp)
if [ -f "${TOBIKO_CONF}" ]; then if [ -f "${TOBIKO_CONF}" ]; then
@ -23,6 +28,7 @@ function configure_tobiko {
echo_summary "Write compute service options to ${TOBIKO_CONF}" echo_summary "Write compute service options to ${TOBIKO_CONF}"
iniset "${tobiko_conf}" nova image "$(get_image)" iniset "${tobiko_conf}" nova image "$(get_image)"
iniset "${tobiko_conf}" nova flavor "$(get_flavor)" iniset "${tobiko_conf}" nova flavor "$(get_flavor)"
iniset "${tobiko_conf}" nova key_file "${nova_key_file}"
echo_summary "Write networking options to ${TOBIKO_CONF}" echo_summary "Write networking options to ${TOBIKO_CONF}"
iniset "${tobiko_conf}" neutron floating_network \ iniset "${tobiko_conf}" neutron floating_network \

View File

@ -22,4 +22,8 @@ def register_tobiko_options(conf):
opts=[cfg.StrOpt('image', opts=[cfg.StrOpt('image',
help="Default image for new server instances"), help="Default image for new server instances"),
cfg.StrOpt('flavor', cfg.StrOpt('flavor',
help="Default flavor for new server instances")]) help="Default flavor for new server instances"),
cfg.StrOpt('key_file', default='~/.ssh/id_rsa',
help="ssh key file for new server instances"),
cfg.StrOpt('key_name', default='nova_ssh_key',
help="ssh key name for new server instances")])

View File

@ -16,6 +16,8 @@ from __future__ import absolute_import
import os import os
import six
from tobiko import config from tobiko import config
from tobiko.openstack import heat from tobiko.openstack import heat
from tobiko.openstack import neutron from tobiko.openstack import neutron
@ -110,3 +112,18 @@ class SecurityGroupsFixture(heat.HeatStackFixture):
""" """
#: Heat template file #: Heat template file
template = heat_template_file('security_groups.yaml') template = heat_template_file('security_groups.yaml')
class KeyPairFixture(heat.HeatStackFixture):
template = heat_template_file('key_pair.yaml')
key_file = os.path.expanduser(CONF.tobiko.nova.key_file)
key_name = CONF.tobiko.nova.key_name
@property
def public_key(self):
with open(self.key_file + '.pub', 'r') as fd:
key = fd.read()
if not isinstance(key, six.string_types):
# on Python 3 must convert key to string
key = key.decode()
return key

View File

@ -1,11 +1,13 @@
heat_template_version: newton heat_template_version: newton
description: | description: |
Stack of resources used to test floating IP Stack of resources used to test floating IP
parameters: parameters:
key_name:
type: string
flavor: flavor:
type: string type: string
@ -39,6 +41,7 @@ resources:
server: server:
type: OS::Nova::Server type: OS::Nova::Server
properties: properties:
key_name: {get_param: key_name}
image: {get_param: image} image: {get_param: image}
flavor: {get_param: flavor} flavor: {get_param: flavor}
networks: networks:

View File

@ -0,0 +1,18 @@
heat_template_version: 2015-04-30
description: |
Creates a nova ssh keypair
parameters:
public_key:
type: string
key_name:
type: string
default: 'nova_ssh_key'
resources:
nova_ssh_key_pair:
type: OS::Nova::KeyPair
properties:
name: {get_param: key_name}
public_key: {get_param: public_key}

View File

@ -57,8 +57,9 @@ class FloatingIPFixture(heat.HeatStackFixture):
stacks.InternalNetworkFixture) stacks.InternalNetworkFixture)
# --- class parameters --- # --- class parameters ---
#: Whenever port security on internal network is enable #: Whenever port security on internal network is enable
key_pair_stack = tobiko.required_setup_fixture(stacks.KeyPairFixture)
key_name = CONF.tobiko.nova.key_name
port_security_enabled = False port_security_enabled = False
#: Security groups to be associated to network ports #: Security groups to be associated to network ports
@ -81,6 +82,10 @@ class FloatingIPFixture(heat.HeatStackFixture):
port_security_enabled=self.port_security_enabled, port_security_enabled=self.port_security_enabled,
security_groups=self.security_groups or []) security_groups=self.security_groups or [])
def setup_stack(self):
self.key_pair_stack.wait_for_create_complete()
super(FloatingIPFixture, self).setup_stack()
class FloatingIPTest(base.TobikoTest): class FloatingIPTest(base.TobikoTest):
"""Tests connectivity to Nova instances via floating IPs""" """Tests connectivity to Nova instances via floating IPs"""