Exemple #1
0
 def process(self,
             conf_tree,
             item,
             orig_keys=None,
             orig_value=None,
             **kwargs):
     """Export environment variables in an [env] in "conf_tree.node"."""
     env_node = conf_tree.node.get([item], no_ignore=True)
     if env_node is None:
         return
     if "UNDEF" in os.environ:
         os.environ.pop("UNDEF")
     environ = {}
     if env_node and not env_node.state:
         for key, node in env_node.value.items():
             if node.state:
                 continue
             try:
                 environ[key] = env_var_process(node.value)
             except UnboundEnvironmentVariableError as exc:
                 raise ConfigProcessError([item, key], node.value, exc)
             environ[key] = os.path.expanduser(environ[key])  # ~ expansion
     for key, value in sorted(environ.items()):
         env_export(key, value, self.manager.event_handler)
     return environ
Exemple #2
0
    def run_impl(self, opts, args, uuid, work_files):
        """Run application configuration as a suite task."""
        # "rose task-env"
        t_prop = self.suite_engine_proc.get_task_props(
            cycle=opts.cycle,
            cycle_offsets=opts.cycle_offsets,
            prefix_delim=opts.prefix_delim,
            suffix_delim=opts.suffix_delim)
        is_changed = False
        for key, value in t_prop:
            if os.getenv(key) != value:
                env_export(key, value, self.event_handler)
                is_changed = True

        path_globs = opts.path_globs
        if path_globs is None:
            path_globs = []
        prepend_paths_map = get_prepend_paths(self.event_handler,
                                              t_prop.suite_dir,
                                              path_globs,
                                              full_mode=is_changed)
        for key, prepend_paths in prepend_paths_map.items():
            orig_paths = []
            orig_v = os.getenv(key, "")
            if orig_v:
                orig_paths = orig_v.split(os.pathsep)
            value = os.pathsep.join(prepend_paths + orig_paths)
            env_export(key, value, self.event_handler)

        # Name association with builtin applications
        builtin_app = None
        if opts.app_mode is None:
            builtin_apps_manager = self.app_runner.builtins_manager
            builtin_app = builtin_apps_manager.guess_handler(t_prop.task_name)
            if builtin_app is not None:
                opts.app_mode = builtin_app.SCHEME

        # Determine what app config to use
        if not opts.conf_dir:
            for app_key in [opts.app_key, os.getenv("ROSE_TASK_APP")]:
                if app_key is not None:
                    conf_dir = os.path.join(t_prop.suite_dir, "app", app_key)
                    if not os.path.isdir(conf_dir):
                        raise TaskAppNotFoundError(t_prop.task_name, app_key)
                    break
            else:
                app_key = t_prop.task_name
                conf_dir = os.path.join(t_prop.suite_dir, "app",
                                        t_prop.task_name)
                if (not os.path.isdir(conf_dir) and builtin_app is not None
                        and builtin_app.get_app_key(t_prop.task_name)):
                    # A builtin application may select a different app_key
                    # based on the task name.
                    app_key = builtin_app.get_app_key(t_prop.task_name)
                    conf_dir = os.path.join(t_prop.suite_dir, "app", app_key)
                if not os.path.isdir(conf_dir):
                    raise TaskAppNotFoundError(t_prop.task_name, app_key)
            opts.conf_dir = conf_dir

        return self.app_runner(opts, args)
Exemple #3
0
    def _run_orig(self, app_runner, conf_tree, opts, args, uuid, task,
                  orig_cont_map):
        """Run "fcm make" in original location."""
        # Determine the destination
        dest_orig_str = _conf_value(conf_tree, ["dest-orig"])
        if (dest_orig_str is None and _conf_value(conf_tree, ["use-pwd"])
                not in ["True", "true"]):
            dest_orig_str = os.path.join("share", task.task_name)
        dest_orig = dest_orig_str
        if dest_orig is not None and not os.path.isabs(dest_orig):
            dest_orig = os.path.join(task.suite_dir, dest_orig)
        dests = [dest_orig]

        # Determine if mirror is necessary or not
        # Determine the name of the continuation task
        task_name_cont = task.task_name.replace(orig_cont_map[ORIG],
                                                orig_cont_map[CONT])
        # TODO: get_task_auth currently does nothing
        auth = app_runner.suite_engine_proc.get_task_auth(
            task.suite_name, task_name_cont)
        if auth is not None:
            dest_cont = _conf_value(conf_tree, ["dest-cont"])
            if dest_cont is None:
                if dest_orig_str is not None:
                    dest_cont = dest_orig_str
                elif dest_orig:
                    dest_cont = os.path.join("share", task.task_name)
                else:
                    dest_cont = os.path.join("work", task.task_cycle_time,
                                             task_name_cont)
            if not os.path.isabs(dest_cont):
                dest_cont = os.path.join(task.suite_dir_rel, dest_cont)
            dests.append(auth + ":" + dest_cont)
            # Environment variables for backward compat. "fcm make"
            # supports arguments as extra configurations since version
            # 2014-03.
            for name in ["ROSE_TASK_MIRROR_TARGET", "MIRROR_TARGET"]:
                env_export(name, dests[CONT], app_runner.event_handler)

            # "mirror" for backward compat. Use can specify a null string as
            # value to switch off the mirror target configuration.
            mirror_step = _conf_value(conf_tree, ["mirror-step"], "mirror")
            if mirror_step:
                args.append("%s.target=%s" % (mirror_step, dests[CONT]))
                # "mirror.prop{config-file.name}" requires fcm-2015.05+
                make_name_cont = _conf_value(
                    conf_tree, ["make-name-cont"],
                    orig_cont_map[CONT].replace(orig_cont_map[ORIG], ""))
                if make_name_cont:
                    args.append("%s.prop{config-file.name}=%s" %
                                (mirror_step, make_name_cont))

        # Launch "fcm make"
        self._invoke_fcm_make(app_runner, conf_tree, opts, args, uuid, task,
                              dests,
                              _conf_value(conf_tree, ["fast-dest-root-orig"]),
                              _conf_value(conf_tree, ["make-name-orig"]))
Exemple #4
0
 def test_report_new(self):
     """Ensure that env_export only reports 1st time or on change."""
     events = []
     env_export("FOO", "foo", events.append)
     env_export("FOO", "foo", events.append)
     env_export("FOO", "food", events.append)
     env_export("FOO", "foot", events.append)
     env_export("FOO", "foot", events.append)
     event_args = [event.args[1] for event in events]
     self.assertEqual(event_args, ["foo", "food", "foot"], "events")
Exemple #5
0
 def test_report_old(self):
     """Ensure that env_export only reports 1st time or on change."""
     events = []
     os.environ["BAR"] = "bar"
     env_export("BAR", "bar", events.append)
     env_export("BAR", "bar", events.append)
     env_export("BAR", "bar", events.append)
     env_export("BAR", "barley", events.append)
     env_export("BAR", "barley", events.append)
     env_export("BAR", "barber", events.append)
     event_args = [event.args[1] for event in events]
     self.assertEqual(event_args, ["bar", "barley", "barber"], "events")