Beispiel #1
0
def temp_cfg(mock_backend, etcd3):
    """
    Fixture of temporary config backend, with data in the db,
    which are deleted after the test(s) finished executing.

    Uses the etcd3 fixture.
    """
    mock_backend.return_value = etcd3
    cfg = config.Config(global_prefix=PREFIX)

    for txn in cfg.txn():
        try:
            txn.raw.create(f"{PREFIX}/my_path", "MyValue")
            txn.raw.create(f"{PREFIX}/pb/pb-20210101-test/state",
                           '{"pb": "info"}')
            txn.raw.create(f"{PREFIX}/pb/pb-20220101-test/state",
                           '{"pb": "info"}')
            txn.raw.create(f"{PREFIX}/workflow/batch:test:0.0.0",
                           '{"image": "image"}')
            txn.raw.create(f"{PREFIX}/workflow/batch:test:0.0.1",
                           '{"image": "image"}')
        except ConfigCollision:
            # if still in db, do not recreate
            pass

    return cfg
Beispiel #2
0
def main(argv=None):
    """Run ska-sdp."""
    if argv is None:
        argv = sys.argv[1:]

    args = docopt(__doc__, argv=argv, options_first=True)
    cfg = config.Config()

    if args[COMMAND] == "list":
        sdp_list.main(argv, cfg)

    elif args[COMMAND] == "get" or args[COMMAND] == "watch":
        sdp_get.main(argv, cfg)

    elif args[COMMAND] == "create":
        sdp_create.main(argv, cfg)

    elif args[COMMAND] == "update" or args[COMMAND] == "edit":
        sdp_update.main(argv, cfg)

    elif args[COMMAND] == "delete":
        sdp_delete.main(argv, cfg)

    elif args[COMMAND] == "import":
        sdp_import.main(argv, cfg)

    else:
        LOG.error(
            "Command '%s' is not supported. Run 'ska-sdp --help' to view usage.",
            args[COMMAND],
        )
Beispiel #3
0
def test_import_workflows(mock_backend, etcd3):
    """
    Test that sdp_import correctly adds, updates, and deletes workflows, from input dictionary.
    """
    mock_backend.return_value = etcd3
    cfg = config.Config(global_prefix=PREFIX)
    # clean up before test runs
    for txn in cfg.txn():
        cmd_delete(txn, "/", {"--quiet": True, "-R": True})

    # workflows to be imported
    workflows = {
        ("batch", "test", "0.0.0"): {
            "image": "batch-test:0.0.0"
        },  # to update
        ("realtime", "test", "0.1.0"): {
            "image": "realtime-test:0.1.0"
        },  # to be inserted
    }

    # keys already in db (added in first txn loop)
    keys_in_db = [
        f"{PREFIX}/workflow/batch:test:0.0.0",  # to be updated
        f"{PREFIX}/workflow/batch:test:0.0.1",  # to be deleted
    ]
    for txn in cfg.txn():
        txn.raw.create(keys_in_db[0], '{"image": "image"}')
        txn.raw.create(keys_in_db[1], '{"image": "image"}')

    # double check that keys are there and value is as created above,
    # then import workflows from dict
    for txn in cfg.txn():
        assert json.loads(txn.raw.get(keys_in_db[0]))["image"] == "image"
        assert txn.raw.list_keys(f"{PREFIX}/workflow", recurse=8) == keys_in_db

        import_workflows(txn, workflows, sync=True)

    # keys in db after importing
    updated_keys_in_db = [
        f"{PREFIX}/workflow/batch:test:0.0.0",  # updated
        f"{PREFIX}/workflow/realtime:test:0.1.0",  # added
    ]

    # test that one key is correctly updated, one removed, and one added
    for txn in cfg.txn():
        assert json.loads(txn.raw.get(
            keys_in_db[0]))["image"] == "batch-test:0.0.0"
        assert txn.raw.list_keys(f"{PREFIX}/workflow",
                                 recurse=8) == updated_keys_in_db
def cfg():
    host = os.getenv('SDP_TEST_HOST', '127.0.0.1')
    with config.Config(global_prefix=PREFIX, host=host) as cfg:
        cfg._backend.delete(PREFIX, must_exist=False, recursive=True)
        yield cfg
        cfg._backend.delete(PREFIX, must_exist=False, recursive=True)