0

I'm trying to run graphite tests on a more-or-less stock Graphite installation.

This means I'm in directory /opt/graphite/webapp and invoking a single test:

python manage.py test --settings=tests.settings -p "test_finders.py" -v 3 --traceback

The error occurs no matter what file (e.g., above, "test_finders.py" or not) I use.

The error text returned is:

/usr/lib/python2.6/site-packages/django/conf/__init__.py:75: DeprecationWarning: The ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
  "use STATIC_URL instead.", DeprecationWarning)
graphite.finders.standard.StandardFinder
Creating test database for alias 'default' ('test_graphite')...
Got an error creating the test database: (1044, "Access denied for user 'graphite'@'%' to database 'test_graphite'")
Type 'yes' if you would like to try deleting the test database 'test_graphite', or 'no' to cancel: yes
Destroying old test database 'default'...
Got an error recreating the test database: (1044, "Access denied for user 'graphite'@'%' to database 'test_graphite'")

I'm not finding answers about how to get this done.

Kevin J. Rice
  • 3,337
  • 2
  • 24
  • 23

1 Answers1

0

Turns out, I didn't have my Django environment set up correctly.

  1. Make sure you can invoke django-admin command and not get errors. I tried this and kept getting error messages of:

    django-admin shell Error: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.

But, setting this variable wasn't obvious what it should be set to. I kept using a path concept of /opt/graphite/webapp/graphite/settings, which is wrong. instead it should be:

export DJANGO_SETTINGS_MODULE=graphite.settings

then invoke django-admin shell and see:

/usr/lib/python2.6/site-packages/django/conf/__init__.py:75: DeprecationWarning: The ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
  "use STATIC_URL instead.", DeprecationWarning)
/usr/lib/python2.6/site-packages/django/core/cache/__init__.py:82: DeprecationWarning:  settings.CACHE_* is deprecated; use settings.CACHES instead.
  DeprecationWarning
Python 2.6.6 (r266:84292, Jul 20 2011, 10:22:43) 
[GCC 4.4.5 20110214 (Red Hat 4.4.5-6)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> 

The root cause of the problem we're seeing with 'access denied for user' is that Django needs to store data about the tests it runs in a database. It's trying to connect to whatever database is specified in the settings.py module (or local_settings.py if you have a database defined there).

Basically, it cannot create a new database named 'test_graphite' in the database specified in your settings file(s). So, you need to either (a) allow your database user to have create_database permissions, or (b) change to using the standard sqlite database, where it can create this database.

To see that we have a problem, invoke dbshell and watch which database comes up:

django-admin dbshell

this should show you which db you're using.

  1. In order to not use my production database for testing, I moved my local_settings.py file off (renamed it) and expected Django to use Sqlite3 as specified in settings.py.

WRONG!

I forgot to move off the local_settings.pyc file (yes, PYC files mess us up once again). Once I did so, I got the correct response:

$ python manage.py test --settings=tests.settings -p "test_finders.py" -v 3 --traceback
Could not import graphite.local_settings, using defaults!
/opt/graphite.github/webapp/graphite/settings.py:204: UserWarning: SECRET_KEY is set to an unsafe   default. This should be set in local_settings.py for better security
  warn('SECRET_KEY is set to an unsafe default. This should be set in local_settings.py for better  security')
/usr/lib/python2.6/site-packages/django/conf/__init__.py:75: DeprecationWarning: The ADMIN_MEDIA_PREFIX setting has been removed; use STATIC_URL instead.
  "use STATIC_URL instead.", DeprecationWarning)
graphite.finders.standard.StandardFinder
Creating test database for alias 'default' (':memory:')...
Creating tables ...
Creating table account_profile
Creating table account_variable
Creating table account_view
Creating table account_window
...
Installed 0 object(s) from 0 fixture(s)
test_custom_finder (tests.test_finders.FinderTest) ... tests.test_finders.DummyFinder
ok

----------------------------------------------------------------------
Ran 1 test in 0.004s

OK
Destroying test database for alias 'default' (':memory:')...

And now it works!

Kevin J. Rice
  • 3,337
  • 2
  • 24
  • 23