Add "components" to apt-ostree
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>
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -159,6 +159,21 @@ def release_option(f):
|
|||||||
)(f)
|
)(f)
|
||||||
|
|
||||||
|
|
||||||
|
def component_option(f):
|
||||||
|
"""Component option"""
|
||||||
|
def callback(ctxt, param, value):
|
||||||
|
state = ctxt.ensure_object(State)
|
||||||
|
state.component = value
|
||||||
|
return value
|
||||||
|
return click.option(
|
||||||
|
"--component",
|
||||||
|
help="Component release version (e.g. 24.03.1)",
|
||||||
|
nargs=1,
|
||||||
|
required=True,
|
||||||
|
callback=callback
|
||||||
|
)(f)
|
||||||
|
|
||||||
|
|
||||||
def origin_option(f):
|
def origin_option(f):
|
||||||
"""Origin option"""
|
"""Origin option"""
|
||||||
def callback(ctxt, param, value):
|
def callback(ctxt, param, value):
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -9,6 +9,7 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from apt_ostree.cmd.options import component_option
|
||||||
from apt_ostree.cmd.options import feed_option
|
from apt_ostree.cmd.options import feed_option
|
||||||
from apt_ostree.cmd.options import packages_option
|
from apt_ostree.cmd.options import packages_option
|
||||||
from apt_ostree.cmd.options import release_option
|
from apt_ostree.cmd.options import release_option
|
||||||
@@ -20,8 +21,9 @@ from apt_ostree.repo import Repo
|
|||||||
@pass_state_context
|
@pass_state_context
|
||||||
@feed_option
|
@feed_option
|
||||||
@release_option
|
@release_option
|
||||||
|
@component_option
|
||||||
@packages_option
|
@packages_option
|
||||||
def add(state, feed, release, packages):
|
def add(state, feed, release, component, packages):
|
||||||
try:
|
try:
|
||||||
Repo(state).add()
|
Repo(state).add()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ from apt_ostree.cmd import pass_state_context
|
|||||||
from apt_ostree.repo import Repo
|
from apt_ostree.repo import Repo
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="Create a Debian package repsoitory.")
|
@click.command(help="Create a Debian package repository.")
|
||||||
@pass_state_context
|
@pass_state_context
|
||||||
@feed_option
|
@feed_option
|
||||||
@release_option
|
@release_option
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from apt_ostree.cmd.options import component_option
|
||||||
from apt_ostree.cmd.options import feed_option
|
from apt_ostree.cmd.options import feed_option
|
||||||
from apt_ostree.cmd.options import release_option
|
from apt_ostree.cmd.options import release_option
|
||||||
from apt_ostree.cmd import pass_state_context
|
from apt_ostree.cmd import pass_state_context
|
||||||
@@ -20,7 +21,8 @@ from apt_ostree.repo import Repo
|
|||||||
@pass_state_context
|
@pass_state_context
|
||||||
@feed_option
|
@feed_option
|
||||||
@release_option
|
@release_option
|
||||||
def show(state, feed, release):
|
@component_option
|
||||||
|
def show(state, feed, release, component):
|
||||||
try:
|
try:
|
||||||
Repo(state).show()
|
Repo(state).show()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -10,6 +10,7 @@ import sys
|
|||||||
|
|
||||||
import click
|
import click
|
||||||
|
|
||||||
|
from apt_ostree.cmd.options import component_option
|
||||||
from apt_ostree.cmd.options import feed_option
|
from apt_ostree.cmd.options import feed_option
|
||||||
from apt_ostree.cmd.options import packages_option
|
from apt_ostree.cmd.options import packages_option
|
||||||
from apt_ostree.cmd.options import release_option
|
from apt_ostree.cmd.options import release_option
|
||||||
@@ -17,12 +18,13 @@ from apt_ostree.cmd import pass_state_context
|
|||||||
from apt_ostree.repo import Repo
|
from apt_ostree.repo import Repo
|
||||||
|
|
||||||
|
|
||||||
@click.command(help="Remove debian package(s) from reposiotry.")
|
@click.command(help="Remove debian package(s) from repository.")
|
||||||
@pass_state_context
|
@pass_state_context
|
||||||
@feed_option
|
@feed_option
|
||||||
@release_option
|
@release_option
|
||||||
|
@component_option
|
||||||
@packages_option
|
@packages_option
|
||||||
def remove(state, feed, release, packages):
|
def remove(state, feed, release, component, packages):
|
||||||
try:
|
try:
|
||||||
Repo(state).remove()
|
Repo(state).remove()
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -65,21 +65,33 @@ class Repo:
|
|||||||
)
|
)
|
||||||
|
|
||||||
def add(self):
|
def add(self):
|
||||||
"""Add Debian package(s) to repository."""
|
"""Add Debian package(s) to a component."""
|
||||||
|
config = self.repo.joinpath("conf/distributions")
|
||||||
|
component = self.state.component or self.state.origin
|
||||||
|
|
||||||
|
utils.check_and_append_component(config, component)
|
||||||
|
|
||||||
for pkg in self.state.packages:
|
for pkg in self.state.packages:
|
||||||
self.logging.info(f"Adding {pkg}.")
|
self.logging.info(
|
||||||
|
f"Adding {pkg} to component {component}.")
|
||||||
r = utils.run_command(
|
r = utils.run_command(
|
||||||
["reprepro", "-b", str(self.repo), "includedeb",
|
["reprepro", "-b", str(self.repo), "-C", component,
|
||||||
self.state.release, pkg])
|
"includedeb", self.state.release, pkg])
|
||||||
if r.returncode == 0:
|
if r.returncode == 0:
|
||||||
self.logging.info(f"Successfully added {pkg}\n")
|
self.logging.info(
|
||||||
|
f"Successfully added {pkg} to component {component}\n")
|
||||||
else:
|
else:
|
||||||
self.logging.error(f"Failed to add {pkg}\n")
|
self.logging.error(
|
||||||
|
f"Failed to add {pkg} to component {component}\n")
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
"""Display a table of packages in the archive."""
|
"""Display a table of packages in the archive."""
|
||||||
|
component = self.state.component or self.state.origin
|
||||||
|
|
||||||
r = utils.run_command(
|
r = utils.run_command(
|
||||||
["reprepro", "-b", str(self.repo), "list", self.state.release],
|
["reprepro", "-b", str(self.repo),
|
||||||
|
"-C", component,
|
||||||
|
"list", self.state.release],
|
||||||
stdout=subprocess.PIPE,
|
stdout=subprocess.PIPE,
|
||||||
stderr=subprocess.STDOUT,
|
stderr=subprocess.STDOUT,
|
||||||
check=False,
|
check=False,
|
||||||
@@ -107,17 +119,21 @@ class Repo:
|
|||||||
self.console.print(table)
|
self.console.print(table)
|
||||||
|
|
||||||
def remove(self):
|
def remove(self):
|
||||||
"""Remove a Debian package from an archive."""
|
"""Remove a Debian package from a component."""
|
||||||
|
component = self.state.component or self.state.origin
|
||||||
|
|
||||||
for pkg in self.state.packages:
|
for pkg in self.state.packages:
|
||||||
self.logging.info(f"Removing {pkg}.")
|
self.logging.info(f"Removing {pkg}.")
|
||||||
r = utils.run_command(
|
r = utils.run_command(
|
||||||
["reprepro", "-b", str(self.repo), "remove",
|
["reprepro", "-b", str(self.repo), "-C", component,
|
||||||
self.state.release, pkg],
|
"remove", self.state.release, pkg],
|
||||||
check=True)
|
check=True)
|
||||||
if r.returncode == 0:
|
if r.returncode == 0:
|
||||||
self.logging.info(f"Successfully removed {pkg}\n")
|
self.logging.info(
|
||||||
|
f"Successfully removed {pkg} from component {component}\n")
|
||||||
else:
|
else:
|
||||||
self.logging.error(f"Failed to remove {pkg}\n")
|
self.logging.error(
|
||||||
|
f"Failed to remove {pkg} from component {component}\n")
|
||||||
|
|
||||||
def disable_repo(self):
|
def disable_repo(self):
|
||||||
"""Disable Debian feed via apt-add-repository."""
|
"""Disable Debian feed via apt-add-repository."""
|
||||||
|
@@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Copyright (c) 2023 Wind River Systems, Inc.
|
Copyright (c) 2023-2024 Wind River Systems, Inc.
|
||||||
|
|
||||||
SPDX-License-Identifier: Apache-2.0
|
SPDX-License-Identifier: Apache-2.0
|
||||||
|
|
||||||
@@ -85,3 +85,18 @@ def run_sandbox_command(
|
|||||||
check=check,
|
check=check,
|
||||||
env=env,
|
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)
|
||||||
|
@@ -10,7 +10,7 @@ oslotest>=3.8.0 # Apache-2.0
|
|||||||
testresources>=2.0.0 # Apache-2.0/BSD
|
testresources>=2.0.0 # Apache-2.0/BSD
|
||||||
testscenarios>=0.4 # Apache-2.0/BSD
|
testscenarios>=0.4 # Apache-2.0/BSD
|
||||||
testtools>=2.5.0 # MIT
|
testtools>=2.5.0 # MIT
|
||||||
pytest
|
pytest<=8.1.1
|
||||||
pylint
|
pylint
|
||||||
yamllint<1.26.4 # GPLv3
|
yamllint<1.26.4 # GPLv3
|
||||||
doc8
|
doc8
|
||||||
|
2
tox.ini
2
tox.ini
@@ -17,6 +17,8 @@ setenv =
|
|||||||
deps =
|
deps =
|
||||||
-r{toxinidir}/test-requirements.txt
|
-r{toxinidir}/test-requirements.txt
|
||||||
-r{toxinidir}/requirements.txt
|
-r{toxinidir}/requirements.txt
|
||||||
|
allowlist_externals =
|
||||||
|
pytest
|
||||||
commands = pytest -rx -v ./apt_ostree/tests
|
commands = pytest -rx -v ./apt_ostree/tests
|
||||||
|
|
||||||
[testenv:lower-constraints]
|
[testenv:lower-constraints]
|
||||||
|
Reference in New Issue
Block a user