Пример #1
0
def do_test():
    """Runs test phase, erroring if any return false.
	"""
    shutit = shutit_global.shutit
    if not shutit.build['dotest']:
        shutit.log('Tests configured off, not running', level=logging.DEBUG)
        return
    # Test in reverse order
    shutit.log('PHASE: test', level=logging.DEBUG)
    if shutit.build['interactive'] >= 3:
        print '\nNow doing test phase' + shutit_util.colourise(
            '32', '\n\n[Hit return to continue]\n')
        shutit_util.util_raw_input()
    stop_all()
    start_all()
    for module_id in shutit_util.module_ids(rev=True):
        # Only test if it's installed.
        if shutit_util.is_installed(shutit.shutit_map[module_id]):
            shutit.log('RUNNING TEST ON: ' + module_id, level=logging.DEBUG)
            shutit.login(prompt_prefix=module_id, command='bash')
            if not shutit.shutit_map[module_id].test(shutit):
                shutit.fail(module_id + ' failed on test',
                            shutit_pexpect_child=shutit.
                            get_shutit_pexpect_session_from_id(
                                'target_child').pexpect_child)
            shutit.logout()
Пример #2
0
def do_remove(loglevel=logging.DEBUG):
	"""Remove modules by calling remove method on those configured for removal.
	"""
	shutit = shutit_global.shutit
	cfg = shutit.cfg
	# Now get the run_order keys in order and go.
	shutit.log('PHASE: remove', level=loglevel)
	shutit.pause_point('\nNow removing any modules that need removing', print_input=False, level=3)
	# Login at least once to get the exports.
	for module_id in shutit_util.module_ids():
		module = shutit.shutit_map[module_id]
		shutit.log('considering whether to remove: ' + module_id, level=logging.DEBUG)
		if cfg[module_id]['shutit.core.module.remove']:
			shutit.log('removing: ' + module_id, level=logging.DEBUG)
			shutit.login(prompt_prefix=module_id,command='bash')
			if not module.remove(shutit):
				shutit.log(shutit_util.print_modules(), level=logging.DEBUG)
				shutit.fail(module_id + ' failed on remove', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').pexpect_child)
			else:
				if shutit.build['delivery'] in ('docker','dockerfile'):
					# Create a directory and files to indicate this has been removed.
					shutit.send(' mkdir -p ' + shutit.build['build_db_dir'] + '/module_record/' + module.module_id + ' && rm -f ' + shutit.build['build_db_dir'] + '/module_record/' + module.module_id + '/built && touch ' + shutit.build['build_db_dir'] + '/module_record/' + module.module_id + '/removed', loglevel=loglevel)
					# Remove from "installed" cache
					if module.module_id in shutit_global.shutit.get_current_shutit_pexpect_session_environment().modules_installed:
						shutit_global.shutit.get_current_shutit_pexpect_session_environment().modules_installed.remove(module.module_id)
					# Add to "not installed" cache
					shutit_global.shutit.get_current_shutit_pexpect_session_environment().modules_not_installed.append(module.module_id)
			shutit.logout()
Пример #3
0
def do_finalize():
    """Runs finalize phase; run after all builds are complete and all modules
	have been stopped.
	"""
    shutit = shutit_global.shutit
    # Stop all the modules
    if shutit.build['interactive'] >= 3:
        print('\nStopping all modules before finalize phase' +
              shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
        shutit_util.util_raw_input()
    stop_all()
    # Finalize in reverse order
    shutit.log('PHASE: finalize', level=logging.DEBUG)
    if shutit.build['interactive'] >= 3:
        print('\nNow doing finalize phase, which we do when all builds are ' +
              'complete and modules are stopped' +
              shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
        shutit_util.util_raw_input()
    # Login at least once to get the exports.
    for module_id in shutit_util.module_ids(rev=True):
        # Only finalize if it's thought to be installed.
        if shutit_util.is_installed(shutit.shutit_map[module_id]):
            shutit.login(prompt_prefix=module_id, command='bash')
            if not shutit.shutit_map[module_id].finalize(shutit):
                shutit.fail(module_id + ' failed on finalize',
                            shutit_pexpect_child=shutit.
                            get_shutit_pexpect_session_from_id(
                                'target_child').pexpect_child)
            shutit.logout()
Пример #4
0
def do_build():
	"""Runs build phase, building any modules that we've determined
	need building.
	"""
	shutit = shutit_global.shutit
	cfg = shutit.cfg
	shutit.log('PHASE: build, repository work', level=logging.DEBUG)
	module_id_list = shutit_util.module_ids()
	if shutit.build['deps_only']:
		module_id_list_build_only = filter(lambda x: cfg[x]['shutit.core.module.build'], module_id_list)
	for module_id in module_id_list:
		module = shutit.shutit_map[module_id]
		shutit.log('Considering whether to build: ' + module.module_id, level=logging.INFO)
		if cfg[module.module_id]['shutit.core.module.build']:
			if shutit.build['delivery'] not in module.ok_delivery_methods:
				shutit.fail('Module: ' + module.module_id + ' can only be built with one of these --delivery methods: ' + str(module.ok_delivery_methods) + '\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation')
			if shutit_util.is_installed(module):
				shutit.build['report'] = (shutit.build['report'] + '\nBuilt already: ' + module.module_id + ' with run order: ' + str(module.run_order))
			else:
				# We move to the module directory to perform the build, returning immediately afterwards.
				if shutit.build['deps_only'] and module_id == module_id_list_build_only[-1]:
					# If this is the last module, and we are only building deps, stop here.
					shutit.build['report'] = (shutit.build['report'] + '\nSkipping: ' + module.module_id + ' with run order: ' + str(module.run_order) + '\n\tas this is the final module and we are building dependencies only')
				else:
					revert_dir = os.getcwd()
					shutit_global.shutit.get_current_shutit_pexpect_session_environment().module_root_dir = os.path.dirname(module.__module_file)
					shutit.chdir(shutit_global.shutit.get_current_shutit_pexpect_session_environment().module_root_dir)
					shutit.login(prompt_prefix=module_id,command='bash')
					build_module(module)
					shutit.logout()
					shutit.chdir(revert_dir)
		if shutit_util.is_installed(module):
			shutit.log('Starting module',level=logging.DEBUG)
			if not module.start(shutit):
				shutit.fail(module.module_id + ' failed on start', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').pexpect_child)
Пример #5
0
def check_conflicts(shutit):
    """Checks for any conflicts between modules configured to be built.
	"""
    cfg = shutit.cfg
    # Now consider conflicts
    shutit.log('PHASE: conflicts', level=logging.DEBUG)
    errs = []
    shutit.pause_point('\nNow checking for conflicts between modules',
                       print_input=False,
                       level=3)
    for module_id in shutit_util.module_ids():
        if not cfg[module_id]['shutit.core.module.build']:
            continue
        conflicter = shutit.shutit_map[module_id]
        for conflictee in conflicter.conflicts_with:
            # If the module id isn't there, there's no problem.
            conflictee_obj = shutit.shutit_map.get(conflictee)
            if conflictee_obj == None:
                continue
            if ((cfg[conflicter.module_id]['shutit.core.module.build']
                 or shutit_util.is_to_be_built_or_is_installed(conflicter)) and
                (cfg[conflictee_obj.module_id]['shutit.core.module.build'] or
                 shutit_util.is_to_be_built_or_is_installed(conflictee_obj))):
                errs.append((
                    'conflicter module id: ' + conflicter.module_id +
                    ' is configured to be built or is already built but conflicts with module_id: '
                    + conflictee_obj.module_id, ))
    return errs
Пример #6
0
def do_test(shutit):
	"""Runs test phase, erroring if any return false.
	"""
	cfg = shutit.cfg
	if not cfg['build']['dotest']:
		shutit.log('Tests configured off, not running')
		return
	# Test in reverse order
	shutit.log('PHASE: test', code='32')
	if cfg['build']['interactive'] >= 3:
		print '\nNow doing test phase' + shutit_util.colour('32',
			'\n\n[Hit return to continue]\n')
		shutit_util.util_raw_input(shutit=shutit)
	stop_all(shutit)
	start_all(shutit)
	for module_id in shutit_util.module_ids(shutit, rev=True):
		module = shutit.shutit_map[module_id]
		# Only test if it's installed.
		if shutit_util.is_installed(shutit, shutit.shutit_map[module_id]):
			shutit.log('RUNNING TEST ON: ' + module_id, code='32')
			shutit.login(prompt_prefix=module_id,command='bash')
			if not shutit.shutit_map[module_id].test(shutit):
				shutit.fail(module_id + ' failed on test',
				child=shutit.pexpect_children['target_child'])
			shutit.logout()
Пример #7
0
def check_deps(shutit):
	"""Dependency checking phase is performed in this method.
	"""
	cfg = shutit.cfg
	shutit.log('PHASE: dependencies', code='32')
	shutit.pause_point('\nNow checking for dependencies between modules',
	                   print_input=False, level=3)
	# Get modules we're going to build
	to_build = [
		shutit.shutit_map[module_id] for module_id in shutit.shutit_map
		if module_id in cfg and cfg[module_id]['shutit.core.module.build']
	]
	# Add any deps we may need by extending to_build and altering cfg
	for module in to_build:
		resolve_dependencies(shutit, to_build, module)

	# Dep checking
	def err_checker(errs, triples):
		"""Collate error information.
		""" 
		new_triples = []
		for err, triple in zip(errs, triples):
			if not err:
				new_triples.append(triple)
				continue
			found_errs.append(err)
		return new_triples

	found_errs = []
	triples    = []
	for depender in to_build:
		for dependee_id in depender.depends_on:
			triples.append((depender, shutit.shutit_map.get(dependee_id),
							dependee_id))

	triples = err_checker([
		check_dependee_exists(shutit, depender, dependee, dependee_id)
		for depender, dependee, dependee_id in triples
	], triples)
	triples = err_checker([
		check_dependee_build(shutit, depender, dependee, dependee_id)
		for depender, dependee, dependee_id in triples
	], triples)
	triples = err_checker([
		check_dependee_order(shutit, depender, dependee, dependee_id)
		for depender, dependee, dependee_id in triples
	], triples)

	if found_errs:
		return [(err,) for err in found_errs]

	if cfg['build']['debug']:
		shutit.log('Modules configured to be built (in order) are: ', code='32')
		for module_id in shutit_util.module_ids(shutit):
			module = shutit.shutit_map[module_id]
			if cfg[module_id]['shutit.core.module.build']:
				shutit.log(module_id + '    ' + str(module.run_order), code='32')
		shutit.log('\n', code='32')

	return []
Пример #8
0
def check_conflicts(shutit):
	"""Checks for any conflicts between modules configured to be built.
	"""
	cfg = shutit.cfg
	# Now consider conflicts
	shutit.log('PHASE: conflicts', code='32')
	errs = []
	shutit.pause_point('\nNow checking for conflicts between modules',
	                   print_input=False, level=3)
	for module_id in shutit_util.module_ids(shutit):
		if not cfg[module_id]['shutit.core.module.build']:
			continue
		conflicter = shutit.shutit_map[module_id]
		for conflictee in conflicter.conflicts_with:
			# If the module id isn't there, there's no problem.
			conflictee_obj = shutit.shutit_map.get(conflictee)
			if conflictee_obj == None:
				continue
			if ((cfg[conflicter.module_id]['shutit.core.module.build'] or
			     shutit_util.is_to_be_built_or_is_installed(shutit,conflicter)) and
			    (cfg[conflictee_obj.module_id]['shutit.core.module.build'] or
			     shutit_util.is_to_be_built_or_is_installed(shutit,conflictee_obj))):
			    errs.append(('conflicter module id: ' + conflicter.module_id +
	                    ' is configured to be built or is already built but ' +
	                    'conflicts with module_id: ' + conflictee_obj.module_id,))
	return errs
Пример #9
0
def check_ready(shutit, throw_error=True):
	"""Check that all modules are ready to be built, calling check_ready on
	each of those configured to be built and not already installed
	(see shutit_util.is_installed).
	"""
	cfg = shutit.cfg
	shutit.log('PHASE: check_ready', code='32')
	errs = []
	shutit.pause_point('\nNow checking whether we are ready to build modules' + 
	                   ' configured to be built',
	                   print_input=False, level=3)
	# Find out who we are to see whether we need to log in and out or not. 
	for module_id in shutit_util.module_ids(shutit):
		module = shutit.shutit_map[module_id]
		shutit.log('considering check_ready (is it ready to be built?): ' +
		           module_id, code='32')
		if cfg[module_id]['shutit.core.module.build'] and module.module_id not in cfg['environment'][cfg['build']['current_environment_id']]['modules_ready'] and not shutit_util.is_installed(shutit,module):
			shutit.log('checking whether module is ready to build: ' + module_id,
			           code='32')
			shutit.login(prompt_prefix=module_id,command='bash')
			# Move to the directory so context is correct (eg for checking for
			# the existence of files needed for build)
			revert_dir = os.getcwd()
			cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir'] = os.path.dirname(module.__module_file)
			shutit.chdir(cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir'])
			if not is_ready(shutit, module) and throw_error:
				errs.append((module_id + ' not ready to install.\nRead the ' +
				            'check_ready function in the module,\nor log ' + 
				            'messages above to determine the issue.\n\n',
				            shutit.pexpect_children['target_child']))
			shutit.logout()
			shutit.chdir(revert_dir)
	return errs
Пример #10
0
def do_finalize(shutit):
	"""Runs finalize phase; run after all builds are complete and all modules
	have been stopped.
	"""
	cfg = shutit.cfg
	# Stop all the modules
	if cfg['build']['interactive'] >= 3:
		print('\nStopping all modules before finalize phase' + shutit_util.colour('32',
		      '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input(shutit=shutit)
	stop_all(shutit)
	# Finalize in reverse order
	shutit.log('PHASE: finalize', code='32')
	if cfg['build']['interactive'] >= 3:
		print('\nNow doing finalize phase, which we do when all builds are ' +
		      'complete and modules are stopped' +
		      shutit_util.colour('32', '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input(shutit=shutit)
	# Login at least once to get the exports.
	for module_id in shutit_util.module_ids(shutit, rev=True):
		# Only finalize if it's thought to be installed.
		if shutit_util.is_installed(shutit, shutit.shutit_map[module_id]):
			shutit.login(prompt_prefix=module_id,command='bash')
			if not shutit.shutit_map[module_id].finalize(shutit):
				shutit.fail(module_id + ' failed on finalize',
			                child=shutit.pexpect_children['target_child'])
			shutit.logout()
Пример #11
0
def check_ready(throw_error=True):
	"""Check that all modules are ready to be built, calling check_ready on
	each of those configured to be built and not already installed
	(see shutit_util.is_installed).
	"""
	shutit = shutit_global.shutit
	cfg = shutit.cfg
	shutit.log('PHASE: check_ready', level=logging.DEBUG)
	errs = []
	shutit.pause_point('\nNow checking whether we are ready to build modules configured to be built', print_input=False, level=3)
	# Find out who we are to see whether we need to log in and out or not.
	for module_id in shutit_util.module_ids():
		module = shutit.shutit_map[module_id]
		shutit.log('considering check_ready (is it ready to be built?): ' + module_id, level=logging.DEBUG)
		if cfg[module_id]['shutit.core.module.build'] and module.module_id not in shutit_global.shutit.get_current_shutit_pexpect_session_environment().modules_ready and not shutit_util.is_installed(module):
			shutit.log('checking whether module is ready to build: ' + module_id, level=logging.DEBUG)
			shutit.login(prompt_prefix=module_id,command='bash')
			# Move to the correct directory (eg for checking for the existence of files needed for build)
			revert_dir = os.getcwd()
			shutit_global.shutit.get_current_shutit_pexpect_session_environment().module_root_dir = os.path.dirname(module.__module_file)
			shutit.chdir(shutit_global.shutit.get_current_shutit_pexpect_session_environment().module_root_dir)
			if not is_ready(module) and throw_error:
				errs.append((module_id + ' not ready to install.\nRead the check_ready function in the module,\nor log messages above to determine the issue.\n\n', shutit.get_shutit_pexpect_session_from_id('target_child')))
			shutit.logout()
			shutit.chdir(revert_dir)
	return errs
Пример #12
0
def stop_all(run_order=-1):
	"""Runs stop method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we clean up state
	before committing run files etc.
	"""
	shutit = shutit_global.shutit
	# sort them so they're stopped in reverse order
	for module_id in shutit_util.module_ids(rev=True):
		shutit_module_obj = shutit.shutit_map[module_id]
		if run_order == -1 or shutit_module_obj.run_order <= run_order:
			if shutit_util.is_installed(shutit_module_obj):
				if not shutit_module_obj.stop(shutit):
					shutit.fail('failed to stop: ' + module_id, shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').shutit_pexpect_child)
Пример #13
0
def start_all(run_order=-1):
	"""Runs start method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we can export a clean
	target and still depended-on modules running if necessary.
	"""
	shutit = shutit_global.shutit
	# sort them so they're started in order
	for module_id in shutit_util.module_ids():
		shutit_module_obj = shutit.shutit_map[module_id]
		if run_order == -1 or shutit_module_obj.run_order <= run_order:
			if shutit_util.is_installed(shutit_module_obj):
				if not shutit_module_obj.start(shutit):
					shutit.fail('failed to start: ' + module_id, shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').shutit_pexpect_child)
Пример #14
0
def do_remove(shutit, loglevel=logging.DEBUG):
    """Remove modules by calling remove method on those configured for removal.
	"""
    cfg = shutit.cfg
    # Now get the run_order keys in order and go.
    shutit.log('PHASE: remove', level=loglevel)
    shutit.pause_point('\nNow removing any modules that need removing',
                       print_input=False,
                       level=3)
    # Login at least once to get the exports.
    for module_id in shutit_util.module_ids(shutit):
        module = shutit.shutit_map[module_id]
        shutit.log('considering whether to remove: ' + module_id,
                   level=logging.DEBUG)
        if cfg[module_id]['shutit.core.module.remove']:
            shutit.log('removing: ' + module_id, level=logging.DEBUG)
            shutit.login(prompt_prefix=module_id,
                         command='bash --noprofile --norc',
                         echo=False)
            if not module.remove(shutit):
                shutit.log(shutit_util.print_modules(shutit),
                           level=logging.DEBUG)
                shutit.fail(
                    module_id + ' failed on remove',
                    shutit_pexpect_child=shutit.
                    get_shutit_pexpect_session_from_id(
                        'target_child').pexpect_child)  # pragma: no cover
            else:
                if shutit.build['delivery'] in ('docker', 'dockerfile'):
                    # Create a directory and files to indicate this has been removed.
                    shutit.send(
                        ' command mkdir -p ' + shutit.build['build_db_dir'] +
                        '/module_record/' + module.module_id +
                        ' && command rm -f ' + shutit.build['build_db_dir'] +
                        '/module_record/' + module.module_id +
                        '/built && command touch ' +
                        shutit.build['build_db_dir'] + '/module_record/' +
                        module.module_id + '/removed',
                        loglevel=loglevel)
                    # Remove from "installed" cache
                    if module.module_id in shutit.get_current_shutit_pexpect_session_environment(
                    ).modules_installed:
                        shutit.get_current_shutit_pexpect_session_environment(
                        ).modules_installed.remove(module.module_id)
                    # Add to "not installed" cache
                    shutit.get_current_shutit_pexpect_session_environment(
                    ).modules_not_installed.append(module.module_id)
            shutit.logout(echo=False)
Пример #15
0
def stop_all(shutit, run_order=-1):
    """Runs stop method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we clean up state
	before committing run files etc.
	"""
    # sort them so they're stopped in reverse order
    for module_id in shutit_util.module_ids(shutit, rev=True):
        shutit_module_obj = shutit.shutit_map[module_id]
        if run_order == -1 or shutit_module_obj.run_order <= run_order:
            if shutit_util.is_installed(shutit, shutit_module_obj):
                if not shutit_module_obj.stop(shutit):
                    shutit.fail(
                        'failed to stop: ' + module_id,
                        shutit_pexpect_child=shutit.
                        get_shutit_pexpect_session_from_id('target_child').
                        shutit_pexpect_child)  # pragma: no cover
Пример #16
0
def start_all(run_order=-1):
	"""Runs start method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we can export a clean
	target and still depended-on modules running if necessary.
	"""
	shutit = shutit_global.shutit
	if shutit.build['interactive'] >= 3:
		print('\nRunning start on all modules' + shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input()
	# sort them so they're started in order
	for module_id in shutit_util.module_ids():
		shutit_module_obj = shutit.shutit_map[module_id]
		if run_order == -1 or shutit_module_obj.run_order <= run_order:
			if shutit_util.is_installed(shutit_module_obj):
				if not shutit_module_obj.start(shutit):
					shutit.fail('failed to start: ' + module_id, shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').shutit_pexpect_child)
Пример #17
0
def start_all(shutit, run_order=-1):
    """Runs start method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we can export a clean
	target and still depended-on modules running if necessary.
	"""
    # sort them so they're started in order
    for module_id in shutit_util.module_ids(shutit):
        shutit_module_obj = shutit.shutit_map[module_id]
        if run_order == -1 or shutit_module_obj.run_order <= run_order:
            if shutit_util.is_installed(shutit, shutit_module_obj):
                if not shutit_module_obj.start(shutit):
                    shutit.fail(
                        'failed to start: ' + module_id,
                        shutit_pexpect_child=shutit.
                        get_shutit_pexpect_session_from_id('target_child').
                        shutit_pexpect_child)  # pragma: no cover
Пример #18
0
def stop_all(run_order=-1):
	"""Runs stop method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we clean up state
	before committing run files etc.
	"""
	shutit = shutit_global.shutit
	if shutit.build['interactive'] >= 3:
		print('\nRunning stop on all modules' + shutit_util.colourise('32', '\n\n[Hit return to continue]'))
		shutit_util.util_raw_input()
	# sort them so they're stopped in reverse order
	for module_id in shutit_util.module_ids(rev=True):
		shutit_module_obj = shutit.shutit_map[module_id]
		if run_order == -1 or shutit_module_obj.run_order <= run_order:
			if shutit_util.is_installed(shutit_module_obj):
				if not shutit_module_obj.stop(shutit):
					shutit.fail('failed to stop: ' + module_id, shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').shutit_pexpect_child)
Пример #19
0
def do_finalize():
	"""Runs finalize phase; run after all builds are complete and all modules
	have been stopped.
	"""
	shutit = shutit_global.shutit
	# Stop all the modules
	stop_all()
	# Finalize in reverse order
	shutit.log('PHASE: finalize', level=logging.DEBUG)
	# Login at least once to get the exports.
	for module_id in shutit_util.module_ids(rev=True):
		# Only finalize if it's thought to be installed.
		if shutit_util.is_installed(shutit.shutit_map[module_id]):
			shutit.login(prompt_prefix=module_id,command='bash')
			if not shutit.shutit_map[module_id].finalize(shutit):
				shutit.fail(module_id + ' failed on finalize', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').pexpect_child)
			shutit.logout()
Пример #20
0
def do_build(shutit):
	"""Runs build phase, building any modules that we've determined
	need building.
	"""
	cfg = shutit.cfg
	shutit.log('PHASE: build, repository work', code='32')
	shutit.log(shutit_util.print_config(cfg))
	if cfg['build']['interactive'] >= 3:
		print ('\nNow building any modules that need building' +
	 	       shutit_util.colour('32', '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input(shutit=shutit)
	module_id_list = shutit_util.module_ids(shutit)
	if cfg['build']['deps_only']:
		module_id_list_build_only = filter(lambda x: cfg[x]['shutit.core.module.build'], module_id_list)
	for module_id in module_id_list:
		module = shutit.shutit_map[module_id]
		shutit.log('considering whether to build: ' + module.module_id,
		           code='32')
		if cfg[module.module_id]['shutit.core.module.build']:
			if cfg['build']['delivery'] not in module.ok_delivery_methods:
				shutit.fail('Module: ' + module.module_id + ' can only be built with one of these --delivery methods: ' + str(module.ok_delivery_methods) + '\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation')
			if shutit_util.is_installed(shutit,module):
				cfg['build']['report'] = (cfg['build']['report'] +
				    '\nBuilt already: ' + module.module_id +
				    ' with run order: ' + str(module.run_order))
			else:
				# We move to the module directory to perform the build, returning immediately afterwards.
				if cfg['build']['deps_only'] and module_id == module_id_list_build_only[-1]:
					# If this is the last module, and we are only building deps, stop here.
					cfg['build']['report'] = (cfg['build']['report'] + '\nSkipping: ' +
					    module.module_id + ' with run order: ' + str(module.run_order) +
					    '\n\tas this is the final module and we are building dependencies only')
				else:
					revert_dir = os.getcwd()
					cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir'] = os.path.dirname(module.__module_file)
					shutit.chdir(cfg['environment'][cfg['build']['current_environment_id']]['module_root_dir'])
					shutit.login(prompt_prefix=module_id,command='bash')
					build_module(shutit, module)
					shutit.logout()
					shutit.chdir(revert_dir)
		if shutit_util.is_installed(shutit, module):
			shutit.log('Starting module')
			if not module.start(shutit):
				shutit.fail(module.module_id + ' failed on start',
				    child=shutit.pexpect_children['target_child'])
Пример #21
0
def stop_all(shutit, run_order=-1):
	"""Runs stop method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we clean up state
	before committing run files etc.
	"""
	cfg = shutit.cfg
	if cfg['build']['interactive'] >= 3:
		print('\nRunning stop on all modules' + \
			shutit_util.colour('32', '\n\n[Hit return to continue]'))
		shutit_util.util_raw_input(shutit=shutit)
	# sort them so they're stopped in reverse order
	for module_id in shutit_util.module_ids(shutit, rev=True):
		shutit_module_obj = shutit.shutit_map[module_id]
		if run_order == -1 or shutit_module_obj.run_order <= run_order:
			if shutit_util.is_installed(shutit, shutit_module_obj):
				if not shutit_module_obj.stop(shutit):
					shutit.fail('failed to stop: ' + \
						module_id, child=shutit.pexpect_children['target_child'])
Пример #22
0
def check_ready(throw_error=True):
    """Check that all modules are ready to be built, calling check_ready on
	each of those configured to be built and not already installed
	(see shutit_util.is_installed).
	"""
    shutit = shutit_global.shutit
    cfg = shutit.cfg
    shutit.log('PHASE: check_ready', level=logging.DEBUG)
    errs = []
    shutit.pause_point(
        '\nNow checking whether we are ready to build modules configured to be built',
        print_input=False,
        level=3)
    # Find out who we are to see whether we need to log in and out or not.
    for module_id in shutit_util.module_ids():
        module = shutit.shutit_map[module_id]
        shutit.log('considering check_ready (is it ready to be built?): ' +
                   module_id,
                   level=logging.DEBUG)
        if cfg[module_id][
                'shutit.core.module.build'] and module.module_id not in shutit_global.shutit.get_current_shutit_pexpect_session_environment(
                ).modules_ready and not shutit_util.is_installed(module):
            shutit.log('checking whether module is ready to build: ' +
                       module_id,
                       level=logging.DEBUG)
            shutit.login(prompt_prefix=module_id,
                         command='bash --noprofile --norc',
                         echo=False)
            # Move to the correct directory (eg for checking for the existence of files needed for build)
            revert_dir = os.getcwd()
            shutit_global.shutit.get_current_shutit_pexpect_session_environment(
            ).module_root_dir = os.path.dirname(module.__module_file)
            shutit.chdir(shutit_global.
                         shutit.get_current_shutit_pexpect_session_environment(
                         ).module_root_dir)
            if not is_ready(module) and throw_error:
                errs.append((
                    module_id +
                    ' not ready to install.\nRead the check_ready function in the module,\nor log messages above to determine the issue.\n\n',
                    shutit.get_shutit_pexpect_session_from_id('target_child')))
            shutit.logout(echo=False)
            shutit.chdir(revert_dir)
    return errs
Пример #23
0
def do_test():
	"""Runs test phase, erroring if any return false.
	"""
	shutit = shutit_global.shutit
	if not shutit.build['dotest']:
		shutit.log('Tests configured off, not running',level=logging.DEBUG)
		return
	# Test in reverse order
	shutit.log('PHASE: test', level=logging.DEBUG)
	stop_all()
	start_all()
	for module_id in shutit_util.module_ids(rev=True):
		# Only test if it's installed.
		if shutit_util.is_installed(shutit.shutit_map[module_id]):
			shutit.log('RUNNING TEST ON: ' + module_id, level=logging.DEBUG)
			shutit.login(prompt_prefix=module_id,command='bash')
			if not shutit.shutit_map[module_id].test(shutit):
				shutit.fail(module_id + ' failed on test', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').pexpect_child)
			shutit.logout()
Пример #24
0
 def _finalize(shutit):
     # Stop all the modules
     stop_all(shutit)
     # Finalize in reverse order
     shutit.log('PHASE: finalizing object ' + str(shutit),
                level=logging.DEBUG)
     # Login at least once to get the exports.
     for module_id in shutit_util.module_ids(shutit, rev=True):
         # Only finalize if it's thought to be installed.
         if shutit_util.is_installed(shutit, shutit.shutit_map[module_id]):
             shutit.login(prompt_prefix=module_id,
                          command='bash --noprofile --norc',
                          echo=False)
             if not shutit.shutit_map[module_id].finalize(shutit):
                 shutit.fail(
                     module_id + ' failed on finalize',
                     shutit_pexpect_child=shutit.
                     get_shutit_pexpect_session_from_id(
                         'target_child').pexpect_child)  # pragma: no cover
             shutit.logout(echo=False)
Пример #25
0
def stop_all(run_order=-1):
    """Runs stop method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we clean up state
	before committing run files etc.
	"""
    shutit = shutit_global.shutit
    if shutit.build['interactive'] >= 3:
        print('\nRunning stop on all modules' +
              shutit_util.colourise('32', '\n\n[Hit return to continue]'))
        shutit_util.util_raw_input()
    # sort them so they're stopped in reverse order
    for module_id in shutit_util.module_ids(rev=True):
        shutit_module_obj = shutit.shutit_map[module_id]
        if run_order == -1 or shutit_module_obj.run_order <= run_order:
            if shutit_util.is_installed(shutit_module_obj):
                if not shutit_module_obj.stop(shutit):
                    shutit.fail('failed to stop: ' + module_id,
                                shutit_pexpect_child=shutit.
                                get_shutit_pexpect_session_from_id(
                                    'target_child').shutit_pexpect_child)
Пример #26
0
def start_all(run_order=-1):
    """Runs start method on all modules less than the passed-in run_order.
	Used when target is exporting itself mid-build, so we can export a clean
	target and still depended-on modules running if necessary.
	"""
    shutit = shutit_global.shutit
    if shutit.build['interactive'] >= 3:
        print('\nRunning start on all modules' +
              shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
        shutit_util.util_raw_input()
    # sort them so they're started in order
    for module_id in shutit_util.module_ids():
        shutit_module_obj = shutit.shutit_map[module_id]
        if run_order == -1 or shutit_module_obj.run_order <= run_order:
            if shutit_util.is_installed(shutit_module_obj):
                if not shutit_module_obj.start(shutit):
                    shutit.fail('failed to start: ' + module_id,
                                shutit_pexpect_child=shutit.
                                get_shutit_pexpect_session_from_id(
                                    'target_child').shutit_pexpect_child)
Пример #27
0
def do_finalize():
    """Runs finalize phase; run after all builds are complete and all modules
	have been stopped.
	"""
    shutit = shutit_global.shutit
    # Stop all the modules
    stop_all()
    # Finalize in reverse order
    shutit.log('PHASE: finalize', level=logging.DEBUG)
    # Login at least once to get the exports.
    for module_id in shutit_util.module_ids(rev=True):
        # Only finalize if it's thought to be installed.
        if shutit_util.is_installed(shutit.shutit_map[module_id]):
            shutit.login(prompt_prefix=module_id,
                         command='bash --noprofile --norc',
                         echo=False)
            if not shutit.shutit_map[module_id].finalize(shutit):
                shutit.fail(module_id + ' failed on finalize',
                            shutit_pexpect_child=shutit.
                            get_shutit_pexpect_session_from_id(
                                'target_child').pexpect_child)
            shutit.logout(echo=False)
Пример #28
0
def do_finalize():
	"""Runs finalize phase; run after all builds are complete and all modules
	have been stopped.
	"""
	shutit = shutit_global.shutit
	# Stop all the modules
	if shutit.build['interactive'] >= 3:
		print('\nStopping all modules before finalize phase' + shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input()
	stop_all()
	# Finalize in reverse order
	shutit.log('PHASE: finalize', level=logging.DEBUG)
	if shutit.build['interactive'] >= 3:
		print('\nNow doing finalize phase, which we do when all builds are ' + 'complete and modules are stopped' + shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
		shutit_util.util_raw_input()
	# Login at least once to get the exports.
	for module_id in shutit_util.module_ids(rev=True):
		# Only finalize if it's thought to be installed.
		if shutit_util.is_installed(shutit.shutit_map[module_id]):
			shutit.login(prompt_prefix=module_id,command='bash')
			if not shutit.shutit_map[module_id].finalize(shutit):
				shutit.fail(module_id + ' failed on finalize', shutit_pexpect_child=shutit.get_shutit_pexpect_session_from_id('target_child').pexpect_child)
			shutit.logout()
Пример #29
0
def do_test(shutit):
    """Runs test phase, erroring if any return false.
	"""
    if not shutit.build['dotest']:
        shutit.log('Tests configured off, not running', level=logging.DEBUG)
        return
    # Test in reverse order
    shutit.log('PHASE: test', level=logging.DEBUG)
    stop_all(shutit)
    start_all(shutit)
    for module_id in shutit_util.module_ids(shutit, rev=True):
        # Only test if it's installed.
        if shutit_util.is_installed(shutit, shutit.shutit_map[module_id]):
            shutit.log('RUNNING TEST ON: ' + module_id, level=logging.DEBUG)
            shutit.login(prompt_prefix=module_id,
                         command='bash --noprofile --norc',
                         echo=False)
            if not shutit.shutit_map[module_id].test(shutit):
                shutit.fail(
                    module_id + ' failed on test',
                    shutit_pexpect_child=shutit.
                    get_shutit_pexpect_session_from_id(
                        'target_child').pexpect_child)  # pragma: no cover
            shutit.logout(echo=False)
Пример #30
0
def check_deps():
    """Dependency checking phase is performed in this method.
	"""
    shutit = shutit_global.shutit
    cfg = shutit.cfg
    shutit.log('PHASE: dependencies', level=logging.DEBUG)
    shutit.pause_point('\nNow checking for dependencies between modules',
                       print_input=False,
                       level=3)
    # Get modules we're going to build
    to_build = [
        shutit.shutit_map[module_id] for module_id in shutit.shutit_map
        if module_id in cfg and cfg[module_id]['shutit.core.module.build']
    ]
    # Add any deps we may need by extending to_build and altering cfg
    for module in to_build:
        resolve_dependencies(to_build, module)

    # Dep checking
    def err_checker(errs, triples):
        """Collate error information.
		"""
        new_triples = []
        for err, triple in zip(errs, triples):
            if not err:
                new_triples.append(triple)
                continue
            found_errs.append(err)
        return new_triples

    found_errs = []
    triples = []
    for depender in to_build:
        for dependee_id in depender.depends_on:
            triples.append(
                (depender, shutit.shutit_map.get(dependee_id), dependee_id))

    triples = err_checker([
        check_dependee_exists(depender, dependee, dependee_id)
        for depender, dependee, dependee_id in triples
    ], triples)
    triples = err_checker([
        check_dependee_build(depender, dependee, dependee_id)
        for depender, dependee, dependee_id in triples
    ], triples)
    triples = err_checker([
        check_dependee_order(depender, dependee, dependee_id)
        for depender, dependee, dependee_id in triples
    ], triples)

    if found_errs:
        return [(err, ) for err in found_errs]

    shutit.log('Modules configured to be built (in order) are: ',
               level=logging.DEBUG)
    for module_id in shutit_util.module_ids():
        module = shutit.shutit_map[module_id]
        if cfg[module_id]['shutit.core.module.build']:
            shutit.log(module_id + '    ' + str(module.run_order),
                       level=logging.DEBUG)
    shutit.log('\n', level=logging.DEBUG)

    return []
Пример #31
0
def do_build():
    """Runs build phase, building any modules that we've determined
	need building.
	"""
    shutit = shutit_global.shutit
    cfg = shutit.cfg
    shutit.log('PHASE: build, repository work', level=logging.DEBUG)
    if shutit.build['interactive'] >= 3:
        print('\nNow building any modules that need building' +
              shutit_util.colourise('32', '\n\n[Hit return to continue]\n'))
        shutit_util.util_raw_input()
    module_id_list = shutit_util.module_ids()
    if shutit.build['deps_only']:
        module_id_list_build_only = filter(
            lambda x: cfg[x]['shutit.core.module.build'], module_id_list)
    for module_id in module_id_list:
        module = shutit.shutit_map[module_id]
        shutit.log('Considering whether to build: ' + module.module_id,
                   level=logging.INFO)
        if cfg[module.module_id]['shutit.core.module.build']:
            if shutit.build['delivery'] not in module.ok_delivery_methods:
                shutit.fail(
                    'Module: ' + module.module_id +
                    ' can only be built with one of these --delivery methods: '
                    + str(module.ok_delivery_methods) +
                    '\nSee shutit build -h for more info, or try adding: --delivery <method> to your shutit invocation'
                )
            if shutit_util.is_installed(module):
                shutit.build['report'] = (shutit.build['report'] +
                                          '\nBuilt already: ' +
                                          module.module_id +
                                          ' with run order: ' +
                                          str(module.run_order))
            else:
                # We move to the module directory to perform the build, returning immediately afterwards.
                if shutit.build[
                        'deps_only'] and module_id == module_id_list_build_only[
                            -1]:
                    # If this is the last module, and we are only building deps, stop here.
                    shutit.build['report'] = (
                        shutit.build['report'] + '\nSkipping: ' +
                        module.module_id + ' with run order: ' +
                        str(module.run_order) +
                        '\n\tas this is the final module and we are building dependencies only'
                    )
                else:
                    revert_dir = os.getcwd()
                    shutit_global.shutit.get_current_shutit_pexpect_session_environment(
                    ).module_root_dir = os.path.dirname(module.__module_file)
                    shutit.chdir(
                        shutit_global.
                        shutit.get_current_shutit_pexpect_session_environment(
                        ).module_root_dir)
                    shutit.login(prompt_prefix=module_id, command='bash')
                    build_module(module)
                    shutit.logout()
                    shutit.chdir(revert_dir)
        if shutit_util.is_installed(module):
            shutit.log('Starting module', level=logging.DEBUG)
            if not module.start(shutit):
                shutit.fail(module.module_id + ' failed on start',
                            shutit_pexpect_child=shutit.
                            get_shutit_pexpect_session_from_id(
                                'target_child').pexpect_child)