
Adds support to apt-ostree to manage the Debian packages in logically separated components. With that, the apt-ostree can manage packages from different release versions without mixing them. Changed "add", "list" and "remove" repo commands to have an optional argument "--component". If passed, the package will be added, list or removed from the specified component, if not the package will be added, listed or removed from the default component, created on the apt-ostree setup with the "--origin" argument (e.g. updates). Pinned pytest to a specific version to fix py3 job. Test plan: PASS Installed apt-ostree from git repo PASS Run to initialize the repo "apt-ostree repo init \ --feed <feed_dir> --release bookworm --origin updates" Test plan add: PASS Download the desired Debian package PASS Run "apt-ostree repo add --feed <feed_dir> \ --release bookworm --component 24.03.01 <package.deb>" Test plan list PASS Run "apt-ostree repo list --feed <feed_dir> \ --release bookworm --component 24.03.01" Test plan remove: PASS Run "sudo apt-ostree repo remove --feed <feed_dir> \ --release bookworm --component 24.03.01 <package>" PASS Run list command to check if the package was removed Story: 2010867 Task: 50118 Change-Id: I4c6e0df5fccd29e2b3b9a7932932c008f2fe0386 Signed-off-by: Lindley Werner <Lindley.Vieira@windriver.com>
103 lines
2.4 KiB
Python
103 lines
2.4 KiB
Python
"""
|
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
|
|
|
SPDX-License-Identifier: Apache-2.0
|
|
|
|
"""
|
|
|
|
import logging
|
|
import os
|
|
import subprocess
|
|
|
|
from apt_ostree import exceptions
|
|
|
|
LOG = logging.getLogger(__name__)
|
|
|
|
|
|
def run_command(cmd,
|
|
debug=False,
|
|
stdin=None,
|
|
stdout=None,
|
|
stderr=None,
|
|
check=True,
|
|
env=None,
|
|
cwd=None):
|
|
"""Run a command in a shell."""
|
|
_env = os.environ.copy()
|
|
if env:
|
|
_env.update(env)
|
|
try:
|
|
return subprocess.run(
|
|
cmd,
|
|
stdin=stdin,
|
|
stdout=stdout,
|
|
stderr=stderr,
|
|
env=_env,
|
|
cwd=cwd,
|
|
check=check,
|
|
)
|
|
except FileNotFoundError:
|
|
msg = "%s is not found in $PATH" % cmd[0]
|
|
LOG.error(msg)
|
|
raise exceptions.CommandError(msg)
|
|
except subprocess.CalledProcessError as e:
|
|
msg = "Shell execution error: %s, Output: %s" \
|
|
% (e.returncode, e.stderr.decode("utf-8"))
|
|
LOG.error(msg)
|
|
raise exceptions.CommandError(msg)
|
|
|
|
|
|
def run_sandbox_command(
|
|
args,
|
|
rootfs,
|
|
stdin=None,
|
|
stdout=None,
|
|
stderr=None,
|
|
check=True,
|
|
env=None
|
|
):
|
|
"""Run a shell wrapped with bwrap."""
|
|
cmd = [
|
|
"bwrap",
|
|
"--proc", "/proc",
|
|
"--dev", "/dev",
|
|
"--dir", "/run",
|
|
"--bind", "/tmp", "/tmp",
|
|
"--bind", f"{rootfs}/boot", "/boot",
|
|
"--bind", f"{rootfs}/usr", "/usr",
|
|
"--bind", f"{rootfs}/etc", "/etc",
|
|
"--bind", f"{rootfs}/var", "/var",
|
|
"--symlink", "/usr/lib", "/lib",
|
|
"--symlink", "/usr/lib64", "/lib64",
|
|
"--symlink", "/usr/bin", "/bin",
|
|
"--symlink", "/usr/sbin", "/sbin",
|
|
"--share-net",
|
|
"--die-with-parent",
|
|
"--chdir", "/",
|
|
]
|
|
cmd += args
|
|
|
|
return run_command(
|
|
cmd,
|
|
stdin=stdin,
|
|
stdout=stdout,
|
|
stderr=stderr,
|
|
check=check,
|
|
env=env,
|
|
)
|
|
|
|
|
|
def check_and_append_component(config_path, component):
|
|
with open(config_path, 'r') as file:
|
|
lines = file.readlines()
|
|
|
|
for i, line in enumerate(lines):
|
|
if line.startswith("Components:"):
|
|
components = line.split()[1:]
|
|
if component not in components:
|
|
lines[i] = line.strip() + f" {component}\n"
|
|
break
|
|
|
|
with open(config_path, 'w') as file:
|
|
file.writelines(lines)
|