#2761 cli: rpminfo with non-exist rpm
Merged a year ago by tkopecek. Opened a year ago by jcupova.
jcupova/koji issue-2643  into  master

file modified
+5 -1
@@ -3150,10 +3150,12 @@ 

      if len(args) < 1:

          parser.error(_("Please specify an RPM"))

      ensure_connection(session, goptions)

+     error_hit = False

      for rpm in args:

          info = session.getRPM(rpm)

          if info is None:

-             print("No such rpm: %s\n" % rpm)

+             warn("No such rpm: %s\n" % rpm)

+             error_hit = True

              continue

          if info['epoch'] is None:

              info['epoch'] = ""
@@ -3211,6 +3213,8 @@ 

                  print("  %s %s %s %s" % ('-' * 8, '-' * 28, '-' * 8, '-' * 29))

              for br_info in br_list:

                  print("  %(id)8i %(tag_name)-28s %(arch)-8s %(host_name)-29s" % br_info)

+     if error_hit:

+         error()

  

  

  def anon_handle_buildinfo(goptions, session, args):

@@ -0,0 +1,140 @@ 

+ from __future__ import absolute_import

+ import koji

+ import mock

+ import os

+ import time

+ from six.moves import StringIO

+ 

+ from koji_cli.commands import anon_handle_rpminfo

+ from . import utils

+ 

+ 

+ class TestRpminfo(utils.CliTestCase):

+     def setUp(self):

+         self.maxDiff = None

+         self.options = mock.MagicMock()

+         self.options.quiet = True

+         self.options.debug = False

+         self.session = mock.MagicMock()

+         self.session.getAPIVersion.return_value = koji.API_VERSION

+         self.original_timezone = os.environ.get('TZ')

+         os.environ['TZ'] = 'UTC'

+         time.tzset()

+         self.buildroot_info = {'arch': 'x86_64',

+                                'br_type': 0,

+                                'host_id': 1,

+                                'host_name': 'kojibuilder',

+                                'id': 3,

+                                'repo_id': 2,

+                                'tag_id': 4,

+                                'tag_name': 'test-tag',

+                                'task_id': 10}

+         self.buildinfo = {'build_id': 1,

+                           'epoch': 7,

+                           'id': 1,

+                           'name': 'test-rpm',

+                           'nvr': 'test-rpm-1.1-11',

+                           'package_id': 2,

+                           'package_name': 'test-rpm',

+                           'release': '11',

+                           'task_id': 8,

+                           'version': '1.1'}

+         self.getrpminfo = {'arch': 'noarch',

+                            'build_id': 1,

+                            'buildroot_id': 3,

+                            'buildtime': 1615877809,

+                            'epoch': 7,

+                            'id': 294,

+                            'name': 'test-rpm',

+                            'release': '11',

+                            'version': '1.1',

+                            'payloadhash': 'b2b95550390e5f213fc25f33822425f7',

+                            'size': 7030}

+ 

+     def tearDown(self):

+         if self.original_timezone is None:

+             del os.environ['TZ']

+         else:

+             os.environ['TZ'] = self.original_timezone

+         time.tzset()

+ 

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     def test_handle_rpminfo_valid(self, stdout):

+         rpm_nvra = 'test-rpm-1.1-11.noarch'

+         self.session.getBuildroot.return_value = self.buildroot_info

+         self.session.listBuildroots.return_value = [self.buildroot_info]

+         self.session.getBuild.return_value = self.buildinfo

+         self.session.getRPM.return_value = self.getrpminfo

+         expected_output = """RPM: 7:test-rpm-1.1-11.noarch [294]

+ RPM Path: /mnt/koji/packages/test-rpm/1.1/11/noarch/test-rpm-1.1-11.noarch.rpm

+ SRPM: 7:test-rpm-1.1-11 [1]

+ SRPM Path: /mnt/koji/packages/test-rpm/1.1/11/src/test-rpm-1.1-11.src.rpm

+ Built: Tue, 16 Mar 2021 06:56:49 UTC

+ SIGMD5: b2b95550390e5f213fc25f33822425f7

+ Size: 7030

+ Build ID: 1

+ Buildroot: 3 (tag test-tag, arch x86_64, repo 2)

+ Build Host: kojibuilder

+ Build Task: 10

+ Used in 1 buildroots:

+         id build tag                    arch     build host                   

+   -------- ---------------------------- -------- -----------------------------

+          3 test-tag                     x86_64   kojibuilder                  

+ """

+ 

+         anon_handle_rpminfo(self.options, self.session, ['--buildroot', rpm_nvra])

+         self.assert_console_message(stdout, expected_output)

+         self.session.getBuildroot.assert_called_once_with(self.getrpminfo['buildroot_id'])

+         self.session.listBuildroots.assert_called_once_with(queryOpts={'order': 'buildroot.id'},

+                                                             rpmID=self.getrpminfo['id'])

+         self.session.getBuild.assert_called_once_with(self.getrpminfo['build_id'])

+         self.session.getRPM.assert_called_once_with(rpm_nvra)

+ 

+     @mock.patch('sys.stderr', new_callable=StringIO)

+     def test_handle_rpminfo_non_exist_nvra(self, stderr):

+         rpm_nvra = 'test-rpm-nvra.arch'

+         self.session.getRPM.return_value = None

+         expected = "No such rpm: %s\n" % rpm_nvra + "\n"

+         with self.assertRaises(SystemExit) as ex:

+             anon_handle_rpminfo(self.options, self.session, ['--buildroot', rpm_nvra])

+         self.assertExitCode(ex, 1)

+         self.assert_console_message(stderr, expected)

+ 

+     @mock.patch('sys.stderr', new_callable=StringIO)

+     @mock.patch('sys.stdout', new_callable=StringIO)

+     def test_handle_rpminfo_more_nvra_non_exist_nvra(self, stdout, stderr):

+         rpm_nvra = 'test-rpm-1.1-11.noarch'

+         non_exist_rpm_nvra = 'not-test-rpm-11-112.arch'

+         self.session.getBuildroot.return_value = self.buildroot_info

+         self.session.listBuildroots.return_value = [self.buildroot_info]

+         self.session.getBuild.return_value = self.buildinfo

+         self.session.getRPM.side_effect = [None, self.getrpminfo]

+         expected_output = """RPM: 7:test-rpm-1.1-11.noarch [294]

+ RPM Path: /mnt/koji/packages/test-rpm/1.1/11/noarch/test-rpm-1.1-11.noarch.rpm

+ SRPM: 7:test-rpm-1.1-11 [1]

+ SRPM Path: /mnt/koji/packages/test-rpm/1.1/11/src/test-rpm-1.1-11.src.rpm

+ Built: Tue, 16 Mar 2021 06:56:49 UTC

+ SIGMD5: b2b95550390e5f213fc25f33822425f7

+ Size: 7030

+ Build ID: 1

+ Buildroot: 3 (tag test-tag, arch x86_64, repo 2)

+ Build Host: kojibuilder

+ Build Task: 10

+ Used in 1 buildroots:

+         id build tag                    arch     build host                   

+   -------- ---------------------------- -------- -----------------------------

+          3 test-tag                     x86_64   kojibuilder                  

+ """

+ 

+         expected_error = "No such rpm: %s\n" % non_exist_rpm_nvra + "\n"

+         with self.assertRaises(SystemExit) as ex:

+             anon_handle_rpminfo(self.options, self.session,

+                                 ['--buildroot', non_exist_rpm_nvra, rpm_nvra])

+         self.assertExitCode(ex, 1)

+         self.assert_console_message(stdout, expected_output)

+         self.assert_console_message(stderr, expected_error)

+         self.session.getBuildroot.assert_called_once_with(self.getrpminfo['buildroot_id'])

+         self.session.listBuildroots.assert_called_once_with(queryOpts={'order': 'buildroot.id'},

+                                                             rpmID=self.getrpminfo['id'])

+         self.session.getBuild.assert_called_once_with(self.getrpminfo['build_id'])

+         self.assertEqual(self.session.getRPM.call_count, 2)

It should use warn and store error so it can be raised in the end after going through all data. Secondly, test depends on CET timezone, it should set it explicitly if needed.

rebased onto 61a54ceaac1dfc5156478063826a37633d27f511

a year ago

rebased onto 1fd4654c1aa54429259113ba4534d641aafc5574

a year ago

rebased onto 5339a540ba90c0b1913b57cf76d031e8073bbc07

a year ago

rebased onto 723964a55edabcdfd32e195746f2fb984a94e25a

a year ago

rebased onto 99e7e09

a year ago

Metadata Update from @tkopecek:
- Pull-request tagged with: testing-ready

a year ago

Metadata Update from @mfilip:
- Pull-request tagged with: testing-done

a year ago

Commit ea5f462 fixes this pull-request

Pull-Request has been merged by tkopecek

a year ago