Patchwork [bitbake-devel,1/1] bitbake: cooker: mark setFeatures command as read-only

login
register
mail settings
Submitter Alexandru DAMIAN
Date April 1, 2014, 11:24 a.m.
Message ID <1396351489-13076-1-git-send-email-alexandru.damian@intel.com>
Download mbox | patch
Permalink /patch/69819/
State New
Headers show

Comments

Alexandru DAMIAN - April 1, 2014, 11:24 a.m.
From: Alexandru DAMIAN <alexandru.damian@intel.com>

This patch makes sure that the setFeatures command is marked
as read-only and that it can only run if the cooker is in
the initial state.

Additionally, remove logging from the XMLRPC module in favor
of sending the exception to the client for easy processing.

	[YOCTO #6089]

Signed-off-by: Alexandru DAMIAN <alexandru.damian@intel.com>
---
 bitbake/lib/bb/command.py       | 4 ++++
 bitbake/lib/bb/cooker.py        | 3 +++
 bitbake/lib/bb/server/xmlrpc.py | 2 +-
 3 files changed, 8 insertions(+), 1 deletion(-)

Patch

diff --git a/bitbake/lib/bb/command.py b/bitbake/lib/bb/command.py
index 3788207..84fcdf9 100644
--- a/bitbake/lib/bb/command.py
+++ b/bitbake/lib/bb/command.py
@@ -264,6 +264,10 @@  class CommandsSync:
         features = params[0]
         command.cooker.setFeatures(features)
 
+    # although we change the internal state of the cooker, this is transparent since
+    # we always take and leave the cooker in state.initial
+    setFeatures.readonly = True
+
 class CommandsAsync:
     """
     A class of asynchronous commands
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index e6916a6..f41f594 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -159,6 +159,9 @@  class BBCooker:
         self.state = state.forceshutdown
 
     def setFeatures(self, features):
+        # we only accept a new feature set if we're in state initial, so we can reset without problems
+        if self.state != state.initial:
+            raise Exception("Illegal state for feature set change")
         original_featureset = list(self.featureset)
         for feature in features:
             self.featureset.setFeature(feature)
diff --git a/bitbake/lib/bb/server/xmlrpc.py b/bitbake/lib/bb/server/xmlrpc.py
index bf867b5..5dcaa6c 100644
--- a/bitbake/lib/bb/server/xmlrpc.py
+++ b/bitbake/lib/bb/server/xmlrpc.py
@@ -292,7 +292,7 @@  class BitBakeXMLRPCServerConnection(BitBakeBaseServerConnection):
 
         _, error = self.connection.runCommand(["setFeatures", self.featureset])
         if error:
-            logger.error("Unable to set the cooker to the correct featureset: %s" % error)
+            # no need to log it here, the error shall be sent to the client
             raise BaseException(error)
 
         return self