koji-wrapper: Run all blocking commands with fresh ccache
If keytab is used for authentication, other commands than runroot can possibly fail due to the credentials cache being overwritten. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
68351fa5a8
commit
f27f3ce4ba
@ -113,7 +113,7 @@ class KojiWrapper(object):
|
||||
return cmd
|
||||
|
||||
@contextlib.contextmanager
|
||||
def get_runroot_env(self):
|
||||
def get_koji_cmd_env(self):
|
||||
"""Get environment variables for running a koji command.
|
||||
|
||||
If we are authenticated with a keytab, we need a fresh credentials
|
||||
@ -133,7 +133,7 @@ class KojiWrapper(object):
|
||||
contains the id, it will be captured and returned.
|
||||
"""
|
||||
task_id = None
|
||||
with self.get_runroot_env() as env:
|
||||
with self.get_koji_cmd_env() as env:
|
||||
retcode, output = run(command, can_fail=True, logfile=log_file, show_cmd=True, env=env)
|
||||
if "--task-id" in command:
|
||||
first_line = output.splitlines()[0]
|
||||
@ -316,7 +316,8 @@ class KojiWrapper(object):
|
||||
its exit code and parsed task id. This method will block until the
|
||||
command finishes.
|
||||
"""
|
||||
retcode, output = run(command, can_fail=True, logfile=log_file)
|
||||
with self.get_koji_cmd_env() as env:
|
||||
retcode, output = run(command, can_fail=True, logfile=log_file, env=env)
|
||||
|
||||
match = re.search(r"Created task: (\d+)", output)
|
||||
if not match:
|
||||
|
@ -463,7 +463,22 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234})
|
||||
self.assertItemsEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None)])
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={})])
|
||||
|
||||
@mock.patch('pungi.util.temp_dir')
|
||||
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||
def test_with_keytab(self, run, temp_dir):
|
||||
temp_dir.return_value.__enter__.return_value = '/tmp/foo'
|
||||
self.koji.koji_module.config.keytab = 'foo'
|
||||
output = 'Created task: 1234\nHello\n'
|
||||
run.return_value = (0, output)
|
||||
|
||||
result = self.koji.run_blocking_cmd('cmd')
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234})
|
||||
self.assertItemsEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None,
|
||||
env={'KRB5CCNAME': 'DIR:/tmp/foo'})])
|
||||
|
||||
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||
def test_with_log(self, run):
|
||||
@ -474,7 +489,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 0, 'output': output, 'task_id': 1234})
|
||||
self.assertItemsEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile='logfile')])
|
||||
[mock.call('cmd', can_fail=True, logfile='logfile', env={})])
|
||||
|
||||
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||
def test_fail_with_task_id(self, run):
|
||||
@ -485,7 +500,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 1, 'output': output, 'task_id': 1234})
|
||||
self.assertItemsEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None)])
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={})])
|
||||
|
||||
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||
def test_fail_without_task_id(self, run):
|
||||
@ -496,7 +511,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
self.koji.run_blocking_cmd('cmd')
|
||||
|
||||
self.assertItemsEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None)])
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={})])
|
||||
self.assertIn('Could not find task ID', str(ctx.exception))
|
||||
|
||||
@mock.patch('pungi.wrappers.kojiwrapper.run')
|
||||
@ -509,7 +524,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 0, 'output': retry, 'task_id': 1234})
|
||||
self.assertEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None),
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={}),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
can_fail=True, logfile=None)])
|
||||
|
||||
@ -523,7 +538,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 1, 'output': retry, 'task_id': 1234})
|
||||
self.assertEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None),
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={}),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
can_fail=True, logfile=None)])
|
||||
|
||||
@ -538,7 +553,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertDictEqual(result, {'retcode': 0, 'output': retry, 'task_id': 1234})
|
||||
self.assertEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None),
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={}),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
can_fail=True, logfile=None),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
@ -559,7 +574,7 @@ class RunBlockingCmdTest(KojiWrapperBaseTestCase):
|
||||
|
||||
self.assertIn('Failed to wait', str(ctx.exception))
|
||||
self.assertEqual(run.mock_calls,
|
||||
[mock.call('cmd', can_fail=True, logfile=None),
|
||||
[mock.call('cmd', can_fail=True, logfile=None, env={}),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
can_fail=True, logfile=None),
|
||||
mock.call(['koji', '--profile=custom-koji', 'watch-task', '1234'],
|
||||
|
Loading…
Reference in New Issue
Block a user