Beispiel #1
0
def scheduler_cli(parser, options, args, is_restart=False):
    """CLI main."""
    reg = args[0]
    # Check suite is not already running before start of host selection.
    try:
        suite_files.detect_old_contact_file(reg)
    except SuiteServiceFileError as exc:
        sys.exit(exc)

    suite_run_dir = get_suite_run_dir(reg)

    if not os.path.exists(suite_run_dir):
        sys.stderr.write(f'suite service directory not found '
                         f'at: {suite_run_dir}\n')
        sys.exit(1)

    # Create auth files if needed.
    suite_files.create_auth_files(reg)

    # Extract job.sh from library, for use in job scripts.
    extract_resources(suite_files.get_suite_srv_dir(reg), ['etc/job.sh'])

    # Check whether a run host is explicitly specified, else select one.
    if not options.host:
        try:
            host = HostAppointer().appoint_host()
        except EmptyHostList as exc:
            if cylc.flow.flags.debug:
                raise
            else:
                sys.exit(str(exc))
        if is_remote_host(host):
            if is_restart:
                base_cmd = ["restart"] + sys.argv[1:]
            else:
                base_cmd = ["run"] + sys.argv[1:]
            # Prevent recursive host selection
            base_cmd.append("--host=localhost")
            return remote_cylc_cmd(base_cmd, host=host)
    if remrun(set_rel_local=True):  # State localhost as above.
        sys.exit()

    try:
        suite_files.get_suite_source_dir(args[0], options.owner)
    except SuiteServiceFileError:
        # Source path is assumed to be the run directory
        suite_files.register(args[0], get_suite_run_dir(args[0]))

    try:
        scheduler = Scheduler(is_restart, options, args)
    except SuiteServiceFileError as exc:
        sys.exit(exc)
    scheduler.start()
Beispiel #2
0
def _auto_register():
    """Register a suite installed in the cylc-run directory."""
    try:
        reg = suite_files.register()
    except SuiteServiceFileError as exc:
        sys.exit(exc)
    # Replace this process with "cylc run REG ..." for 'ps -f'.
    os.execv(sys.argv[0], [sys.argv[0]] + [reg] + sys.argv[1:])
Beispiel #3
0
def test_register(mocked_check_nested_run_dirs,
                  mocked_get_suite_srv_dir,
                  mocked_abspath,
                  mocked_getcwd,
                  mocked_isabs,
                  mocked_isfile,
                  mocked_readlink,
                  mocked_symlink,
                  mocked_makedirs,
                  mocked_unlink):
    """Test the register function."""
    def mkdirs_standin(_, exist_ok=False):
        return True

    mocked_abspath.side_effect = lambda x: x
    # mocked_check_nested_run_dirs - no side effect as we're just ignoring it

    for (reg, source, redirect, cwd, isabs, isfile, suite_srv_dir,
            readlink, expected_symlink, expected, e_expected,
            e_message) in get_register_test_cases():
        mocked_getcwd.side_effect = lambda: cwd
        mocked_isabs.side_effect = lambda x: isabs

        mocked_isfile.side_effect = lambda x: isfile
        mocked_get_suite_srv_dir.return_value = str(suite_srv_dir)
        mocked_makedirs.return_value = True
        mocked_unlink.return_value = True
        if readlink == OSError:
            mocked_readlink.side_effect = readlink
        else:
            mocked_readlink.side_effect = lambda x: readlink

        if e_expected is None:
            reg = suite_files.register(reg, source, redirect)
            assert reg == expected
            if mocked_symlink.call_count > 0:
                # first argument, of the first call
                arg0 = mocked_symlink.call_args[0][0]
                assert arg0 == expected_symlink
        else:
            with pytest.raises(e_expected) as exc:
                suite_files.register(reg, source, redirect)
            if e_message is not None:
                assert e_message in str(exc.value)
Beispiel #4
0
    def test_register(self, mocked_get_suite_srv_dir, mocked_abspath,
                      mocked_getcwd, mocked_isabs, mocked_isfile,
                      mocked_readlink, mocked_symlink, mocked_makedirs,
                      mocked_unlink):
        """Test the register function."""
        def mkdirs_standin(_, exist_ok=False):
            return True

        mocked_abspath.side_effect = lambda x: x

        for reg, source, redirect, cwd, isabs, isfile, \
            suite_srv_dir, readlink, expected_symlink, \
            expected, e_expected, e_message \
                in get_register_test_cases():
            mocked_getcwd.side_effect = lambda: cwd
            mocked_isabs.side_effect = lambda x: isabs

            mocked_isfile.side_effect = lambda x: isfile
            mocked_get_suite_srv_dir.return_value = str(suite_srv_dir)
            mocked_makedirs.return_value = True
            mocked_unlink.return_value = True
            if readlink == OSError:
                mocked_readlink.side_effect = readlink
            else:
                mocked_readlink.side_effect = lambda x: readlink

            if e_expected is None:
                reg = suite_files.register(reg, source, redirect)
                self.assertEqual(expected, reg)
                if mocked_symlink.call_count > 0:
                    # first argument, of the first call
                    arg0 = mocked_symlink.call_args[0][0]
                    self.assertEqual(expected_symlink, arg0)
            else:
                with self.assertRaises(e_expected) as cm:
                    suite_files.register(reg, source, redirect)
                if e_message is not None:
                    the_exception = cm.exception
                    self.assertTrue(e_message in str(the_exception),
                                    str(the_exception))
Beispiel #5
0
def main(parser, opts, reg=None, src=None):
    register(reg, src, redirect=opts.redirect, rundir=opts.rundir)