Skip to content

Commit

Permalink
Merge pull request #1572 from lxbsz/deb
Browse files Browse the repository at this point in the history
task/install/deb: retry installing the package if resource temporarily unavailable

Reviewed-by: Kefu Chai <kchai@redhat.com>
  • Loading branch information
tchaikov committed Nov 9, 2020
2 parents 41b569f + f032123 commit 79c79b9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 13 deletions.
26 changes: 23 additions & 3 deletions teuthology/task/install/deb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,32 @@
from io import StringIO

from teuthology.orchestra import run
from teuthology.contextutil import safe_while

from teuthology.task.install.util import _get_builder_project, _get_local_dir


log = logging.getLogger(__name__)

def _retry_if_eagain_in_output(remote, args):
# wait at most 5 minutes
with safe_while(sleep=10, tries=30) as proceed:
while proceed():
stderr = StringIO()
try:
return remote.run(args=args, stderr=stderr)
except run.CommandFailedError:
if "could not get lock" in stderr.getvalue().lower():
stdout = StringIO()
args = ['sudo', 'fuser', '-v', '/var/lib/dpkg/lock-frontend']
remote.run(args=args, stdout=stdout)
log.info("The processes holding 'lock-frontend':\n{}".format(stdout.getvalue()))
continue
else:
raise

def install_dep_packages(remote, args):
_retry_if_eagain_in_output(remote, args)

def _update_package_list_and_install(ctx, remote, debs, config):
"""
Expand Down Expand Up @@ -71,11 +91,11 @@ def _update_package_list_and_install(ctx, remote, debs, config):
'Dpkg::Options::="--force-confold"'),
'install',
]
remote.run(
install_dep_packages(remote,
args=install_cmd + ['%s=%s' % (d, version) for d in debs],
)
if system_pkglist:
remote.run(
install_dep_packages(remote,
args=install_cmd + system_pkglist,
)
ldir = _get_local_dir(config, remote)
Expand Down Expand Up @@ -195,7 +215,7 @@ def _upgrade_packages(ctx, config, remote, debs):
builder.install_repo()

remote.run(args=['sudo', 'apt-get', 'update'], check_status=False)
remote.run(
install_dep_packages(remote,
args=[
'sudo',
'DEBIAN_FRONTEND=noninteractive', 'apt-get', '-y', '--force-yes',
Expand Down
21 changes: 11 additions & 10 deletions teuthology/task/kernel.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
get_koji_task_result,
get_builder_project,
)
from teuthology.task.install.deb import install_dep_packages

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -1078,8 +1079,8 @@ def get_latest_image_version_deb(remote, ostype):
# Note that a dependency list may have multiple comma-separated entries,
# but also each entry may be an alternative (pkg1 | pkg2)
if 'debian' in ostype:
remote.run(args=['sudo', 'apt-get', '-y', 'install',
'linux-image-amd64'], stdout=output)
args=['sudo', 'apt-get', '-y', 'install', 'linux-image-amd64']
install_dep_packages(remote, args)
remote.run(args=['dpkg', '-s', 'linux-image-amd64'], stdout=output)
for line in output.getvalue().split('\n'):
if 'Depends:' in line:
Expand All @@ -1089,23 +1090,23 @@ def get_latest_image_version_deb(remote, ostype):
# Ubuntu is a depend in a depend.
if 'ubuntu' in ostype:
try:
remote.run(args=['sudo', 'DEBIAN_FRONTEND=noninteractive',
'apt-get', '-y', 'install',
'linux-image-current-generic'])
args=['sudo', 'DEBIAN_FRONTEND=noninteractive',
'apt-get', '-y', 'install', 'linux-image-current-generic']
install_dep_packages(remote, args)
remote.run(args=['dpkg', '-s', 'linux-image-current-generic'],
stdout=output)
for line in output.getvalue().split('\n'):
if 'Depends:' in line:
depends = line.split('Depends: ')[1]
remote.run(args=['sudo', 'apt-get', '-y', 'install',
depends])
install_dep_packages(remote, args=['sudo', 'apt-get', '-y',
'install', depends])
remote.run(args=['dpkg', '-s', depends], stdout=output)
except run.CommandFailedError:
# Non precise ubuntu machines (like trusty) don't have
# linux-image-current-generic so use linux-image-generic instead.
remote.run(args=['sudo', 'DEBIAN_FRONTEND=noninteractive',
'apt-get', '-y', 'install',
'linux-image-generic'], stdout=output)
args=['sudo', 'DEBIAN_FRONTEND=noninteractive',
'apt-get', '-y', 'install', 'linux-image-generic']
install_dep_packages(remote, args)
remote.run(args=['dpkg', '-s', 'linux-image-generic'],
stdout=output)
for line in output.getvalue().split('\n'):
Expand Down

0 comments on commit 79c79b9

Please sign in to comment.