[Erp5-report] r45380 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:16:27 CEST 2011
Author: luke
Date: Wed Apr 13 15:16:26 2011
New Revision: 45380
URL: http://svn.erp5.org?rev=45380&view=rev
Log:
- stop the crazy circural imports
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=45380&r1=45379&r2=45380&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:16:26 2011
@@ -402,3 +402,18 @@ class Partition(object):
supervisor.addProcessGroup(gname)
self.logger.info('Updated %r' % gname)
self.logger.debug('Supervisord updated')
+
+"""Exposed exceptions"""
+
+
+class PathDoesNotExistError(Exception):
+ pass
+
+
+class WrongPermissionError(Exception):
+ pass
+
+
+class BuildoutFailedError(Exception):
+ pass
+
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=45380&r1=45379&r2=45380&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:16:26 2011
@@ -37,10 +37,11 @@ import subprocess
import traceback
#from time import strftime
-from SlapObject import Software, Partition
+from SlapObject import Software, Partition, WrongPermissionError, \
+ PathDoesNotExistError
+from optparse import OptionParser
from utils import updateFile
from utils import createPrivateDirectory
-from utils import parseArgumentTupleAndReturnSlapgridObject
from utils import setRunning
from utils import setFinished
from utils import getSoftwareUrlHash
@@ -54,6 +55,178 @@ import StringIO
from lxml import etree
+MANDATORY_PARAMETER_LIST = [
+ 'computer_id',
+ 'instance_root',
+ 'master_url',
+ 'software_root',
+]
+
+
+def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
+ """Parses arguments either from command line, from method parameters or from
+ config file. Then returns a new instance of slapgrid.Slapgrid with those
+ parameters. Also returns the options dict and unused variable list, and
+ configures logger.
+ """
+ usage = """
+Typical usage:
+ * %prog [options] CONFIGURATION_FILE
+
+Note : Command-line arguments supersede configuration file arguments.""".strip()
+
+ parser = OptionParser(usage=usage)
+ parser.add_option("--instance-root",
+ help="The instance root directory location.")
+ parser.add_option("--software-root",
+ help="The software_root directory location.")
+ parser.add_option("--master-url",
+ help="The master server URL. Mandatory.")
+ parser.add_option("--computer-id",
+ help="The computer id defined in the server.")
+ parser.add_option("--supervisord-socket",
+ help="The socket supervisor will use.")
+ parser.add_option("--buildout-parameter",
+ help="The parameters given to buildout. Default is '-U'.")
+ parser.add_option("--supervisord-configuration-path",
+ help="The location where supervisord configuration " \
+ "will be stored.")
+ parser.add_option("--usage-report-periodicity",
+ type="int", default="24",
+ help="The periodicity of usage report sends, in hours.")
+ parser.add_option("--pidfile",
+ help="The location where pidfile will be created.")
+ parser.add_option("--logfile",
+ help="The location where slapgrid logfile will be " \
+ "created.")
+ parser.add_option("--key_file", help="SSL Authorisation key file.")
+ parser.add_option("--cert_file", help="SSL Authorisation certificate file.")
+ parser.add_option("--master_ca_file", help="Root certificate of SlapOS "
+ "master key.")
+ parser.add_option("--certificate_repository_path", help="Path to directory "
+ "where downloaded certificates would be stored.")
+ parser.add_option("-c", "--console", action="store_true", default=False,
+ help="Enables console output and live output from subcommands.")
+ parser.add_option("-v", "--verbose", action="store_true", default=False,
+ help="Be verbose.")
+
+ # Parses arguments
+ if argument_tuple == ():
+ # No arguments given to entry point : we parse sys.argv.
+ (argument_option_instance, argument_list) = parser.parse_args()
+ else:
+ (argument_option_instance, argument_list) = \
+ parser.parse_args(list(argument_tuple))
+ if len(argument_list) != 1:
+ parser.error("Configuration file is obligatory. Consult documentation by "
+ "calling with -h.")
+ configuration_file = argument_list[0]
+ #FIXME library that gives not iterable instances of crap.
+ argument_option_dict = \
+ dict(instance_root=argument_option_instance.instance_root,
+ software_root=argument_option_instance.software_root,
+ master_url=argument_option_instance.master_url,
+ computer_id=argument_option_instance.computer_id,
+ supervisord_socket=argument_option_instance.supervisord_socket,
+ supervisord_configuration_path=argument_option_instance\
+ .supervisord_configuration_path,
+ usage_report_periodicity=argument_option_instance\
+ .usage_report_periodicity,
+ pidfile=argument_option_instance.pidfile,
+ logfile=argument_option_instance.logfile,
+ key_file=argument_option_instance.key_file,
+ cert_file=argument_option_instance.cert_file,
+ master_ca_file=argument_option_instance.master_ca_file,
+ console=argument_option_instance.console,
+ verbose=argument_option_instance.verbose,
+ )
+ # Parses arguments from config file, if needed, then merge previous arguments
+ option_dict = {}
+ if not os.path.exists(configuration_file):
+ parser.error("Could not read configuration file : %s" \
+ % configuration_file)
+ # Loads config (if config specified)
+ import ConfigParser
+ slapgrid_configuration = ConfigParser.SafeConfigParser()
+ slapgrid_configuration.read(configuration_file)
+ # Merges the two dictionnaries
+ option_dict = dict(slapgrid_configuration.items("slapos"))
+ for key in argument_option_dict:
+ if argument_option_dict[key] is not None:
+ option_dict.update({key: argument_option_dict[key]})
+ # Configures logger.
+ #XXX: We need to configure it as soon as possible, so I do it here.
+ logger_format = '%(asctime)s %(name)-18s: %(levelname)-8s %(message)s'
+ if option_dict['verbose']:
+ level=logging.DEBUG
+ else:
+ level=logging.INFO
+ if option_dict.get('logfile'):
+ logging.basicConfig(filename=option_dict['logfile'],
+ format=logger_format, level=level)
+ if option_dict['console']:
+ logging.basicConfig(level=level)
+ missing_mandatory_parameter_list = []
+ for mandatory_parameter in MANDATORY_PARAMETER_LIST:
+ if not mandatory_parameter in option_dict:
+ missing_mandatory_parameter_list.append(mandatory_parameter)
+
+ repository_required = False
+ if 'key_file' in option_dict:
+ repository_required = True
+ if not 'cert_file' in option_dict:
+ missing_mandatory_parameter_list.append('cert_file')
+ if 'cert_file' in option_dict:
+ repository_required = True
+ if not 'key_file' in option_dict:
+ missing_mandatory_parameter_list.append('key_file')
+ if repository_required:
+ if 'certificate_repository_path' not in option_dict:
+ missing_mandatory_parameter_list.append('certificate_repository_path')
+
+ if len(missing_mandatory_parameter_list) > 0:
+ parser.error('Missing mandatory parameters:\n%s' % '\n'.join(
+ missing_mandatory_parameter_list))
+
+ key_file = option_dict.get('key_file')
+ cert_file = option_dict.get('cert_file')
+ master_ca_file = option_dict.get('master_ca_file')
+
+ for f in [key_file, cert_file, master_ca_file]:
+ if f is not None:
+ if not os.path.exists(f):
+ parser.error('File %r does not exists.' % f)
+
+ certificate_repository_path = option_dict.get('certificate_repository_path')
+ if certificate_repository_path is not None:
+ if not os.path.isdir(certificate_repository_path):
+ parser.error('Directory %r does not exists' % certificate_repository_path)
+
+ # Supervisord configuration location
+ if not option_dict.get('supervisord_configuration_path'):
+ option_dict['supervisord_configuration_path'] = \
+ os.path.join(option_dict['instance_root'], 'etc', 'supervisord.conf')
+ # Supervisord socket
+ if not option_dict.get('supervisord_socket'):
+ option_dict['supervisord_socket'] = \
+ os.path.join(option_dict['instance_root'], 'supervisord.socket')
+ # Returning new Slapgrid instance and options
+ return ([Slapgrid(software_root=option_dict['software_root'],
+ instance_root=option_dict['instance_root'],
+ master_url=option_dict['master_url'],
+ computer_id=option_dict['computer_id'],
+ supervisord_socket=option_dict['supervisord_socket'],
+ supervisord_configuration_path=option_dict[
+ 'supervisord_configuration_path'],
+ usage_report_periodicity=option_dict['usage_report_periodicity'],
+ key_file=key_file,
+ cert_file=cert_file,
+ master_ca_file=master_ca_file,
+ certificate_repository_path=certificate_repository_path,
+ console=option_dict['console']),
+ option_dict])
+
+
def realRun(argument_tuple, method_list):
clean_run = True
slapgrid_object, option_dict = \
@@ -487,18 +660,3 @@ class Slapgrid(object):
logger.info("Finished usage reports...")
return clean_run
-
-
-"""Exposed exceptions"""
-
-
-class PathDoesNotExistError(Exception):
- pass
-
-
-class WrongPermissionError(Exception):
- pass
-
-
-class BuildoutFailedError(Exception):
- pass
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=45380&r1=45379&r2=45380&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:16:26 2011
@@ -28,13 +28,12 @@ import logging
import hashlib
import os
import pkg_resources
-import slapgrid
import stat
import subprocess
import sys
-from optparse import OptionParser
import pwd
import grp
+from SlapObject import BuildoutFailedError, WrongPermissionError
from hashlib import md5
# Such umask by default will create paths with full permission
@@ -83,14 +82,6 @@ LOCALE_ENVIRONEMNT_REMOVE_LIST = [
'LC_TIME',
]
-MANDATORY_PARAMETER_LIST = [
- 'computer_id',
- 'instance_root',
- 'master_url',
- 'software_root',
-]
-
-
class AlreadyRunning(Exception):
pass
@@ -127,170 +118,6 @@ def getCleanEnvironment(home_path='/tmp'
return env
-def parseArgumentTupleAndReturnSlapgridObject(*argument_tuple):
- """Parses arguments either from command line, from method parameters or from
- config file. Then returns a new instance of slapgrid.Slapgrid with those
- parameters. Also returns the options dict and unused variable list, and
- configures logger.
- """
- usage = """
-Typical usage:
- * %prog [options] CONFIGURATION_FILE
-
-Note : Command-line arguments supersede configuration file arguments.""".strip()
-
- parser = OptionParser(usage=usage)
- parser.add_option("--instance-root",
- help="The instance root directory location.")
- parser.add_option("--software-root",
- help="The software_root directory location.")
- parser.add_option("--master-url",
- help="The master server URL. Mandatory.")
- parser.add_option("--computer-id",
- help="The computer id defined in the server.")
- parser.add_option("--supervisord-socket",
- help="The socket supervisor will use.")
- parser.add_option("--buildout-parameter",
- help="The parameters given to buildout. Default is '-U'.")
- parser.add_option("--supervisord-configuration-path",
- help="The location where supervisord configuration " \
- "will be stored.")
- parser.add_option("--usage-report-periodicity",
- type="int", default="24",
- help="The periodicity of usage report sends, in hours.")
- parser.add_option("--pidfile",
- help="The location where pidfile will be created.")
- parser.add_option("--logfile",
- help="The location where slapgrid logfile will be " \
- "created.")
- parser.add_option("--key_file", help="SSL Authorisation key file.")
- parser.add_option("--cert_file", help="SSL Authorisation certificate file.")
- parser.add_option("--master_ca_file", help="Root certificate of SlapOS "
- "master key.")
- parser.add_option("--certificate_repository_path", help="Path to directory "
- "where downloaded certificates would be stored.")
- parser.add_option("-c", "--console", action="store_true", default=False,
- help="Enables console output and live output from subcommands.")
- parser.add_option("-v", "--verbose", action="store_true", default=False,
- help="Be verbose.")
-
- # Parses arguments
- if argument_tuple == ():
- # No arguments given to entry point : we parse sys.argv.
- (argument_option_instance, argument_list) = parser.parse_args()
- else:
- (argument_option_instance, argument_list) = \
- parser.parse_args(list(argument_tuple))
- if len(argument_list) != 1:
- parser.error("Configuration file is obligatory. Consult documentation by "
- "calling with -h.")
- configuration_file = argument_list[0]
- #FIXME library that gives not iterable instances of crap.
- argument_option_dict = \
- dict(instance_root=argument_option_instance.instance_root,
- software_root=argument_option_instance.software_root,
- master_url=argument_option_instance.master_url,
- computer_id=argument_option_instance.computer_id,
- supervisord_socket=argument_option_instance.supervisord_socket,
- supervisord_configuration_path=argument_option_instance\
- .supervisord_configuration_path,
- usage_report_periodicity=argument_option_instance\
- .usage_report_periodicity,
- pidfile=argument_option_instance.pidfile,
- logfile=argument_option_instance.logfile,
- key_file=argument_option_instance.key_file,
- cert_file=argument_option_instance.cert_file,
- master_ca_file=argument_option_instance.master_ca_file,
- console=argument_option_instance.console,
- verbose=argument_option_instance.verbose,
- )
- # Parses arguments from config file, if needed, then merge previous arguments
- option_dict = {}
- if not os.path.exists(configuration_file):
- parser.error("Could not read configuration file : %s" \
- % configuration_file)
- # Loads config (if config specified)
- import ConfigParser
- slapgrid_configuration = ConfigParser.SafeConfigParser()
- slapgrid_configuration.read(configuration_file)
- # Merges the two dictionnaries
- option_dict = dict(slapgrid_configuration.items("slapos"))
- for key in argument_option_dict:
- if argument_option_dict[key] is not None:
- option_dict.update({key: argument_option_dict[key]})
- # Configures logger.
- #XXX: We need to configure it as soon as possible, so I do it here.
- logger_format = '%(asctime)s %(name)-18s: %(levelname)-8s %(message)s'
- if option_dict['verbose']:
- level=logging.DEBUG
- else:
- level=logging.INFO
- if option_dict.get('logfile'):
- logging.basicConfig(filename=option_dict['logfile'],
- format=logger_format, level=level)
- if option_dict['console']:
- logging.basicConfig(level=level)
- missing_mandatory_parameter_list = []
- for mandatory_parameter in MANDATORY_PARAMETER_LIST:
- if not mandatory_parameter in option_dict:
- missing_mandatory_parameter_list.append(mandatory_parameter)
-
- repository_required = False
- if 'key_file' in option_dict:
- repository_required = True
- if not 'cert_file' in option_dict:
- missing_mandatory_parameter_list.append('cert_file')
- if 'cert_file' in option_dict:
- repository_required = True
- if not 'key_file' in option_dict:
- missing_mandatory_parameter_list.append('key_file')
- if repository_required:
- if 'certificate_repository_path' not in option_dict:
- missing_mandatory_parameter_list.append('certificate_repository_path')
-
- if len(missing_mandatory_parameter_list) > 0:
- parser.error('Missing mandatory parameters:\n%s' % '\n'.join(
- missing_mandatory_parameter_list))
-
- key_file = option_dict.get('key_file')
- cert_file = option_dict.get('cert_file')
- master_ca_file = option_dict.get('master_ca_file')
-
- for f in [key_file, cert_file, master_ca_file]:
- if f is not None:
- if not os.path.exists(f):
- parser.error('File %r does not exists.' % f)
-
- certificate_repository_path = option_dict.get('certificate_repository_path')
- if certificate_repository_path is not None:
- if not os.path.isdir(certificate_repository_path):
- parser.error('Directory %r does not exists' % certificate_repository_path)
-
- # Supervisord configuration location
- if not option_dict.get('supervisord_configuration_path'):
- option_dict['supervisord_configuration_path'] = \
- os.path.join(option_dict['instance_root'], 'etc', 'supervisord.conf')
- # Supervisord socket
- if not option_dict.get('supervisord_socket'):
- option_dict['supervisord_socket'] = \
- os.path.join(option_dict['instance_root'], 'supervisord.socket')
- # Returning new Slapgrid instance and options
- return ([slapgrid.Slapgrid(software_root=option_dict['software_root'],
- instance_root=option_dict['instance_root'],
- master_url=option_dict['master_url'],
- computer_id=option_dict['computer_id'],
- supervisord_socket=option_dict['supervisord_socket'],
- supervisord_configuration_path=option_dict[
- 'supervisord_configuration_path'],
- usage_report_periodicity=option_dict['usage_report_periodicity'],
- key_file=key_file,
- cert_file=cert_file,
- master_ca_file=master_ca_file,
- certificate_repository_path=certificate_repository_path,
- console=option_dict['console']),
- option_dict])
-
-
def setRunning(pid_file):
"""Creates a pidfile. If a pidfile already exists, we exit"""
logger = logging.getLogger('Slapgrid')
@@ -423,11 +250,11 @@ def bootstrapBuildout(path, additional_b
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r:\n%s\n' % (
path, result)
- raise slapgrid.BuildoutFailedError(message)
+ raise BuildoutFailedError(message)
else:
logger.debug('Successful run:\n%s' % result)
except OSError as error:
- raise slapgrid.BuildoutFailedError(error)
+ raise BuildoutFailedError(error)
finally:
old_umask = os.umask(umask)
logger.debug('Restore umask from %03o to %03o' % (old_umask, umask))
@@ -472,11 +299,11 @@ def launchBuildout(path, buildout_binary
if process_handler.returncode is None or process_handler.returncode != 0:
message = 'Failed to run buildout profile in directory %r:\n%s\n' % (
path, result)
- raise slapgrid.BuildoutFailedError(message)
+ raise BuildoutFailedError(message)
else:
logger.debug('Successful run:\n%s' % result)
except OSError as error:
- raise slapgrid.BuildoutFailedError(error)
+ raise BuildoutFailedError(error)
finally:
old_umask = os.umask(umask)
logger.debug('Restore umask from %03o to %03o' % (old_umask, umask))
@@ -512,6 +339,6 @@ def createPrivateDirectory(path):
os.chmod(path, stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
permission = oct(stat.S_IMODE(os.stat(path).st_mode))
if permission not in ('0700'):
- raise slapgrid.WrongPermissionError('Wrong permissions in %s ' \
+ raise WrongPermissionError('Wrong permissions in %s ' \
': is %s, should be 0700'
% path, permission)
More information about the Erp5-report
mailing list