Scripted Installation: Setup django superuser

624 views
Skip to first unread message

Johannes Madel

unread,
Jun 16, 2013, 3:04:54 AM6/16/13
to gets...@googlegroups.com
Hey group,

I'm about to setup setup sentry using a configuration management tool (I use salt stack, which is a configuration management tool similar to puppet or chef). For that I would have to script and parameterize all the steps needed to installation. I use postgres as a database backend.

Now while the steps needed to installing sentry are not rocket science (installing postgres, creating a sentry database, creating a virtualenv-environment for python, copying the sentry configfile to the right location etc.) are not complicated, the initialisation the database is making problems. For when I execute
# sentry-config=/etc/sentry/sentry.conf upgrade
I have to enter data interactively (config-data for the superuser), and I can't script that propery.

After some research I found out, that
# sentry-config=/etc/sentry/sentry.conf upgrade --noinput
does run without asking my question interactively (manage.py syncdb does take the --noinput option either)

But now I have to add the django superuser afterwords, In this post, http://source.mihelac.org/2009/10/23/django-avoiding-typing-password-for-superuser/ claims that this could be dony by the command
echo "from django.contrib.auth.models import User; User.objects.create_superuser('admin', 'ad...@example.com', 'pass')" | ./manage.py shell
, however I found this not to be working either (neither by using /lib/python2.7/site-packages/django/conf/project_template/manage.py nor by using django-admin.py instead of manage.py)

So: How can I add the django superuser to the database with this approach? How do I init the sentry database using a script?

Best regards,
Johannes

David Cramer

unread,
Jun 16, 2013, 2:48:06 PM6/16/13
to gets...@googlegroups.com
Take a look at this page for an example of how to do this: http://sentry.readthedocs.org/en/latest/faq/index.html#how-do-i
--
You received this message because you are subscribed to the Google Groups "sentry" group.
To unsubscribe from this group and stop receiving emails from it, send an email to getsentry+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Johannes Madel

unread,
Jun 16, 2013, 4:11:37 PM6/16/13
to gets...@googlegroups.com
Thanks man, I'll try that asap.

Jordi Llonch

unread,
Jun 16, 2013, 4:27:35 PM6/16/13
to gets...@googlegroups.com
David,

Do you consider the option to encapsulate this functionality in management/commands in order to do something like:

sentry group_add my_group
sentry project_add -g my_group my_project

Thanks,



2013/6/17 Johannes Madel <johanne...@gmail.com>
--

Johannes Madel

unread,
Jun 21, 2013, 2:40:58 AM6/21/13
to gets...@googlegroups.com
Hey again,

I trued running the script posted on http://sentry.readthedocs.org/en/latest/faq/index.html#how-do-i (included here again for reference):

---
# Bootstrap the Sentry environment
from sentry.utils.runner import configure
configure()

# Do something crazy
from sentry.models import Team, Project, User

user = User()
user.username = 'admin'
user.email = 'admin@localhost'
user.is_superuser = True
user.set_password('admin')
user.save()

team = Team()
team.name = 'Sentry'
team.owner = user
team.save()

project = Project()
project.team = team
project.owner = user
project.name = 'Default'
project.save()

key = ProjectKey.objects.filter(project=project)[0]
print 'SENTRY_DSN = "%s"' % (key.get_dsn(),)

---

However, when I run it I get an error message:
---
# SENTRY_CONF=/etc/sentry/sentry.conf python sentry_init.py
Traceback (most recent call last):
  File "/usr/share/nginx/sentry/local/lib/python2.7/site-packages/logan/runner.py", line 101, in settings_callback
    'settings': settings,
  File "/usr/share/nginx/sentry/local/lib/python2.7/site-packages/sentry/utils/runner.py", line 171, in initialize_app
    from sentry.app import env
  File "/usr/share/nginx/sentry/local/lib/python2.7/site-packages/sentry/app.py", line 25, in <module>
    buffer = get_instance(settings.BUFFER, settings.BUFFER_OPTIONS)
  File "/usr/share/nginx/sentry/local/lib/python2.7/site-packages/sentry/app.py", line 20, in get_instance
    cls = import_string(path)
  File "/usr/share/nginx/sentry/local/lib/python2.7/site-packages/sentry/utils/imports.py", line 40, in import_string
    raise ImportError(path)
ImportError: sentry.buffer.Buffer
---

The problem seems to be this code here (taken from file sentry.utils.imports), where import_string is called with the string argument "'sentry.buffer.Buffer'".

---

class ModuleProxyCache(dict):
    def __missing__(self, key):
        if not '.' in key:
            return __import__(key)

        module_name, class_name = key.rsplit('.', 1)

        module = __import__(module_name, {}, {}, [class_name], -1)
        handler = getattr(module, class_name)

        # We cache a NoneType for missing imports to avoid repeated lookups
        self[key] = handler

        return handler

_cache = ModuleProxyCache()


def import_string(path):
    """
    Path must be module.path.ClassName

    >>> cls = import_string('sentry.models.Group')
    """
    result = _cache[path]
    return result


---


On the file system everything seems to be ok:

---
# ls -l ./sentry/lib/python2.7/site-packages/sentry/buffer/
total 28
-rw-r--r-- 1 root root 1976 Jun 15 04:54 base.py
-rw-r--r-- 1 root root 2905 Jun 15 04:56 base.pyc
-rw-r--r-- 1 root root  192 Jun 15 04:54 __init__.py
-rw-r--r-- 1 root root  391 Jun 15 04:56 __init__.pyc
-rw-r--r-- 1 root root 4091 Jun 15 04:54 redis.py
-rw-r--r-- 1 root root 5037 Jun 15 04:56 redis.pyc
# cat ./sentry/lib/python2.7/site-packages/sentry/buffer/__init__.py
"""
sentry.buffer
~~~~~~~~~~~~~

:copyright: (c) 2010-2013 by the Sentry Team, see AUTHORS for more details.
:license: BSD, see LICENSE for more details.
"""

from .base import Buffer  # NOQA

---

Futher confusing: The other imports are functioning well (e.g. sentry.utils.runner in sentry_init.py). What am I doing wrong?
Thanks in advance.

Best regards,
Johannes

David Cramer

unread,
Jun 21, 2013, 2:41:40 AM6/21/13
to gets...@googlegroups.com
You're missing a library, likely redis

If you use sentry==dev the error message is more clear

Johannes Madel

unread,
Jun 21, 2013, 4:41:54 PM6/21/13
to gets...@googlegroups.com
Hey again,

still not lucky. Doing the same setup again with sentry==dev led to the follogin error message:

---

SENTRY_CONF=/etc/sentry/sentry.conf python sentry_init.py
Traceback (most recent call last):
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/logan-0.5.6-py2.7.egg/logan/runner.py", line 100, in settings_callback
    'settings': settings,
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/utils/runner.py", line 185, in initialize_app
    from sentry.app import env
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/app.py", line 23, in <module>
    buffer = get_instance(settings.BUFFER, settings.BUFFER_OPTIONS)
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/app.py", line 20, in get_instance
    cls = import_string(path)
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/utils/imports.py", line 34, in import_string
    result = _cache[path]
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/utils/imports.py", line 17, in __missing__

    module = __import__(module_name, {}, {}, [class_name], -1)
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/buffer/__init__.py", line 9, in <module>

    from .base import Buffer  # NOQA
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/sentry-5.5.0_DEV-py2.7.egg/sentry/buffer/base.py", line 9, in <module>
    from django.db.models import F
  File "/usr/share/nginx/sentry3/local/lib/python2.7/site-packages/Django-1.5.1-py2.7.egg/django/db/models/__init__.py", line 3, in <module>
    from django.db import connection
ImportError: cannot import name connection
---

Now I guess that is not a missing packet issue. According to http://stackoverflow.com/questions/11711536/django-1-4-database-router-cannot-import-name-connection , django.db.connections has to be included in settings.py . Tried that, doesn't work.

# By the way, my installed packages are as such:
---
# pip freeze
BeautifulSoup==3.2.1
Django==1.5.1
Pygments==1.6
South==0.7.6
argparse==1.2.1
billiard==2.7.3.28
celery==3.0.19
cssutils==0.9.10b1
distribute==0.6.24
django-celery==3.0.17
django-crispy-forms==1.2.8
django-paging==0.2.5
django-picklefield==0.3.0
django-social-auth==0.7.23
django-social-auth-trello==1.0.3
django-static-compiler==0.3.3
django-templatetag-sugar==0.1
gunicorn==0.17.4
httpagentparser==1.2.2
kombu==2.5.10
logan==0.5.6
nydus==0.10.6
oauth2==1.5.211
pynliner==0.4.0
python-dateutil==1.5
python-openid==2.2.5
raven==3.3.10
redis==2.7.6
sentry==5.5.0-DEV
setproctitle==1.1.7
simplejson==3.1.3
six==1.3.0
wsgiref==0.1.2
---

Should I fine a bug report?

Best regards,
Johannes


Am Sonntag, 16. Juni 2013 09:04:54 UTC+2 schrieb Johannes Madel:

David Cramer

unread,
Jun 21, 2013, 6:25:33 PM6/21/13
to gets...@googlegroups.com
Are you using Postgres? If so you're missing psycopg2

Are you using MySQL? If so you're missing mysqldb

I would go through the quick start again and make sure you didn't miss any steps.

If you do figure out what's missing in this case, it might be worth filing a ticket so we can improve the reporting.
--
Reply all
Reply to author
Forward
0 new messages