Added minimal support for running Lettuce-based inspections

This commit is contained in:
Maxim Kulkin 2013-10-16 11:32:28 +04:00
parent 7e225e4f00
commit d1997d616b
5 changed files with 98 additions and 2 deletions

View File

@ -4,7 +4,7 @@ from itertools import groupby
from ostack_validator.common import Issue, MarkedIssue, Inspection
from ostack_validator.model import OpenstackComponent
from ostack_validator.discovery import OpenstackDiscovery
from ostack_validator.inspections import KeystoneAuthtokenSettingsInspection, KeystoneEndpointsInspection
from ostack_validator.inspections import KeystoneAuthtokenSettingsInspection, KeystoneEndpointsInspection, LettuceRunnerInspection
def indent_prefix(indent=0):
s = ''
@ -62,7 +62,7 @@ def main():
openstack = discovery.discover(['172.18.65.179'], 'root', private_key=private_key)
all_inspections = [KeystoneAuthtokenSettingsInspection, KeystoneEndpointsInspection]
all_inspections = [KeystoneAuthtokenSettingsInspection, KeystoneEndpointsInspection, LettuceRunnerInspection]
for inspection in all_inspections:
x = inspection()
x.inspect(openstack)

View File

@ -1,3 +1,4 @@
from ostack_validator.inspections.keystone_authtoken import KeystoneAuthtokenSettingsInspection
from ostack_validator.inspections.keystone_endpoints import KeystoneEndpointsInspection
from ostack_validator.inspections.lettuce_runner import LettuceRunnerInspection

View File

@ -0,0 +1,8 @@
Feature: Configuration consistency
Scenario: Nova has proper Keystone host
Given I use OpenStack 2013.1
And Nova has "auth_strategy" equal to "keystone"
And Keystone addresses are @X
Then Nova should have "keystone_authtoken.auth_host" in "$X"

View File

@ -0,0 +1,67 @@
import string
from lettuce import *
from ostack_validator.common import Issue, Version, find
from ostack_validator.model import *
def get_variable(name):
if not hasattr(world, 'variables'):
return None
return world.variables.get(name)
def set_variable(name, value):
if not hasattr(world, 'variables'):
world.variables = {}
world.variables[name] = value
def subst(template):
if not hasattr(world, 'variables'):
return template
tmpl = string.Template(template)
return tmpl.safe_substitute(world.variables)
def stop():
assert False, "stop"
@step(r'I use OpenStack (\w+)')
def use_openstack_version(step, version):
version = Version(version)
for component in [c for c in world.openstack.components if isinstance(c, OpenstackComponent)]:
if not Version(component.version) >= version: stop()
@step(r'Nova has "(.+)" equal to "(.*)"')
def nova_has_property(step, name, value):
name = subst(name)
value = subst(value)
for nova in [c for c in world.openstack.components if c.name.startswith('nova')]:
if not nova.config[name] == value: stop()
@step(r'Keystone addresses are @(\w+)')
def keystone_addresses(self, variable):
keystone = find(world.openstack.components, lambda c: c.name == 'keystone')
if keystone.config['bind_host'] == '0.0.0.0':
addresses = filter(lambda ip: not ip.startswith('127.'), keystone.host.network_addresses)
else:
addresses = [keystone.config['bind_host']]
set_variable(variable, addresses)
@step(r'Nova should have "(.+)" in "(.*)"')
def nova_property_assertion(self, name, values):
name = subst(name)
values = subst(values)
if not values:
return
for nova in [c for c in world.openstack.components if c.name.startswith('nova')]:
nova_value = nova.config[name]
if not (nova_value and nova_value in values):
nova.report_issue(Issue(Issue.ERROR, 'Nova should have "%s" in %s' % (name, values)))

View File

@ -0,0 +1,20 @@
import os.path
import lettuce
from ostack_validator.common import Inspection, Issue
class LettuceRunnerInspection(Inspection):
def inspect(self, openstack):
runner = lettuce.Runner(
base_path=os.path.join(os.path.dirname(__file__), 'lettuce')
)
lettuce.world.openstack = openstack
result = runner.run()
del lettuce.world.openstack
for feature_result in result.feature_results:
for scenario_result in [s for s in feature_result.scenario_results if not s.passed]:
for step in scenario_result.steps_undefined:
openstack.report_issue(Issue(Issue.ERROR, 'Undefined step "%s"' % step.sentence))