Exemplo n.º 1
0
def run(dry_run):
    quay_api_store = get_quay_api_store()

    current_state = fetch_current_state(quay_api_store)
    desired_state = fetch_desired_state()

    # calculate diff
    diff = current_state.diff(desired_state)

    # Ensure all quay org/teams are declared as dependencies:
    # any item that appears in `diff['insert']` means that it's not listed
    # in a `/dependencies/quay-org-1.yml` datafile.
    if len(diff['insert']) > 0:
        unknown_teams = [
            "- {}/{}".format(
                item["params"]["org"],
                item["params"]["team"],
            ) for item in diff['insert']
        ]

        raise RunnerException(("Unknown quay/org/team found:\n"
                               "{}").format("\n".join(unknown_teams)))

    # Run actions
    runner_action = RunnerAction(dry_run, quay_api_store)
    runner = AggregatedDiffRunner(diff)

    runner.register("update-insert", runner_action.add_to_team())
    runner.register("update-delete", runner_action.del_from_team())
    runner.register("delete", runner_action.del_from_team())

    runner.run()
Exemplo n.º 2
0
    def test_run_cond_false():
        left = AggregatedList()
        right = AggregatedList()

        right.add({"on": "insert"}, ["qwerty"])

        runner = AggregatedDiffRunner(left.diff(right))

        recorder = []
        runner.register("insert", lambda p, i: recorder.append("True"), lambda p: False)

        runner.run()

        assert not recorder
    def test_run_cond_false(self):
        left = AggregatedList()
        right = AggregatedList()

        right.add({'on': 'insert'}, ["qwerty"])

        runner = AggregatedDiffRunner(left.diff(right))

        recorder = []
        runner.register("insert", lambda p, i: recorder.append('True'),
                        lambda p: False)

        runner.run()

        assert recorder == []
    def test_run(self):
        left = AggregatedList()
        right = AggregatedList()

        # test insert
        right.add({'on': 'insert'}, ["i"])

        # test delete
        left.add({'on': 'delete'}, ["d"])

        # test update-insert
        left.add({'on': 'update-insert'}, ["ui1"])
        right.add({'on': 'update-insert'}, ["ui1", "ui2"])

        # test update-delete
        left.add({'on': 'update-delete'}, ["ud1", "ud2"])
        right.add({'on': 'update-delete'}, ["ud1"])

        on_insert = []
        on_delete = []
        on_update_insert = []
        on_update_delete = []

        def recorder(l):
            return lambda p, i: l.append([p, i])

        runner = AggregatedDiffRunner(left.diff(right))

        runner.register("insert", recorder(on_insert))
        runner.register("delete", recorder(on_delete))
        runner.register("update-insert", recorder(on_update_insert))
        runner.register("update-delete", recorder(on_update_delete))

        runner.run()

        assert on_insert == [[{'on': 'insert'}, ['i']]]
        assert on_delete == [[{'on': 'delete'}, ['d']]]
        assert on_update_insert == [[{'on': 'update-insert'}, ['ui2']]]
        assert on_update_delete == [[{'on': 'update-delete'}, ['ud2']]]
Exemplo n.º 5
0
    def test_run():
        left = AggregatedList()
        right = AggregatedList()

        # test insert
        right.add({"on": "insert"}, ["i"])

        # test delete
        left.add({"on": "delete"}, ["d"])

        # test update-insert
        left.add({"on": "update-insert"}, ["ui1"])
        right.add({"on": "update-insert"}, ["ui1", "ui2"])

        # test update-delete
        left.add({"on": "update-delete"}, ["ud1", "ud2"])
        right.add({"on": "update-delete"}, ["ud1"])

        on_insert = []
        on_delete = []
        on_update_insert = []
        on_update_delete = []

        def recorder(ls):
            return lambda p, i: ls.append([p, i])

        runner = AggregatedDiffRunner(left.diff(right))

        runner.register("insert", recorder(on_insert))
        runner.register("delete", recorder(on_delete))
        runner.register("update-insert", recorder(on_update_insert))
        runner.register("update-delete", recorder(on_update_delete))

        runner.run()

        assert on_insert == [[{"on": "insert"}, ["i"]]]
        assert on_delete == [[{"on": "delete"}, ["d"]]]
        assert on_update_insert == [[{"on": "update-insert"}, ["ui2"]]]
        assert on_update_delete == [[{"on": "update-delete"}, ["ud2"]]]
Exemplo n.º 6
0
def run(dry_run):
    quay_api_store = get_quay_api_store(managed_repos=True)

    current_state = fetch_current_state(quay_api_store)
    desired_state = fetch_desired_state()

    # calculate diff
    diff = current_state.diff(desired_state)

    # Verify that there are no repeated repo declarations
    for items in diff.values():
        for repo in items:
            assert len(repo['items']) == 1

    # Run actions
    runner_action = RunnerAction(dry_run, quay_api_store)
    runner = AggregatedDiffRunner(diff)

    runner.register("update-insert",
                    runner_action.update_fields(current_state))
    runner.register("insert", runner_action.create_repo())
    runner.register("delete", runner_action.delete_repo())

    runner.run()
Exemplo n.º 7
0
def run(dry_run):
    quay_api_store = get_quay_api_store()

    current_state = fetch_current_state(quay_api_store)
    desired_state = fetch_desired_state()

    # calculate diff
    diff = current_state.diff(desired_state)
    logging.debug("State diff: %s", diff)

    # Run actions
    runner_action = RunnerAction(dry_run, quay_api_store)
    runner = AggregatedDiffRunner(diff)

    runner.register("insert", runner_action.create_team())
    runner.register("update-insert", runner_action.add_to_team())
    runner.register("update-delete", runner_action.del_from_team())
    runner.register("delete", runner_action.del_from_team())

    status = runner.run()
    if not status:
        sys.exit(ExitCodes.ERROR)
Exemplo n.º 8
0
def run(dry_run):
    config = get_config()
    gh_api_store = GHApiStore(config)

    current_state = fetch_current_state(gh_api_store)
    desired_state = fetch_desired_state()

    # Ensure current_state and desired_state match orgs
    current_orgs = set([
        item["params"]["org"]
        for item in current_state.dump()
    ])

    desired_orgs = set([
        item["params"]["org"]
        for item in desired_state.dump()
    ])

    assert current_orgs == desired_orgs, \
        "Current orgs ({}) don't match desired orgs ({})".format(
            current_orgs,
            desired_orgs
        )

    # Calculate diff
    diff = current_state.diff(desired_state)

    # Run actions
    runner_action = RunnerAction(dry_run, gh_api_store)
    runner = AggregatedDiffRunner(diff)

    # insert github-org
    runner.register(
        "insert",
        runner_action.raise_exception("Cannot create a Github Org"),
        service_is("github-org"),
    )

    # insert github-org-team
    runner.register(
        "insert",
        runner_action.create_team(),
        service_is("github-org-team"),
    )
    runner.register(
        "insert",
        runner_action.add_to_team(),
        service_is("github-org-team"),
    )

    # delete github-org
    runner.register(
        "delete",
        runner_action.raise_exception("Cannot delete a Github Org"),
        service_is("github-org"),
    )

    # delete github-org-team
    runner.register(
        "delete",
        runner_action.del_from_team(),
        service_is("github-org-team"),
    )

    # update-insert github-org
    runner.register(
        "update-insert",
        runner_action.add_to_org(),
        service_is("github-org"),
    )

    # update-insert github-org-team
    runner.register(
        "update-insert",
        runner_action.add_to_team(),
        service_is("github-org-team"),
    )

    # update-delete github-org
    runner.register(
        "update-delete",
        runner_action.del_from_org(),
        service_is("github-org"),
    )

    # update-delete github-org-team
    runner.register(
        "update-delete",
        runner_action.del_from_team(),
        service_is("github-org-team"),
    )

    runner.run()