From 63162060054aba36b5b5722cc6d0109437951905 Mon Sep 17 00:00:00 2001 From: Paul Belanger Date: Mon, 19 Oct 2015 22:06:20 -0400 Subject: [PATCH] Disable cache for cmd testcases Right now, we don't actually need a cache for our current tests, so for now we'll disable it. Future cmd tests, will enable this making sure we have the proper coverage. Change-Id: If7a25c3281fd57257473054348555aa06b5b6d95 Signed-off-by: Paul Belanger --- grafana_dashboards/cache.py | 4 +++- grafana_dashboards/parser.py | 7 ++++++- tests/cmd/base.py | 8 +++++++- tests/fixtures/cmd/grafyaml.conf | 5 +++++ 4 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 tests/fixtures/cmd/grafyaml.conf diff --git a/grafana_dashboards/cache.py b/grafana_dashboards/cache.py index 17f3268..6fe21eb 100644 --- a/grafana_dashboards/cache.py +++ b/grafana_dashboards/cache.py @@ -24,10 +24,12 @@ class Cache(object): def __init__(self, cachedir): cache_dir = self._get_cache_dir(cachedir) + filename = os.path.join(cache_dir, 'cache.dbm') + LOG.debug('Using cache: %s' % filename) self.region = make_region().configure( 'dogpile.cache.dbm', arguments={ - 'filename': os.path.join(cache_dir, 'cache.dbm') + 'filename': filename, } ) diff --git a/grafana_dashboards/parser.py b/grafana_dashboards/parser.py index f51ab48..6f17df6 100644 --- a/grafana_dashboards/parser.py +++ b/grafana_dashboards/parser.py @@ -15,12 +15,15 @@ import hashlib import io import json +import logging import yaml from slugify import slugify from grafana_dashboards.schema.dashboard import Dashboard +LOG = logging.getLogger(__name__) + class YamlParser(object): @@ -31,8 +34,10 @@ class YamlParser(object): data = self.data.get('dashboard', {}).get(slug, None) md5 = None if data: - content = json.dumps(data) + # Sort json keys to help our md5 hash are constant. + content = json.dumps(data, sort_keys=True) md5 = hashlib.md5(content.encode('utf-8')).hexdigest() + LOG.debug('Dashboard %s: %s' % (slug, md5)) return data, md5 diff --git a/tests/cmd/base.py b/tests/cmd/base.py index 37da17c..3124209 100644 --- a/tests/cmd/base.py +++ b/tests/cmd/base.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import os import sys import fixtures @@ -22,6 +23,8 @@ from tests.base import TestCase class TestCase(TestCase): + configfile = os.path.join( + os.path.dirname(__file__), 'fixtures/cmd/grafyaml.conf') def shell(self, argstr, exitcodes=(0,)): orig = sys.stdout @@ -29,7 +32,10 @@ class TestCase(TestCase): try: sys.stdout = six.StringIO() sys.stderr = six.StringIO() - argv = ['grafana-dashboards'] + argv = [ + 'grafana-dashboards', + '--config-file=%s' % self.configfile, + ] argv += argstr.split() self.useFixture(fixtures.MonkeyPatch('sys.argv', argv)) cmd.main() diff --git a/tests/fixtures/cmd/grafyaml.conf b/tests/fixtures/cmd/grafyaml.conf new file mode 100644 index 0000000..fbf6b94 --- /dev/null +++ b/tests/fixtures/cmd/grafyaml.conf @@ -0,0 +1,5 @@ +[grafana] +url = http://grafana.example.org + +[cache] +enabled = false