[Kimchi-devel] [PATCH] [Kimchi 1/6] Specify objectstore location when running on test mode

Aline Manera alinefm at linux.vnet.ibm.com
Thu Feb 9 02:01:57 UTC 2017


That way, the objectstore file can be deleted on server shutting down
and the system keeps clean of any changes while running on test mode.

Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
---
 root.py | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/root.py b/root.py
index bffaef0..5ba4f68 100644
--- a/root.py
+++ b/root.py
@@ -17,9 +17,10 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 
+import cherrypy
 import json
 import os
-import cherrypy
+import tempfile
 
 from wok.plugins.kimchi import config, mockmodel, websocket
 from wok.plugins.kimchi.i18n import messages
@@ -44,12 +45,22 @@ class Kimchi(WokRoot):
             if not os.path.isdir(directory):
                 os.makedirs(directory)
 
-        if hasattr(wok_options, "model"):
-            self.model = wok_options.model
-        elif wok_options.test:
-            self.model = mockmodel.MockModel()
+        # When running on test mode, specify the objectstore location to
+        # remove the file on server shutting down. That way, the system will
+        # not suffer any change while running on test mode
+        if wok_options.test and (wok_options.test is True or
+                                 wok_options.test.lower() == 'true'):
+            self.objectstore_loc = tempfile.mktemp()
+            self.model = mockmodel.MockModel(self.objectstore_loc)
+
+            def remove_objectstore():
+                if os.path.exists(self.objectstore_loc):
+                    os.unlink(self.objectstore_loc)
+            cherrypy.engine.subscribe('exit', remove_objectstore)
         else:
             self.model = kimchiModel.Model()
+            ws_proxy = websocket.new_ws_proxy()
+            cherrypy.engine.subscribe('exit', ws_proxy.terminate)
 
         dev_env = wok_options.environment != 'production'
         super(Kimchi, self).__init__(self.model, dev_env)
@@ -57,10 +68,6 @@ class Kimchi(WokRoot):
         for ident, node in sub_nodes.items():
             setattr(self, ident, node(self.model))
 
-        if isinstance(self.model, kimchiModel.Model):
-            ws_proxy = websocket.new_ws_proxy()
-            cherrypy.engine.subscribe('exit', ws_proxy.terminate)
-
         self.api_schema = json.load(open(os.path.join(os.path.dirname(
                                     os.path.abspath(__file__)), 'API.json')))
         self.paths = config.kimchiPaths
-- 
2.9.3



More information about the Kimchi-devel mailing list