예제 #1
0
    def test_exec_env(self):
        with open("exec_env.py", "w") as f:
            f.write("""#!/usr/bin/env python\n
import os
import json
with open("exec_env_exec_env.json") as f:
     exec_env = json.load(f)
assert exec_env["TEST_ENV"] == "123"
assert exec_env["NOT_SET"] is None
                """)
        os.chmod("exec_env.py", stat.S_IEXEC + stat.S_IREAD)

        with open("EXEC_ENV", "w") as f:
            f.write("EXECUTABLE exec_env.py\n")
            f.write("EXEC_ENV TEST_ENV 123\n")
            f.write("EXEC_ENV NOT_SET")

        ext_job = ExtJob("EXEC_ENV", False)
        job_list = ExtJoblist()
        job_list.add_job("EXEC_ENV", ext_job)
        forward_model = ForwardModel(job_list)
        forward_model.add_job("EXEC_ENV")
        global_args = SubstitutionList()
        env_varlist = EnvironmentVarlist()
        forward_model.formatted_fprintf("run_id", None, "data_root",
                                        global_args, 0, env_varlist)

        for msg in list(JobRunner().run([])):
            if isinstance(msg, Start):
                with open("exec_env_exec_env.json") as f:
                    exec_env = json.load(f)
                    assert exec_env["TEST_ENV"] == "123"
                    assert exec_env["NOT_SET"] is None
예제 #2
0
    def test_exec_env(self):
        with TestAreaContext("exec_env_test"):
            with open("exec_env.py", "w") as f:
                f.write("""#!/usr/bin/env python\n
import os
import json
with open("exec_env_exec_env.json") as f:
     exec_env = json.load(f)
assert exec_env["TEST_ENV"] == "123"
assert exec_env["NOT_SET"] is None
                """)
            os.chmod("exec_env.py", stat.S_IEXEC + stat.S_IREAD)

            with open("EXEC_ENV", "w") as f:
                f.write("EXECUTABLE exec_env.py\n")
                f.write("EXEC_ENV TEST_ENV 123\n")
                f.write("EXEC_ENV NOT_SET")

            ext_job = ExtJob("EXEC_ENV", False)
            job_list = ExtJoblist()
            job_list.add_job("EXEC_ENV", ext_job)
            forward_model = ForwardModel(job_list)
            forward_model.add_job("EXEC_ENV")
            global_args = SubstitutionList()
            env_varlist = EnvironmentVarlist()
            forward_model.formatted_fprintf( "run_id", None, "data_root", global_args, 0, env_varlist)

            jobm = JobManager(json_file = "jobs.json")
            job0 = jobm[0]
            exec_env = job0.get("exec_env")
            self.assertEqual(len(exec_env), 2)
            exit_status, msg = jobm.runJob(job0)
            self.assertEqual(exit_status, 0)
예제 #3
0
    def __init__(self, user_config_file=None, config_content=None, config_dict=None):

        configs = sum([1 for x in [user_config_file, config_content, config_dict] if x is not None])

        if configs > 1:
            raise ValueError("Attempting to construct SiteConfig with multiple config objects")

        if configs == 0:
            raise ValueError("Attempting to construct SiteConfig with no config objects")

        c_ptr = None
        if user_config_file is not None:
            if not os.path.isfile(user_config_file):
                raise IOError('No such configuration file "%s".' % user_config_file)
            c_ptr = self._alloc_load_user_config(user_config_file)

        elif config_content is not None:
            c_ptr = self._alloc(config_content)

        elif config_dict is not None:
            __license_root_path = None
            if ConfigKeys.LICENSE_PATH in config_dict:
                license_root_path = config_dict.get(ConfigKeys.LICENSE_PATH)
                license_root_path_site = os.path.realpath(license_root_path)
                __license_root_path = os.path.join(
                    license_root_path_site,
                    os.getenv("USER"),
                    str(os.getpid())
                )

            # Create joblist
            ext_job_list = ExtJoblist()
            for job in config_dict.get(ConfigKeys.INSTALL_JOB, []):
                if not os.path.isfile(job[ConfigKeys.PATH]):
                    print("WARNING: Unable to locate job file {}".format(job[ConfigKeys.PATH]))
                    continue
                try:
                    new_job = ExtJob(config_file=job[ConfigKeys.PATH], private=False, name=job[ConfigKeys.NAME], license_root_path=__license_root_path)
                    new_job.convertToCReference(None)
                    ext_job_list.add_job(job[ConfigKeys.NAME], new_job)
                except:
                    print("WARNING: Unable to create job from {}".format(job[ConfigKeys.PATH]))

            for job_path in config_dict.get(ConfigKeys.INSTALL_JOB_DIRECTORY, []):
                if not os.path.isdir(job_path):
                    print("WARNING: Unable to locate job directory {}".format(job_path))
                    continue
                files = os.listdir(job_path)
                for file_name in files:
                    full_path = os.path.join(job_path, file_name)
                    if os.path.isfile(full_path):
                        try:
                            new_job = ExtJob(config_file=full_path, private=False, license_root_path=__license_root_path)
                            new_job.convertToCReference(None)
                            ext_job_list.add_job(new_job.name(), new_job)
                        except:
                            print("WARNING: Unable to create job from {}".format(full_path))

            ext_job_list.convertToCReference(None)

            # Create varlist)
            env_var_list = EnvironmentVarlist()
            for (var, value) in config_dict.get(ConfigKeys.SETENV, []):
                env_var_list[var] = value

            env_var_list.convertToCReference(None)
            umask = config_dict.get(ConfigKeys.UMASK)

            c_ptr = self._alloc_full(ext_job_list, env_var_list, umask)

        if c_ptr is None:
            raise ValueError('Failed to construct SiteConfig instance.')

        super(SiteConfig, self).__init__(c_ptr)