aboutsummaryrefslogtreecommitdiff
blob: 436b846cf3790d759c9cb667e612830dccab3923 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
# Copyright 2012-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2

import sys
import textwrap

import portage
from portage import os
from portage.const import SUPPORTED_GENTOO_BINPKG_FORMATS
from portage.tests import TestCase
from portage.tests.resolver.ResolverPlayground import ResolverPlayground
from portage.util import ensure_dirs
from portage._global_updates import _do_global_updates
from portage.output import colorize


class MoveEntTestCase(TestCase):
    def testMoveEnt(self):
        ebuilds = {
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        installed = {
            "dev-libs/A-1::test_repo": {
                "EAPI": "4",
            },
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        binpkgs = {
            "dev-libs/A-1::test_repo": {
                "EAPI": "4",
            },
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        updates = textwrap.dedent(
            """
			move dev-libs/A dev-libs/A-moved
		"""
        )

        for binpkg_format in SUPPORTED_GENTOO_BINPKG_FORMATS:
            with self.subTest(binpkg_format=binpkg_format):
                print(colorize("HILITE", binpkg_format), end=" ... ")
                sys.stdout.flush()
                playground = ResolverPlayground(
                    binpkgs=binpkgs,
                    ebuilds=ebuilds,
                    installed=installed,
                    user_config={
                        "make.conf": (
                            f'BINPKG_FORMAT="{binpkg_format}"',
                            'FEATURES="-binpkg-signing"',
                        ),
                    },
                )

                settings = playground.settings
                trees = playground.trees
                eroot = settings["EROOT"]
                test_repo_location = settings.repositories["test_repo"].location
                portdb = trees[eroot]["porttree"].dbapi
                vardb = trees[eroot]["vartree"].dbapi
                bindb = trees[eroot]["bintree"].dbapi

                updates_dir = os.path.join(test_repo_location, "profiles", "updates")

                try:
                    ensure_dirs(updates_dir)
                    with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
                        f.write(updates)

                    # Create an empty updates directory, so that this
                    # repo doesn't inherit updates from the main repo.
                    ensure_dirs(
                        os.path.join(
                            portdb.getRepositoryPath("dont_apply_updates"),
                            "profiles",
                            "updates",
                        )
                    )

                    global_noiselimit = portage.util.noiselimit
                    portage.util.noiselimit = -2
                    try:
                        _do_global_updates(trees, {})
                    finally:
                        portage.util.noiselimit = global_noiselimit

                    # Workaround for cache validation not working
                    # correctly when filesystem has timestamp precision
                    # of 1 second.
                    vardb._clear_cache()

                    # A -> A-moved
                    self.assertRaises(KeyError, vardb.aux_get, "dev-libs/A-1", ["EAPI"])
                    vardb.aux_get("dev-libs/A-moved-1", ["EAPI"])
                    # The original package should still exist because a binary
                    # package move is a copy on write operation.
                    bindb.aux_get("dev-libs/A-1", ["EAPI"])
                    bindb.aux_get("dev-libs/A-moved-1", ["EAPI"])

                    # dont_apply_updates
                    self.assertRaises(
                        KeyError, vardb.aux_get, "dev-libs/A-moved-2", ["EAPI"]
                    )
                    vardb.aux_get("dev-libs/A-2", ["EAPI"])
                    self.assertRaises(
                        KeyError, bindb.aux_get, "dev-libs/A-moved-2", ["EAPI"]
                    )
                    bindb.aux_get("dev-libs/A-2", ["EAPI"])

                finally:
                    playground.cleanup()

    def testMoveEntWithSignature(self):
        ebuilds = {
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        installed = {
            "dev-libs/A-1::test_repo": {
                "EAPI": "4",
            },
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        binpkgs = {
            "dev-libs/A-1::test_repo": {
                "EAPI": "4",
            },
            "dev-libs/A-2::dont_apply_updates": {
                "EAPI": "4",
                "SLOT": "2",
            },
        }

        updates = textwrap.dedent(
            """
			move dev-libs/A dev-libs/A-moved
		"""
        )

        for binpkg_format in ("gpkg",):
            with self.subTest(binpkg_format=binpkg_format):
                print(colorize("HILITE", binpkg_format), end=" ... ")
                sys.stdout.flush()
                playground = ResolverPlayground(
                    binpkgs=binpkgs,
                    ebuilds=ebuilds,
                    installed=installed,
                    user_config={
                        "make.conf": (f'BINPKG_FORMAT="{binpkg_format}"',),
                    },
                )

                settings = playground.settings
                trees = playground.trees
                eroot = settings["EROOT"]
                test_repo_location = settings.repositories["test_repo"].location
                portdb = trees[eroot]["porttree"].dbapi
                vardb = trees[eroot]["vartree"].dbapi
                bindb = trees[eroot]["bintree"].dbapi

                updates_dir = os.path.join(test_repo_location, "profiles", "updates")

                try:
                    ensure_dirs(updates_dir)
                    with open(os.path.join(updates_dir, "1Q-2010"), "w") as f:
                        f.write(updates)

                    # Create an empty updates directory, so that this
                    # repo doesn't inherit updates from the main repo.
                    ensure_dirs(
                        os.path.join(
                            portdb.getRepositoryPath("dont_apply_updates"),
                            "profiles",
                            "updates",
                        )
                    )

                    global_noiselimit = portage.util.noiselimit
                    portage.util.noiselimit = -2
                    try:
                        _do_global_updates(trees, {})
                    finally:
                        portage.util.noiselimit = global_noiselimit

                    # Workaround for cache validation not working
                    # correctly when filesystem has timestamp precision
                    # of 1 second.
                    vardb._clear_cache()

                    # A -> A-moved
                    self.assertRaises(KeyError, vardb.aux_get, "dev-libs/A-1", ["EAPI"])
                    vardb.aux_get("dev-libs/A-moved-1", ["EAPI"])
                    # The original package should still exist because a binary
                    # package move is a copy on write operation.
                    bindb.aux_get("dev-libs/A-1", ["EAPI"])
                    print(bindb.aux_get("dev-libs/A-1", "PF"))
                    self.assertRaises(
                        KeyError, bindb.aux_get, "dev-libs/A-moved-1", ["EAPI"]
                    )

                    # dont_apply_updates
                    self.assertRaises(
                        KeyError, vardb.aux_get, "dev-libs/A-moved-2", ["EAPI"]
                    )
                    vardb.aux_get("dev-libs/A-2", ["EAPI"])
                    self.assertRaises(
                        KeyError, bindb.aux_get, "dev-libs/A-moved-2", ["EAPI"]
                    )
                    bindb.aux_get("dev-libs/A-2", ["EAPI"])

                finally:
                    playground.cleanup()