Make tenant and pipeline optional in zuul-changes
When using zuul-changes to save pipeline states one currently needs to have a list of all tenant/pipeline combinations in the deployment. In large deployments this can be a hassle. Making tenant and pipeline optional makes this quite easy to save a complete pipeline state of the entire zuul deployment. Change-Id: Ibfa0bf3e3d23c729e24c208699294ef143f20945
This commit is contained in:
parent
e858b8dfce
commit
7d983fd51f
|
@ -14,45 +14,75 @@
|
|||
# License for the specific language governing permissions and limitations
|
||||
# under the License.
|
||||
|
||||
import urllib2
|
||||
try:
|
||||
from urllib.request import urlopen
|
||||
except ImportError:
|
||||
from urllib2 import urlopen
|
||||
import json
|
||||
import argparse
|
||||
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument('url', help='The URL of the running Zuul instance')
|
||||
parser.add_argument('tenant', help='The Zuul tenant')
|
||||
parser.add_argument('pipeline', help='The name of the Zuul pipeline')
|
||||
parser.add_argument('tenant', help='The Zuul tenant', nargs='?')
|
||||
parser.add_argument('pipeline', help='The name of the Zuul pipeline',
|
||||
nargs='?')
|
||||
options = parser.parse_args()
|
||||
|
||||
# Check if tenant is white label
|
||||
info = json.loads(urllib2.urlopen('%s/api/info' % options.url).read())
|
||||
info = json.loads(urlopen('%s/api/info' % options.url).read())
|
||||
api_tenant = info.get('info', {}).get('tenant')
|
||||
tenants = []
|
||||
if api_tenant:
|
||||
if api_tenant == options.tenant:
|
||||
status_url = '%s/api/status' % options.url
|
||||
tenants.append(None)
|
||||
else:
|
||||
print("Error: %s doesn't match tenant %s (!= %s)" % (
|
||||
options.url, options.tenant, api_tenant))
|
||||
exit(1)
|
||||
else:
|
||||
status_url = '%s/api/tenant/%s/status' % (options.url, options.tenant)
|
||||
tenants_url = '%s/api/tenants' % options.url
|
||||
data = json.loads(urlopen(tenants_url).read())
|
||||
for tenant in data:
|
||||
tenants.append(tenant['name'])
|
||||
|
||||
data = json.loads(urllib2.urlopen(status_url).read())
|
||||
for tenant in tenants:
|
||||
if tenant is None:
|
||||
status_url = '%s/api/status' % options.url
|
||||
else:
|
||||
status_url = '%s/api/tenant/%s/status' % (options.url, tenant)
|
||||
|
||||
for pipeline in data['pipelines']:
|
||||
if pipeline['name'] != options.pipeline:
|
||||
continue
|
||||
for queue in pipeline['change_queues']:
|
||||
for head in queue['heads']:
|
||||
for change in head:
|
||||
if not change['live']:
|
||||
continue
|
||||
cid, cps = change['id'].split(',')
|
||||
print(
|
||||
"zuul enqueue --tenant %s --trigger gerrit "
|
||||
"--pipeline %s --project %s --change %s,%s" % (
|
||||
options.tenant,
|
||||
options.pipeline,
|
||||
change['project_canonical'],
|
||||
cid, cps)
|
||||
)
|
||||
data = json.loads(urlopen(status_url).read())
|
||||
|
||||
for pipeline in data['pipelines']:
|
||||
if options.pipeline and pipeline['name'] != options.pipeline:
|
||||
continue
|
||||
for queue in pipeline['change_queues']:
|
||||
for head in queue['heads']:
|
||||
for change in head:
|
||||
if not change['live']:
|
||||
continue
|
||||
|
||||
if change['id'] and ',' in change['id']:
|
||||
# change triggered
|
||||
cid, cps = change['id'].split(',')
|
||||
print("zuul enqueue"
|
||||
" --tenant %s"
|
||||
" --trigger gerrit"
|
||||
" --pipeline %s"
|
||||
" --project %s"
|
||||
" --change %s,%s" % (tenant, pipeline['name'],
|
||||
change['project_canonical'],
|
||||
cid, cps))
|
||||
else:
|
||||
# ref triggered
|
||||
cmd = 'zuul enqueue-ref' \
|
||||
' --tenant %s' \
|
||||
' --pipeline %s' \
|
||||
' --trigger timer' \
|
||||
' --project %s' \
|
||||
' --ref %s' % (tenant, pipeline['name'],
|
||||
change['project_canonical'],
|
||||
change['ref'])
|
||||
if change['id']:
|
||||
cmd += ' --newrev %s' % change['id']
|
||||
print(cmd)
|
||||
|
|
Loading…
Reference in New Issue