[Toaster] [review-request][PATCH 1/3] toaster: Always run bldcontrol migrations

Smith, Elliot elliot.smith at intel.com
Tue Oct 13 05:02:44 PDT 2015


On 9 October 2015 at 14:35, Michael Wood <michael.g.wood at intel.com> wrote:

> On 30/09/15 15:54, Elliot Smith wrote:
>
>> The toaster startup script conditionally migrates the database
>> tables depending on whether you are in managed mode or not. This
>> means that if you are in analysis mode, some of the bldcontrol*
>> database tables used by managed mode are not available.
>>
>> As a consequence, some of the code in toaster which refers to
>> those tables can break in analysis mode, as there's no clean
>> isolation of the two modes.
>>
>> To prevent this from happening, always run the migrations for
>> managed mode and create the bldcontrol* tables, even if in
>> analysis mode.
>>
>> Also clean up the function which starts up toaster so the
>> logic is easier to follow.
>>
>> [YOCTO #8277]
>>
>> Signed-off-by: Elliot Smith <elliot.smith at intel.com>
>> ---
>>   bitbake/bin/toaster | 58
>> +++++++++++++++++++++++++++++++++++------------------
>>   1 file changed, 39 insertions(+), 19 deletions(-)
>>
>> diff --git a/bitbake/bin/toaster b/bitbake/bin/toaster
>> index ac27826..05dabc9 100755
>> --- a/bitbake/bin/toaster
>> +++ b/bitbake/bin/toaster
>> @@ -54,35 +54,55 @@ webserverStartAll()
>>       fi
>>         retval=0
>> -    if [ "$TOASTER_MANAGED" '=' '1' ]; then
>> +    if [ "$TOASTER_MANAGED" = '1' ]; then
>>           python $BBBASEDIR/lib/toaster/manage.py syncdb || retval=1
>>       else
>>           python $BBBASEDIR/lib/toaster/manage.py syncdb --noinput ||
>> retval=1
>>       fi
>> -    python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=2
>> +
>>       if [ $retval -eq 1 ]; then
>> -        echo "Failed db sync, stopping system start" 1>&2
>> -    elif [ $retval -eq 2 ]; then
>> -        printf "\nError on migration, trying to recover... \n"
>> +        echo "Failed db sync, aborting system start" 1>&2
>> +        return $retval
>> +    fi
>> +
>> +    python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
>> +
>> +    if [ $retval -eq 1 ]; then
>> +        printf "\nError on orm migration, rolling back...\n"
>>           python $BBBASEDIR/lib/toaster/manage.py migrate orm
>> 0001_initial --fake
>> -        retval=0
>> -        python $BBBASEDIR/lib/toaster/manage.py migrate orm || retval=1
>> +        return $retval
>>       fi
>> +
>> +    python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol ||
>> retval=1
>> +
>> +    if [ $retval -eq 1 ]; then
>> +        printf "\nError on bldcontrol migration, rolling back...\n"
>> +        python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol
>> 0001_initial --fake
>> +        return $retval
>> +    fi
>> +
>>       if [ "$TOASTER_MANAGED" = '1' ]; then
>> -        python $BBBASEDIR/lib/toaster/manage.py migrate bldcontrol ||
>> retval=1
>> -        python $BBBASEDIR/lib/toaster/manage.py checksettings
>> --traceback || retval=1
>> +        python $BBBASEDIR/lib/toaster/manage.py checksettings
>> --traceback || retval=1
>>       fi
>> -    if [ $retval -eq 0 ]; then
>> -        echo "Starting webserver..."
>> -        python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT"
>> </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 & echo $!
>> >${BUILDDIR}/.toastermain.pid
>> -        sleep 1
>> -        if ! cat "${BUILDDIR}/.toastermain.pid" | xargs -I{} kill -0 {}
>> ; then
>> -            retval=1
>> -            rm "${BUILDDIR}/.toastermain.pid"
>> -        else
>> -            echo "Webserver address:  http://0.0.0.0:$WEB_PORT/"
>> -        fi
>> +
>> +    if [ $retval -eq 1 ]; then
>> +        printf "\nError while checking settings; aborting\n"
>> +        return $retval
>> +    fi
>> +
>> +    echo "Starting webserver..."
>> +
>> +    python $BBBASEDIR/lib/toaster/manage.py runserver "0.0.0.0:$WEB_PORT"
>> </dev/null >>${BUILDDIR}/toaster_web.log 2>&1 & echo $!
>> >${BUILDDIR}/.toastermain.pid
>> +
>> +    sleep 1
>> +
>> +    if ! cat "${BUILDDIR}/.toastermain.pid" | xargs -I{} kill -0 {} ;
>> then
>> +        retval=1
>> +        rm "${BUILDDIR}/.toastermain.pid"
>> +    else
>> +        echo "Webserver address:  http://0.0.0.0:$WEB_PORT/"
>>       fi
>> +
>>       return $retval
>>   }
>>
>>
>
> If you want to run all migrations we can do just do ./manage migrate --all
>

The reason for doing them individually is so that if one series of
migrations fails, we can roll just that series back and exit the startup
sequence.

Elliot


>
>
> ---------------------------------------------------------------------
> Intel Corporation (UK) Limited
> Registered No. 1134945 (England)
> Registered Office: Pipers Way, Swindon SN3 1RJ
> VAT No: 860 2173 47
>
> This e-mail and any attachments may contain confidential material for
> the sole use of the intended recipient(s). Any review or distribution
> by others is strictly prohibited. If you are not the intended
> recipient, please contact the sender and delete all copies.
>
>


-- 
Elliot Smith
Software Engineer
Intel Open Source Technology Centre
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.yoctoproject.org/pipermail/toaster/attachments/20151013/640905a7/attachment-0001.html>


More information about the toaster mailing list