Add support for faults
Added: * Faults manager - a compnent for managing faults (load them, connect os-faults to cloud, exdcute faults, etc.). * Faults for test_floatingip test class Also, modified test_floatingip tests to run faults if faults manager set up properly (loaded configuration file, managed to connect the nodes of the cloud, etc.). Change-Id: I1dd48bc9a7cc385a46d9b3b2382000581a614b42
This commit is contained in:
parent
280f7d5e1d
commit
b0c1da528f
3
Pipfile
3
Pipfile
@ -4,8 +4,9 @@ verify_ssl = true
|
||||
name = "pypi"
|
||||
|
||||
[packages]
|
||||
tobiko = {editable = true, path = "."}
|
||||
tobiko = {editable = true,path = "."}
|
||||
ansible = "*"
|
||||
testscenarios = "*"
|
||||
|
||||
[dev-packages]
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
# Optional tobiko requirements
|
||||
# Tobiko extra requirements
|
||||
|
||||
ansible>=2.4.0 # GPLv3
|
||||
os-faults>=0.1.18 # Apache-2.0
|
||||
tempest>=17.1.0 # Apache-2.0
|
||||
|
@ -7,3 +7,4 @@ python-heatclient>=1.5.0 # Apache-2.0
|
||||
python-neutronclient>=6.7.0 # Apache-2.0
|
||||
stestr>=2.0 # Apache-2.0
|
||||
testtools>=2.2.0 # MIT
|
||||
testscenarios>=0.4 # Apache-2.0/BSD
|
||||
|
72
tobiko/common/managers/fault.py
Normal file
72
tobiko/common/managers/fault.py
Normal file
@ -0,0 +1,72 @@
|
||||
# Copyright 2018 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 os
|
||||
|
||||
import os_faults
|
||||
import yaml
|
||||
|
||||
from oslo_log import log
|
||||
|
||||
LOG = log.getLogger(__name__)
|
||||
|
||||
try:
|
||||
FileNotFoundError
|
||||
except NameError:
|
||||
FileNotFoundError = IOError # pylint: disable=redefined-builtin
|
||||
|
||||
CONF_DIR = os.path.expanduser('~')
|
||||
CONF_FILE = 'os-faults.yaml'
|
||||
|
||||
|
||||
class FaultManager():
|
||||
"""Manages faults."""
|
||||
|
||||
def __init__(self, test_file):
|
||||
self.faults_dir = os.path.join(os.path.dirname(test_file), 'faults')
|
||||
faults_f_name = os.path.splitext(os.path.basename(test_file))[0]
|
||||
self.faults_file = os.path.join(self.faults_dir, faults_f_name)
|
||||
fault_config_f = os.path.join(CONF_DIR, CONF_FILE)
|
||||
try:
|
||||
self.cloud = os_faults.connect(config_filename=fault_config_f)
|
||||
self.cloud.verify()
|
||||
self.scenarios = self.get_scenarios()
|
||||
except os_faults.ansible.executor.AnsibleExecutionUnreachable:
|
||||
LOG.warning("Couldn't verify connectivity to the"
|
||||
" cloud with os-faults configuration")
|
||||
self.scenarios = None
|
||||
except FileNotFoundError:
|
||||
LOG.warning("Couldn't find os-faults configuration file")
|
||||
self.scenarios = None
|
||||
|
||||
def get_scenarios(self):
|
||||
"""Returns list of scenarios based on defined faults.
|
||||
|
||||
A scenario composed out of scenario name and the fault to execute.
|
||||
"""
|
||||
scenarios = []
|
||||
with open(self.faults_file, 'r') as stream:
|
||||
faults_yaml = yaml.load(stream)
|
||||
for fault in faults_yaml:
|
||||
scenarios.append((fault['name'], dict(fault=fault['action'])))
|
||||
return scenarios
|
||||
|
||||
def run_fault(self, fault):
|
||||
"""Executes given fault."""
|
||||
if self.scenarios:
|
||||
os_faults.human_api(self.cloud, fault)
|
||||
else:
|
||||
LOG.debug("Skipped fault: '{}' since".format(fault),
|
||||
" scenarios are not defined.")
|
@ -73,7 +73,7 @@ FIXTURES = FixtureManager()
|
||||
|
||||
class FixtureMeta(abc.ABCMeta):
|
||||
|
||||
def __new__(cls, name, bases, members):
|
||||
def __new__(cls, name, bases, members): # pylint: disable=arguments-differ
|
||||
fixture_class = super(FixtureMeta, cls).__new__(cls, name, bases,
|
||||
members)
|
||||
if not inspect.isabstract(fixture_class):
|
||||
|
@ -32,6 +32,7 @@ class ScenarioTestsBase(base.TobikoTest):
|
||||
templates_dir = os.path.join(os.path.dirname(__file__), 'templates')
|
||||
stacks = stack_manager.StackManager(clients, templates_dir)
|
||||
stack = None
|
||||
fault = None
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
|
2
tobiko/tests/scenario/faults/test_floatingip
Normal file
2
tobiko/tests/scenario/faults/test_floatingip
Normal file
@ -0,0 +1,2 @@
|
||||
- name: 'Restart OVS'
|
||||
action: 'restart openvswitch service'
|
@ -14,13 +14,24 @@
|
||||
# under the License.
|
||||
from __future__ import absolute_import
|
||||
|
||||
import testscenarios
|
||||
from testscenarios.scenarios import multiply_scenarios
|
||||
|
||||
from tobiko.tests.scenario import base
|
||||
from tobiko.common.asserts import assert_ping
|
||||
from tobiko.common.managers import fault
|
||||
|
||||
load_tests = testscenarios.load_tests_apply_scenarios
|
||||
|
||||
|
||||
class FloatingIPTest(base.ScenarioTestsBase):
|
||||
"""Tests server connectivity"""
|
||||
|
||||
fault_manager = fault.FaultManager(__file__)
|
||||
test_faults = fault_manager.scenarios
|
||||
if test_faults:
|
||||
scenarios = multiply_scenarios(test_faults)
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(FloatingIPTest, cls).setUpClass()
|
||||
@ -29,7 +40,9 @@ class FloatingIPTest(base.ScenarioTestsBase):
|
||||
|
||||
def test_ping_floating_ip(self):
|
||||
"""Validates connectivity to a server post upgrade."""
|
||||
self.fault_manager.run_fault(self.fault)
|
||||
assert_ping(self.fip)
|
||||
|
||||
def test_ping_unreachable_floating_ip(self):
|
||||
self.fault_manager.run_fault(self.fault)
|
||||
assert_ping(self.unreachable_fip, should_fail=True)
|
||||
|
Loading…
x
Reference in New Issue
Block a user