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

@@ -16,6 +16,8 @@ from __future__ import absolute_import
import os
import six
from tobiko import config
from tobiko.openstack import heat
from tobiko.openstack import neutron
@@ -110,3 +112,18 @@ class SecurityGroupsFixture(heat.HeatStackFixture):
"""
#: Heat template file
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
description: |
Stack of resources used to test floating IP
parameters:
key_name:
type: string
flavor:
type: string
@@ -39,6 +41,7 @@ resources:
server:
type: OS::Nova::Server
properties:
key_name: {get_param: key_name}
image: {get_param: image}
flavor: {get_param: flavor}
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)
# --- class parameters ---
#: 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
#: Security groups to be associated to network ports
@@ -81,6 +82,10 @@ class FloatingIPFixture(heat.HeatStackFixture):
port_security_enabled=self.port_security_enabled,
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):
"""Tests connectivity to Nova instances via floating IPs"""