def start_ganga(): import sys import os.path file_path = os.path.dirname(os.path.realpath(__file__)) ganga_python_dir = os.path.join(file_path, '..', '..', '..') ganga_python_dir = os.path.realpath(ganga_python_dir) sys.path.insert(0, ganga_python_dir) print("Adding: %s to Python Path\n" % ganga_python_dir) sys.path.insert(0, ganga_python_dir) import Ganga.PACKAGE Ganga.PACKAGE.standardSetup() # End taken from the ganga binary import Ganga.Runtime import Ganga.Utility.logging logger = Ganga.Utility.logging.getLogger() # Start ganga by passing some options for unittesting logger.info("Starting ganga") logger.info("Parsing Command Line options") import Ganga.Runtime this_argv = [ 'ganga', # `argv[0]` is usually the name of the program so fake that here '-o[Configuration]RUNTIME_PATH=GangaTest', '-o[Configuration]user=testframework', '-o[Configuration]gangadir=$HOME/gangadir_testing', '-o[Configuration]repositorytype=LocalXML', '-o[PollThread]autostart_monThreads=False', '-o[TestingFramework]ReleaseTesting=True', ] # FIXME Should we need to add the ability to load from a custom .ini file # to configure tests without editting this? # Actually parse the options Ganga.Runtime._prog = Ganga.Runtime.GangaProgram(argv=this_argv) Ganga.Runtime._prog.parseOptions() # Determine if ganga has actually finished initializing... # This is here to protect against the startGanga being called on an # initialized ganga environment try: do_config = not Ganga.Utility.Config.Config._after_bootstrap except: do_config = True if do_config: # Perform the configuration and bootstrap steps in ganga logger.info("Parsing Configuration Options") Ganga.Runtime._prog.configure() logger.info("Initializing") Ganga.Runtime._prog.initEnvironment(opt_rexec=False) else: # We need to test if the internal services need to be reinitialized from Ganga.Core.InternalServices import Coordinator if not Coordinator.servicesEnabled: # Start internal services logger.info("InternalServices restarting") from Ganga.GPI import reactivate reactivate() else: logger.info("InternalServices still running") logger.info("Bootstrapping") Ganga.Runtime._prog.bootstrap(interactive=False) # [PollThread]autostart_monThreads=False has turned this off being done automatically. # The thread pool is emptied by _ganga_run_exitfuncs from Ganga.Core.MonitoringComponent.Local_GangaMC_Service import _makeThreadPool _makeThreadPool() # Adapted from the Coordinator class, check for the required credentials and stop if not found # Hopefully stops us falling over due to no AFS access of something similar from Ganga.Core.InternalServices import Coordinator missing_cred = Coordinator.getMissingCredentials() logger.info("Checking Credentials") if missing_cred: raise Exception("Failed due to missing credentials %s" % str(missing_cred)) logger.info("Passing to Unittest")
def start_ganga(gangadir_for_test='$HOME/gangadir_testing', extra_opts=[]): import sys import os.path file_path = os.path.dirname(os.path.realpath(__file__)) ganga_python_dir = os.path.join(file_path, '..', '..', '..') ganga_python_dir = os.path.realpath(ganga_python_dir) if len(sys.path) >= 1 and ganga_python_dir != sys.path[0]: sys.path.insert(0, ganga_python_dir) print("Adding: %s to Python Path\n" % ganga_python_dir) import Ganga.PACKAGE Ganga.PACKAGE.standardSetup() # End taken from the ganga binary import Ganga.Runtime from Ganga.Utility.logging import getLogger logger = getLogger() # Start ganga by passing some options for unittesting logger.info("Starting ganga") logger.info("Parsing Command Line options") import Ganga.Runtime this_argv = [ 'ganga', # `argv[0]` is usually the name of the program so fake that here ] # These are the default options for all test instances # They can be overridden by extra_opts default_opts = [ ('Configuration', 'RUNTIME_PATH', 'GangaTest'), ('Configuration', 'gangadir', gangadir_for_test), ('Configuration', 'user', 'testframework'), ('Configuration', 'repositorytype', 'LocalXML'), ('TestingFramework', 'ReleaseTesting', True), ('Queues', 'NumWorkerThreads', 2), ] # FIXME Should we need to add the ability to load from a custom .ini file # to configure tests without editting this? # Actually parse the options Ganga.Runtime._prog = Ganga.Runtime.GangaProgram(argv=this_argv) Ganga.Runtime._prog.parseOptions() # Determine if ganga has actually finished initializing... # This is here to protect against the startGanga being called on an # initialized ganga environment try: do_config = not Ganga.Utility.Config.Config._after_bootstrap except: do_config = True # For all the default and extra options, we set the session value from Ganga.Utility.Config import setConfigOption for opt in default_opts + extra_opts: setConfigOption(*opt) if do_config: # Perform the configuration and bootstrap steps in ganga logger.info("Parsing Configuration Options") Ganga.Runtime._prog.configure() logger.info("Initializing") Ganga.Runtime._prog.initEnvironment(opt_rexec=False) else: # We need to test if the internal services need to be reinitialized from Ganga.Core.InternalServices import Coordinator if not Coordinator.servicesEnabled: # Start internal services logger.info("InternalServices restarting") from Ganga.GPI import reactivate reactivate() else: logger.info("InternalServices still running") # The queues are shut down by the atexit handlers so we need to start them here from Ganga.Core.GangaThread.WorkerThreads import startUpQueues startUpQueues() logger.info("Bootstrapping") Ganga.Runtime._prog.bootstrap(interactive=False) # Adapted from the Coordinator class, check for the required credentials and stop if not found # Hopefully stops us falling over due to no AFS access of something similar from Ganga.Core.InternalServices import Coordinator missing_cred = Coordinator.getMissingCredentials() logger.info("Checking Credentials") if missing_cred: raise Exception("Failed due to missing credentials %s" % str(missing_cred)) logger.info("Passing to Unittest")
# No need to perform the bootstrap but we need to test if the internal # services need to be reinitialized from Ganga.Utility.Config import setConfigOption setConfigOption('PollThread', 'forced_shutdown_policy', 'batch') from Ganga.Core.InternalServices import Coordinator if not Coordinator.servicesEnabled: # Start internal services logger.info("InternalServices restarting") def testing_cb(t_total, critical_thread_ids, non_critical_thread_ids): return True from Ganga.Core.GangaThread import GangaThreadPool thread_pool = GangaThreadPool.getInstance() thread_pool.shutdown(should_wait_cb=testing_cb) from Ganga.GPI import reactivate reactivate() else: logger.info("InternalServices still running") # Adapted from the Coordinator class, check for the required credentials and stop if not found # Hopefully stops us falling over due to no AFS access of something similar from Ganga.Core.InternalServices import Coordinator missing_cred = Coordinator.getMissingCredentials() logger.info("Checking Credentials") if missing_cred: raise Exception("Failed due to missing credentials %s" % str(missing_cred)) logger.info("Passing to Unittest")