Update shared fixture classes.

- fix writing to local process STDIN
- rename shared fixture classes
- add a sample test_floating_ip test case

Change-Id: I8cd7349dafa06526a1fae31d12313c7622832354
This commit is contained in:
Federico Ressi 2019-06-07 09:39:26 +02:00
parent 3ade57be61
commit 96065e0c2a
9 changed files with 55 additions and 19 deletions

View File

@ -18,7 +18,7 @@ from __future__ import absolute_import
from tobiko.openstack.stacks import _neutron
from tobiko.openstack.stacks import _nova
NovaKeyPairStackFixture = _nova.NovaKeyPairStackFixture
KeyPairStackFixture = _nova.KeyPairStackFixture
NeutronNetworkStackFixture = _neutron.NeutronNetworkStackFixture
NeutronServerStackFixture = _neutron.NeutronServerStackFixture
NetworkStackFixture = _neutron.NetworkStackFixture
FloatingIpServerStackFixture = _neutron.FloatingIpServerStackFixture

View File

@ -27,7 +27,7 @@ from tobiko.shell import ssh
CONF = config.CONF
class NeutronNetworkStackFixture(heat.HeatStackFixture):
class NetworkStackFixture(heat.HeatStackFixture):
"""Heat stack for creating internal network with a router to external
"""
@ -57,14 +57,14 @@ class NeutronNetworkStackFixture(heat.HeatStackFixture):
return bool(self.gateway_network)
class NeutronServerStackFixture(heat.HeatStackFixture):
class FloatingIpServerStackFixture(heat.HeatStackFixture):
#: Heat template file
template = _hot.heat_template_file('neutron/server.yaml')
key_pair_stack = tobiko.required_setup_fixture(
_nova.NovaKeyPairStackFixture)
network_stack = tobiko.required_setup_fixture(NeutronNetworkStackFixture)
_nova.KeyPairStackFixture)
network_stack = tobiko.required_setup_fixture(NetworkStackFixture)
#: Glance image used to create a Nova server instance
image = CONF.tobiko.nova.image

View File

@ -27,7 +27,7 @@ from tobiko.openstack.stacks import _hot
CONF = config.CONF
class NovaKeyPairStackFixture(heat.HeatStackFixture):
class KeyPairStackFixture(heat.HeatStackFixture):
template = _hot.heat_template_file('nova/key_pair.yaml')
key_file = os.path.expanduser(CONF.tobiko.nova.key_file)
public_key = None
@ -35,7 +35,7 @@ class NovaKeyPairStackFixture(heat.HeatStackFixture):
def setup_fixture(self):
self.read_keys()
super(NovaKeyPairStackFixture, self).setup_fixture()
super(KeyPairStackFixture, self).setup_fixture()
def read_keys(self):
with open(self.key_file, 'r') as fd:

View File

@ -299,10 +299,6 @@ class StdinSSHChannelFile(SSHChannelFile):
def write_ready(self):
return self.channel.send_ready()
def write(self, data):
super(StdinSSHChannelFile, self).write(data)
return len(data)
class StdoutSSHChannelFile(SSHChannelFile):

View File

@ -109,9 +109,11 @@ class ShellWritable(ShellIOBase):
def writable(self):
return True
def write(self, chunk):
witten_bytes = self.delegate.write(chunk)
self._data_chunks.append(chunk)
def write(self, data):
witten_bytes = self.delegate.write(data)
if witten_bytes is None:
witten_bytes = len(data)
self._data_chunks.append(data)
return witten_bytes
@property

View File

@ -0,0 +1,38 @@
# 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
class FloatingIPTest(testtools.TestCase):
"""Tests connectivity to Nova instances via floating IPs"""
floating_ip_stack = tobiko.required_setup_fixture(
stacks.FloatingIpServerStackFixture)
@property
def floating_ip_address(self):
"""Floating IP address"""
return self.floating_ip_stack.outputs.floating_ip_address
def test_ping(self):
"""Test connectivity to floating IP address"""
ping.ping_until_received(self.floating_ip_address).assert_replied()

View File

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

View File

@ -65,7 +65,7 @@ class FloatingIPFixture(heat.HeatStackFixture):
# --- class parameters ---
#: Whenever port security on internal network is enable
key_pair_stack = tobiko.required_setup_fixture(
stacks.NovaKeyPairStackFixture)
stacks.KeyPairStackFixture)
port_security_enabled = False
#: Security groups to be associated to network ports