From e448620c77912c7833e04dd097740596f7c18237 Mon Sep 17 00:00:00 2001 From: Maxim Kulkin Date: Fri, 18 Oct 2013 15:04:18 +0400 Subject: [PATCH] Added Rules as a more fine grained inspections --- ostack_validator/common.py | 15 +++++- .../inspections/lettuce_runner.py | 19 +++++-- requirements.txt | 1 + webui.py | 49 ++++++++++--------- 4 files changed, 56 insertions(+), 28 deletions(-) diff --git a/ostack_validator/common.py b/ostack_validator/common.py index 1566d16..5bd1cb7 100644 --- a/ostack_validator/common.py +++ b/ostack_validator/common.py @@ -1,4 +1,7 @@ import copy +import os.path + +from recordtype import recordtype def find(l, predicate): @@ -24,7 +27,7 @@ def all_subclasses(klass): def path_relative_to(path, base_path): if not path.startswith('/'): - path = os.path.join(base_path, paste_config_path) + path = os.path.join(base_path, path) return path @@ -178,11 +181,21 @@ class MarkedIssue(Issue): ) +Rule = recordtype('Rule', ['name', 'description']) + + class Inspection(object): @classmethod def all_inspections(klass): return [c for c in all_subclasses(klass)] + @classmethod + def rules(klass): + if hasattr(klass, 'name') and hasattr(klass, 'description'): + return [Rule(klass.name, klass.description)] + else: + return [] + def inspect(self, openstack): pass diff --git a/ostack_validator/inspections/lettuce_runner.py b/ostack_validator/inspections/lettuce_runner.py index 54dbb04..7a7a74a 100644 --- a/ostack_validator/inspections/lettuce_runner.py +++ b/ostack_validator/inspections/lettuce_runner.py @@ -1,15 +1,26 @@ import os.path import lettuce +import lettuce.fs -from ostack_validator.common import Inspection, Issue +from ostack_validator.common import Inspection, Rule, Issue class LettuceRunnerInspection(Inspection): + base_path = os.path.join(os.path.dirname(__file__), 'lettuce') + + @classmethod + def rules(klass): + rules = [] + + loader = lettuce.fs.FeatureLoader(klass.base_path) + for path in loader.find_feature_files(): + feature = lettuce.Feature.from_file(path) + for scenario in feature.scenarios: + rules.append(Rule(scenario.name, + "\n".join(scenario.remaining_lines))) def inspect(self, openstack): - runner = lettuce.Runner( - base_path=os.path.join(os.path.dirname(__file__), 'lettuce') - ) + runner = lettuce.Runner(base_path=self.base_path) lettuce.world.openstack = openstack result = runner.run() diff --git a/requirements.txt b/requirements.txt index abada26..dc5e514 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,3 +10,4 @@ honcho==0.4.2 jinja2==2.7 lettuce>=0.2.19 pymongo==2.6.1 +recordtype==1.1 diff --git a/webui.py b/webui.py index f535d53..de1047e 100644 --- a/webui.py +++ b/webui.py @@ -8,17 +8,16 @@ from wtforms import StringField, TextAreaField, SubmitField, SelectMultipleField from wtforms.validators import DataRequired import wtforms_json from pymongo import MongoClient +from recordtype import recordtype from ostack_validator.celery import app as celery, ostack_inspect_task, InspectionRequest -from ostack_validator.common import Issue, MarkedIssue +from ostack_validator.common import Inspection, Issue, MarkedIssue from ostack_validator.model import Openstack -app = Flask(__name__, static_folder='config-validator-ui-concept', static_url_path='/static') +app = Flask(__name__, + static_folder='config-validator-ui-concept', + static_url_path='/static') Bootstrap(app) -app.debug = True -app.config.update( - WTF_CSRF_SECRET_KEY='foo bar baz' -) app.secret_key = 'A0Zr98j/3fooN]LWX/,?RT' wtforms_json.init() @@ -160,6 +159,7 @@ def to_label(s): def index(): return send_file(os.path.join(app.static_folder, 'index.html')) + @app.route('/clusters') def get_clusters(): db = get_db() @@ -182,23 +182,26 @@ def add_cluster(): @app.route('/rules') def get_rules(): - db = get_db() - rules = [Rule.from_doc(doc) for doc in db['rules'].find()] - rules = [ - Rule('rule1', RuleGroup.VALIDITY, 'Nova has proper Keystone host', - """Given I use OpenStack Grizzly 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" """ - ), - Rule('rule1', RuleGroup.VALIDITY, 'Nova has proper Keystone host', - """Given I use OpenStack Grizzly 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" """ - ) - ] - return json.dumps(rules) + rules = [] + for inspection in Inspection.all_inspections(): + rules.extend(inspection.rules()) + +# rules = [Rule.from_doc(doc) for doc in db['rules'].find()] +# rules = [ +# Rule(id='rule1', group=RuleGroup.VALIDITY, +# name='Nova has proper Keystone host', +# description="""Given I use OpenStack Grizzly 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" """), +# Rule(id='rule1', group=RuleGroup.VALIDITY, +# name='Nova has proper Keystone host', +# description="""Given I use OpenStack Grizzly 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" """)] + return json.dumps(rules) + @app.route('/rules/') def get_rules_group(group):