src/tests/cli/t_pkg_info.py
changeset 3339 c88573eb98ea
parent 3193 618a7acf5f09
child 3456 d5a35cfaf951
equal deleted inserted replaced
3338:3c357007fc55 3339:c88573eb98ea
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
    18 # information: Portions Copyright [yyyy] [name of copyright owner]
    19 #
    19 #
    20 # CDDL HEADER END
    20 # CDDL HEADER END
    21 #
    21 #
    22 
    22 
    23 # Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
    23 # Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
    24 
    24 
    25 import testutils
    25 from . import testutils
    26 if __name__ == "__main__":
    26 if __name__ == "__main__":
    27         testutils.setup_environment("../../../proto")
    27         testutils.setup_environment("../../../proto")
    28 import pkg5unittest
    28 import pkg5unittest
    29 
    29 
    30 import json
    30 import json
    31 import os
    31 import os
    32 import shutil
    32 import shutil
       
    33 import six
    33 import unittest
    34 import unittest
    34 
    35 
    35 import pkg.catalog as catalog
    36 import pkg.catalog as catalog
    36 import pkg.actions as actions
    37 import pkg.actions as actions
    37 import pkg.fmri as fmri
    38 import pkg.fmri as fmri
    88             "tmp/baz"]
    89             "tmp/baz"]
    89 
    90 
    90         def __check_qoutput(self, errout=False):
    91         def __check_qoutput(self, errout=False):
    91                 self.assertEqualDiff(self.output, "")
    92                 self.assertEqualDiff(self.output, "")
    92                 if errout:
    93                 if errout:
    93                         self.assert_(self.errout != "",
    94                         self.assertTrue(self.errout != "",
    94                             "-q must print fatal errors!")
    95                             "-q must print fatal errors!")
    95                 else:
    96                 else:
    96                         self.assert_(self.errout == "",
    97                         self.assertTrue(self.errout == "",
    97                             "-q should only print fatal errors!")
    98                             "-q should only print fatal errors!")
    98 
    99 
    99         def setUp(self):
   100         def setUp(self):
   100                 pkg5unittest.SingleDepotTestCase.setUp(self)
   101                 pkg5unittest.SingleDepotTestCase.setUp(self)
   101                 self.make_misc_files(self.misc_files)
   102                 self.make_misc_files(self.misc_files)
   205                 # Remove the publisher, and verify a remote or local request
   206                 # Remove the publisher, and verify a remote or local request
   206                 # fails since the manifest isn't cached within the image and we
   207                 # fails since the manifest isn't cached within the image and we
   207                 # can't retrieve it.
   208                 # can't retrieve it.
   208                 self.pkg("unset-publisher test")
   209                 self.pkg("unset-publisher test")
   209                 self.pkg("info -r jade", su_wrap=True, exit=1)
   210                 self.pkg("info -r jade", su_wrap=True, exit=1)
   210                 self.assert_("no errors" not in self.errout, self.errout)
   211                 self.assertTrue("no errors" not in self.errout, self.errout)
   211                 self.assert_("Unknown" not in self.errout, self.errout)
   212                 self.assertTrue("Unknown" not in self.errout, self.errout)
   212 
   213 
   213                 self.pkg("info jade", su_wrap=True, exit=1)
   214                 self.pkg("info jade", su_wrap=True, exit=1)
   214                 self.assert_("no errors" not in self.errout, self.errout)
   215                 self.assertTrue("no errors" not in self.errout, self.errout)
   215                 self.assert_("Unknown" not in self.errout, self.errout)
   216                 self.assertTrue("Unknown" not in self.errout, self.errout)
   216 
   217 
   217                 self.pkg("set-publisher test")
   218                 self.pkg("set-publisher test")
   218                 self.pkg("info -r jade", su_wrap=True, exit=1)
   219                 self.pkg("info -r jade", su_wrap=True, exit=1)
   219                 self.assert_("no errors" not in self.errout, self.errout)
   220                 self.assertTrue("no errors" not in self.errout, self.errout)
   220                 self.assert_("Unknown" not in self.errout, self.errout)
   221                 self.assertTrue("Unknown" not in self.errout, self.errout)
   221 
   222 
   222                 self.pkg("info jade", su_wrap=True, exit=1)
   223                 self.pkg("info jade", su_wrap=True, exit=1)
   223                 self.assert_("no errors" not in self.errout, self.errout)
   224                 self.assertTrue("no errors" not in self.errout, self.errout)
   224                 self.assert_("Unknown" not in self.errout, self.errout)
   225                 self.assertTrue("Unknown" not in self.errout, self.errout)
   225 
   226 
   226                 self.pkg("set-publisher -p {0} test".format(self.durl))
   227                 self.pkg("set-publisher -p {0} test".format(self.durl))
   227 
   228 
   228                 # Check local info
   229                 # Check local info
   229                 self.pkg("info jade | grep 'State: Installed'")
   230                 self.pkg("info jade | grep 'State: Installed'")
   373                 self.pkg("verify -v")
   374                 self.pkg("verify -v")
   374  
   375  
   375                 # grep for some attributes that are defined and they have
   376                 # grep for some attributes that are defined and they have
   376                 # single values
   377                 # single values
   377                 self.pkg("info jade")
   378                 self.pkg("info jade")
   378                 self.assert_("Category" in self.output) 
   379                 self.assertTrue("Category" in self.output) 
   379                 
   380                 
   380                 # grep for some attributes that are defined and they have
   381                 # grep for some attributes that are defined and they have
   381                 # multiple values
   382                 # multiple values
   382                 self.pkg("info jade")
   383                 self.pkg("info jade")
   383                 self.assert_("Project Maintainer" in self.output) 
   384                 self.assertTrue("Project Maintainer" in self.output) 
   384 
   385 
   385                 # grep for some attributes that are defined , with no value
   386                 # grep for some attributes that are defined , with no value
   386                 self.pkg("info jade")
   387                 self.pkg("info jade")
   387                 self.assert_("Project Maintainer URL" not in self.output) 
   388                 self.assertTrue("Project Maintainer URL" not in self.output) 
   388                    
   389                    
   389                 # grep for same attributes that are defined above in different
   390                 # grep for same attributes that are defined above in different
   390                 # packages, with some value 
   391                 # packages, with some value 
   391                 self.pkg("info copper")
   392                 self.pkg("info copper")
   392                 self.assert_("Project Maintainer URL" in self.output) 
   393                 self.assertTrue("Project Maintainer URL" in self.output) 
   393 
   394 
   394                 # grep for attributes that are not defined
   395                 # grep for attributes that are not defined
   395                 self.pkg("info jade")
   396                 self.pkg("info jade")
   396                 self.assert_("info.foo" not in self.output) 
   397                 self.assertTrue("info.foo" not in self.output) 
   397 
   398 
   398         def test_info_bad_packages(self):
   399         def test_info_bad_packages(self):
   399                 """Verify that pkg info handles packages with invalid
   400                 """Verify that pkg info handles packages with invalid
   400                 metadata."""
   401                 metadata."""
   401 
   402 
   443         def test_ranked(self):
   444         def test_ranked(self):
   444                 """Verify that pkg info -r returns expected results when
   445                 """Verify that pkg info -r returns expected results when
   445                 multiple publishers provide the same package based on
   446                 multiple publishers provide the same package based on
   446                 publisher search order."""
   447                 publisher search order."""
   447 
   448 
   448 		# because we compare date strings we must run this in
   449                 # because we compare date strings we must run this in
   449 		# a consistent locale, which we made 'C'
   450                 # a consistent locale, which we made 'C'
   450 
   451 
   451 		os.environ['LC_ALL'] = 'C'
   452                 os.environ['LC_ALL'] = 'C'
   452 
   453 
   453                 # Create an isolated repository for this test
   454                 # Create an isolated repository for this test
   454                 repodir = os.path.join(self.test_root, "test-ranked")
   455                 repodir = os.path.join(self.test_root, "test-ranked")
   455                 self.create_repo(repodir)
   456                 self.create_repo(repodir)
   456                 self.pkgrepo("add-publisher -s {0} test".format(repodir))
   457                 self.pkgrepo("add-publisher -s {0} test".format(repodir))
   576  Size: 54.00 B
   577  Size: 54.00 B
   577  FMRI: pkg://test3/[email protected]:20110908T004546Z
   578  FMRI: pkg://test3/[email protected]:20110908T004546Z
   578 """
   579 """
   579                 self.assertEqualDiff(expected, self.reduceSpaces(self.output))
   580                 self.assertEqualDiff(expected, self.reduceSpaces(self.output))
   580 
   581 
       
   582                 if six.PY3:
       
   583                         os.environ["LC_ALL"] = "en_US.UTF-8"
       
   584 
   581         def test_renamed_packages(self):
   585         def test_renamed_packages(self):
   582                 """Verify that info returns the expected output for renamed
   586                 """Verify that info returns the expected output for renamed
   583                 packages."""
   587                 packages."""
   584 
   588 
   585 		# because we compare date strings we must run this in
   589                 # because we compare date strings we must run this in
   586 		# a consistent locale, which we made 'C'
   590                 # a consistent locale, which we made 'C'
   587 
   591 
   588 		os.environ['LC_ALL'] = 'C'
   592                 os.environ['LC_ALL'] = 'C'
   589 
   593 
   590                 target10 = """
   594                 target10 = """
   591                     open [email protected]
   595                     open [email protected]
   592                     close
   596                     close
   593                 """
   597                 """
   713           Size: 0.00 B
   717           Size: 0.00 B
   714           FMRI: {pkg_fmri}
   718           FMRI: {pkg_fmri}
   715 """.format(pkg_date=pkg_date, pkg_fmri=pfmri.get_fmri(include_build=False))
   719 """.format(pkg_date=pkg_date, pkg_fmri=pfmri.get_fmri(include_build=False))
   716                 self.assertEqualDiff(expected, actual)
   720                 self.assertEqualDiff(expected, actual)
   717 
   721 
       
   722                 if six.PY3:
       
   723                         os.environ["LC_ALL"] = "en_US.UTF-8"
       
   724 
   718         def test_appropriate_license_files(self):
   725         def test_appropriate_license_files(self):
   719                 """Verify that the correct license file is displayed."""
   726                 """Verify that the correct license file is displayed."""
   720 
   727 
   721                 self.image_create(self.rurl)
   728                 self.image_create(self.rurl)
   722 
   729 
   724                 self.assertEqual("tmp/copyright1\n", self.output)
   731                 self.assertEqual("tmp/copyright1\n", self.output)
   725                 self.pkg("info -r --license [email protected]")
   732                 self.pkg("info -r --license [email protected]")
   726                 self.assertEqual("tmp/copyright0\n", self.output)
   733                 self.assertEqual("tmp/copyright0\n", self.output)
   727 
   734 
   728                 self.pkg("install --licenses [email protected]")
   735                 self.pkg("install --licenses [email protected]")
   729                 self.assert_("tmp/copyright0" in self.output, "Expected "
   736                 self.assertTrue("tmp/copyright0" in self.output, "Expected "
   730                     "tmp/copyright0 to be in the output of the install. Output "
   737                     "tmp/copyright0 to be in the output of the install. Output "
   731                     "was:\n{0}".format(self.output))
   738                     "was:\n{0}".format(self.output))
   732                 self.pkg("info -l --license bronze")
   739                 self.pkg("info -l --license bronze")
   733                 self.assertEqual("tmp/copyright0\n", self.output)
   740                 self.assertEqual("tmp/copyright0\n", self.output)
   734                 self.pkg("info -r --license bronze")
   741                 self.pkg("info -r --license bronze")
   735                 self.assertEqual("tmp/copyright1\n", self.output)
   742                 self.assertEqual("tmp/copyright1\n", self.output)
   736                 self.pkg("info -r --license [email protected]")
   743                 self.pkg("info -r --license [email protected]")
   737                 self.assertEqual("tmp/copyright1\n", self.output)
   744                 self.assertEqual("tmp/copyright1\n", self.output)
   738 
   745 
   739                 self.pkg("update --licenses [email protected]")
   746                 self.pkg("update --licenses [email protected]")
   740                 self.assert_("tmp/copyright1" in self.output, "Expected "
   747                 self.assertTrue("tmp/copyright1" in self.output, "Expected "
   741                     "tmp/copyright1 to be in the output of the install. Output "
   748                     "tmp/copyright1 to be in the output of the install. Output "
   742                     "was:\n{0}".format(self.output))
   749                     "was:\n{0}".format(self.output))
   743                 self.pkg("info -r --license bronze")
   750                 self.pkg("info -r --license bronze")
   744                 self.assertEqual("tmp/copyright1\n", self.output)
   751                 self.assertEqual("tmp/copyright1\n", self.output)
   745                 self.pkg("info -l --license bronze")
   752                 self.pkg("info -l --license bronze")
   772                 # Last update should be existed this time.
   779                 # Last update should be existed this time.
   773                 last_update = catalog.basic_ts_to_datetime(
   780                 last_update = catalog.basic_ts_to_datetime(
   774                     entry["last-update"]).strftime("%c")
   781                     entry["last-update"]).strftime("%c")
   775                 self.pkg(("info bronze | grep 'Last Update Time: "
   782                 self.pkg(("info bronze | grep 'Last Update Time: "
   776                     "{0}'").format(last_update))
   783                     "{0}'").format(last_update))
       
   784 
       
   785                 if six.PY3:
       
   786                         os.environ["LC_ALL"] = "en_US.UTF-8"
   777 
   787 
   778 
   788 
   779 class TestPkgInfoPerTestRepo(pkg5unittest.SingleDepotTestCase):
   789 class TestPkgInfoPerTestRepo(pkg5unittest.SingleDepotTestCase):
   780         """A separate test class is needed because these tests modify packages
   790         """A separate test class is needed because these tests modify packages
   781         after they've been published and need to avoid corrupting packages for
   791         after they've been published and need to avoid corrupting packages for
   805                 self.plist = self.pkgsend_bulk(self.rurl, (self.bronze10))
   815                 self.plist = self.pkgsend_bulk(self.rurl, (self.bronze10))
   806 
   816 
   807         def __mangle_license(self, fmri):
   817         def __mangle_license(self, fmri):
   808                 repo = self.dc.get_repo()
   818                 repo = self.dc.get_repo()
   809                 m_path = repo.manifest(fmri)
   819                 m_path = repo.manifest(fmri)
   810                 with open(m_path, "rb") as fh:
   820                 with open(m_path, "r") as fh:
   811                         fmri_lines = fh.readlines()
   821                         fmri_lines = fh.readlines()
   812                 with open(m_path, "wb") as fh:
   822                 with open(m_path, "w") as fh:
   813                         a = None
   823                         a = None
   814                         for l in fmri_lines:
   824                         for l in fmri_lines:
   815                                 if "license=copyright" in l:
   825                                 if "license=copyright" in l:
   816                                         continue
   826                                         continue
   817                                 elif "path=etc/bronze1" in l:
   827                                 elif "path=etc/bronze1" in l:
   818                                         a = actions.fromstr(l)
   828                                         a = actions.fromstr(l)
   819                                 fh.write(l)
   829                                 fh.write(l)
   820                         self.assert_(a)
   830                         self.assertTrue(a)
   821                         l = """\
   831                         l = """\
   822 license {hash} license=foo chash={chash} pkg.csize={csize} \
   832 license {hash} license=foo chash={chash} pkg.csize={csize} \
   823 pkg.size={size}""".format(
   833 pkg.size={size}""".format(
   824     hash=a.hash,
   834     hash=a.hash,
   825     chash=a.attrs["chash"],
   835     chash=a.attrs["chash"],
   836 
   846 
   837                 self.image_create(self.rurl)
   847                 self.image_create(self.rurl)
   838                 self.pkg("install bronze")
   848                 self.pkg("install bronze")
   839 
   849 
   840                 self.pkg("info --license bronze")
   850                 self.pkg("info --license bronze")
   841                 self.assert_("tmp/copyright1" in self.output)
   851                 self.assertTrue("tmp/copyright1" in self.output)
   842                 self.__mangle_license(self.plist[0])
   852                 self.__mangle_license(self.plist[0])
   843 
   853 
   844                 self.pkg("refresh --full")
   854                 self.pkg("refresh --full")
   845 
   855 
   846                 self.pkg("info --license bronze")
   856                 self.pkg("info --license bronze")
   847                 self.assert_("tmp/bronze1" not in self.output)
   857                 self.assertTrue("tmp/bronze1" not in self.output)
   848                 self.assert_("tmp/copyright1" in self.output)
   858                 self.assertTrue("tmp/copyright1" in self.output)
   849 
   859 
   850                 self.pkg("info -r --license bronze")
   860                 self.pkg("info -r --license bronze")
   851                 self.assert_("tmp/bronze1" not in self.output)
   861                 self.assertTrue("tmp/bronze1" not in self.output)
   852                 self.assert_("tmp/copyright1" in self.output)
   862                 self.assertTrue("tmp/copyright1" in self.output)
   853 
   863 
   854         def test_info_uninstalled_changed_manifest(self):
   864         def test_info_uninstalled_changed_manifest(self):
   855                 """Test that if an uninstalled manifest has changed in the
   865                 """Test that if an uninstalled manifest has changed in the
   856                 repository but is cached locally, that the changed manifest is
   866                 repository but is cached locally, that the changed manifest is
   857                 reflected in info -r."""
   867                 reflected in info -r."""
   858 
   868 
   859                 # First test remote retrieval.
   869                 # First test remote retrieval.
   860                 self.image_create(self.rurl)
   870                 self.image_create(self.rurl)
   861 
   871 
   862                 self.pkg("info -r  --license bronze")
   872                 self.pkg("info -r  --license bronze")
   863                 self.assert_("tmp/copyright1" in self.output)
   873                 self.assertTrue("tmp/copyright1" in self.output)
   864                 self.__mangle_license(self.plist[0])
   874                 self.__mangle_license(self.plist[0])
   865                 self.pkg("refresh --full")
   875                 self.pkg("refresh --full")
   866 
   876 
   867                 self.pkg("info -r  --license bronze")
   877                 self.pkg("info -r  --license bronze")
   868                 self.assert_("tmp/bronze1" in self.output)
   878                 self.assertTrue("tmp/bronze1" in self.output)
   869                 self.assert_("tmp/copyright1" not in self.output)
   879                 self.assertTrue("tmp/copyright1" not in self.output)
   870 
   880 
   871 
   881 
   872 if __name__ == "__main__":
   882 if __name__ == "__main__":
   873         unittest.main()
   883         unittest.main()