Initial commit of schema
Here we are using voluptuous to help validate our yaml files. Right now we we just have support for text panels, but it is a start. Signed-off-by: Paul Belanger <pabelanger@redhat.com>
This commit is contained in:
parent
f65385a578
commit
71e14b74f2
42
grafana_dashboards/schema/panel.py
Normal file
42
grafana_dashboards/schema/panel.py
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
# Copyright 2015 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# 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 voluptuous as v
|
||||||
|
|
||||||
|
|
||||||
|
class BasePanel(object):
|
||||||
|
|
||||||
|
def validate(self, data):
|
||||||
|
panel = {
|
||||||
|
v.Required('editable', default=True): v.All(bool),
|
||||||
|
v.Required('error', default=False): v.All(bool),
|
||||||
|
v.Required('span', default=12): v.All(int, v.Range(min=0, max=12)),
|
||||||
|
v.Required('title'): v.All(str, v.Length(min=1)),
|
||||||
|
v.Required('type'): v.All(str),
|
||||||
|
v.Optional('id'): int,
|
||||||
|
}
|
||||||
|
panel.update(self.fields)
|
||||||
|
schema = v.Schema({
|
||||||
|
'panels': [panel]
|
||||||
|
})
|
||||||
|
|
||||||
|
return schema(data)
|
||||||
|
|
||||||
|
|
||||||
|
class Text(BasePanel):
|
||||||
|
fields = {
|
||||||
|
v.Required('content'): v.All(str),
|
||||||
|
v.Required('mode'): v.All(str),
|
||||||
|
v.Optional('style'): dict(),
|
||||||
|
}
|
@ -1,28 +0,0 @@
|
|||||||
# -*- coding: utf-8 -*-
|
|
||||||
|
|
||||||
# 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.
|
|
||||||
|
|
||||||
"""
|
|
||||||
test_grafana_dashboards
|
|
||||||
----------------------------------
|
|
||||||
|
|
||||||
Tests for `grafana_dashboards` module.
|
|
||||||
"""
|
|
||||||
|
|
||||||
from grafana_dashboards.tests import base
|
|
||||||
|
|
||||||
|
|
||||||
class TestGrafana_dashboards(base.TestCase):
|
|
||||||
|
|
||||||
def test_something(self):
|
|
||||||
pass
|
|
@ -4,3 +4,6 @@
|
|||||||
|
|
||||||
pbr>=0.6,!=0.7,<1.0
|
pbr>=0.6,!=0.7,<1.0
|
||||||
Babel>=1.3
|
Babel>=1.3
|
||||||
|
|
||||||
|
PyYAML>=3.1.0
|
||||||
|
voluptuous>=0.7
|
||||||
|
0
tests/__init__.py
Normal file
0
tests/__init__.py
Normal file
0
tests/schema/__init__.py
Normal file
0
tests/schema/__init__.py
Normal file
10
tests/schema/fixtures/text-no-title.yaml
Normal file
10
tests/schema/fixtures/text-no-title.yaml
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
panels:
|
||||||
|
- type: text
|
||||||
|
title: no title (click here)
|
||||||
|
error: false
|
||||||
|
editable: true
|
||||||
|
span: 12
|
||||||
|
id: 1
|
||||||
|
mode: markdown
|
||||||
|
content: ''
|
||||||
|
style: {}
|
32
tests/schema/test_panel.py
Normal file
32
tests/schema/test_panel.py
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
# Copyright 2015 Red Hat, Inc.
|
||||||
|
#
|
||||||
|
# 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 yaml
|
||||||
|
|
||||||
|
from testtools import TestCase
|
||||||
|
|
||||||
|
from grafana_dashboards.schema import panel
|
||||||
|
|
||||||
|
FIXTURE_DIR = os.path.join(os.path.dirname(__file__),
|
||||||
|
'fixtures')
|
||||||
|
|
||||||
|
|
||||||
|
class TestCaseSchemaPanel(TestCase):
|
||||||
|
def test_layouts(self):
|
||||||
|
for fn in os.listdir(os.path.join(FIXTURE_DIR)):
|
||||||
|
layout = os.path.join(FIXTURE_DIR, fn)
|
||||||
|
data = yaml.load(open(layout))
|
||||||
|
schema = panel.Text()
|
||||||
|
schema.validate(data)
|
Loading…
Reference in New Issue
Block a user