dnfjson: use repo config hash as repo ID

Defined a Hash() method on rpmmd.RepoConfig that calculates a SHA-256 ID
for a repository based on its configuration.  Identical configurations
should produce the same ID.  The Name and ImageTypeTags of a repository
aren't taken into account.  These attributes affect a repository's
functional configuration.

This ID lets us change the way we handle repository configurations in a
few places:
- Preparing the depsolve job arguments is simpler since we have
  predictable IDs for the repository configurations.  We don't need to
  rely on the index of a RepoConfig in a list to identify or access it,
  which prevented us from building a list of all repository
  configurations, since we needed them to be placed in the list in a
  certain order.
- Associating packages from the depsolve result with the repository
  configuration (in depsToRPMMD) no longer relies on an ID string
  converted from and back to an integer index.  Repositories define
  their own IDs.
- Tests are a bit messier now but the changes simplify the main code, so
  it's an acceptable trade-off.
    - Fixtures need to change based on the repository configuration for
      the test.
    - We need to calculate the ID for the repository configuration for
      the temporary file server URL.
This commit is contained in:
Achilleas Koutsou 2022-05-04 20:13:34 +02:00 committed by Tom Gundersen
parent 46e4f0cf5e
commit 1c4d8f9988
6 changed files with 139 additions and 247 deletions

View file

@ -54,7 +54,7 @@ func createBaseDepsolveFixture() []dnfjson.PackageSpec {
Version: "3.0.3",
Release: "1.fc30",
Arch: "x86_64",
RepoID: "0",
RepoID: "REPOID", // added by mock-dnf-json
},
{
Name: "dep-package1",
@ -62,7 +62,7 @@ func createBaseDepsolveFixture() []dnfjson.PackageSpec {
Version: "1.33",
Release: "2.fc30",
Arch: "x86_64",
RepoID: "0",
RepoID: "REPOID", // added by mock-dnf-json
},
{
Name: "dep-package2",
@ -70,7 +70,7 @@ func createBaseDepsolveFixture() []dnfjson.PackageSpec {
Version: "2.9",
Release: "1.fc30",
Arch: "x86_64",
RepoID: "0",
RepoID: "REPOID", // added by mock-dnf-json
},
}
}
@ -111,14 +111,14 @@ type ResponseGenerator func(string) string
func Base(tmpdir string) string {
deps := map[string]interface{}{
"checksums": map[string]string{
"0": "test:responsechecksum",
"REPOID": "test:responsechecksum",
},
"dependencies": createBaseDepsolveFixture(),
}
pkgs := map[string]interface{}{
"checksums": map[string]string{
"0": "test:responsechecksum",
"REPOID": "test:responsechecksum",
},
"packages": generatePackageList(),
}
@ -152,7 +152,7 @@ func BadDepsolve(tmpdir string) string {
}
pkgs := map[string]interface{}{
"checksums": map[string]string{
"0": "test:responsechecksum",
"REPOID": "test:responsechecksum",
},
"packages": generatePackageList(),
}