summaryrefslogtreecommitdiff
path: root/tools/deprecated-queues.py
blob: dfd9df497caf394cf6c47527ead02510fcef70f3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/env python3
# Copyright 2022 Acme Gating, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#    http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
# implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import requests


def main():
    parser = argparse.ArgumentParser(
        description="Find where a project declares a queue")
    parser.add_argument("url", help="Zuul URL")
    parser.add_argument("tenant", help="Zuul tenant name")
    parser.add_argument("--verbose", help="Display progress",
                        action='store_true')
    args = parser.parse_args()

    projects = requests.get(
        f'{args.url}/api/tenant/{args.tenant}/projects',
    ).json()

    pipeline_contexts = set()
    for tenant_project in projects:
        if args.verbose:
            print(f"Checking {tenant_project['name']}")
        project = requests.get(
            f"{args.url}/api/tenant/{args.tenant}/project/"
            f"{tenant_project['name']}",
        ).json()

        for config in project['configs']:
            for pipeline in config['pipelines']:
                if pipeline['queue_name']:
                    pipeline_contexts.add(repr(config['source_context']))

    if pipeline_contexts:
        print("The following project-pipeline stanzas define a queue.")
        print("This syntax is deprecated and queue definitions should")
        print("be moved to the project level.")
        print("See https://zuul-ci.org/docs/zuul/latest/"
              "releasenotes.html#relnotes-4-1-0-deprecation-notes")
        for c in pipeline_contexts:
            print(c)
    else:
        print("Good, no project-pipeline queue definitions found.")


if __name__ == '__main__':
    main()