From 262274093fa4ad19d9d45d3e00ff6dc79d027ee9 Mon Sep 17 00:00:00 2001 From: ZhangXiao Date: Thu, 11 Nov 2021 15:04:22 +0800 Subject: [PATCH] aptly_deb_usage: remove time.sleep from delete_package_local and __create_snapshot Python module aptly_api modified several interfaces to return a task thus we can use wait_task_by_id to wait for it to complete. Avoiding the use of time.sleep. Related functions: delete_package_local and __create_snapshot. Story: 2008846 Task: 43865 Signed-off-by: ZhangXiao Change-Id: I1845d5cc405ac326ef1c6617ddb1d16e5d256239 --- build-tools/stx/aptly_deb_usage.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/build-tools/stx/aptly_deb_usage.py b/build-tools/stx/aptly_deb_usage.py index b13ad37d..3cc53609 100755 --- a/build-tools/stx/aptly_deb_usage.py +++ b/build-tools/stx/aptly_deb_usage.py @@ -138,15 +138,13 @@ class Deb_aptly(): task = self.aptly.publish.drop(prefix=name, distribution=publish.distribution, force_delete=True) self.aptly.tasks.wait_for_task_by_id(task.id) if self.aptly.tasks.show(task.id).state != 'SUCCEEDED': - self.logger.warning('Drop publish failed %s : %s', name, self.aptly.tasks.show(task.id).state) + self.logger.warning('Remove publication failed %s : %s' % (name, self.aptly.tasks.show(task.id).state)) # Rename the snapshot if exists snap_list = self.aptly.snapshots.list() for snap in snap_list: if snap.name == name: backup_name = 'backup-' + name - self.aptly.snapshots.update(name, backup_name) - # update operation doesn't return a task, thus we can only sleep for a while. - time.sleep(1) + self.aptly.tasks.wait_for_task_by_id(self.aptly.snapshots.update(name, backup_name).id) # crate a snapshot task = None @@ -157,15 +155,14 @@ class Deb_aptly(): self.aptly.tasks.wait_for_task_by_id(task.id) if self.aptly.tasks.show(task.id).state != 'SUCCEEDED': if backup_name: - self.aptly.snapshots.update(backup_name, name) - time.sleep(1) - self.logger.warning('Snapshot for %s create failed: %s. ', name, self.aptly.tasks.show(task.id).state) + self.aptly.tasks.wait_for_task_by_id(self.aptly.snapshots.update(backup_name, name).id) + self.logger.warning('Snapshot for %s creation failed: %s. ' % (name, self.aptly.tasks.show(task.id).state)) return False if backup_name: task = self.aptly.snapshots.delete(snapshotname=backup_name, force=True) self.aptly.tasks.wait_for_task_by_id(task.id) if self.aptly.tasks.show(task.id).state != 'SUCCEEDED': - self.logger.warning('Drop snapshot failed %s : %s', backup_name, self.aptly.tasks.show(task.id).state) + self.logger.warning('Remove snapshot failed %s : %s' % (backup_name, self.aptly.tasks.show(task.id).state)) return True # Publish a snap called "name" with prefix as name, "bullseye" as the distribution @@ -395,7 +392,7 @@ class Deb_aptly(): # pkg_type: 'binary' or 'source' # pkg_version: version of the deb file # Output: None - def delete_pkg_local(self, local_repo, pkg_name, pkg_type, pkg_version = None): + def delete_pkg_local(self, local_repo, pkg_name, pkg_type, pkg_version=None): '''Delete a binary package from a local repository.''' # self.logger.debug('delete_pkg_local not supported yet.') if pkg_type not in {'binary', 'source'}: @@ -407,11 +404,14 @@ class Deb_aptly(): query = pkg_name + ' (' + pkg_version + ')' # If we want more detailed info, add "detailed=True, with_deps=True" for search_packages. search_result = self.aptly.repos.search_packages(local_repo, query=query) - self.logger.debug('delete_pkg_local find %d packages.', len(search_result)) + self.logger.debug('delete_pkg_local find %d packages.' % len(search_result)) for pkg in search_result: if (pkg_type == 'source' and pkg.key.split()[0] == 'Psource') or \ - (pkg_type != 'source' and pkg.key.split()[0] != 'Psource') : - self.aptly.repos.delete_packages_by_key(local_repo, pkg.key) + (pkg_type != 'source' and pkg.key.split()[0] != 'Psource'): + task = self.aptly.repos.delete_packages_by_key(local_repo, pkg.key) + self.aptly.tasks.wait_for_task_by_id(task.id) + if self.aptly.tasks.show(task.id).state != 'SUCCEEDED': + self.logger.warning('Delete package failed %s : %s' % (pkg_name, self.aptly.tasks.show(task.id).state)) # Search a package in a set of repos, return True if find, or False # repolist: a list of repo names, including local repo and mirror