src/tests/api/t_file_manager.py
author Brock Pytlik <bpytlik@sun.com>
Mon, 16 Aug 2010 16:48:50 -0700
changeset 2026 d1b30615bc99
parent 1715 8f305f0a6864
child 2028 b2c674e6ee28
permissions -rw-r--r--
9196 pkg(5) should have support for cryptographic manifest signatures 11611 pkg5 should provide for hash validation on manifests 16654 Expose ability to upload by file path
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     1
#!/usr/bin/python
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     2
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     3
# CDDL HEADER START
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     4
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     5
# The contents of this file are subject to the terms of the
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     6
# Common Development and Distribution License (the "License").
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     7
# You may not use this file except in compliance with the License.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     8
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
     9
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    10
# or http://www.opensolaris.org/os/licensing.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    11
# See the License for the specific language governing permissions
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    12
# and limitations under the License.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    13
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    14
# When distributing Covered Code, include this CDDL HEADER in each
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    15
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    16
# If applicable, add the following below this CDDL HEADER, with the
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    17
# fields enclosed by brackets "[]" replaced with your own identifying
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    18
# information: Portions Copyright [yyyy] [name of copyright owner]
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    19
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    20
# CDDL HEADER END
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    21
#
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    22
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    23
#
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    24
# Copyright (c) 2009, 2010, Oracle and/or its affiliates. All rights reserved.
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    25
#
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    26
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
    27
import testutils
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
    28
if __name__ == "__main__":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
    29
        testutils.setup_environment("../../../proto")
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
    30
import pkg5unittest
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
    31
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
    32
import errno
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    33
import os
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    34
import shutil
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    35
import sys
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    36
import tempfile
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    37
import unittest
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    38
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    39
import pkg.file_layout.file_manager as file_manager
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    40
import pkg.file_layout.layout as layout
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    41
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    42
class TestFileManager(pkg5unittest.Pkg5TestCase):
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    43
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    44
        @staticmethod
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    45
        def old_hash(s):
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    46
                return os.path.join(s[0:2], s[2:8], s)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    47
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
    48
        def touch_old_file(self, s, data=None):
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
    49
                if data is None:
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
    50
                        data = s
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    51
                p = os.path.join(self.base_dir, self.old_hash(s))
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
    52
                if not os.path.exists(os.path.dirname(p)):
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
    53
                        os.makedirs(os.path.dirname(p))
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    54
                fh = open(p, "wb")
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
    55
                fh.write(data)
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    56
                fh.close()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    57
                return p
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    58
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    59
        @staticmethod
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    60
        def check_exception(func, ex, str_bits, *args, **kwargs):
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    61
                try:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    62
                        func(*args, **kwargs)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    63
                except ex, e:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    64
                        s = str(e)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    65
                        for b in str_bits:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    66
                                if b not in s:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    67
                                        raise RuntimeError("Expected to find "
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    68
                                            "%s in %s" % (b, s))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    69
                else:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    70
                        raise RuntimeError("Didn't raise expected exception")
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    71
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    72
        def check_readonly(self, fm, unmoved, p):
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    73
                self.assert_(os.path.isfile(p))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    74
                self.assertEqual(fm.lookup(unmoved), p)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    75
                fh = fm.lookup(unmoved, opener=True)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    76
                try:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    77
                        self.assertEqual(fh.read(), unmoved)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    78
                finally:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    79
                        fh.close()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    80
                self.assert_(os.path.isfile(p))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    81
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    82
                self.check_exception(fm.insert,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    83
                    file_manager.NeedToModifyReadOnlyFileManager,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    84
                    ["create", unmoved], unmoved, p)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    85
                self.assert_(os.path.isfile(p))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    86
                self.check_exception(fm.remove,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    87
                    file_manager.NeedToModifyReadOnlyFileManager,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    88
                    ["remove", unmoved], unmoved)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    89
                self.assert_(os.path.isfile(p))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    90
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    91
        def setUp(self):
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    92
                pkg5unittest.Pkg5TestCase.setUp(self)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    93
                # Move base_dir down one level so that the tests don't assume
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    94
                # sole control over the contents of self.test_root.
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    95
                self.base_dir = os.path.join(self.test_root, "fm")
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    96
                os.mkdir(self.base_dir)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
    97
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
    98
        def test_1(self):
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
    99
                """Verify base functionality works as expected."""
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   100
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   101
                t = tempfile.gettempdir()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   102
                no_dir = os.path.join(t, "not_exist")
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   103
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   104
                self.check_exception(file_manager.FileManager,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   105
                    file_manager.NeedToModifyReadOnlyFileManager,
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   106
                    ["create", no_dir], no_dir, readonly=True)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   107
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   108
                # Test that a read only FileManager won't modify the file
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   109
                # system.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   110
                fm = file_manager.FileManager(self.base_dir, readonly=True)
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   111
                self.assertEqual(os.listdir(self.base_dir), [])
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   112
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   113
                unmoved = "4b7c923af3a047d4685a39ad7bc9b0382ccde671"
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   114
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   115
                p = self.touch_old_file(unmoved)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   116
                self.check_readonly(fm, unmoved, p)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   117
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   118
                self.assertEqual(set(fm.walk()),
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   119
                    set([unmoved]))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   120
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   121
                # Test a FileManager that can write to the file system.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   122
                fm = file_manager.FileManager(self.base_dir, False)
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   123
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   124
                hash1 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cb"
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   125
                hash2 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   126
                hash3 = "994b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   127
                hash4 = "cc1f76cdad188714d1c3b92a4eebb4ec7d646166"
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   128
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   129
                l = layout.V1Layout()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   130
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   131
                self.assertEqual(l.lookup(hash1),
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   132
                    "58/584b6ab7d7eb446938a02e57101c3a2fecbfb3cb")
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   133
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   134
                # Test that looking up a file stored under the old system gets
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   135
                # moved to the correct location, that the new location is
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   136
                # correctly returned, and that the old location's parent
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   137
                # directory no longer exists as only a single file existed
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   138
                # there.  Finally, remove it for the next test if successful.
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   139
                p1 = self.touch_old_file(hash1)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   140
                self.assert_(os.path.isfile(p1))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   141
                self.assert_(os.path.isdir(os.path.dirname(p1)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   142
                self.assertEqual(fm.lookup(hash1),
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   143
                    os.path.join(self.base_dir, l.lookup(hash1)))
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   144
                self.assert_(not os.path.exists(p1))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   145
                self.assert_(not os.path.exists(os.path.dirname(p1)))
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   146
                fm.remove(hash1)
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   147
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   148
                # Test that looking up a file stored under the old system gets
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   149
                # moved to the correct location, that the new location is
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   150
                # correctly returned, and that the old location's parent
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   151
                # directory still exists as multiple files were stored there.
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   152
                # Finally, remove file stored in the old location for the next
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   153
                # few tests.
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   154
                p1 = self.touch_old_file(hash1)
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   155
                self.touch_old_file(hash2)
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   156
                self.assert_(os.path.isfile(p1))
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   157
                self.assert_(os.path.isdir(os.path.dirname(p1)))
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   158
                self.assertEqual(fm.lookup(hash1),
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   159
                    os.path.join(self.base_dir, l.lookup(hash1)))
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   160
                self.assert_(not os.path.exists(p1))
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   161
                self.assert_(os.path.exists(os.path.dirname(p1)))
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   162
                fm.remove(hash2)
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   163
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   164
                # Test that looking up a file stored under the old system gets
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   165
                # moved and that it returns a file handle with the correct
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   166
                # contents.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   167
                p4 = self.touch_old_file(hash4)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   168
                self.assert_(os.path.isfile(p4))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   169
                self.assert_(os.path.isdir(os.path.dirname(p4)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   170
                fh = fm.lookup(hash4, opener=True)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   171
                try:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   172
                        self.assertEqual(fh.read(), hash4)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   173
                finally:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   174
                        fh.close()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   175
                self.assert_(not os.path.exists(p4))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   176
                self.assert_(not os.path.exists(os.path.dirname(p4)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   177
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   178
                p3 = self.touch_old_file(hash3)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   179
                self.assert_(os.path.isfile(p3))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   180
                self.assert_(os.path.isdir(os.path.dirname(p3)))
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   181
                fm.insert(hash3, p3)
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   182
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   183
                self.assert_(not os.path.exists(p3))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   184
                self.assert_(not os.path.exists(os.path.dirname(p3)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   185
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   186
                fh = fm.lookup(hash3, opener=True)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   187
                try:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   188
                        self.assertEqual(fh.read(), hash3)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   189
                finally:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   190
                        fh.close()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   191
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   192
                # Test that walk returns the expected values.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   193
                self.assertEqual(set(fm.walk()),
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   194
                    set([unmoved, hash1, hash4, hash3]))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   195
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   196
                # Test that walking with a different set of layouts works as
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   197
                # expected.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   198
                fm2 = file_manager.FileManager(self.base_dir, readonly=True,
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   199
                    layouts=[layout.get_preferred_layout()])
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   200
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   201
                fs = set([hash1, hash4, hash3])
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   202
                try:
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   203
                        for i in fm2.walk():
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   204
                                fs.remove(i)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   205
                except file_manager.UnrecognizedFilePaths, e:
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   206
                        self.assertEqual(e.fps, [p[len(self.base_dir) + 1:]])
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   207
                self.assertEqual(fs, set())
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   208
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   209
                # Test removing a file works and removes the containing
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   210
                # directory and that remove removes all instances of a hash
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   211
                # from the file manager.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   212
                hash3_loc = os.path.join(self.base_dir, l.lookup(hash3))
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   213
                v0_hash3_loc = self.touch_old_file(hash3)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   214
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   215
                self.assert_(os.path.isfile(hash3_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   216
                self.assert_(os.path.isfile(v0_hash3_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   217
                fm.remove(hash3)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   218
                self.assertEqual(fm.lookup(hash3), None)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   219
                self.assert_(not os.path.exists(hash3_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   220
                self.assert_(not os.path.exists(os.path.dirname(hash3_loc)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   221
                self.assert_(not os.path.exists(v0_hash3_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   222
                self.assert_(not os.path.exists(os.path.dirname(v0_hash3_loc)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   223
                self.assert_(os.path.isfile(fm.lookup(hash1)))
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   224
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   225
                rh2_fd, raw_hash_2_loc = tempfile.mkstemp(dir=self.base_dir)
1452
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   226
                rh2_fh = os.fdopen(rh2_fd, "w")
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   227
                rh2_fh.write(hash2)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   228
                rh2_fh.close()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   229
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   230
                fm.insert(hash2, raw_hash_2_loc)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   231
                h2_loc = fm.lookup(hash2)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   232
                self.assert_(os.path.isfile(fm.lookup(hash2)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   233
                # Test that the directory has two files in it as expected.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   234
                self.assertEqual(set(os.listdir(
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   235
                    os.path.dirname(fm.lookup(hash2)))),
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   236
                    set([hash1, hash2]))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   237
                # Test removing one of the two files doesn't remove the other.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   238
                fm.remove(hash1)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   239
                self.assert_(os.path.isfile(h2_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   240
                self.assertEqual(fm.lookup(hash2), h2_loc)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   241
                self.assertEqual(fm.lookup(hash1), None)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   242
                # Test that removing the second file works and removes the
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   243
                # containing directory as well.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   244
                fm.remove(hash2)
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   245
                self.assert_(not os.path.exists(h2_loc))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   246
                self.assert_(not os.path.exists(os.path.dirname(h2_loc)))
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   247
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   248
                # Test that setting the read_only property works and that none
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   249
                # of the activities has effected the location where unmoved has
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   250
                # been stored.
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   251
                fm.set_read_only()
bd6ffa78fed9 7960 client and depot need different organization of files
Brock Pytlik <bpytlik@sun.com>
parents:
diff changeset
   252
                self.check_readonly(fm, unmoved, p)
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   253
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   254
        def test_2_reverse(self):
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   255
                """Verify that reverse layout migration works as expected."""
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   256
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   257
                # Verify that reverse layout migration works as expected.
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   258
                hash1 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cb"
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   259
                hash2 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   260
                hash3 = "994b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   261
                hash4 = "cc1f76cdad188714d1c3b92a4eebb4ec7d646166"
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   262
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   263
                l0 = layout.V0Layout()
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   264
                l1 = layout.V1Layout()
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   265
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   266
                # Populate the managed location using the v0 layout.
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   267
                for fhash in (hash1, hash2, hash3, hash4):
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   268
                        self.touch_old_file(fhash)
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   269
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   270
                # Migrate it to the v1 layout.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   271
                fm = file_manager.FileManager(self.base_dir, False)
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   272
                for fhash in fm.walk():
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   273
                        self.assertEqual(fm.lookup(fhash),
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   274
                            os.path.join(self.base_dir, l1.lookup(fhash)))
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   275
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   276
                # After migration verify that no v0 parent directories remain.
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   277
                for fhash in fm.walk():
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   278
                        self.assertFalse(os.path.exists(os.path.dirname(
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   279
                            os.path.join(self.base_dir, l0.lookup(fhash)))))
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   280
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   281
                # Re-create the FileManager using v0 as the preferred layout.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   282
                fm = file_manager.FileManager(self.base_dir, False,
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   283
                    layouts=[l0, l1])
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   284
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   285
                # Test that looking up a file stored under the v1 layout is
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   286
                # correctly moved to the v0 layout.
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   287
                for fhash in fm.walk():
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   288
                        self.assertEqual(fm.lookup(fhash),
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   289
                            os.path.join(self.base_dir, l0.lookup(fhash)))
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   290
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   291
        def test_3_replace(self):
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   292
                """Verify that insert will replace an existing file even though
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   293
                the hashval is the same."""
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   294
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   295
                # Verify that reverse layout migration works as expected.
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   296
                hash1 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cb"
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   297
                hash2 = "584b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   298
                hash3 = "994b6ab7d7eb446938a02e57101c3a2fecbfb3cc"
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   299
                hash4 = "cc1f76cdad188714d1c3b92a4eebb4ec7d646166"
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   300
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   301
                l1 = layout.V1Layout()
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   302
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   303
                # Populate the managed location using the v0 layout.
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   304
                for fhash in (hash1, hash2, hash3, hash4):
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   305
                        self.touch_old_file(fhash, data="old-%s" % fhash)
1476
397d9bbe70d9 12570 publication can fail when republishing existing content
Shawn Walker <srw@sun.com>
parents: 1452
diff changeset
   306
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   307
                # Migrate it to the v1 layout and verify that each
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   308
                # file contains the expected data.
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   309
                fm = file_manager.FileManager(self.base_dir, False)
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   310
                for fhash in fm.walk():
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   311
                        loc = fm.lookup(fhash)
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   312
                        self.assertEqual(loc, os.path.join(self.base_dir,
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   313
                            l1.lookup(fhash)))
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   314
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   315
                        f = open(loc, "rb")
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   316
                        self.assertEqual(f.read(), "old-%s" % fhash)
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   317
                        f.close()
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   318
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   319
                # Now replace each file using the old hashnames and verify
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   320
                # that the each contains the expected data.
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   321
                for fhash in fm.walk():
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   322
                        loc = os.path.join(self.base_dir, l1.lookup(fhash))
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   323
                        self.assertTrue(os.path.exists(loc))
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   324
2026
d1b30615bc99 9196 pkg(5) should have support for cryptographic manifest signatures
Brock Pytlik <bpytlik@sun.com>
parents: 1715
diff changeset
   325
                        npath = os.path.join(self.base_dir, "new-%s" % fhash)
1485
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   326
                        nfile = open(npath, "wb")
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   327
                        nfile.write("new-%s" % fhash)
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   328
                        nfile.close()
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   329
                        fm.insert(fhash, npath)
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   330
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   331
                        loc = fm.lookup(fhash)
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   332
                        f = open(loc, "rb")
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   333
                        self.assertEqual(f.read(), "new-%s" % fhash)
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   334
                        f.close()
6aeae7c6ca4c 12596 compressed repository files not upgraded to new format automatically
Shawn Walker <srw@sun.com>
parents: 1476
diff changeset
   335
1715
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
   336
if __name__ == "__main__":
8f305f0a6864 8265 EINVAL on rmdir running "make test"
Dan Price <dp@eng.sun.com>
parents: 1485
diff changeset
   337
        unittest.main()