[Erp5-report] r45379 luke - /slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/

nobody at svn.erp5.org nobody at svn.erp5.org
Wed Apr 13 15:04:08 CEST 2011


Author: luke
Date: Wed Apr 13 15:04:08 2011
New Revision: 45379

URL: http://svn.erp5.org?rev=45379&view=rev
Log:
 - separate supervisor backend in own module

Added:
    slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/svcbackend.py
Modified:
    slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/SlapObject.py
    slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/slapgrid.py
    slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/utils.py

Modified: slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/SlapObject.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/SlapObject.py?rev=45379&r1=45378&r2=45379&view=diff
==============================================================================
--- slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/SlapObject.py [utf8] (original)
+++ slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/SlapObject.py [utf8] Wed Apr 13 15:04:08 2011
@@ -36,7 +36,8 @@ import slapgrid
 import pwd
 from utils import launchBuildout, getCleanEnvironment,\
                    dropPrivileges, bootstrapBuildout, updateFile,\
-                   getSoftwareUrlHash, SlapPopen, getSupervisorRPC
+                   getSoftwareUrlHash, SlapPopen
+from svcbackend import getSupervisorRPC
 
 REQUIRED_COMPUTER_PARTITION_PERMISSION = '0750'
 

Modified: slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/slapgrid.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/slapgrid.py?rev=45379&r1=45378&r2=45379&view=diff
==============================================================================
--- slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/slapgrid.py [utf8] (original)
+++ slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/slapgrid.py [utf8] Wed Apr 13 15:04:08 2011
@@ -46,9 +46,9 @@ from utils import setFinished
 from utils import getSoftwareUrlHash
 from slapos import slap
 from slapos.slap import NotFoundError
-from utils import getSupervisorRPC
 from utils import dropPrivileges
 from utils import SlapPopen
+from svcbackend import launchSupervisord
 import tempfile
 import StringIO
 from lxml import etree
@@ -218,43 +218,9 @@ class Slapgrid(object):
     logger.info("Finished software releases...")
     return clean_run
 
-  def _launchSupervisor(self):
-    supervisor = getSupervisorRPC(self.supervisord_socket)
-    if os.path.exists(self.supervisord_socket):
-      try:
-        status = supervisor.getState()
-      except Exception:
-        # In case if there is problem with connection, assume that supervisord
-        # is not running and try to run it
-        pass
-      else:
-        if status['statename'] == 'RUNNING' and status['statecode'] == 1:
-          self.logger.info('Supervisord already running.')
-          return
-        else:
-          log_message = 'Unknown supervisord state %r. Will try to start.' % status
-          self.logger.warning(log_message)
-
-    self.logger.info("Launching supervisord with clean environment.")
-    # Extract python binary to prevent shebang size limit
-    invocation_list = ["supervisord", '-c']
-    invocation_list.append("import sys ; sys.path=" + str(sys.path) + " ; import "
-        "supervisor.supervisord ; sys.argv[1:1]=['-c','" +
-        self.supervisord_configuration_path +
-        "'] ; supervisor.supervisord.main()")
-    supervisord_popen = SlapPopen(invocation_list,
-        env={},
-        executable=sys.executable)
-    result = supervisord_popen.communicate()[0]
-    if supervisord_popen.returncode == 0:
-      log_message = 'Supervisord command invoked with: %s' % result
-      self.logger.info(log_message)
-      status = supervisor.getState()
-      if status['statename'] == 'RUNNING' and status['statecode'] == 1:
-        self.logger.info('Supervisord started correctly.')
-    else:
-      log_message = 'Supervisord unknown problem: %s' % result
-      self.logger.info(log_message)
+  def _launchSupervisord(self):
+    launchSupervisord(self.supervisord_socket,
+        self.supervisord_configuration_path)
 
   def processComputerPartitionList(self):
     """Will start supervisord and process each Computer Partition.
@@ -263,7 +229,7 @@ class Slapgrid(object):
     logger.info("Processing computer partitions...")
     # Prepares environment
     self.checkEnvironmentAndCreateStructure()
-    self._launchSupervisor()
+    self._launchSupervisord()
     # Process Computer Partitions
     clean_run = True
     for computer_partition in self.getComputerPartitionList():

Added: slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/svcbackend.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/svcbackend.py?rev=45379&view=auto
==============================================================================
--- slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/svcbackend.py (added)
+++ slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/svcbackend.py [utf8] Wed Apr 13 15:04:08 2011
@@ -0,0 +1,82 @@
+##############################################################################
+#
+# Copyright (c) 2010 Vifib SARL and Contributors. All Rights Reserved.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsibility of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# guarantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+# This program is Free Software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 3
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#
+##############################################################################
+
+from supervisor import xmlrpc
+from utils import SlapPopen
+import logging
+import os
+import sys
+import xmlrpclib
+
+
+def getSupervisorRPC(socket):
+  supervisor_transport = xmlrpc.SupervisorTransport('', '',
+      'unix://' + socket)
+  server_proxy = xmlrpclib.ServerProxy('http://127.0.0.1',
+      supervisor_transport)
+  return getattr(server_proxy, 'supervisor')
+
+
+def launchSupervisord(socket, configuration_file):
+  logger = logging.getLogger('SVCBackend')
+  supervisor = getSupervisorRPC(socket)
+  if os.path.exists(socket):
+    try:
+      status = supervisor.getState()
+    except Exception:
+      # In case if there is problem with connection, assume that supervisord
+      # is not running and try to run it
+      pass
+    else:
+      if status['statename'] == 'RUNNING' and status['statecode'] == 1:
+        logger.info('Supervisord already running.')
+        return
+      else:
+        log_message = 'Unknown supervisord state %r. Will try to start.' % status
+        logger.warning(log_message)
+
+  logger.info("Launching supervisord with clean environment.")
+  # Extract python binary to prevent shebang size limit
+  invocation_list = ["supervisord", '-c']
+  invocation_list.append("import sys ; sys.path=" + str(sys.path) + " ; import "
+      "supervisor.supervisord ; sys.argv[1:1]=['-c','" +
+      configuration_file +
+      "'] ; supervisor.supervisord.main()")
+  supervisord_popen = SlapPopen(invocation_list,
+      env={},
+      executable=sys.executable)
+  result = supervisord_popen.communicate()[0]
+  if supervisord_popen.returncode == 0:
+    log_message = 'Supervisord command invoked with: %s' % result
+    logger.info(log_message)
+    status = supervisor.getState()
+    if status['statename'] == 'RUNNING' and status['statecode'] == 1:
+      logger.info('Supervisord started correctly.')
+  else:
+    log_message = 'Supervisord unknown problem: %s' % result
+    logger.info(log_message)
+

Modified: slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/utils.py
URL: http://svn.erp5.org/slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/utils.py?rev=45379&r1=45378&r2=45379&view=diff
==============================================================================
--- slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/utils.py [utf8] (original)
+++ slapos/trunk/util/slapos.tool.grid/src/slapos/tool/grid/utils.py [utf8] Wed Apr 13 15:04:08 2011
@@ -36,8 +36,6 @@ from optparse import OptionParser
 import pwd
 import grp
 from hashlib import md5
-from supervisor import xmlrpc
-import xmlrpclib
 
 # Such umask by default will create paths with full permission
 # for user, non writable by group and not accessible by others
@@ -502,14 +500,6 @@ def updateFile(file_path, content, mode=
   return altered
 
 
-def getSupervisorRPC(socket):
-  supervisor_transport = xmlrpc.SupervisorTransport('', '',
-      'unix://' + socket)
-  server_proxy = xmlrpclib.ServerProxy('http://127.0.0.1',
-      supervisor_transport)
-  return getattr(server_proxy, 'supervisor')
-
-
 def updateExecutable(executable_path, content):
   """Creates an executable with "content" as content."""
   return updateFile(executable_path, content, '0700')



More information about the Erp5-report mailing list