#600 'lint' can run with different 'rpmlint' versions
Merged 3 years ago by onosek. Opened 3 years ago by onosek.
onosek/rpkg lint_version  into  master

file modified
+17 -4
@@ -1296,7 +1296,7 @@ 

      def _get_build_arches_from_spec(self):

          """Given the path to an spec, retrieve the build arches"""

  

-         spec = os.path.join(self.path, self.spec)

+         spec = os.path.join(self.layout.specdir, self.spec)

          try:

              hdr = rpm.spec(spec)

          except Exception:
@@ -2649,7 +2649,7 @@ 

  

          mockdir = os.path.join(

              "results_%s" % self.repo_name, self.ver, self.rel)

-         if (os.path.exists(mockdir)):

+         if os.path.exists(mockdir):

              log.info("Mockbuild results directory found. "

                       "Linting mockbuild results.")

              rpm_globs.add(os.path.join(mockdir, '*.rpm'))
@@ -2682,13 +2682,26 @@ 

              log.warning('No rpm found')

  

          cmd = ['rpmlint']

+ 

+         user_config_file_switch = '-f'  # switch that uses rpmlint version 1.x

+         # get rpmlint version installed in the system

+         ret, stdout, _ = self._run_command(cmd + ['--version'],

+                                            return_stdout=True,

+                                            return_text=True)

+         if ret == 0:

+             res = re.search(r'(\d)\.\d', stdout)

+             if res is not None:

+                 if res.groups()[0] == '2':

+                     user_config_file_switch = '-r'

+                     self.log.debug('rpmlint version 2.x detected')

+ 

          default_rpmlintconf = '{0}.rpmlintrc'.format(self.repo_name)

          if info:

              cmd.extend(['-i'])

          if rpmlintconf:

-             cmd.extend(["-f", os.path.join(self.path, rpmlintconf)])

+             cmd.extend([user_config_file_switch, os.path.join(self.path, rpmlintconf)])

          elif os.path.isfile(os.path.join(self.path, default_rpmlintconf)):

-             cmd.extend(["-f", os.path.join(self.path, default_rpmlintconf)])

+             cmd.extend([user_config_file_switch, os.path.join(self.path, default_rpmlintconf)])

          elif os.path.isfile(os.path.join(self.path, ".rpmlint")):

              self.log.warning('.rpmlint file usage as default rpmlint configuration is deprecated '

                               'Use {0} instead'.format(default_rpmlintconf))

file modified
+49 -11
@@ -1055,13 +1055,16 @@ 

          self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-7')

  

          cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path, 'lint']

+         _run_command.return_value = [0, "version X.X", None]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.lint()

  

-         rpmlint = ['rpmlint', os.path.join(cli.cmd.path, cli.cmd.spec)]

-         _run_command.assert_called_once_with(rpmlint, shell=True)

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', os.path.join(cli.cmd.path, cli.cmd.spec)], shell=True),

+         ])

  

      @patch('pyrpkg.Commands._run_command')

      def test_lint_warning_with_info(self, _run_command):
@@ -1069,13 +1072,16 @@ 

  

          cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path,

                     'lint', '--info']

+         _run_command.return_value = [0, "version X.X", None]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.lint()

  

-         rpmlint = ['rpmlint', '-i', os.path.join(cli.cmd.path, cli.cmd.spec)]

-         _run_command.assert_called_once_with(rpmlint, shell=True)

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', '-i', os.path.join(cli.cmd.path, cli.cmd.spec)], shell=True),

+         ])

  

      @patch('pyrpkg.Commands._run_command')

      def test_lint_with_default_config_file(self, _run_command):
@@ -1085,13 +1091,37 @@ 

          open(lint_config_path, 'a').close()

  

          cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path, 'lint']

+         _run_command.return_value = [0, "version 1.1", None]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.lint()

  

-         rpmlint = ['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)]

-         _run_command.assert_called_once_with(rpmlint, shell=True)

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],

+                  shell=True),

+         ])

+ 

+     @patch('pyrpkg.Commands._run_command')

+     def test_lint_with_default_config_file_newer_lint_package(self, _run_command):

+         self.checkout_branch(git.Repo(self.cloned_repo_path), 'eng-rhel-7')

+ 

+         lint_config_path = os.path.join(self.cloned_repo_path, 'docpkg.rpmlintrc')

+         open(lint_config_path, 'a').close()

+ 

+         cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path, 'lint']

+         _run_command.return_value = [0, "version 2.0", None]

+ 

+         with patch('sys.argv', new=cli_cmd):

+             cli = self.new_cli()

+             cli.lint()

+ 

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', '-r', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],

+                  shell=True),

+         ])

  

      @patch('pyrpkg.Commands._run_command')

      def test_lint_with_default_and_deprecated_config_files(self, _run_command):
@@ -1103,13 +1133,17 @@ 

          open(deprecated_lint_config_path, 'a').close()

  

          cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path, 'lint']

+         _run_command.return_value = [0, "version 1.1", None]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.lint()

  

-         rpmlint = ['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)]

-         _run_command.assert_called_once_with(rpmlint, shell=True)

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', '-f', lint_config_path, os.path.join(cli.cmd.path, cli.cmd.spec)],

+                  shell=True),

+         ])

  

      @patch('pyrpkg.Commands._run_command')

      def test_lint_with_custom_config_file(self, _run_command):
@@ -1122,14 +1156,18 @@ 

  

          cli_cmd = ['rpkg', '--name', 'docpkg', '--path', self.cloned_repo_path,

                     'lint', '--rpmlintconf', 'custom.rpmlintrc']

+         _run_command.return_value = [0, "version 1.1", None]

  

          with patch('sys.argv', new=cli_cmd):

              cli = self.new_cli()

              cli.lint()

  

-         rpmlint = ['rpmlint', '-f', custom_lint_config_path, os.path.join(cli.cmd.path,

-                                                                           cli.cmd.spec)]

-         _run_command.assert_called_once_with(rpmlint, shell=True)

+         _run_command.assert_has_calls([

+             call(['rpmlint', '--version'], return_stdout=True, return_text=True),

+             call(['rpmlint', '-f', custom_lint_config_path,

+                   os.path.join(cli.cmd.path, cli.cmd.spec)],

+                  shell=True),

+         ])

  

  

  class TestGitUrl(CliTestCase):

file modified
+15 -3
@@ -1004,12 +1004,16 @@ 

          glob.side_effect = _mock_glob

          cmd._get_build_arches_from_spec = Mock(

              return_value=['x86_64', 'x86_64'])

+         run.return_value = [0, "version 1.1", None]

  

          cmd.lint()

  

          self.assertEqual(

              run.call_args_list,

-             [call(['rpmlint',

+             [call(['rpmlint', '--version'],

+                   return_stdout=True,

+                   return_text=True),

+              call(['rpmlint',

                     os.path.join(cmd.path, 'docpkg.spec'),

                     srpm_path,

                     bin_path,
@@ -1040,12 +1044,16 @@ 

  

          exists.side_effect = _mock_exists

          glob.side_effect = _mock_glob

+         run.return_value = [0, "version 1.1", None]

  

          cmd.lint()

  

          self.assertEqual(

              run.call_args_list,

-             [call(['rpmlint',

+             [call(['rpmlint', '--version'],

+                   return_stdout=True,

+                   return_text=True),

+              call(['rpmlint',

                     os.path.join(cmd.path, 'docpkg.spec'),

                     srpm_path,

                     bin_path,
@@ -1072,12 +1080,16 @@ 

  

          exists.side_effect = _mock_exists

          glob.side_effect = _mock_glob

+         run.return_value = [0, "version 1.1", None]

  

          cmd.lint()

  

          self.assertEqual(

              run.call_args_list,

-             [call(['rpmlint',

+             [call(['rpmlint', '--version'],

+                   return_stdout=True,

+                   return_text=True),

+              call(['rpmlint',

                     os.path.join(cmd.path, 'dockpkg.spec'),

                     srpm_path,

                     bin_path,

'lint' subcommand internally executes 'rpmlint' binary. With 'rpmlint' package version 2.x it changed some of its input arguments. Rpkg has to recognize the installed 'rpmlint' version and use the corresponding switch/argument. Specifically, '-f' switch for user config file has changed to '-r' in the newer version.
Additionally, fixes some paths to source RPMs.

JIRA: RHELCMP-7842
Resolves: rhbz#1967821

Signed-off-by: Ondrej Nosek onosek@redhat.com

rebased onto f0d95d61ffe245593abb022ab10734213a38e6db

3 years ago

Rebased and modified to support previously merged https://pagure.io/rpkg/pull-request/589

rebased onto 07a4cd3d17e86bc463d778e96590561e431cfe2c

3 years ago

rebased onto b9fff7d0a29908a5f18c427b011f607de450de72

3 years ago

Looks OK for me.

I see only one stylistic issue.
https://pagure.io/fork/onosek/rpkg/blob/083376330b54f5528dd228c7b0207ee2944cecf4/f/pyrpkg/__init__.py#_2652

if (os.path.exists(mockdir)):

there are redundant parentheses around the condition.

rebased onto 6793433

3 years ago

Pull-Request has been merged by onosek

3 years ago