src/tests/cli/t_pkgsend.py
changeset 3315 e2377565405f
parent 3234 3a90dc0b66c9
child 3339 c88573eb98ea
equal deleted inserted replaced
3314:0c8948c04faa 3315:e2377565405f
    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 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
    34 import pwd
    34 import pwd
    35 import shutil
    35 import shutil
    36 import stat
    36 import stat
    37 import tempfile
    37 import tempfile
    38 import unittest
    38 import unittest
       
    39 import six
    39 from six.moves import range
    40 from six.moves import range
    40 from six.moves.urllib.error import HTTPError
    41 from six.moves.urllib.error import HTTPError
    41 from six.moves.urllib.request import urlopen, Request, pathname2url
    42 from six.moves.urllib.request import urlopen, Request, pathname2url
    42 
    43 
    43 from pkg import misc
    44 from pkg import misc
    52         sha512_supported = False
    53         sha512_supported = False
    53 
    54 
    54 
    55 
    55 class TestPkgsendBasics(pkg5unittest.SingleDepotTestCase):
    56 class TestPkgsendBasics(pkg5unittest.SingleDepotTestCase):
    56         persistent_setup = False
    57         persistent_setup = False
       
    58         # Tests in this suite use the read only data directory.
       
    59         need_ro_data = True
    57 
    60 
    58         def setUp(self):
    61         def setUp(self):
    59                 # This test suite needs an actual depot.
    62                 # This test suite needs an actual depot.
    60                 pkg5unittest.SingleDepotTestCase.setUp(self, start_depot=True)
    63                 pkg5unittest.SingleDepotTestCase.setUp(self, start_depot=True)
    61 
    64 
  1404                         owner=owner, group=group)
  1407                         owner=owner, group=group)
  1405 
  1408 
  1406                 self.assertEqualDiff(self.reduceSpaces(expected),
  1409                 self.assertEqualDiff(self.reduceSpaces(expected),
  1407                     self.reduceSpaces(actual))
  1410                     self.reduceSpaces(actual))
  1408 
  1411 
       
  1412         def test_28_content_attrs(self):
       
  1413                 """Ensure that content-related attributes are ignored for
       
  1414                 'pgksend publish'."""
       
  1415 
       
  1416                 mfpath = os.path.join(self.test_root, "content-attrs.p5m")
       
  1417                 with open(mfpath, "wb") as mf:
       
  1418                         mf.write("""\
       
  1419 set name=pkg.fmri value=pkg://test/[email protected]
       
  1420 file elftest.so.1 mode=0755 owner=root group=bin path=bin/true pkg.size=ignored pkg.csize=ignored elfhash=ignored elfbits=ignored elfarch=ignored
       
  1421 """)
       
  1422 
       
  1423                 # Verify pkgsend publish can be performed even though values for
       
  1424                 # content-related attributes are invalid.  They should be
       
  1425                 # forcibly dropped and added back.
       
  1426                 ret, pfmri = self.pkgsend(self.dc.get_depot_url(),
       
  1427                     "publish -d {0} {1}".format(self.ro_data_root, mfpath))
       
  1428 
       
  1429                 # Now get the actual manifest and ensure all attributes were
       
  1430                 # overwritten.
       
  1431                 repo = self.dc.get_repo()
       
  1432                 rmpath = repo.manifest(pfmri)
       
  1433                 rm = manifest.Manifest()
       
  1434                 rm.set_content(pathname=rmpath)
       
  1435                 a = list(rm.gen_actions_by_type('file'))[0]
       
  1436 
       
  1437                 # These attributes should always match pre-determined values.
       
  1438                 expected = {
       
  1439                     'elfarch': 'i386',
       
  1440                     'elfbits': '32',
       
  1441                     'group': 'bin',
       
  1442                     'mode': '0755',
       
  1443                     'owner': 'root',
       
  1444                     'path': 'bin/true',
       
  1445                     'pkg.csize': '1358',
       
  1446                     'pkg.size': '3948'
       
  1447                 }
       
  1448                 actual = dict(
       
  1449                     (k, v) for (k, v) in six.iteritems(a.attrs)
       
  1450                     if k in expected
       
  1451                 )
       
  1452                 self.assertEqualDiff(expected, actual)
       
  1453 
       
  1454                 # 'elfhash' can vary depending upon whether we've changed the
       
  1455                 # content-hashing algorithms, so we only verify it exists and
       
  1456                 # doesn't have a value of 'ignored'.
       
  1457                 self.assertNotEqual(a.attrs['elfhash'], 'ignored')
       
  1458 
  1409 
  1459 
  1410 class TestPkgsendHardlinks(pkg5unittest.CliTestCase):
  1460 class TestPkgsendHardlinks(pkg5unittest.CliTestCase):
  1411 
  1461 
  1412         def test_bundle_dir_hardlinks(self):
  1462         def test_bundle_dir_hardlinks(self):
  1413                 """Verify that hardlink targeting works correctly."""
  1463                 """Verify that hardlink targeting works correctly."""