def run_tasklist(passed_env): """Run the task list for the current host. This function runs in a separate process, that is spawned by the ``multiprocessing`` module that Fabric uses for its parallel execution. The ``passed_env`` argument is the environment as it was passed through by our parent. This is required for Windows that does not have ``fork()`` and therefore we need to re-initialize the environment. """ env.update(passed_env) host = fab.env.host_string fab.env.hosts = [host] fab.env.parallel = False vmname = env.host_info[host] appname = env.appdef['name'] for vmdef in env.appdef['vms']: if vmdef['name'] == vmname: break for vm in env.application['vms']: if vm['name'] == vmname: break env.vm = vm shell_env = env.shell_env = {} shell_env['RAVELLO_TEST_ID'] = env.test_id shell_env['RAVELLO_TEST_USER'] = '******' shell_env['RAVELLO_APP_ID'] = env.application['id'] shell_env['RAVELLO_APP_NAME'] = env.application['name'] shell_env['RAVELLO_APPDEF_NAME'] = env.appdef['name'] shell_env['RAVELLO_PROJECT'] = env.api._project shell_env['RAVELLO_SERVICE_URL'] = env.api.url shell_env['RAVELLO_SERVICE_COOKIE'] = env.api._cookie shell_env['RAVELLO_VM_ID'] = vm['id'] shell_env['RAVELLO_VM_NAME'] = vm['name'] def debug(message, *args, **kwargs): message = message.format(*args, **kwargs) console.debug('[VM {0}] {1}', vmname, message) debug('Running task list for `{0}`', host) try: debug('Pre-initialize VM') preinit() sync_task = None for taskdef in vmdef['tasks']: debug('Running task `{0}`.', taskdef['name']) env.shell_env['RAVELLO_TASK_NAME'] = taskdef['name'] clsname = taskdef.get('class', 'testmill.tasks.Task') cls = util.load_class(clsname) task = cls(**taskdef) vmstate = env.shared_state[vmname] vmstate['current_task'] = task.name env.shared_state[vmname] = vmstate # sync shared state if sync_task: debug('Sync state on task `{0}`.', sync_task) completed = synchronize_on_task(sync_task) for name,state in completed.items(): if state['exited']: break update = state['shell_env_update'].get(sync_task) if update: debug('Updated {0} environment vars.', len(update)) env.shell_env.update(update) if completed and state['exited']: debug('Stopping due to failed task on VM `{0}`.', name) break task.run() vmstate = env.shared_state[vmname] vmstate['completed_tasks'][task.name] = task.return_code vmstate['shell_env_update'][task.name] = task.env_update if task.return_code != 0 and not env.args.continue_: vmstate['exited'] = True env.shared_state[vmname] = vmstate # sync shared state with env.lock: show_output(task) if vmstate['exited']: break sync_task = taskdef['name'] except Exception as e: with env.lock: console.show_exception(e) vmstate = env.shared_state[vmname] vmstate['exited'] = True env.shared_state[vmname] = vmstate # sync
def can_load_class(name): return bool(util.load_class(name))