use hub version check for compat code
This commit is contained in:
parent
fe3474c0e8
commit
030a54b8d4
1 changed files with 36 additions and 45 deletions
|
|
@ -8016,32 +8016,26 @@ def anon_handle_scheduler_info(goptions, session, args):
|
||||||
if options.state:
|
if options.state:
|
||||||
clauses.append(('state', koji.TASK_STATES[options.state]))
|
clauses.append(('state', koji.TASK_STATES[options.state]))
|
||||||
|
|
||||||
|
fields = ('id', 'task_id', 'host_name', 'state', 'create_ts', 'start_ts', 'completion_ts')
|
||||||
runs = None
|
kwargs = {'clauses': clauses, 'fields': fields}
|
||||||
|
if session.hub_version < (1, 34, 0):
|
||||||
|
error("Hub version is %s and doesn't support scheduler methods "
|
||||||
|
"introduced in 1.34." % session.hub_version_str)
|
||||||
if options.limit is not None:
|
if options.limit is not None:
|
||||||
try:
|
if session.hub_version > (1, 34, 1):
|
||||||
runs = session.scheduler.getTaskRuns(
|
kwargs['opts'] = {'order': '-id', 'limit': options.limit}
|
||||||
clauses=clauses,
|
runs = session.scheduler.getTaskRuns(**kwargs)
|
||||||
fields=('task_id', 'host_name', 'state', 'create_ts', 'start_ts', 'completion_ts'),
|
|
||||||
opts={'order': '-id', 'limit': options.limit}
|
if options.limit is not None:
|
||||||
)
|
if session.hub_version > (1, 34, 1):
|
||||||
# iterator is sufficient here as we don't modify the list
|
# server did it for us, but we need to reverse
|
||||||
runs = reversed(runs)
|
runs = reversed(runs)
|
||||||
except koji.ParameterError:
|
else:
|
||||||
# 1.34.0 hub, we will try again with no opts usage
|
# emulate limit
|
||||||
pass
|
|
||||||
except koji.GenericError as ex:
|
|
||||||
if 'Invalid method' in str(ex):
|
|
||||||
error("Hub version is %s and doesn't support scheduler methods "
|
|
||||||
"introduced in 1.34." % session.hub_version_str)
|
|
||||||
if runs is None:
|
|
||||||
# hub could be 1.34.0 without opts support or user doesn't use --limit
|
|
||||||
runs = session.scheduler.getTaskRuns(
|
|
||||||
clauses=clauses,
|
|
||||||
fields=('task_id', 'host_name', 'state', 'create_ts', 'start_ts', 'completion_ts')
|
|
||||||
)
|
|
||||||
if options.limit:
|
|
||||||
runs = runs[-options.limit:]
|
runs = runs[-options.limit:]
|
||||||
|
if session.hub_version < (1, 34, 1):
|
||||||
|
# emulate order
|
||||||
|
runs.sort(key=lambda r:r['id'])
|
||||||
|
|
||||||
mask = '%(task_id)-9s %(host_name)-20s %(state)-7s ' \
|
mask = '%(task_id)-9s %(host_name)-20s %(state)-7s ' \
|
||||||
'%(create_ts)-17s %(start_ts)-17s %(completion_ts)-17s'
|
'%(create_ts)-17s %(start_ts)-17s %(completion_ts)-17s'
|
||||||
|
|
@ -8088,7 +8082,7 @@ def handle_scheduler_logs(goptions, session, args):
|
||||||
(options, args) = parser.parse_args(args)
|
(options, args) = parser.parse_args(args)
|
||||||
if len(args) != 0:
|
if len(args) != 0:
|
||||||
parser.error("There are no arguments for this command")
|
parser.error("There are no arguments for this command")
|
||||||
if options.from_ts and options.to_ts and options.limit:
|
if options.from_ts and options.to_ts and options.limit is not None:
|
||||||
parser.error("If both --from and --to are used, --limit shouldn't be used")
|
parser.error("If both --from and --to are used, --limit shouldn't be used")
|
||||||
|
|
||||||
clauses = []
|
clauses = []
|
||||||
|
|
@ -8105,30 +8099,27 @@ def handle_scheduler_logs(goptions, session, args):
|
||||||
if options.to_ts:
|
if options.to_ts:
|
||||||
clauses.append(['msg_ts', '<', options.to_ts])
|
clauses.append(['msg_ts', '<', options.to_ts])
|
||||||
|
|
||||||
# reverse order, so we can apply limit if needed
|
fields=('id', 'task_id', 'host_id', 'host_name', 'msg_ts', 'msg')
|
||||||
logs = None
|
kwargs = {'clauses': clauses, 'fields': fields}
|
||||||
|
if session.hub_version < (1, 34, 0):
|
||||||
|
error("Hub version is %s and doesn't support scheduler methods "
|
||||||
|
"introduced in 1.34." % session.hub_version_str)
|
||||||
if options.limit is not None:
|
if options.limit is not None:
|
||||||
try:
|
if session.hub_version > (1, 34, 1):
|
||||||
logs = session.scheduler.getLogMessages(clauses,
|
kwargs['opts'] = {'order': '-id', 'limit': options.limit}
|
||||||
fields=('task_id', 'host_id', 'host_name',
|
logs = session.scheduler.getLogMessages(**kwargs)
|
||||||
'msg_ts', 'msg'),
|
|
||||||
opts={'order': '-id', 'limit': options.limit})
|
if options.limit is not None:
|
||||||
|
if session.hub_version > (1, 34, 1):
|
||||||
|
# server did it for us, but we need to reverse
|
||||||
# don't use reversed() as it will be exhausted after modification loop later
|
# don't use reversed() as it will be exhausted after modification loop later
|
||||||
logs.reverse()
|
logs = logs.reverse()
|
||||||
except koji.ParameterError:
|
else:
|
||||||
# 1.34.0 hub, we will try again with no opts usage
|
# emulate limit
|
||||||
pass
|
|
||||||
except koji.GenericError as ex:
|
|
||||||
if 'Invalid method' in str(ex):
|
|
||||||
error("Hub version is %s and doesn't support scheduler methods "
|
|
||||||
"introduced in 1.34." % session.hub_version_str)
|
|
||||||
if logs is None:
|
|
||||||
# hub could be 1.34.0 without opts support or user doesn't use --limit
|
|
||||||
logs = session.scheduler.getLogMessages(clauses,
|
|
||||||
fields=('task_id', 'host_id', 'host_name',
|
|
||||||
'msg_ts', 'msg'))
|
|
||||||
if options.limit:
|
|
||||||
logs = logs[-options.limit:]
|
logs = logs[-options.limit:]
|
||||||
|
if session.hub_version < (1, 34, 1):
|
||||||
|
# emulate order
|
||||||
|
logs.sort(key=lambda r:r['id'])
|
||||||
|
|
||||||
for log in logs:
|
for log in logs:
|
||||||
log['time'] = time.asctime(time.localtime(log['msg_ts']))
|
log['time'] = time.asctime(time.localtime(log['msg_ts']))
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue