forked from Mirror/pmbootstrap
* The APKINDEX parser used to return a dictionary with one package for a given package name. This works for the installed packages database, because there can only be one provider for a package. But when parsing packages from binary repositories, we need to support multiple providers for one package. It is now possible to get a dictionary with either multiple providers, or just a single provider for each package. * Dependency parsing logic has been adjusted, to support multiple providers. For multiple providers, the one with the same package name as the package we are looking up is prefered. If there is none (eg. "so:libEGL.so.1" is provided by "mesa-egl"), it prefers packages that will be installed anyway, and after that packages that are already installed. When all else fails, it just picks the first one and prints a note in the "pmbootstrap log". * Added testcases for all functions in pmb.parse.apkindex and pmb.parse.depends * pmbootstrap chroot has a new "--add" parameter to specify packages that pmbootstrap should build if neccessary, and install in the chroot. This can be used to quickly test the depencency resolution of pmbootstrap without doing a full "pmbootstrap install". Fixes #1122.
84 lines
2.9 KiB
Python
84 lines
2.9 KiB
Python
"""
|
|
Copyright 2018 Oliver Smith
|
|
|
|
This file is part of pmbootstrap.
|
|
|
|
pmbootstrap is free software: you can redistribute it and/or modify
|
|
it under the terms of the GNU General Public License as published by
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
(at your option) any later version.
|
|
|
|
pmbootstrap is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
|
|
"""
|
|
import os
|
|
import sys
|
|
import pytest
|
|
import glob
|
|
import filecmp
|
|
|
|
# Import from parent directory
|
|
sys.path.append(os.path.realpath(
|
|
os.path.join(os.path.dirname(__file__) + "/..")))
|
|
import pmb.parse.apkindex
|
|
import pmb.helpers.logging
|
|
|
|
|
|
@pytest.fixture
|
|
def args(request):
|
|
import pmb.parse
|
|
sys.argv = ["pmbootstrap.py", "chroot"]
|
|
args = pmb.parse.arguments()
|
|
args.log = args.work + "/log_testsuite.txt"
|
|
pmb.helpers.logging.init(args)
|
|
request.addfinalizer(args.logfd.close)
|
|
return args
|
|
|
|
|
|
def test_keys(args):
|
|
# Get the alpine-keys apk filename
|
|
pmb.chroot.init(args)
|
|
version = pmb.parse.apkindex.package(args, "alpine-keys")["version"]
|
|
pattern = (args.work + "/cache_apk_" + args.arch_native + "/alpine-keys-" +
|
|
version + ".*.apk")
|
|
filename = os.path.basename(glob.glob(pattern)[0])
|
|
|
|
# Extract it to a temporary folder
|
|
temp = "/tmp/test_keys_extract"
|
|
temp_outside = args.work + "/chroot_native" + temp
|
|
if os.path.exists(temp_outside):
|
|
pmb.chroot.root(args, ["rm", "-r", temp])
|
|
pmb.chroot.user(args, ["mkdir", "-p", temp])
|
|
pmb.chroot.user(args, ["tar", "xvf", "/var/cache/apk/" + filename],
|
|
working_dir=temp)
|
|
|
|
# Get all relevant key file names as {"filename": "full_outside_path"}
|
|
keys_upstream = {}
|
|
for arch in pmb.config.build_device_architectures + ["x86_64"]:
|
|
pattern = temp_outside + "/usr/share/apk/keys/" + arch + "/*.pub"
|
|
for path in glob.glob(pattern):
|
|
keys_upstream[os.path.basename(path)] = path
|
|
assert len(keys_upstream)
|
|
|
|
# Check if the keys are mirrored correctly
|
|
mirror_path_keys = os.path.dirname(__file__) + "/../keys"
|
|
for key, original_path in keys_upstream.items():
|
|
mirror_path = mirror_path_keys + "/" + key
|
|
assert filecmp.cmp(mirror_path, original_path, False)
|
|
|
|
# Find postmarketOS keys
|
|
keys_pmos = ["pmos-5a03a13a.rsa.pub"]
|
|
for key in keys_pmos:
|
|
assert os.path.exists(mirror_path_keys + "/" + key)
|
|
|
|
# Find outdated keys, which need to be removed
|
|
glob_result = glob.glob(mirror_path_keys + "/*.pub")
|
|
assert len(glob_result)
|
|
for path in glob_result:
|
|
key = os.path.basename(key)
|
|
assert key in keys_pmos or key in keys_upstream
|