Skip to content

Commit 37016ce

Browse files
Super Userdustymabe
authored andcommitted
koji: Add functions to check/ensure the build tag
- Add check_tag, to check if the tag was added to the build; - Add ensure_tag, if the tag is not part of the build, add it. Signed-off-by: Renata Ravanelli <[email protected]>
1 parent 7dd937e commit 37016ce

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

src/cmd-koji-upload

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,37 @@ class Search(_KojiBase):
439439
# to 4, let's get an empty return
440440
return ""
441441

442+
def check_tag(self, nvr, tag):
443+
"""
444+
Check if the build contains the tag
445+
:param nvr: The nvr name from Brew
446+
:param tag: The tag to be checked
447+
"""
448+
449+
tags = self.session.listTags(build=nvr)
450+
for build_tag in tags:
451+
if tag == build_tag['name']:
452+
return True
453+
454+
return False
455+
456+
def ensure_tag(self, nvr, tag):
457+
"""
458+
Ensure if the build contains the tag
459+
:param nvr: The nvr name from Brew
460+
:param tag: The tag to be checked
461+
"""
462+
463+
if not self.check_tag(nvr, tag):
464+
log.info('Build %s was not tagged. Adding tag: %s' % (nvr, tag))
465+
task_id = self.session.tagBuild(tag, nvr)
466+
task_result = klib.watch_tasks(self.session, [task_id], quiet=True, poll_interval=15)
467+
if task_result != 0:
468+
raise Exception('failed to tag builds')
469+
log.info('Tag %s successfully added' % (tag))
470+
else:
471+
log.info('Tag %s already exists' % (tag))
472+
442473

443474
class Reserve(_KojiBase):
444475
"""
@@ -924,6 +955,8 @@ Environment variables are supported:
924955
search_cmd = sub_commands.add_parser(
925956
"search", help="Search for a build", parents=[parent_parser], add_help=False)
926957

958+
ensure_cmd = sub_commands.add_parser(
959+
"ensure-tag", help="Ensure the build tag is correct", parents=[parent_parser], add_help=False)
927960
sub_commands.add_parser(
928961
"reserve-id", help="Reserves a koji id", parents=[parent_parser], add_help=False)
929962

@@ -960,6 +993,14 @@ Environment variables are supported:
960993
'--nvr', required=True,
961994
help='NVR to look for')
962995

996+
ensure_cmd.add_argument(
997+
'--nvr', required=True,
998+
help='NVR to look for')
999+
1000+
ensure_cmd.add_argument(
1001+
'--tag', required=True,
1002+
help='Ensure the tag if the build does not have it')
1003+
9631004
args, extra_args = parser.parse_known_args()
9641005
set_logger(args.log_level)
9651006

@@ -978,6 +1019,8 @@ Environment variables are supported:
9781019
kinit(args.keytab, args.owner)
9791020
if args._command == 'search':
9801021
print(Search(args.profile).get_state(args.nvr))
1022+
if args._command == 'ensure-tag':
1023+
Search(args.profile).ensure_tag(args.nvr, args.tag)
9811024
if args._command == 'upload':
9821025

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

0 commit comments

Comments
 (0)