From: Michael Wood <michael.g.wood@intel.com>
To: Michael Wood <michael.g.wood@intel.com>,
"toaster@yoctoproject.org" <toaster@yoctoproject.org>
Subject: Re: [PATCH v2 1/6] toaster: Remove DATABASE_URL being passed around as an environment var
Date: Thu, 5 May 2016 16:41:11 +0100 [thread overview]
Message-ID: <572B6997.6070802@intel.com> (raw)
In-Reply-To: <1462453952-8837-1-git-send-email-michael.g.wood@intel.com>
On 05/05/16 14:12, Michael Wood wrote:
> We don't need to pass the DATABASE_URL around and read it back if we
> setup the django framework in the correct way.
> We make the default sqlite database path a full path so that the
> database isn't being assumed to be in CWD.
>
> Also add some more useful comments on the database settings.
>
> This is preparation work to migrate the build tests and be able to
> trigger builds on differently configured databases.
>
> Signed-off-by: Michael Wood <michael.g.wood@intel.com>
> ---
> bitbake/bin/toaster | 2 -
> bitbake/lib/bb/ui/buildinfohelper.py | 20 +++----
> .../toastermain/management/commands/get-dburl.py | 9 ---
> bitbake/lib/toaster/toastermain/settings.py | 69 ++++------------------
> 4 files changed, 22 insertions(+), 78 deletions(-)
> delete mode 100644 bitbake/lib/toaster/toastermain/management/commands/get-dburl.py
>
> diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
> index 987d53c1..91716e6 100755
> --- a/bitbake/bin/toaster
> +++ b/bitbake/bin/toaster
> @@ -100,7 +100,6 @@ stop_system()
> fi
> webserverKillAll
> # unset exported variables
> - unset DATABASE_URL
> unset TOASTER_CONF
> unset TOASTER_DIR
> unset BITBAKE_UI
> @@ -278,7 +277,6 @@ case $CMD in
> return 4
> fi
> export BITBAKE_UI='toasterui'
> - export DATABASE_URL=`$MANAGE get-dburl`
> $MANAGE runbuilds & echo $! >${BUILDDIR}/.runbuilds.pid
> # set fail safe stop system on terminal exit
> trap stop_system SIGHUP
> diff --git a/bitbake/lib/bb/ui/buildinfohelper.py b/bitbake/lib/bb/ui/buildinfohelper.py
> index 9397905..b07dc81 100644
> --- a/bitbake/lib/bb/ui/buildinfohelper.py
> +++ b/bitbake/lib/bb/ui/buildinfohelper.py
> @@ -21,19 +21,19 @@ import bb
> import re
> import os
>
> -os.environ["DJANGO_SETTINGS_MODULE"] = "toaster.toastermain.settings"
> -
> -
> import django
> from django.utils import timezone
>
> +import toaster
> +# Add toaster module to the search path to help django.setup() find the right
> +# modules
> +sys.path.insert(0, os.path.dirname(toaster.__file__))
>
> -def _configure_toaster():
> - """ Add toaster to sys path for importing modules
> - """
> - sys.path.append(os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))), 'toaster'))
> -_configure_toaster()
> -
> +#Set the DJANGO_SETTINGS_MODULE if it's not already set
> +os.environ["DJANGO_SETTINGS_MODULE"] =\
> + os.environ.get("DJANGO_SETTINGS_MODULE",
> + "toaster.toastermain.settings")
> +# Setup django framework (needs to be done before importing modules)
> django.setup()
>
> from orm.models import Build, Task, Recipe, Layer_Version, Layer, Target, LogMessage, HelpText
> @@ -54,11 +54,11 @@ from datetime import datetime, timedelta
>
> from django.db import transaction, connection
>
> +
> # pylint: disable=invalid-name
> # the logger name is standard throughout BitBake
> logger = logging.getLogger("ToasterLogger")
>
> -
> class NotExisting(Exception):
> pass
>
> diff --git a/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py b/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py
> deleted file mode 100644
> index 22b3eb7..0000000
> --- a/bitbake/lib/toaster/toastermain/management/commands/get-dburl.py
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -from toastermain.settings import getDATABASE_URL
> -from django.core.management.base import NoArgsCommand
> -
> -class Command(NoArgsCommand):
> - args = ""
> - help = "get database url"
> -
> - def handle_noargs(self,**options):
> - print getDATABASE_URL()
> diff --git a/bitbake/lib/toaster/toastermain/settings.py b/bitbake/lib/toaster/toastermain/settings.py
> index 74ab604..cab7c2e 100644
> --- a/bitbake/lib/toaster/toastermain/settings.py
> +++ b/bitbake/lib/toaster/toastermain/settings.py
> @@ -21,7 +21,7 @@
>
> # Django settings for Toaster project.
>
> -import os, re
> +import os
>
> DEBUG = True
> TEMPLATE_DEBUG = DEBUG
> @@ -38,14 +38,21 @@ ADMINS = (
>
> MANAGERS = ADMINS
>
> +TOASTER_SQLITE_DEFAULT_DIR = os.path.join(os.environ.get('TOASTER_DIR', ''),
> + 'build')
> +
> +print "default path %s" % TOASTER_SQLITE_DEFAULT_DIR
Just noticed this debug statement I left in ^^
Will roll a v3
- Michael
> +
> DATABASES = {
> 'default': {
> - 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
> - 'NAME': 'toaster.sqlite', # Or path to database file if using sqlite3.
> + # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'.
> + 'ENGINE': 'django.db.backends.sqlite3',
> + # DB name or full path to database file if using sqlite3.
> + 'NAME': "%s/toaster1.sqlite" % TOASTER_SQLITE_DEFAULT_DIR,
> 'USER': '',
> 'PASSWORD': '',
> - 'HOST': '127.0.0.1', # Empty for localhost through domain sockets or '127.0.0.1' for localhost through TCP.
> - 'PORT': '3306', # Set to empty string for default.
> + #'HOST': '127.0.0.1', # e.g. mysql server
> + #'PORT': '3306', # e.g. mysql port
> }
> }
>
> @@ -55,58 +62,6 @@ DATABASES = {
> if 'sqlite' in DATABASES['default']['ENGINE']:
> DATABASES['default']['OPTIONS'] = { 'timeout': 20 }
>
> -# Reinterpret database settings if we have DATABASE_URL environment variable defined
> -
> -if 'DATABASE_URL' in os.environ:
> - dburl = os.environ['DATABASE_URL']
> -
> - if dburl.startswith('sqlite3://'):
> - result = re.match('sqlite3://(.*)', dburl)
> - if result is None:
> - raise Exception("ERROR: Could not read sqlite database url: %s" % dburl)
> - DATABASES['default'] = {
> - 'ENGINE': 'django.db.backends.sqlite3',
> - 'NAME': result.group(1),
> - 'USER': '',
> - 'PASSWORD': '',
> - 'HOST': '',
> - 'PORT': '',
> - }
> - elif dburl.startswith('mysql://'):
> - # URL must be in this form: mysql://user:pass@host:port/name
> - result = re.match(r"mysql://([^:]*):([^@]*)@([^:]*):(\d*)/([^/]*)", dburl)
> - if result is None:
> - raise Exception("ERROR: Could not read mysql database url: %s" % dburl)
> - DATABASES['default'] = {
> - 'ENGINE': 'django.db.backends.mysql',
> - 'NAME': result.group(5),
> - 'USER': result.group(1),
> - 'PASSWORD': result.group(2),
> - 'HOST': result.group(3),
> - 'PORT': result.group(4),
> - }
> - else:
> - raise Exception("FIXME: Please implement missing database url schema for url: %s" % dburl)
> -
> -
> -# Allows current database settings to be exported as a DATABASE_URL environment variable value
> -
> -def getDATABASE_URL():
> - d = DATABASES['default']
> - if d['ENGINE'] == 'django.db.backends.sqlite3':
> - if d['NAME'] == ':memory:':
> - return 'sqlite3://:memory:'
> - elif d['NAME'].startswith("/"):
> - return 'sqlite3://' + d['NAME']
> - return "sqlite3://" + os.path.join(os.getcwd(), d['NAME'])
> -
> - elif d['ENGINE'] == 'django.db.backends.mysql':
> - return "mysql://" + d['USER'] + ":" + d['PASSWORD'] + "@" + d['HOST'] + ":" + d['PORT'] + "/" + d['NAME']
> -
> - raise Exception("FIXME: Please implement missing database url schema for engine: %s" % d['ENGINE'])
> -
> -
> -
> # Hosts/domain names that are valid for this site; required if DEBUG is False
> # See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
> ALLOWED_HOSTS = []
next prev parent reply other threads:[~2016-05-05 15:41 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-04-25 18:04 [PATCH 1/5] toaster: Remove DATABASE_URL being passed around as an environment var Michael Wood
2016-04-25 18:04 ` [PATCH 2/5] toaster: runbuilds move the execution sequence out of the poll loop Michael Wood
2016-04-25 18:04 ` [PATCH 3/5] toaster: Add a specific test settings file Michael Wood
2016-04-25 18:04 ` [PATCH 4/5] toaster: tests Add a BuildTest helper class Michael Wood
2016-04-25 18:04 ` [PATCH 5/5] toaster: tests build Add a test for a build of core-image-minimal Michael Wood
2016-05-05 13:12 ` [PATCH v2 1/6] toaster: Remove DATABASE_URL being passed around as an environment var Michael Wood
2016-05-05 13:12 ` [PATCH v2 2/6] toaster: runbuilds move the execution sequence out of the poll loop Michael Wood
2016-05-05 13:12 ` [PATCH v2 3/6] toaster: Add a specific test settings file Michael Wood
2016-05-05 13:12 ` [PATCH v2 4/6] toaster: tests Add a BuildTest helper class Michael Wood
2016-05-05 13:12 ` [PATCH v2 5/6] toaster: tests build Add a test for a build of core-image-minimal Michael Wood
2016-05-05 13:12 ` [PATCH v2 6/6] toaster: tests builds Add SSTATE_MISS as a valid condition for tc=833 Michael Wood
2016-05-05 15:16 ` Smith, Elliot
2016-05-05 15:41 ` Michael Wood [this message]
2016-04-26 17:10 ` [PATCH 1/5] toaster: Remove DATABASE_URL being passed around as an environment var Smith, Elliot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=572B6997.6070802@intel.com \
--to=michael.g.wood@intel.com \
--cc=toaster@yoctoproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.