[bitbake-devel] [PATCH 2/3] toaster: Avoid unnecessary local to local copy of cooker log

brian avery avery.brian at gmail.com
Fri Sep 11 20:57:29 UTC 2015


From: Elliot Smith <elliot.smith at intel.com>

The cooker log is copied from its original (bitbake) location
to an artifact directory chosen by the user (chosen when
checksettings.py runs as part of the managed mode;
it's one of the annoying questions you're asked at startup).
The copy happens as part of the runbuilds script run, which
is started in a loop from the toaster startup script
in managed mode.

When a user requests the log for a build via toaster, they
are getting the log which has been copied to the artifact
directory, not the original bitbake log.

This works for the managed case, where the runbuilds command is
running in a loop and copying log files for completed builds to
the artifact directory. However, in analysis mode, there are two
problems:

1. checksettings isn't run, so the artifacts directory isn't
set. toaster is then unable to figure out where the log files
should have been copied to.

2. The log files aren't copied to the artifacts directory
anyway, as runbuilds isn't running in analysis mode.

To fix this, just point the user to the local bitbake log file
in its original location. This avoids the copy step, and means
we can remove a whole question from the toaster startup sequence,
as we no longer need an artifact directory.

The only downside to this is that it's not appropriate for
remote bitbake servers. We will need to revisit this and
possibly reinstate the copy step once we have to reconcile
local and remote builds and make their logs available in
the same way.

[YOCTO #8209]

Signed-off-by: Elliot Smith <elliot.smith at intel.com>
Signed-off-by: brian avery <avery.brian at gmail.com>
---
 .../management/commands/checksettings.py           | 22 --------------------
 .../bldcontrol/management/commands/runbuilds.py    | 24 ++--------------------
 lib/toaster/toastergui/views.py                    | 13 ++++++------
 3 files changed, 8 insertions(+), 51 deletions(-)

diff --git a/lib/toaster/bldcontrol/management/commands/checksettings.py b/lib/toaster/bldcontrol/management/commands/checksettings.py
index 3ccc7c6..b2c573c 100644
--- a/lib/toaster/bldcontrol/management/commands/checksettings.py
+++ b/lib/toaster/bldcontrol/management/commands/checksettings.py
@@ -64,27 +64,6 @@ class Command(NoArgsCommand):
             return ""
         return DN(self._find_first_path_for_file(DN(self.guesspath), "bblayers.conf", 4))
 
-
-    def _verify_artifact_storage_dir(self):
-        # verify that we have a settings for downloading artifacts
-        while ToasterSetting.objects.filter(name="ARTIFACTS_STORAGE_DIR").count() == 0:
-            guessedpath = os.getcwd() + "/toaster_build_artifacts/"
-            print("\nToaster needs to know in which directory it can download build log files and other artifacts.\nToaster suggests \"%s\"." % guessedpath)
-            artifacts_storage_dir = raw_input("Press Enter to select \"%s\" or type the full path to a different directory: " % guessedpath)
-            if len(artifacts_storage_dir) == 0:
-                artifacts_storage_dir = guessedpath
-            if len(artifacts_storage_dir) > 0 and artifacts_storage_dir.startswith("/"):
-                try:
-                    os.makedirs(artifacts_storage_dir)
-                except OSError as ose:
-                    if "File exists" in str(ose):
-                        pass
-                    else:
-                        raise ose
-                ToasterSetting.objects.create(name="ARTIFACTS_STORAGE_DIR", value=artifacts_storage_dir)
-        return 0
-
-
     def _verify_build_environment(self):
         # refuse to start if we have no build environments
         while BuildEnvironment.objects.count() == 0:
@@ -239,7 +218,6 @@ class Command(NoArgsCommand):
 
     def handle_noargs(self, **options):
         retval = 0
-        retval += self._verify_artifact_storage_dir()
         retval += self._verify_build_environment()
         retval += self._verify_default_settings()
         retval += self._verify_builds_in_progress()
diff --git a/lib/toaster/bldcontrol/management/commands/runbuilds.py b/lib/toaster/bldcontrol/management/commands/runbuilds.py
index c3e9b74..718e144 100644
--- a/lib/toaster/bldcontrol/management/commands/runbuilds.py
+++ b/lib/toaster/bldcontrol/management/commands/runbuilds.py
@@ -77,31 +77,11 @@ class Command(NoArgsCommand):
             bec.be.save()
 
     def archive(self):
-        ''' archives data from the builds '''
-        artifact_storage_dir = ToasterSetting.objects.get(name="ARTIFACTS_STORAGE_DIR").value
         for br in BuildRequest.objects.filter(state = BuildRequest.REQ_ARCHIVE):
-            # save cooker log
             if br.build == None:
                 br.state = BuildRequest.REQ_FAILED
-                br.save()
-                continue
-            build_artifact_storage_dir = os.path.join(artifact_storage_dir, "%d" % br.build.pk)
-            try:
-                os.makedirs(build_artifact_storage_dir)
-            except OSError as ose:
-                if "File exists" in str(ose):
-                    pass
-                else:
-                    raise ose
-
-            file_name = os.path.join(build_artifact_storage_dir, "cooker_log.txt")
-            try:
-                with open(file_name, "w") as f:
-                    f.write(br.environment.get_artifact(br.build.cooker_log_path).read())
-            except IOError:
-                os.unlink(file_name)
-
-            br.state = BuildRequest.REQ_COMPLETED
+            else:
+                br.state = BuildRequest.REQ_COMPLETED
             br.save()
 
     def cleanup(self):
diff --git a/lib/toaster/toastergui/views.py b/lib/toaster/toastergui/views.py
index 4e8f69e..784272f 100755
--- a/lib/toaster/toastergui/views.py
+++ b/lib/toaster/toastergui/views.py
@@ -2710,7 +2710,6 @@ if True:
 
     def build_artifact(request, build_id, artifact_type, artifact_id):
         if artifact_type in ["cookerlog"]:
-            # these artifacts are saved after building, so they are on the server itself
             def _mimetype_for_artifact(path):
                 try:
                     import magic
@@ -2741,16 +2740,16 @@ if True:
                 except ImportError:
                     return "binary/octet-stream"
             try:
-                # match code with runbuilds.Command.archive()
-                build_artifact_storage_dir = os.path.join(ToasterSetting.objects.get(name="ARTIFACTS_STORAGE_DIR").value, "%d" % int(build_id))
-                file_name = os.path.join(build_artifact_storage_dir, "cooker_log.txt")
-
+                build = Build.objects.get(pk = build_id)
+                file_name = build.cooker_log_path
                 fsock = open(file_name, "r")
-                content_type=_mimetype_for_artifact(file_name)
+                content_type = _mimetype_for_artifact(file_name)
 
                 response = HttpResponse(fsock, content_type = content_type)
 
-                response['Content-Disposition'] = 'attachment; filename=' + os.path.basename(file_name)
+                disposition = 'attachment; filename=cooker.log'
+                response['Content-Disposition'] = disposition
+
                 return response
             except IOError:
                 context = {
-- 
1.9.1




More information about the bitbake-devel mailing list