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 <pabelanger@redhat.com>
This commit is contained in:
Paul Belanger 2015-10-19 22:06:20 -04:00
parent 319600e106
commit 6316206005
4 changed files with 21 additions and 3 deletions

View File

@ -24,10 +24,12 @@ class Cache(object):
def __init__(self, cachedir): def __init__(self, cachedir):
cache_dir = self._get_cache_dir(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( self.region = make_region().configure(
'dogpile.cache.dbm', 'dogpile.cache.dbm',
arguments={ arguments={
'filename': os.path.join(cache_dir, 'cache.dbm') 'filename': filename,
} }
) )

View File

@ -15,12 +15,15 @@
import hashlib import hashlib
import io import io
import json import json
import logging
import yaml import yaml
from slugify import slugify from slugify import slugify
from grafana_dashboards.schema.dashboard import Dashboard from grafana_dashboards.schema.dashboard import Dashboard
LOG = logging.getLogger(__name__)
class YamlParser(object): class YamlParser(object):
@ -31,8 +34,10 @@ class YamlParser(object):
data = self.data.get('dashboard', {}).get(slug, None) data = self.data.get('dashboard', {}).get(slug, None)
md5 = None md5 = None
if data: 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() md5 = hashlib.md5(content.encode('utf-8')).hexdigest()
LOG.debug('Dashboard %s: %s' % (slug, md5))
return data, md5 return data, md5

View File

@ -12,6 +12,7 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
import os
import sys import sys
import fixtures import fixtures
@ -22,6 +23,8 @@ from tests.base import TestCase
class TestCase(TestCase): class TestCase(TestCase):
configfile = os.path.join(
os.path.dirname(__file__), 'fixtures/cmd/grafyaml.conf')
def shell(self, argstr, exitcodes=(0,)): def shell(self, argstr, exitcodes=(0,)):
orig = sys.stdout orig = sys.stdout
@ -29,7 +32,10 @@ class TestCase(TestCase):
try: try:
sys.stdout = six.StringIO() sys.stdout = six.StringIO()
sys.stderr = six.StringIO() sys.stderr = six.StringIO()
argv = ['grafana-dashboards'] argv = [
'grafana-dashboards',
'--config-file=%s' % self.configfile,
]
argv += argstr.split() argv += argstr.split()
self.useFixture(fixtures.MonkeyPatch('sys.argv', argv)) self.useFixture(fixtures.MonkeyPatch('sys.argv', argv))
cmd.main() cmd.main()

5
tests/fixtures/cmd/grafyaml.conf vendored Normal file
View File

@ -0,0 +1,5 @@
[grafana]
url = http://grafana.example.org
[cache]
enabled = false