#617 koji-wrapper: Run all blocking commands with fresh ccache
Merged 6 years ago by lsedlar. Opened 6 years ago by lsedlar.
lsedlar/pungi keytab-dir  into  master

@@ -113,7 +113,7 @@ 

          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 @@ 

          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 @@ 

          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:

file modified
+23 -8
@@ -463,7 +463,22 @@ 

  

          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 @@ 

  

          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 @@ 

  

          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 @@ 

              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 @@ 

  

          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 @@ 

  

          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 @@ 

  

          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 @@ 

  

          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'],

If keytab is used for authentication, other commands than runroot can possibly fail due to the credentials cache being overwritten.

PR #607 only made the change for runroot commands, but apparently it's possible for other commands to fail as well.

rebased

6 years ago

rebased

6 years ago

Pull-Request has been merged by lsedlar

6 years ago