Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 3.37 KB | None | 0 0
  1. diff --git a/pyrpkg/__init__.py b/pyrpkg/__init__.py
  2. index c094e8a..57c2169 100644
  3. --- a/pyrpkg/__init__.py
  4. +++ b/pyrpkg/__init__.py
  5. @@ -3155,7 +3155,18 @@ class Commands(object):
  6.          try:
  7.              self._run_command(command, env=env)
  8.          except rpkgError as e:
  9. -            if str(e) == '[Errno 2] No such file or directory':
  10. +            # If the exception wraps another one which has .errno == ENOENT
  11. +            # this indicates that the file (mbs-manager executable) wasn't
  12. +            # found. This works in both Python 2 and 3 which throw different
  13. +            # types of exceptions in this case. We use duck-typing rather than
  14. +            # checking for the respective specific exception types because the
  15. +            # Python 3 FileNotFoundError exception isn't known in Python 2 and
  16. +            # special casing this makes the code unnecessarily complicated.
  17. +            e_errno = None
  18. +            if e.args and isinstance(e.args[0], Exception):
  19. +                e_errno = getattr(e.args[0], 'errno', None)
  20. +            if (e_errno == errno.ENOENT
  21. +                    or str(e) == '[Errno 2] No such file or directory'):
  22.                  raise rpkgError('mbs-manager is missing. Please install '
  23.                                  'module-build-service.')
  24.              else:
  25. diff --git a/tests/test_cli.py b/tests/test_cli.py
  26. index 0b35694..ea35afe 100644
  27. --- a/tests/test_cli.py
  28. +++ b/tests/test_cli.py
  29. @@ -10,6 +10,7 @@ import subprocess
  30.  import sys
  31.  import tempfile
  32.  import koji_cli.lib
  33. +import errno
  34.  
  35.  try:
  36.      import unittest2 as unittest
  37. @@ -2605,6 +2606,9 @@ State:    failed
  38.  
  39.      @patch.object(Commands, '_run_command')
  40.      def test_module_build_local_mbs_manager_is_missing(self, mock_run):
  41. +        """
  42. +        Test submitting a local module build with mbs-manager missing #1.
  43. +        """
  44.          mock_run.side_effect = rpkgError('[Errno 2] No such file or directory')
  45.  
  46.          cli_cmd = [
  47. @@ -2622,6 +2626,37 @@ State:    failed
  48.              six.assertRaisesRegex(self, rpkgError, r'mbs-manager is missing.+',
  49.                                    cli.module_build_local)
  50.  
  51. +    @patch.object(Commands, '_run_command')
  52. +    def test_module_build_local_mbs_manager_is_missing_with_errno(
  53. +            self, mock_run):
  54. +        """
  55. +        Test submitting a local module build with mbs-manager missing #2.
  56. +        """
  57. +        try:
  58. +            exc = FileNotFoundError
  59. +        except NameError:
  60. +            exc = IOError
  61. +
  62. +        mock_run.side_effect = rpkgError(exc(
  63. +            errno.ENOENT,
  64. +            "[Errno 2] No such file or directory:"
  65. +            " 'mbs-manager': 'mbs-manager'"))
  66. +
  67. +        cli_cmd = [
  68. +            'rpkg', '--path', self.cloned_repo_path, 'module-build-local'
  69. +        ]
  70. +        with patch('sys.argv', new=cli_cmd):
  71. +            cli = self.new_cli()
  72. +
  73. +            # we create an empty file for the purpose of this test so we don't
  74. +            # raise an exception
  75. +            modulemd_yml = os.path.join(self.cloned_repo_path,
  76. +                                        cli.cmd.repo_name + '.yaml')
  77. +            self.write_file(modulemd_yml)
  78. +
  79. +            six.assertRaisesRegex(self, rpkgError, r'mbs-manager is missing.+',
  80. +                                  cli.module_build_local)
  81. +
  82.  
  83.  class TestOptionNameAndNamespace(CliTestCase):
  84.      """Test CLI option --name and --namespace"""
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement