def main(parser, opts, resource=None, tgt_dir=None):
    if cylc.flow.flags.verbosity < 2:
        disable_timestamps(LOG)
    if not resource or opts.list:
        list_resources()
        sys.exit(0)
    get_resources(resource, tgt_dir)
Exemple #2
0
def test_get_resources_one(tmpdir):
    """Test extraction of a specific resource.

    Check that a file of the right name gets extracted.
    Do not check file content becuase there is no assurance that it will
    remain constant.
    """
    get_resources(tmpdir, resources=['etc/job.sh'])
    assert (tmpdir / 'job.sh').isfile()
Exemple #3
0
def main(parser, opts, *args):
    if opts.list:
        print('\n'.join(list_resources()))
        sys.exit(0)
    elif not args:
        print(parser.usage)
        sys.exit(0)
    target_dir = args[-1]
    resources = args[:-1]
    get_resources(target_dir, resources or None)
def remote_init(install_target: str, rund: str, *dirs_to_symlink: str) -> None:
    """cylc remote-init

    Arguments:
        install_target: target to be initialised
        rund: workflow run directory
        dirs_to_symlink: directories to be symlinked in form
        [directory=symlink_location, ...]
    """
    rund = os.path.expandvars(rund)
    for item in dirs_to_symlink:
        key, val = item.split("=", 1)
        if key == 'run':
            path = rund
        else:
            path = os.path.join(rund, key)
        target = os.path.expandvars(val)
        if '$' in target:
            print(REMOTE_INIT_FAILED)
            print(f'Error occurred when symlinking.'
                  f' {target} contains an invalid environment variable.')
            return
        make_symlink(path, target)
    srvd = os.path.join(rund, WorkflowFiles.Service.DIRNAME)
    os.makedirs(srvd, exist_ok=True)

    client_pub_keyinfo = KeyInfo(KeyType.PUBLIC,
                                 KeyOwner.CLIENT,
                                 workflow_srv_dir=srvd,
                                 install_target=install_target,
                                 server_held=False)
    # Check for existence of client key dir (should only exist on server)
    # Fail if one exists - this may occur on mis-configuration of install
    # target in global.cylc
    client_key_dir = os.path.join(
        srvd, f"{KeyOwner.CLIENT.value}_{KeyType.PUBLIC.value}_keys")
    if os.path.exists(client_key_dir):
        print(REMOTE_INIT_FAILED)
        print(f"Unexpected key directory exists: {client_key_dir}"
              " Check global.cylc install target is configured correctly "
              "for this platform.")
        return
    pattern = re.compile(r"^client_\S*key$")
    for filepath in os.listdir(srvd):
        if pattern.match(filepath) and f"{install_target}" not in filepath:
            # client key for a different install target exists
            print(REMOTE_INIT_FAILED)
            print(f"Unexpected authentication key \"{filepath}\" exists. "
                  "Check global.cylc install target is configured correctly "
                  "for this platform.")
            return
    try:
        remove_keys_on_client(srvd, install_target)
        create_client_keys(srvd, install_target)
    except Exception:
        # Catching all exceptions as need to fail remote init if any problems
        # with key generation.
        print(REMOTE_INIT_FAILED)
        return
    oldcwd = os.getcwd()
    os.chdir(rund)
    # Extract job.sh from library, for use in job scripts.
    get_resources('job.sh', os.path.join(WorkflowFiles.Service.DIRNAME, 'etc'))
    try:
        tarhandle = tarfile.open(fileobj=sys.stdin.buffer, mode='r|')
        tarhandle.extractall()
        tarhandle.close()
    finally:
        os.chdir(oldcwd)
    print("KEYSTART", end='')
    with open(client_pub_keyinfo.full_key_path) as keyfile:
        print(keyfile.read(), end='KEYEND')
    print(REMOTE_INIT_DONE)
    return
Exemple #5
0
def test_get_resources_all(resource, tmpdir):
    get_resources(tmpdir, None)
    assert (tmpdir / Path(resource).name).exists()