Move default server fixture to new cirros module.

Change-Id: I13f5c13d1e04e90c550551e535dc5ce0404d8744
This commit is contained in:
Federico Ressi 2019-07-15 12:57:22 +02:00
parent 5acbc53823
commit 581f4ed338
11 changed files with 189 additions and 121 deletions

View File

@ -15,15 +15,19 @@
# under the License.
from __future__ import absolute_import
from tobiko.openstack.stacks import _cirros
from tobiko.openstack.stacks import _neutron
from tobiko.openstack.stacks import _nova
KeyPairStackFixture = _nova.KeyPairStackFixture
FlavorStackFixture = _nova.FlavorStackFixture
CirrosFlavorStackFixture = _nova.CirrosFlavorStackFixture
CirrosFlavorStackFixture = _cirros.CirrosFlavorStackFixture
CirrosImageFixture = _cirros.CirrosImageFixture
CirrosServerStackFixture = _cirros.CirrosServerStackFixture
NetworkStackFixture = _neutron.NetworkStackFixture
NetworkWithNetMtuWriteStackFixture = (
_neutron.NetworkWithNetMtuWriteStackFixture)
FloatingIpServerStackFixture = _neutron.FloatingIpServerStackFixture
SecurityGroupsFixture = _neutron.SecurityGroupsFixture
ServerStackFixture = _nova.ServerStackFixture
KeyPairStackFixture = _nova.KeyPairStackFixture
FlavorStackFixture = _nova.FlavorStackFixture

View File

@ -0,0 +1,49 @@
# Copyright 2019 Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import tobiko
from tobiko import config
from tobiko.openstack import glance
from tobiko.openstack.stacks import _nova
CONF = config.CONF
CIRROS_IMAGE_URL = \
'http://download.cirros-cloud.net/0.4.0/cirros-0.4.0-x86_64-disk.img'
class CirrosImageFixture(glance.URLGlanceImageFixture):
image_url = CONF.tobiko.cirros.image_url or CIRROS_IMAGE_URL
image_name = CONF.tobiko.cirros.image_name
image_file = CONF.tobiko.cirros.image_file
container_format = CONF.tobiko.cirros.container_format or "bare"
disk_format = CONF.tobiko.cirros.disk_format or "raw"
username = CONF.tobiko.cirros.username or 'cirros'
password = CONF.tobiko.cirros.password or 'gocubsgo'
class CirrosFlavorStackFixture(_nova.FlavorStackFixture):
ram = 128
class CirrosServerStackFixture(_nova.ServerStackFixture):
#: Glance image used to create a Nova server instance
image_fixture = tobiko.required_setup_fixture(CirrosImageFixture)
#: Glance image used to create a Nova server instance
flavor_stack = tobiko.required_setup_fixture(CirrosFlavorStackFixture)

View File

@ -18,14 +18,10 @@ from __future__ import absolute_import
import netaddr
from oslo_log import log
import tobiko
from tobiko import config
from tobiko.openstack import heat
from tobiko.openstack import neutron
from tobiko.openstack import images
from tobiko.openstack.stacks import _hot
from tobiko.openstack.stacks import _nova
from tobiko.shell import ssh
CONF = config.CONF
@ -153,78 +149,3 @@ class SecurityGroupsFixture(heat.HeatStackFixture):
"""
#: Heat template file
template = _hot.heat_template_file('neutron/security_groups.yaml')
@neutron.skip_if_missing_networking_extensions('port-security')
class FloatingIpServerStackFixture(heat.HeatStackFixture):
#: Heat template file
template = _hot.heat_template_file('neutron/floating_ip_server.yaml')
#: stack with the key pair for the server instance
key_pair_stack = tobiko.required_setup_fixture(
_nova.KeyPairStackFixture)
#: stack with the internal where the server port is created
network_stack = tobiko.required_setup_fixture(NetworkStackFixture)
#: Glance image used to create a Nova server instance
image_fixture = tobiko.required_setup_fixture(
images.CirrosGlanceImageFixture)
@property
def image(self):
return self.image_fixture.image_id
@property
def username(self):
"""username used to login to a Nova server instance"""
return self.image_fixture.username
@property
def password(self):
"""password used to login to a Nova server instance"""
return self.image_fixture.password
# Stack used to create flavor for Nova server instance
flavor_stack = tobiko.required_setup_fixture(
_nova.CirrosFlavorStackFixture)
@property
def flavor(self):
"""Flavor for Nova server instance"""
return self.flavor_stack.flavor_id
#: Whenever port security on internal network is enable
port_security_enabled = False
#: Security groups to be associated to network ports
security_groups = []
@property
def key_name(self):
return self.key_pair_stack.key_name
@property
def network(self):
return self.network_stack.network_id
#: Floating IP network where the Neutron floating IP is created
floating_network = CONF.tobiko.neutron.floating_network
@property
def has_floating_ip(self):
return bool(self.floating_network)
@property
def ssh_client(self):
return ssh.ssh_client(
host=self.floating_ip_address,
username=self.username,
password=self.password)
@property
def ssh_command(self):
return ssh.ssh_command(
host=self.floating_ip_address,
username=self.username)

View File

@ -19,9 +19,13 @@ import os
import six
import tobiko
from tobiko import config
from tobiko.openstack import heat
from tobiko.openstack import neutron
from tobiko.openstack.stacks import _hot
from tobiko.openstack.stacks import _neutron
from tobiko.shell import ssh
CONF = config.CONF
@ -57,8 +61,75 @@ class FlavorStackFixture(heat.HeatStackFixture):
vcpus = None
class CirrosFlavorStackFixture(FlavorStackFixture):
ram = 128
@neutron.skip_if_missing_networking_extensions('port-security')
class ServerStackFixture(heat.HeatStackFixture):
#: Heat template file
template = _hot.heat_template_file('neutron/floating_ip_server.yaml')
#: stack with the key pair for the server instance
key_pair_stack = tobiko.required_setup_fixture(KeyPairStackFixture)
#: stack with the internal where the server port is created
network_stack = tobiko.required_setup_fixture(_neutron.NetworkStackFixture)
#: Glance image used to create a Nova server instance
image_fixture = None
@property
def image(self):
return self.image_fixture.image_id
@property
def username(self):
"""username used to login to a Nova server instance"""
return self.image_fixture.username
@property
def password(self):
"""password used to login to a Nova server instance"""
return self.image_fixture.password
# Stack used to create flavor for Nova server instance
flavor_stack = None
@property
def flavor(self):
"""Flavor for Nova server instance"""
return self.flavor_stack.flavor_id
#: Whenever port security on internal network is enable
port_security_enabled = False
#: Security groups to be associated to network ports
security_groups = []
@property
def key_name(self):
return self.key_pair_stack.key_name
@property
def network(self):
return self.network_stack.network_id
#: Floating IP network where the Neutron floating IP is created
floating_network = CONF.tobiko.neutron.floating_network
@property
def has_floating_ip(self):
return bool(self.floating_network)
@property
def ssh_client(self):
client = ssh.ssh_client(host=self.floating_ip_address,
username=self.username,
password=self.password)
return client
@property
def ssh_command(self):
return ssh.ssh_command(host=self.floating_ip_address,
username=self.username)
def as_str(text):

View File

@ -0,0 +1,51 @@
# Copyright (c) 2019 Red Hat, Inc.
#
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from __future__ import absolute_import
import testtools
import tobiko
from tobiko.openstack import stacks
from tobiko.shell import ping
from tobiko.shell import sh
class CirrosServerStackTest(testtools.TestCase):
"""Tests connectivity to Nova instances via floating IPs"""
#: Stack of resources with a server attached to a floating IP
stack = tobiko.required_setup_fixture(stacks.CirrosServerStackFixture)
def test_ping(self):
"""Test connectivity to floating IP address"""
ping.ping_until_received(
self.stack.floating_ip_address).assert_replied()
def test_ssh_connect(self):
"""Test SSH connectivity via Paramiko SSHClient"""
self.stack.ssh_client.connect()
def test_ssh_command(self):
"""Test SSH connectivity via OpenSSH client"""
sh.execute('true', shell=self.stack.ssh_command)
def test_hostname(self):
"""Test that hostname of instance server matches Nova server name"""
self.stack.ssh_client.connect()
hostname, = sh.execute(
'hostname', ssh_client=self.stack.ssh_client).stdout.splitlines()
self.assertEqual(hostname, self.stack.server_name)

View File

@ -20,8 +20,6 @@ import testtools
import tobiko
from tobiko.openstack import neutron
from tobiko.openstack import stacks
from tobiko.shell import ping
from tobiko.shell import sh
class NetworkTestCase(testtools.TestCase):
@ -93,29 +91,3 @@ class NetworkWithNetMtuWriteTestCase(NetworkTestCase):
def test_net_mtu_write(self):
self.assertEqual(self.stack.mtu, self.stack.outputs.mtu)
class FloatingIpServerTest(testtools.TestCase):
"""Tests connectivity to Nova instances via floating IPs"""
#: Stack of resources with a server attached to a floating IP
stack = tobiko.required_setup_fixture(stacks.FloatingIpServerStackFixture)
def test_ping(self):
"""Test connectivity to floating IP address"""
ping.ping_until_received(
self.stack.floating_ip_address).assert_replied()
def test_ssh_connect(self):
"""Test SSH connectivity via Paramiko SSHClient"""
self.stack.ssh_client.connect()
def test_ssh_command(self):
"""Test SSH connectivity via OpenSSH client"""
sh.execute('true', shell=self.stack.ssh_command)
def test_hostname(self):
"""Test that hostname of instance server matches Nova server name"""
result = sh.execute('hostname', ssh_client=self.stack.ssh_client)
hostname, = str(result.stdout).splitlines()
self.assertEqual(hostname, self.stack.server_name)

View File

@ -19,14 +19,14 @@ import testtools
import tobiko
from tobiko.openstack import glance
from tobiko.openstack import images
from tobiko.openstack import stacks
class GlanceApiTestCase(testtools.TestCase):
"""Tests glance images API"""
#: Stack of resources with a network with a gateway router
fixture = tobiko.required_setup_fixture(images.CirrosGlanceImageFixture)
fixture = tobiko.required_setup_fixture(stacks.CirrosImageFixture)
def test_get_image(self):
image = glance.get_image(self.fixture.image_id)

View File

@ -163,7 +163,7 @@ class LocalExecuteTest(ExecuteTest):
class SSHExecuteTest(ExecuteTest):
server_stack = tobiko.required_setup_fixture(
stacks.FloatingIpServerStackFixture)
stacks.CirrosServerStackFixture)
@property
def ssh_client(self):
@ -177,7 +177,7 @@ class SSHExecuteTest(ExecuteTest):
class ExecuteWithSSHCommandTest(ExecuteTest):
server_stack = tobiko.required_setup_fixture(
stacks.FloatingIpServerStackFixture)
stacks.CirrosServerStackFixture)
@property
def shell(self):

View File

@ -30,7 +30,7 @@ class FloatingIPTest(base.TobikoTest):
"""Tests connectivity via floating IPs"""
#: Resources stack with floating IP and Nova server
stack = tobiko.required_setup_fixture(stacks.FloatingIpServerStackFixture)
stack = tobiko.required_setup_fixture(stacks.CirrosServerStackFixture)
def test_stack_create_complete(self):
self.stack.key_pair_stack.wait_for_create_complete()
@ -118,7 +118,7 @@ class FloatingIPTest(base.TobikoTest):
@neutron.skip_if_missing_networking_extensions('port-security',
'security-group')
class FloatingIPWithPortSecurityFixture(stacks.FloatingIpServerStackFixture):
class FloatingIPWithPortSecurityFixture(stacks.CirrosServerStackFixture):
"""Heat stack for testing a floating IP instance with port security"""
#: Resources stack with security group to allow ping Nova servers
@ -199,7 +199,7 @@ class FloatingIPWithICMPSecurityGroupTest(FloatingIPTest):
# --- Test net-mtu-write extension --------------------------------------------
@neutron.skip_if_missing_networking_extensions('net-mtu-writable')
class FloatingIPWithNetMtuWritableFixture(stacks.FloatingIpServerStackFixture):
class FloatingIPWithNetMtuWritableFixture(stacks.CirrosServerStackFixture):
"""Heat stack for testing floating IP with a custom MTU network value"""
#: Heat stack for creating internal network with custom MTU value

View File

@ -23,7 +23,7 @@ from tobiko.openstack import nova
class ServerStackResourcesTest(testtools.TestCase):
stack = tobiko.required_setup_fixture(stacks.FloatingIpServerStackFixture)
stack = tobiko.required_setup_fixture(stacks.CirrosServerStackFixture)
def test_server(self):
"Test actual server details"