Skip to content

Commit

Permalink
Add step in Composer Task for creating a FrequencyUpdateInfoMetadata.…
Browse files Browse the repository at this point in the history
…json

Signed-off-by: RishabhSaini <[email protected]>
  • Loading branch information
RishabhSaini committed Mar 27, 2023
1 parent ceeaad9 commit 7d12d50
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 5 deletions.
67 changes: 67 additions & 0 deletions bodhi-server/bodhi/server/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,73 @@ def modifyrepo(comp_type, compose_path, filetype, extension, source, zchunk):
repodata = os.path.join(repo_path, arch, 'os', 'repodata')
insert_in_repo(comp_type, repodata, filetype, extension, source, zchunk)

class FrequencyUpdateInfoMetadata(object):
"""
This class represents the frequencyupdateinfo.json metadata
"""

def __init__(Release, request, db, compose_dir, Update, UpdateStatus, ReleaseState):
"""
Initialize the FrequencyUpdateInfoMetadata object.
Args:
release (bodhi.server.models.Release): The Release that is being composed.
request (bodhi.server.models.UpdateRequest): The Request that is being composed.
db (): A database session to be used for queries.
composedir (str): A path to the composedir.
update (bodhi.server.models.Update):
update_status (bodhi.server.models.UpdateStatus):
release_state (bodhi.server.models.ReleaseState):
"""
updates = update.query.filter(
update.status.in_(
[update_status.stable])
).filter(
update.release_id == release.id
).filter(
release.state.in_([
release_state.current,
release_state.pending,
])
).order_by(
# Check the older updates first so there is more time for the newer to
# get their test results
update.id.asc()
)
modified_updates = []
for update in updates:
#Getting the specific fields from data required for processing
simplified_update = {
"release" : {
"name" : update.release.name
"version" : update.release.version
}
"alias" : update.alias
"date_stable" : update.date_stable
"builds" : [
]
}
for build in update.builds:
simplified_build = {"nvr_name" : build.nvr_name()}
simplified_update["builds"].push(simplified_build)
modified_updates.push(simplified_update)
self.comp_type = cr.XZ
self.zchunk = True
self.finfo = modified_updates

def insert_frequencyupdateinfo(self, compose_path):
"""
Add the frequencyupdateinfo.xml file to the repository.
Args:
compose_path (str): The path to the compose where the metadata will be inserted.
"""
fd, tmp_file_path = tempfile.mkstemp()
tmp_file_path.write(json.dumps(self.finfo))
repo_path = os.path.join(compose_path, 'compose', 'Everything')
repodata = os.path.join(repo_path, 'source', 'tree', 'repodata')
insert_in_repo(self.comp_type, repodata, 'frequencyupdateinfo', 'json', tmp_file_path, self.zchunk)
os.unlink(tmp_file_path)

class UpdateInfoMetadata(object):
"""
Expand Down
1 change: 1 addition & 0 deletions bodhi-server/bodhi/server/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -757,6 +757,7 @@ class ComposeState(DeclEnum):
pending = 'pending', 'Pending'
initializing = 'initializing', 'Initializing'
updateinfo = 'updateinfo', 'Generating updateinfo.xml'
frequencyupdateinfo = 'frequencyupdateinfo', 'Generating frequency update info'
punging = 'punging', 'Waiting for Pungi to finish'
syncing_repo = 'syncing_repo', 'Wait for the repo to hit the master mirror'
notifying = 'notifying', 'Sending notifications'
Expand Down
30 changes: 25 additions & 5 deletions bodhi-server/bodhi/server/tasks/composer.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,10 @@
from bodhi.server import buildsys, mail, notifications
from bodhi.server.config import config, validate_path
from bodhi.server.exceptions import BodhiException
from bodhi.server.metadata import UpdateInfoMetadata
from bodhi.server.metadata import (
UpdateInfoMetadata,
FrequencyInfoMetadata
)
from bodhi.server.models import (
Compose,
ComposeState,
Expand Down Expand Up @@ -126,12 +129,12 @@ class ComposerHandler(object):
Things to do while we're waiting on compose:
- Add testing updates to updates-testing digest
- Generate/update updateinfo.xml
- Generate/update updateinfo.xml and frequencyUpdateInfo.json
- Have a coffee. Have 7 coffees.
Once compose is done:
- inject the updateinfo it into the repodata
- inject the updateinfo and frequencyUpdateInfo it into the repodata
- Sanity check the repo
- Flip the symlinks to the new repo
- Cache the new repodata
Expand Down Expand Up @@ -373,7 +376,7 @@ def work(self):

# For 'pending' or 'frozen' branched releases, we only want to perform repo-related
# tasks for testing updates. For stable updates, we should just add the
# dist_tag and do everything else other than composing/updateinfo, since
# dist_tag and do everything else other than composing/updateinfo/frequencyUpdateInfo, since
# the nightly build-branched cron job composes for us.
self.skip_compose = False
if self.compose.request is UpdateRequest.stable \
Expand Down Expand Up @@ -941,7 +944,7 @@ def load_state(self):
log.info('Resuming push without any completed repos')

def _compose_updates(self):
"""Start pungi, generate updateinfo, wait for pungi, and wait for the mirrors."""
"""Start pungi, generate updateinfo and frequencyUpdateInfo, wait for pungi, and wait for the mirrors."""
if not os.path.exists(self.compose_dir):
log.info('Creating %s' % self.compose_dir)
os.makedirs(self.compose_dir)
Expand All @@ -956,10 +959,12 @@ def _compose_updates(self):

if not self.skip_compose and not composedone:
uinfo = self._generate_updateinfo()
finfo = self._generate_frequencyUpdateInfo()

self._wait_for_pungi(pungi_process)

uinfo.insert_updateinfo(self.path)
finfo.insert_frequencyUpdateInfo(self.path)

self._sanity_check_repo()
self._wait_for_repo_signature()
Expand Down Expand Up @@ -1013,6 +1018,21 @@ def _create_pungi_config(self):

self._copy_additional_pungi_files(self._pungi_conf_dir, env)

def _generate_frequencyUpdateInfo(self):
"""
Create the frequencyUpdateInfo.xml file for this repository.
Returns:
bodhi.server.metadata.frequencyUpdateInfoMetadata: The frequencyUpdateInfo model that was created for this
repository.
"""
log.info('Generating frequency updateinfo for %s' % self.compose.release.name)
self.save_state(ComposeState.frequencyupdateinfo)
fuinfo = FrequencyUpdateInfoMetadata(self.compose.release, self.compose.request, self.db, self.compose_dir, Update, UpdateStatus, ReleaseState)
log.info('FrequencyUpdateinfo generation for %s complete' % self.compose.release.name)
return fuinfo


def _generate_updateinfo(self):
"""
Create the updateinfo.xml file for this repository.
Expand Down

0 comments on commit 7d12d50

Please sign in to comment.