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
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
import urllib2
|
try:
|
||||||
|
from urllib.request import urlopen
|
||||||
|
except ImportError:
|
||||||
|
from urllib2 import urlopen
|
||||||
import json
|
import json
|
||||||
import argparse
|
import argparse
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('url', help='The URL of the running Zuul instance')
|
parser.add_argument('url', help='The URL of the running Zuul instance')
|
||||||
parser.add_argument('tenant', help='The Zuul tenant')
|
parser.add_argument('tenant', help='The Zuul tenant', nargs='?')
|
||||||
parser.add_argument('pipeline', help='The name of the Zuul pipeline')
|
parser.add_argument('pipeline', help='The name of the Zuul pipeline',
|
||||||
|
nargs='?')
|
||||||
options = parser.parse_args()
|
options = parser.parse_args()
|
||||||
|
|
||||||
# Check if tenant is white label
|
# 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')
|
api_tenant = info.get('info', {}).get('tenant')
|
||||||
|
tenants = []
|
||||||
if api_tenant:
|
if api_tenant:
|
||||||
if api_tenant == options.tenant:
|
if api_tenant == options.tenant:
|
||||||
status_url = '%s/api/status' % options.url
|
tenants.append(None)
|
||||||
else:
|
else:
|
||||||
print("Error: %s doesn't match tenant %s (!= %s)" % (
|
print("Error: %s doesn't match tenant %s (!= %s)" % (
|
||||||
options.url, options.tenant, api_tenant))
|
options.url, options.tenant, api_tenant))
|
||||||
exit(1)
|
exit(1)
|
||||||
else:
|
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']:
|
data = json.loads(urlopen(status_url).read())
|
||||||
if pipeline['name'] != options.pipeline:
|
|
||||||
|
for pipeline in data['pipelines']:
|
||||||
|
if options.pipeline and pipeline['name'] != options.pipeline:
|
||||||
continue
|
continue
|
||||||
for queue in pipeline['change_queues']:
|
for queue in pipeline['change_queues']:
|
||||||
for head in queue['heads']:
|
for head in queue['heads']:
|
||||||
for change in head:
|
for change in head:
|
||||||
if not change['live']:
|
if not change['live']:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
if change['id'] and ',' in change['id']:
|
||||||
|
# change triggered
|
||||||
cid, cps = change['id'].split(',')
|
cid, cps = change['id'].split(',')
|
||||||
print(
|
print("zuul enqueue"
|
||||||
"zuul enqueue --tenant %s --trigger gerrit "
|
" --tenant %s"
|
||||||
"--pipeline %s --project %s --change %s,%s" % (
|
" --trigger gerrit"
|
||||||
options.tenant,
|
" --pipeline %s"
|
||||||
options.pipeline,
|
" --project %s"
|
||||||
|
" --change %s,%s" % (tenant, pipeline['name'],
|
||||||
change['project_canonical'],
|
change['project_canonical'],
|
||||||
cid, cps)
|
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