Added Rules as a more fine grained inspections

This commit is contained in:
Maxim Kulkin 2013-10-18 15:04:18 +04:00
parent b8426b0871
commit e448620c77
4 changed files with 56 additions and 28 deletions

View File

@ -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

View File

@ -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()

View File

@ -10,3 +10,4 @@ honcho==0.4.2
jinja2==2.7
lettuce>=0.2.19
pymongo==2.6.1
recordtype==1.1

View File

@ -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/<group>')
def get_rules_group(group):