From 609bb9e96078962b4b025ccb171e33c71b789755 Mon Sep 17 00:00:00 2001 From: Niels Thykier Date: Sun, 22 Jul 2018 15:12:36 +0000 Subject: [PATCH] Make migration and undo code suite agnotisc Signed-off-by: Niels Thykier --- britney.py | 65 +++++++++++++++++++++++++---------------------- britney2/utils.py | 33 ++++++++++++------------ 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/britney.py b/britney.py index 4d59223..399a086 100755 --- a/britney.py +++ b/britney.py @@ -1270,7 +1270,7 @@ class Britney(object): if not (ssrc and source_suite is not primary_source_suite): # for every binary package produced by this source in testing for this architecture _, _, smoothbins = self._compute_groups(src, - primary_source_suite.name, + primary_source_suite, arch, False) @@ -1777,21 +1777,21 @@ class Britney(object): res.append("%s-%d" % (arch[0], n)) return "%d+%d: %s" % (total, totalbreak, ":".join(res)) - - def _compute_groups(self, source_name, suite, migration_architecture, + def _compute_groups(self, source_name, source_suite, migration_architecture, is_removal, allow_smooth_updates=True, removals=frozenset()): """Compute the groups of binaries being migrated by item - This method will compute the binaries that will be added, - replaced in testing and which of them are smooth updatable. + This method will compute the binaries that will be added to, + replaced in or removed from the target suite and which of + the removals are smooth updatable. Parameters: * "source_name" is the name of the source package, whose binaries are migrating. - * "suite" is the suite from which the binaries are migrating. - [Same as item.suite.name, where available] + * "suite" is the source suite from which the binaries are migrating. + [Same as item.suite, where available] * "migration_architecture" is the architecture determines architecture of the migrating binaries (can be "source" for a "source"-migration, meaning all binaries regardless of @@ -1826,9 +1826,9 @@ class Britney(object): Unlike doop_source, this will not modify any data structure. """ # local copies for better performances - sources = self.sources - binaries_s = self.binaries[suite] - binaries_t = self.binaries['testing'] + target_suite = self.suite_info.target_suite + binaries_s = source_suite.binaries + binaries_t = target_suite.binaries inst_tester = self._inst_tester adds = set() @@ -1837,8 +1837,9 @@ class Britney(object): # remove all binary packages (if the source already exists) if migration_architecture == 'source' or not is_removal: - if source_name in sources['testing']: - source_data = sources['testing'][source_name] + sources_t = target_suite.sources + if source_name in sources_t: + source_data = sources_t[source_name] bins = [] check = set() @@ -1863,7 +1864,7 @@ class Britney(object): for pkg_id in bins: binary, _, parch = pkg_id # if a smooth update is possible for the package, skip it - if allow_smooth_updates and suite == 'unstable' and \ + if allow_smooth_updates and source_suite.suite_class.is_primary_source and \ binary not in binaries_s[parch][0] and \ ('ALL' in self.options.smooth_updates or \ binaries_t[parch][0][binary].section in self.options.smooth_updates): @@ -1917,7 +1918,7 @@ class Britney(object): # must keep them around; they will not be re-added by the # migration so will end up missing from testing if migration_architecture != 'source' and \ - suite != 'unstable' and \ + source_suite.suite_class.is_additional_source and \ binaries_t[parch][0][binary].architecture == 'all': continue else: @@ -1932,7 +1933,7 @@ class Britney(object): # add the new binary packages (if we are not removing) if not is_removal: - source_data = sources[suite][source_name] + source_data = source_suite.sources[source_name] for pkg_id in source_data.binaries: binary, _, parch = pkg_id if migration_architecture not in ['source', parch]: @@ -1961,7 +1962,7 @@ class Britney(object): return (adds, rms, smoothbins) def doop_source(self, item, hint_undo=None, removals=frozenset()): - """Apply a change to the testing distribution as requested by `pkg` + """Apply a change to the target suite as requested by `item` An optional list of undo actions related to packages processed earlier in a hint may be passed in `hint_undo`. @@ -1969,8 +1970,7 @@ class Britney(object): An optional set of binaries may be passed in "removals". Binaries listed in this set will be assumed to be removed at the same time as the "item" will migrate. This may change what binaries will be smooth-updated. - - Binaries in this set must be ("package-name", "version", "architecture") - tuples. + - Binaries in this set must be instances of BinaryPackageId. This method applies the changes required by the action `item` tracking them so it will be possible to revert them. @@ -1985,30 +1985,32 @@ class Britney(object): affected_remain = set() # local copies for better performance - sources = self.sources - packages_t = self.binaries['testing'] + source_suite = item.suite + target_suite = self.suite_info.target_suite + packages_t = target_suite.binaries inst_tester = self._inst_tester eqv_set = set() updates, rms, _ = self._compute_groups(item.package, - item.suite.name, + source_suite, item.architecture, item.is_removal, removals=removals) # Handle the source package if item.architecture == 'source': - if item.package in sources['testing']: - source = sources['testing'][item.package] + sources_t = target_suite.sources + if item.package in sources_t: + source = sources_t[item.package] undo['sources'][item.package] = source - del sources['testing'][item.package] + del sources_t[item.package] else: # the package didn't exist, so we mark it as to-be-removed in case of undo undo['sources']['-' + item.package] = True # add/update the source package if not item.is_removal: - sources['testing'][item.package] = sources[item.suite.name][item.package] + sources_t[item.package] = source_suite.sources[item.package] # If we are removing *and* updating packages, then check for eqv. packages if rms and updates: @@ -2056,7 +2058,7 @@ class Britney(object): # Add/Update binary packages in testing if updates: - packages_s = self.binaries[item.suite.name] + packages_s = source_suite.binaries for updated_pkg_id in updates: binary, new_version, parch = updated_pkg_id @@ -2125,7 +2127,8 @@ class Britney(object): is_accepted = True affected_architectures = set() item = actions - packages_t = self.binaries['testing'] + target_suite = self.suite_info.target_suite + packages_t = target_suite.binaries nobreakall_arches = self.options.nobreakall_arches new_arches = self.options.new_arches @@ -2147,7 +2150,7 @@ class Britney(object): affected_pos = set() affected_remain = set() for item in actions: - _, rms, _ = self._compute_groups(item.package, item.suite.name, + _, rms, _ = self._compute_groups(item.package, item.suite, item.architecture, item.is_removal, allow_smooth_updates=False) @@ -2210,7 +2213,7 @@ class Britney(object): # check if the action improved the uninstallability counters if not is_accepted and automatic_revert: undo_copy = list(reversed(undo_list)) - undo_changes(undo_copy, self._inst_tester, self.sources, self.binaries, self.all_binaries) + undo_changes(undo_copy, self._inst_tester, self.suite_info, self.all_binaries) return (is_accepted, nuninst_after, undo_list, arch) @@ -2228,7 +2231,7 @@ class Britney(object): output_logger = self.output_logger for y in sorted((y for y in packages), key=attrgetter('uvname')): - updates, rms, _ = self._compute_groups(y.package, y.suite.name, y.architecture, y.is_removal) + updates, rms, _ = self._compute_groups(y.package, y.suite, y.architecture, y.is_removal) result = (y, frozenset(updates), frozenset(rms)) group_info[y] = result @@ -2421,7 +2424,7 @@ class Britney(object): return lundo.reverse() - undo_changes(lundo, self._inst_tester, self.sources, self.binaries, self.all_binaries) + undo_changes(lundo, self._inst_tester, self.suite_info, self.all_binaries) output_logger.info("") diff --git a/britney2/utils.py b/britney2/utils.py index b2a1d98..114ad7f 100644 --- a/britney2/utils.py +++ b/britney2/utils.py @@ -95,17 +95,14 @@ def iter_except(func, exception, first=None): pass -def undo_changes(lundo, inst_tester, sources, binaries, all_binary_packages): - """Undoes one or more changes to testing +def undo_changes(lundo, inst_tester, suite_info, all_binary_packages): + """Undoes one or more changes to the target suite * lundo is a list of (undo, item)-tuples * inst_tester is an InstallabilityTester - * sources is the table of all source packages for all suites - * binaries is the table of all binary packages for all suites - and architectures - - The "X=X" parameters are optimizations to avoid "load global" - in loops. + * suite_info is the Suites object + * all_binary_packages is the table of all binary packages for + all suites and architectures """ # We do the undo process in "4 steps" and each step must be @@ -115,26 +112,29 @@ def undo_changes(lundo, inst_tester, sources, binaries, all_binary_packages): # see commit:ef71f0e33a7c3d8ef223ec9ad5e9843777e68133 and # #624716 for the issues we had when we did not do this. + target_suite = suite_info.target_suite + sources_t = target_suite.sources + binaries_t = target_suite.binaries # STEP 1 # undo all the changes for sources for (undo, item) in lundo: for k in undo['sources']: if k[0] == '-': - del sources["testing"][k[1:]] + del sources_t[k[1:]] else: - sources["testing"][k] = undo['sources'][k] + sources_t[k] = undo['sources'][k] # STEP 2 # undo all new binaries (consequence of the above) for (undo, item) in lundo: - if not item.is_removal and item.package in sources[item.suite.name]: - source_data = sources[item.suite.name][item.package] + if not item.is_removal and item.package in item.suite.sources: + source_data = item.suite.sources[item.package] for pkg_id in source_data.binaries: binary, _, arch = pkg_id if item.architecture in ['source', arch]: try: - del binaries["testing"][arch][0][binary] + del binaries_t[arch][0][binary] except KeyError: # If this happens, pkg_id must be a cruft item that # was *not* migrated. @@ -142,13 +142,12 @@ def undo_changes(lundo, inst_tester, sources, binaries, all_binary_packages): assert not inst_tester.any_of_these_are_in_testing((pkg_id,)) inst_tester.remove_testing_binary(pkg_id) - # STEP 3 # undo all other binary package changes (except virtual packages) for (undo, item) in lundo: for p in undo['binaries']: binary, arch = p - binaries_t_a = binaries['testing'][arch][0] + binaries_t_a = binaries_t[arch][0] assert binary not in binaries_t_a pkgdata = all_binary_packages[undo['binaries'][p]] binaries_t_a[binary] = pkgdata @@ -158,10 +157,10 @@ def undo_changes(lundo, inst_tester, sources, binaries, all_binary_packages): # undo all changes to virtual packages for (undo, item) in lundo: for provided_pkg, arch in undo['nvirtual']: - del binaries['testing'][arch][1][provided_pkg] + del binaries_t[arch][1][provided_pkg] for p in undo['virtual']: provided_pkg, arch = p - binaries['testing'][arch][1][provided_pkg] = undo['virtual'][p] + binaries_t[arch][1][provided_pkg] = undo['virtual'][p] def log_and_format_old_libraries(logger, libs):