コード例 #1
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_pre_and_post_cmds0002(self, monkeypatch, mock_platform):
        """Check that the pre/post commands use a shell and don't just exec(3)"""

        config = Config(os.path.join(TEST_DIR, "example.krun"))
        tmp_file = os.path.join(TEST_DIR, "prepost.txt")

        # commands use shell syntax
        config.PRE_EXECUTION_CMDS = ["echo 'pre' > %s" % tmp_file]
        config.POST_EXECUTION_CMDS = ["echo 'post' >> %s" % tmp_file]

        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform,
                                   resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        sched.run()

        with open(tmp_file) as fh:
            got = fh.read()

        os.unlink(tmp_file)
        assert got == "pre\npost\n"
コード例 #2
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_post_exec_cmds0002(self, monkeypatch, mock_platform):
        config = Config(os.path.join(TEST_DIR, "example.krun"))
        path = os.path.join(TEST_DIR, "shell-out")
        cmd = "echo ${KRUN_RESULTS_FILE}:${KRUN_LOG_FILE} > %s" % path
        config.POST_EXECUTION_CMDS = [cmd]
        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform,
                                   resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        assert len(sched) == 8
        sched.run()

        with open(path) as fh:
            got = fh.read().strip()

        os.unlink(path)

        elems = got.split(":")

        assert elems[0].endswith(".json.bz2")
        assert elems[1].endswith(".log")
コード例 #3
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_pre_and_post_cmds0001(self, monkeypatch, mock_platform):
        cap_cmds = []

        def dummy_run_shell_cmd(cmd, failure_fatal=False, extra_env=None):
            cap_cmds.append(cmd)
            return "", "", 0

        monkeypatch.setattr(krun.util, "run_shell_cmd", dummy_run_shell_cmd)

        config = Config(os.path.join(TEST_DIR, "example.krun"))

        config.PRE_EXECUTION_CMDS = ["pre1", "pre2"]
        config.POST_EXECUTION_CMDS = ["post1", "post2"]

        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform,
                                   resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        assert len(sched) == 8
        sched.run()

        expect = ["pre1", "pre2", "post1", "post2"] * 8
        assert cap_cmds == expect
コード例 #4
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_pre_and_post_cmds0001(self, monkeypatch, mock_platform):
        cap_cmds = []
        def dummy_run_shell_cmd(cmd, failure_fatal=False, extra_env=None):
            cap_cmds.append(cmd)
            return "", "", 0

        monkeypatch.setattr(krun.util, "run_shell_cmd", dummy_run_shell_cmd)

        config = Config(os.path.join(TEST_DIR, "example.krun"))

        config.PRE_EXECUTION_CMDS = ["pre1", "pre2"]
        config.POST_EXECUTION_CMDS = ["post1", "post2"]

        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform, resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        assert len(sched) == 8
        sched.run()

        expect = ["pre1", "pre2", "post1", "post2"] * 8
        assert cap_cmds == expect
コード例 #5
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_pre_and_post_cmds0002(self, monkeypatch, mock_platform):
        """Check that the pre/post commands use a shell and don't just exec(3)"""

        config = Config(os.path.join(TEST_DIR, "example.krun"))
        tmp_file = os.path.join(TEST_DIR, "prepost.txt")

        # commands use shell syntax
        config.PRE_EXECUTION_CMDS = ["echo 'pre' > %s" % tmp_file]
        config.POST_EXECUTION_CMDS = ["echo 'post' >> %s" % tmp_file]

        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform, resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        sched.run()

        with open(tmp_file) as fh:
            got = fh.read()

        os.unlink(tmp_file)
        assert got == "pre\npost\n"
コード例 #6
0
ファイル: test_scheduler.py プロジェクト: bennn/krun
    def test_post_exec_cmds0002(self, monkeypatch, mock_platform):
        config = Config(os.path.join(TEST_DIR, "example.krun"))
        path = os.path.join(TEST_DIR, "shell-out")
        cmd = "echo ${KRUN_RESULTS_FILE}:${KRUN_LOG_FILE} > %s" % path
        config.POST_EXECUTION_CMDS = [cmd]
        krun.util.assign_platform(config, mock_platform)

        sched = ExecutionScheduler(config,
                                   mock_platform.mailer,
                                   mock_platform, resume=False,
                                   dry_run=True,
                                   started_by_init=True)
        sched.build_schedule()
        assert len(sched) == 8
        sched.run()

        with open(path) as fh:
            got = fh.read().strip()

        os.unlink(path)

        elems = got.split(":")

        assert elems[0].endswith(".json.bz2")
        assert elems[1].endswith(".log")
コード例 #7
0
    def test_pre_and_post_exec_cmds0002(self, monkeypatch, mock_platform,
                                        no_results_instantiation_check):
        config = Config(os.path.join(TEST_DIR, "one_exec.krun"))
        path = os.path.join(TEST_DIR, "shell-out")
        cmd = "echo ${KRUN_RESULTS_FILE}:${KRUN_LOG_FILE}:${KRUN_MANIFEST_FILE} > %s" % path
        config.POST_EXECUTION_CMDS = [cmd]

        krun.util.assign_platform(config, mock_platform)
        n_reboots, sched = run_with_captured_reboots(config, mock_platform,
                                                     monkeypatch)
        os.unlink(config.results_filename())

        with open(path) as fh:
            got = fh.read().strip()

        os.unlink(path)
        os.unlink(sched.manifest.path)

        assert n_reboots == 1
        elems = got.split(":")
        assert os.path.basename(elems[0]) == "one_exec_results.json.bz2"
        assert os.path.basename(elems[1]) == "one_exec.log"
        assert os.path.basename(elems[2]) == "one_exec.manifest"

        # all paths should be in the same dir
        dirnames = [os.path.dirname(x) for x in elems]
        assert dirnames[0] == dirnames[1] == dirnames[2]
コード例 #8
0
ファイル: test_scheduler.py プロジェクト: softdevteam/krun
    def test_pre_and_post_exec_cmds0002(self, monkeypatch, mock_platform):
        config = Config(os.path.join(TEST_DIR, "one_exec.krun"))
        path = os.path.join(TEST_DIR, "shell-out")
        cmd = "echo ${KRUN_RESULTS_FILE}:${KRUN_LOG_FILE}:${KRUN_MANIFEST_FILE} > %s" % path
        config.POST_EXECUTION_CMDS = [cmd]

        krun.util.assign_platform(config, mock_platform)
        n_reboots, sched = run_with_captured_reboots(config, mock_platform,
                                                     monkeypatch)
        os.unlink(config.results_filename())

        with open(path) as fh:
            got = fh.read().strip()

        os.unlink(path)
        os.unlink(sched.manifest.path)

        assert n_reboots == 1
        elems = got.split(":")
        assert os.path.basename(elems[0]) == "one_exec_results.json.bz2"
        assert os.path.basename(elems[1]) == "one_exec.log"
        assert os.path.basename(elems[2]) == "one_exec.manifest"

        # all paths should be in the same dir
        dirnames = [os.path.dirname(x) for x in elems]
        assert dirnames[0] == dirnames[1] == dirnames[2]
コード例 #9
0
ファイル: test_scheduler.py プロジェクト: warsier/krun
    def test_pre_and_post_exec_cmds0001(self, monkeypatch, mock_platform):
        cap_cmds = []
        def dummy_run_shell_cmd(cmd, failure_fatal=False, extra_env=None):
            cap_cmds.append(cmd)
            return "", "", 0

        monkeypatch.setattr(krun.util, "run_shell_cmd", dummy_run_shell_cmd)

        config = Config(os.path.join(TEST_DIR, "one_exec.krun"))
        config.PRE_EXECUTION_CMDS = ["cmd1", "cmd2"]
        config.POST_EXECUTION_CMDS = ["cmd3", "cmd4"]

        n_reboots, sched = run_with_captured_reboots(config, mock_platform,
                                                     monkeypatch)
        os.unlink(config.results_filename())
        os.unlink(sched.manifest.path)

        assert n_reboots == 1
        expect = ["cmd1", "cmd2", "cmd3", "cmd4"]
        assert cap_cmds == expect
コード例 #10
0
ファイル: test_scheduler.py プロジェクト: warsier/krun
    def test_pre_and_post_cmds0003(self, monkeypatch, mock_platform):
        """Check that the pre/post commands use a shell and don't just exec(3)"""

        config = Config(os.path.join(TEST_DIR, "one_exec.krun"))
        tmp_file = os.path.join(TEST_DIR, "prepost.txt")

        # commands use shell syntax
        config.PRE_EXECUTION_CMDS = ["echo 'pre' > %s" % tmp_file]
        config.POST_EXECUTION_CMDS = ["echo 'post' >> %s" % tmp_file]

        n_reboots, sched = run_with_captured_reboots(config, mock_platform,
                                                     monkeypatch)
        assert n_reboots == 1
        os.unlink(config.results_filename())
        os.unlink(sched.manifest.path)

        with open(tmp_file) as fh:
            got = fh.read()

        os.unlink(tmp_file)
        assert got == "pre\npost\n"