Skip to content

Commit

Permalink
koji: Add search function
Browse files Browse the repository at this point in the history
 - Add search function to look for builds by nvr;
 - We need this feature to ensure an update was
complete successfully, and we don't need to reupload it. An
example is if some fail occurs in the release job.

Signed-off-by: Renata Ravanelli <[email protected]>
  • Loading branch information
ravanelli committed Jul 12, 2023
1 parent 1981a4f commit 0f32f05
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/cmd-koji-upload
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,32 @@ class _KojiBase():
return session


class Search(_KojiBase):
"""
Search for builds
"""

def __init__(self, profile):
"""
Creates a new instance for search.
:param profile: Koji profile name in /etc/koji.conf.d
:type str
"""
super().__init__(profile)

def get_state(self, nvr):
"""
Return the build state.
:param nvr: The nvr name from Brew
"""

info = self.session.getBuild(nvr, strict=False)
if (info):
return (info['state'])
return 0


class Reserve(_KojiBase):
"""
Reserves a place in Koji for later archival.
Expand Down Expand Up @@ -821,6 +847,11 @@ Examples:
--keytab keytab \
--owner [email protected] \
--profile koji
$ cmd-koji-upload search \
--nvr nvr \
--keytab keytab \
--owner [email protected] \
--profile koji
Environment variables are supported:
- KOJI_USERNAME will set the owner
Expand Down Expand Up @@ -867,6 +898,9 @@ Environment variables are supported:
upload_cmd = sub_commands.add_parser(
"upload", help="Uploads to koji", parents=[parent_parser], add_help=False)

search_cmd = sub_commands.add_parser(
"search", help="Search for a build", parents=[parent_parser], add_help=False)

sub_commands.add_parser(
"reserve-id", help="Reserves a koji id", parents=[parent_parser], add_help=False)

Expand Down Expand Up @@ -899,6 +933,10 @@ Environment variables are supported:
'--s3-url', required=False,
help='Store url information in meta.json')

search_cmd.add_argument(
'--nvr', required=True,
help='NVR to look for')

args, extra_args = parser.parse_known_args()
set_logger(args.log_level)

Expand All @@ -915,7 +953,8 @@ Environment variables are supported:

if args.auth:
kinit(args.keytab, args.owner)

if args._command == 'search':
print(Search(args.profile).get_state(args.nvr))
if args._command == 'upload':

upload = Upload(build, args.owner, args.tag, args.profile)
Expand Down

0 comments on commit 0f32f05

Please sign in to comment.