diff options
author | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 14:41:29 -0500 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2015-09-15 14:41:29 -0500 |
commit | 21f9b84b4b729fbd7acbd465e7a3f726e4d20f91 (patch) | |
tree | eb2d091d427ca0813b445509d59cc8e27e8ad25f /yocto-poky/bitbake/lib/toaster/toastermain/management | |
parent | 101cef31e2bf54c678501155cd2106251acbd076 (diff) | |
parent | c124f4f2e04dca16a428a76c89677328bc7bf908 (diff) | |
download | blackbird-openbmc-21f9b84b4b729fbd7acbd465e7a3f726e4d20f91.tar.gz blackbird-openbmc-21f9b84b4b729fbd7acbd465e7a3f726e4d20f91.zip |
Merge commit 'c124f4f2e04dca16a428a76c89677328bc7bf908' as 'yocto-poky'
Diffstat (limited to 'yocto-poky/bitbake/lib/toaster/toastermain/management')
5 files changed, 120 insertions, 0 deletions
diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/__init__.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/__init__.py diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/__init__.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/__init__.py diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py new file mode 100644 index 000000000..343d3114c --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/builddelete.py @@ -0,0 +1,49 @@ +from django.core.management.base import BaseCommand, CommandError +from orm.models import Build +from django.db import OperationalError +import os + + + +class Command(BaseCommand): + args = "buildId" + help = "Deletes selected build(s)" + + def handle(self, buildId, *args, **options): + for bid in buildId.split(","): + b = Build.objects.get(pk = bid) + # theoretically, just b.delete() would suffice + # however SQLite runs into problems when you try to + # delete too many rows at once, so we delete some direct + # relationships from Build manually. + for t in b.target_set.all(): + t.delete() + for t in b.task_build.all(): + t.delete() + for p in b.package_set.all(): + p.delete() + for lv in b.layer_version_build.all(): + lv.delete() + for v in b.variable_build.all(): + v.delete() + for l in b.logmessage_set.all(): + l.delete() + + # delete the build; some databases might have had problem with migration of the bldcontrol app + retry_count = 0 + need_bldcontrol_migration = False + while True: + if retry_count >= 5: + break + retry_count += 1 + if need_bldcontrol_migration: + from django.core import management + management.call_command('migrate', 'bldcontrol', interactive=False) + + try: + b.delete() + break + except OperationalError as e: + # execute migrations + need_bldcontrol_migration = True + diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/buildslist.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/buildslist.py new file mode 100644 index 000000000..cad987fd9 --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/buildslist.py @@ -0,0 +1,13 @@ +from django.core.management.base import NoArgsCommand, CommandError +from orm.models import Build +import os + + + +class Command(NoArgsCommand): + args = "" + help = "Lists current builds" + + def handle_noargs(self,**options): + for b in Build.objects.all(): + print "%d: %s %s %s" % (b.pk, b.machine, b.distro, ",".join([x.target for x in b.target_set.all()])) diff --git a/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/perf.py b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/perf.py new file mode 100644 index 000000000..71a48e95d --- /dev/null +++ b/yocto-poky/bitbake/lib/toaster/toastermain/management/commands/perf.py @@ -0,0 +1,58 @@ +from django.core.management.base import BaseCommand +from django.test.client import Client +import os, sys, re +import requests +from django.conf import settings + +# pylint: disable=E1103 +# Instance of 'WSGIRequest' has no 'status_code' member +# (but some types could not be inferred) (maybe-no-member) + + +class Command(BaseCommand): + help = "Test the response time for all toaster urls" + + def handle(self, *args, **options): + root_urlconf = __import__(settings.ROOT_URLCONF) + patterns = root_urlconf.urls.urlpatterns + global full_url + for pat in patterns: + if pat.__class__.__name__ == 'RegexURLResolver': + url_root_res = str(pat).split('^')[1].replace('>', '') + if 'gui' in url_root_res: + for url_patt in pat.url_patterns: + full_url = self.get_full_url(url_patt, url_root_res) + info = self.url_info(full_url) + status_code = info[0] + load_time = info[1] + print 'Trying \'' + full_url + '\', ' + str(status_code) + ', ' + str(load_time) + + def get_full_url(self, url_patt, url_root_res): + full_url = str(url_patt).split('^')[1].replace('$>', '').replace('(?P<file_path>(?:/[', '/bin/busybox').replace('.*', '') + full_url = str(url_root_res + full_url) + full_url = re.sub('\(\?P<.*?>\\\d\+\)', '1', full_url) + full_url = 'http://localhost:8000/' + full_url + return full_url + + def url_info(self, full_url): + client = Client() + info = [] + try: + resp = client.get(full_url, follow = True) + except Exception as e_status_code: + self.error('Url: %s, error: %s' % (full_url, e_status_code)) + resp = type('object', (), {'status_code':0, 'content': str(e_status_code)}) + status_code = resp.status_code + info.append(status_code) + try: + req = requests.get(full_url) + except Exception as e_load_time: + self.error('Url: %s, error: %s' % (full_url, e_load_time)) + load_time = req.elapsed + info.append(load_time) + return info + + def error(self, *args): + for arg in args: + print >>sys.stderr, arg, + print >>sys.stderr |