Ensure directories are created in /var

According to the ostree documentation "/var" is a state
directory and it should remain empty by default. To ensure
that the directories are created when the image starts we
use systemd-tmpfiles to create the directories.

The directories are symlinked from /usr/rootdirs/var when
the image is created. The list of directories that are suppose
to be symlinked are generated from that directory.

In order to generate the list, the apt package cache is queried
to check which packages write to the "/var" directory. Packages
to check can be excluded by a list as well.

In the future if new packages are added and the package creates
an entry in /var, the directory will be moved to /usr/rootdirs/var
and the list will be generated again during post-configure.

Also update the gate configuration to install python3-apt from
bullseye and use sitepackages since the apt python module is only
available via Debian package not via pypi.

Depends-On: https://review.opendev.org/c/starlingx/apt-ostree/+/890704

Story: 2010867
Task: 48556

Testing:
PASSED Installed apt-ostree from git repo.
PASSED Run "apt-ostree compose create --base config/debian/bookworm \
       --repo=/tmp/test debian/bookworm"
PASSED Checked out debian/bookworm branch
PASSED Checked for usr/lib//tmpfiles.d/ostree-integration-autovar.conf

Change-Id: I2569978fc948e6352edb03acdf1e4766345b02c4
Signed-off-by: Charles Short <charles.short@windriver.com>
This commit is contained in:
Charles Short 2023-08-14 07:40:13 -04:00
parent fd336c49ba
commit 78f2f21084
7 changed files with 64 additions and 1 deletions

View File

@ -20,6 +20,7 @@
nodeset: debian-bullseye
vars:
tox_envlist: py39
tox_extra_args: --sitepackages
- job:
name: apt-ostree-tox-flake8
@ -29,3 +30,4 @@
nodeset: debian-bullseye
vars:
tox_envlist: flake8
tox_extra_args: --sitepackages

View File

@ -11,6 +11,7 @@ import shutil
from apt_ostree.log import complete_step
from apt_ostree.log import log_step
from apt_ostree.platform import create_tmpfile_dir
def create_ostree(rootdir):
@ -20,6 +21,7 @@ def create_ostree(rootdir):
setup_boot(rootdir,
rootdir.joinpath("boot"),
rootdir.joinpath("usr/lib/ostree-boot"))
create_tmpfile_dir(rootdir)
convert_to_ostree(rootdir)

View File

@ -6,3 +6,16 @@ SPDX-License-Identifier: Apache-2.0
"""
VERSION = "0.1"
# packages to exclude from systemd-tmpfiles check.
excluded_packages = [
"ucf",
"dpkg",
"base-files",
"systemd",
"init-system-helpers",
"dbus",
"policykit-1",
"polkitd",
"debconf"
]

43
apt_ostree/platform.py Normal file
View File

@ -0,0 +1,43 @@
"""
Copyright (c) 2023 Wind River Systems, Inc.
SPDX-License-Identifier: Apache-2.0
"""
import os
import apt
from apt_ostree.constants import excluded_packages
from apt_ostree.log import complete_step
def create_tmpfile_dir(rootdir):
"""Ensure directoeies in /var are created."""
with complete_step("Creating systemd-tmpfiles configuration"):
cache = apt.cache.Cache(rootdir=rootdir)
dirs = []
for pkg in cache:
if "/var" in pkg.installed_files and \
pkg.name not in excluded_packages:
dirs += [file for file in pkg.installed_files
if file.startswith("/var")]
if len(dirs) == 0:
return
conf = rootdir.joinpath(
"usr/lib/tmpfiles.d/ostree-integration-autovar.conf")
if conf.exists():
os.unlink(conf)
with open(conf, "w") as f:
f.write("# Auto-genernated by apt-ostree\n")
for d in (dirs):
if d not in [
"/var",
"/var/lock",
"/var/cache",
"/var/spool",
"/var/log",
"/var/lib"]:
f.write(f"L {d} - - - - ../../usr/rootdirs{d}\n")

1
bindep.txt Normal file
View File

@ -0,0 +1 @@
python3-apt [platform:dpkg]

View File

@ -10,6 +10,7 @@ RUN apt-get update && \
debos \
ostree \
python3 \
python3-apt \
python3-click \
python3-pip \
python3-pbr \

View File

@ -7,7 +7,8 @@ ignore_basepython_conflict = true
[testenv]
basepython = python3
usedevelop = True
usedevelop = false
sitepacages = True
setenv =
PYTHONWARNINGS=default::DeprecationWarning
OS_STDOUT_CAPTURE=1