Add two tests for testing instance connectivity

One for pre upgrade (creating the stack and all the related
resources) and for post upgrade to verify it's still reachable.

Change-Id: Iffda72ac5e61ef96444faef443aefee2fde106e2
This commit is contained in:
abregman 2018-08-15 10:29:16 +03:00
parent 4b3a02a3cd
commit 31a6360210
3 changed files with 140 additions and 0 deletions

26
tobiko/tests/base.py Normal file
View File

@ -0,0 +1,26 @@
# Copyright (c) 2018 Red Hat
# 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 tempest import config
import testscenarios
import testtools
class TobikoTest(testtools.testcase.WithAttributes,
testscenarios.WithScenarios,
testtools.TestCase):
def setUp(self):
super(TobikoTest, self).setUp()
self.conf = config.CONF.tobiko_plugin

View File

@ -0,0 +1,60 @@
# Copyright (c) 2018 Red Hat
# 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.
import os
import subprocess
from tempest.common.utils import net_utils
from tempest.lib.common.utils import test_utils
from tobiko.tests import base
from tobiko.common import stack
from tobiko.common import clients
class ScenarioTestsBase(base.TobikoTest):
"""All scenario tests inherit from this scenario base class."""
def setUp(self):
super(ScenarioTestsBase, self).setUp()
self.clientManager = clients.ClientManager()
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
self.stackManager = stack.StackManager(self.clientManager,
templates_dir)
def ping_ip_address(self, ip_address, should_succeed=True,
ping_timeout=None, mtu=None):
timeout = ping_timeout or 120
cmd = ['ping', '-c1', '-w1']
if mtu:
cmd += [
# don't fragment
'-M', 'do',
# ping receives just the size of ICMP payload
'-s', str(net_utils.get_ping_payload_size(mtu, 4))
]
cmd.append(ip_address)
def ping():
proc = subprocess.Popen(cmd,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
proc.communicate()
return (proc.returncode == 0) == should_succeed
result = test_utils.call_until_true(ping, timeout, 1)
return result

View File

@ -0,0 +1,54 @@
# Copyright (c) 2018 Red Hat
# 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 tobiko.tests.scenario import base
class FloatingIPTest(base.ScenarioTestsBase):
"""Tests server connectivity"""
def test_pre_fip(self):
"""Creates a server and checks it can reach it."""
# Defines parameters required by heat template
parameters = {'public_net': self.conf.floating_network_name,
'image': "cirros-0.3.5-x86_64-disk.img",
'flavor': "m1.tiny"}
# creates stack and stores its ID
st = self.stackManager.create_stack(stack_name="fip",
template_name="fip.yaml",
parameters=parameters)
sid = st['stack']['id']
# Before pinging the floating IP, ensure resource is ready
self.stackManager.wait_for_status_complete(sid, 'floating_ip')
# Get floating IP address
stack = self.stackManager.client.stacks.get(sid)
server_fip = stack.outputs[0]['output_value']
# Check if instance is reachable
if not self.ping_ip_address(server_fip):
self.fail("IP address is not reachable: %s" % server_fip)
def test_post_fip(self):
"""Validates connectivity to a server created by another test."""
stack = self.stackManager.get_stack(stack_name="fip")
server_fip = stack.outputs[0]['output_value']
# Check if instance is reachable
if not self.ping_ip_address(server_fip):
self.fail("IP address is not reachable: %s" % server_fip)