Beispiel #1
0
def test_yaml_read_invalid(monkeypatch):
    yaml = load_raw_fixture("util_invalid.yaml")

    monkeypatch.setattr("__builtin__.open", fake_open(yaml, "/tmp/yaml", "r"))
    
    with raises(error.ValidatorError):
        util.yaml_read("/tmp/yaml")
Beispiel #2
0
def init_runtime(store, args):
    store.set("runtime/config", paths.local("config.yml"))

    store.set("runtime/definition", paths.find_definition_file(args.deffile))

    # load defaults / home configuration into variable store
    config = util.yaml_read(store.get("runtime/config"))

    store.set("global", config)

    if args.parallel is False:
        store.set("global/parallel", args.parallel)

    if args.verbose:
        store.set("global/verbose", True)

    # merge with arguments from commandline
    for define in [d.split("=") for d in args.defines]:
        if len(define) != 2:
            warn("Invalid variable definition detected")
            warn("Use -Dscope/variable=value")
            return 1
        store.set(define[0], util.convert_type(define[1]))

    for envvar in filter(lambda x: x.startswith("XII_"), os.environ):
        store.set(envvar[4:], os.environ[envvar])
Beispiel #3
0
def test_yaml_read(monkeypatch, data):
    yaml = load_raw_fixture("util.yaml")
    monkeypatch.setattr("__builtin__.open", fake_open(yaml, "/tmp/yaml", "r"))

    result = util.yaml_read("/tmp/yaml")
    
    assert(result["multiple"]["network"] == "default")
Beispiel #4
0
def run_cli():
    extension.load_builtin()
    parser = cli_arg_parser()
    try:

        # prepare local environment xii runs in
        paths.prepare_local_paths()

        # parse arguments
        cli_args = parser.parse_args()

        # load variable store
        store = Store()
        store.set("runtime/config", paths.local("config.yml"))

        store.set("runtime/definition", paths.find_definition_file(cli_args.deffile))

        # load defaults / home configuration into variable store
        config = util.yaml_read(store.get("runtime/config"))

        store.set("global", config)

        if cli_args.parallel is False:
            store.set("global/parallel", cli_args.parallel)

        # merge with arguments from commandline
        for define in [d.split("=") for d in cli_args.defines]:
            if len(define) != 2:
                warn("Invalid variable definition detected")
                warn("Use -Dscope/variable=value")
                return 1
            store.set(define[0], util.convert_type(define[1]))

        for envvar in filter(lambda x: x.startswith("XII_"), os.environ):
            print("define {} = {}".format(envvar[4:], os.environ[envvar]))
            store.set(envvar[4:], os.environ[envvar])

        # parse definifition file
        defn = util.jinja_read(store.get("runtime/definition"), store)

        # construct component configurations
        definition.prepare_store(defn, store)

        # run command
        instance = command.Register.get(cli_args.command, cli_args.command_args, store)
        # return exit code

        if not instance:
            warn("Invalid command `{}`. Command not unknown.".format(cli_args.command))
            return 1

        return instance.run()
    except Interrupted:
        warn("interrupted... stopping immediately!")
        return 1

    except XiiError as e:
        it = iter(e.error())
        warn(e.error_title() + ": " + next(it))

        for line in it:
            warn(line)

        if cli_args.debug:
            store.dump()
        return 1
Beispiel #5
0
def test_yaml_read_ioerror(monkeypatch):

    monkeypatch.setattr("__builtin__.open", fake_invalid_open())
    
    with raises(error.ConnError):
        util.yaml_read("/tmp/yaml")
Beispiel #6
0
Datei: cli.py Projekt: xii/xii
def init_config(store):
    store.set("runtime/config", paths.local("config.yml"))

    # load defaults / home configuration into variable store
    config = util.yaml_read(store.get("runtime/config"))
    store.set("global", config)