From 65d43117841c2057843a61e5b8740c9642a88e47 Mon Sep 17 00:00:00 2001 From: Zack Cerza Date: Thu, 22 Jan 2015 14:47:50 -0700 Subject: [PATCH] Ensure yum repo file exists before tweaking it Signed-off-by: Zack Cerza --- teuthology/task/install.py | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/teuthology/task/install.py b/teuthology/task/install.py index 4e122baacc..f4493e97ce 100644 --- a/teuthology/task/install.py +++ b/teuthology/task/install.py @@ -367,17 +367,15 @@ def _yum_fix_repo_priority(remote, project, uri): :param remote: the teuthology.orchestra.remote.Remote object :param project: the project whose repos need modification """ + repo_path = '/etc/yum.repos.d/%s.repo' % project remote.run( args=[ - 'sudo', - 'sed', - '-i', - '-e', - run.Raw( - '\':a;N;$!ba;s/enabled=1\\ngpg/enabled=1\\npriority=1\\ngpg/g\''), + 'if', 'test', '-f', repo_path, run.Raw(';'), 'then', + 'sudo', 'sed', '-i', '-e', + run.Raw('\':a;N;$!ba;s/enabled=1\\ngpg/enabled=1\\npriority=1\\ngpg/g\''), '-e', run.Raw("'s;ref/[a-zA-Z0-9_-]*/;{uri}/;g'".format(uri=uri)), - '/etc/yum.repos.d/%s.repo' % project, + repo_path, run.Raw(';'), 'fi' ] ) @@ -390,10 +388,13 @@ def _yum_fix_repo_host(remote, project): new_host = teuth_config.gitbuilder_host if new_host == old_host: return + repo_path = '/etc/yum.repos.d/%s.repo' % project host_sed_expr = "'s/{0}/{1}/'".format(old_host, new_host) remote.run( - args=['sudo', 'sed', '-i', '-e', run.Raw(host_sed_expr), - '/etc/yum.repos.d/%s.repo' % project] + args=[ + 'if', 'test', '-f', repo_path, run.Raw(';'), 'then', + 'sudo', 'sed', '-i', '-e', run.Raw(host_sed_expr), + repo_path, run.Raw(';'), 'fi'] ) -- 2.39.5