Commit Graph

58 Commits

Author SHA1 Message Date
Marcus Schäfer
583f3385df
Add support for BLS zipl
Add support for <bootloader name="zipl" .../> to support BLS
based zipl configuration. This Fixes #2481
2024-03-10 11:28:21 +01:00
Marcus Schäfer
4fc0d2147d
Move DiskFormat to context manager
Change the DiskFormat Factory to be a context manager.
All code using DiskFormat was updated to the following
with statement:

    with DiskFormat(...).new as disk_format:
        disk_format.some_member()

This is related to Issue #2412
2024-02-29 16:42:49 +01:00
Marcus Schäfer
7981095304
Fallback to built-in partition UUID table
If systemd-id128 is not found or failed use the kiwi built-in
table as defined by the UAPI group to assign the partition UUID
2024-02-26 14:59:56 +01:00
Marcus Schäfer
2540d56602
Add support for discoverable partitions
Set PARTUUID according to systemd-id128 if applicable
This Fixes #1385
2024-02-26 09:42:01 +01:00
Dan Čermák
48817a6441
Refactor Command class
Command.run() currently has a bit of a confusing behavior: if raise_on_error is
False and the executable is not found, then a weird CommandT is returned (return
code is -1 and stdout+stderr is None). This makes it possible to hanlde command
not found errors separately, but it makes that needlessly verbose. So instead,
let's just return None in *this* special case.

That in turn uncovered, that in most cases when we set `raise_on_error=True`, we
actually want an error if the command is not present but no error if the command
fails to execute (e.g. because it returns -1 if you run `$cmd --version`). Hence we
introduce the flag `raise_on_command_not_found`, which causes an exception to
be raised if the command is not found. This makes it independent of the
`raise_on_error` flag.

Additionally, we add a small optimization: if command starts with /, then we
assume it's a full path and we omit the call to which (and just check whether it
exists).

Co-authored-by: Marcus Schäfer <marcus.schaefer@gmail.com>
2024-02-19 16:33:24 +01:00
Alexandre Detiste
fb69627ad3
Use unittest.mock from core python everywhere
mock was an independent module that has been merged into the Python standard library.
2024-02-18 22:15:30 +01:00
Marcus Schäfer
9addfcd666
Move Raid Luks and Integrity to context manager
Change the RaidDevice, LuksDevice and IntegrityDevice classes
to context manager:

with RaidDevice(...) as raid:
    raid.some_member()

with LuksDevice(...) as luks:
    luks.some_member()

with IntegrityDevice(...) as integrity:
    integrity.some_member()

In the context of the disk builder an ExitStack is used to
handle the new context manager based classes

This is related to Issue #2412
2024-02-05 09:35:05 +01:00
Marcus Schäfer
09e4758609
Move Disk to context manager
Change the Disk class to be a context manager.
All code using Disk was updated to the following
with statement:

    with Disk(...) as disk:
        disk.some_member()

This is related to Issue #2412
2024-01-31 15:04:10 +01:00
Marcus Schäfer
ee40b83d86
Move FileSystem to context manager
Change the FileSystem class to be a context manager. All code using
FileSystem was updated to the following with statement:

with FileSystem.new(...) as filesystem:
    filesystem.some_member()

This is related to Issue #2412
2024-01-12 20:03:51 +01:00
Marcus Schäfer
cdbe5060ca
Move LoopDevice class to context manager
Change the LoopDevice class to be a context manager.
All code using LoopDevice was updated to the following
with statement:

with LoopDevice(...) as loop_provider:
    loop_provider.some_member()

This is related to Issue #2412
2024-01-11 19:18:01 +01:00
Marcus Schäfer
b3047fb947
Fixed writing correct keyfile path to etc/crypttab
The keyfile path was not correctly set in etc/crypttab which
caused systemd not being able to read the keyfile, consequently
asking for a passphrase. This commit fixes the writing of the
crypttab and also fixes a python name clash with the "os"
namespace.
2023-07-25 17:06:02 +02:00
Marcus Schäfer
8549db8699
Fixed wrong test assertions
Former versions of pytest did ignore invalid assertions.
Now they are reported as an error and show the mistakes
of the past
2023-01-17 16:30:09 +01:00
Marcus Schäfer
8f18b7cdc3
Allow to select partition mapper tool
The recent change from kpartx to partx caused some appliance
builds to break depending on their configuration. I spotted
issues when building disks with veritysetup or integritysetup
root devices. There are also issues with grub-install on other
architectures e.g s390. It seems partx cannot be used as a drop
in replacement and so I suggest to make this a runtime
configuration option with partx as the new default but also
allow for the old method
2022-12-01 16:17:16 +01:00
Neal Gompa
e0212c6006 Eliminate redundant partx calls for cleaning up loop devices
partx can clean up all partition loops associated with a loop device
when deleting the main loop device. Apparently, sometimes it goes and
does this even when only deleting the partition loop, so to avoid
this problem, we will just eliminate the redundant call.

Fixes: 8f2b8fda82
2022-11-30 09:53:29 -05:00
Neal Gompa
8f2b8fda82 Swap from DM kpartx to util-linux partx for creating loop devices
The device-mapper (DM) based loop devices that kiwi has historically
generated creates issues when trying to run kiwi in confined build
environments. The DM tools prefer to have a tighter coupling between
userspace and kernel interfaces, and we cannot necessarily guarantee
that in the variety of build environments that kiwi can be run in.
In particular, Koji uses either nspawn containers or chroots through
Mock to run kiwi and that is where this fails.

However, we do not need to use DM for this purpose when util-linux
provides a perfectly serviceable alternative. This commit changes
kiwi's loop device setup to use partx(8) from util-linux instead.

As long as the appliance image being created doesn't use a disk
scheme that requires DM, it becomes entirely possible to produce
an image without needing DM at runtime at all.
2022-11-29 10:30:01 -05:00
Marcus Schäfer
6d5b0f95d1
Support DM integrity legacy options
Add a new attribute integrity_legacy_hmac="true|false" which
allows to use old flawed HMAC calculation (does not protect superblock).
Add a new attribute integrity_legacy_padding="true|false" which
allows to use inefficient legacy padding. Do not use these attributes
until compatibility with a specific old kernel is required!
2022-09-14 09:59:26 -04:00
Marcus Schäfer
0540d6ddb9
Fixed custom disk start sector setup
The attribute disk_start_sector allows to specify a custom
start sector for the first partition of the disk. On GPT
tables everything works nicely, on DOS tables the used tools
fdisk/sfdisk are not able to manage the start/end values of
subsequent partitions if the first partition doesn't start
with the tooling default. This patch allows to set the
start sector after the partition table has been created
2022-07-07 12:21:08 +02:00
Marcus Schäfer
747f878911
Support squashfs in custom partitions
When using squashfs in a custom partitions setup like the following:

<partitions>
    <partition ... filesystem="squashfs"/>
</partitions>

The build fails because the filesystem needs to be created
using the create_on_file() API and not the create_on_device()
API. In addition the size estimation is bogus when using
squashfs and cannot be pre-calculated because we only know
how much space the filesystem really needs after mksquashfs
as worked on the data and the compression. Thus this commit
also relaxes the required size check in case of squashfs.
Last but not least a squashfs filesystem does not provide
label or UUID and can only be referenced by the PARTUUID
it gets dumped on or by the native unix device node. As
the unix node is a loop during build time of the image and
meaningless this commit also forces by-partuuid mapping in
fstab when mounting the squashfs based device.
2022-06-21 22:19:56 +02:00
Robert Schweikert
4427812ae2
Subformats should also not be compressed when encryption is enabled (#2138)
Subformats should also not be compressed when encryption is enabled
This is a follow on change to bdba953. When the filesystem is encrypted the
resulting image should not be compressed. Also explain why we ignore the
compression seeting in the user configuration for encrypted images.
2022-05-17 08:54:46 +02:00
Marcus Schäfer
e7e8c3bf42
Add support for dm integrity with secret key
Allow to protect the opening of the integrity data map and
journal through a keyfile. For setting the key file two new
optional type attributes were added:

* integrity_keyfile
* integrity_metadata_key_description

The key file format must be correct according to the selected
integrity algorithm. As of now the kiwi default hmac-sha256
algorithm is used with the selected keyfile

The optional integrity_metadata_key_description attribute
allows to specify a custom description of an integrity key
as it is expected to be present in the kernel keyring. The
information is placed in the integrity metadata block. If
not specified kiwi creates a key argument string instead
which is based on the given integrity_keyfile filename.
The format of this key argument is:

:BASENAME_OF_integrity_keyfile_WITHOUT_FILE_EXTENSION
2022-05-04 16:04:37 +02:00
Marcus Schäfer
6b79d15f77
Update get_disksize_mbytes to support clones
When using partition clones the pre-calculation of the
disk size needs to take this into account.
2022-04-28 15:40:31 +02:00
Marcus Schäfer
0fdcff9f97
Merge pull request #2114 from OSInside/add_clone_argument_to_disk_interface
Add support for part clones to the Disk interface
2022-04-27 18:37:52 +02:00
Marcus Schäfer
d5e7e546ca
Add support for standalone dm integrity
There is support in kiwi to use dm_integrity in combination
with the LUKS header and dm_crypt. However there is also the
use case to setup dm_integrity in standalone mode. This commit
allows to create the dm_integrity layer outside of LUKS using
/etc/integritytab to activate the map through a systemd
generator if systemd is used.

Regarding systemd it's required to use a version of system which
provides: system-generators/systemd-integritysetup-generator.
If this generator does not exist in the distribution it will
also be missing in the dracut generated initrd and the boot
will not be able to succeed. It's mentioned here because even
newer distributions might be missing the generator

Along with the implementation there are two new optional
attributes in the <type> section:

    standalone_integrity="true|false"
    embed_integrity_metadata="true|false"

standalone_integrity activates/deactivates the dm_integrity map
on top of the root filesystem. Similar to the veritysetup support
there is the opportunity to create an embedded magic metadata
block at the end of the device containing the root
filesystem via embed_integrity_metadata
2022-04-25 15:40:32 +02:00
Marcus Schäfer
69c5495b79
Add support for part clones to the Disk interface
The Disk class provides methods to create partition(s)
and map names according to its scope and independent of
the actual partition tools. For example: create_root_partition().
This commit adds an additional optional clone parameter to
all methods for which we want to allow partition clones
2022-04-10 16:52:05 +02:00
Marcus Schäfer
009c88a48b
Added new CloneDevice class
Added CloneDevice class to the storage interface.
The class allows to create clone(s) from a given source
block device into a list of target block devices.
The target block devices are clones of the source but
prevents device naming conflicts for unique identifiers
like the UUID. This is requires to still allow to boot
from images containing device clones and needs to be
handled by tools that might work on top of the cloned
devices.
2022-04-05 17:43:41 +02:00
Marcus Schäfer
2da706f5ed
Add support for extended layout to msdos table
This commit adds the following new type attribute

    <type ... dosparttable_extended_layout="true|false"/>

If set it specifies to make use of logical partitions inside
of an extended one. Effective only on type configurations which
uses the msdos table type, it will cause the fourth partition
to be an extended partition and all following partitions will be
placed as logical partitions inside of that extended partition.
This setting is useful if more than 4 partitions needs to be
created in an msdos table.

In addition to the support for extended/logical partitions the
the attributes 'mountpoint' and 'filesystem' in the <partitions>
section becomes optional. This also allows to place partitions
as placeholders not mounted into the system
2022-03-05 21:25:56 +01:00
Marcus Schäfer
9c9250ebc4
Support nose and xunit style tests
The modifications in this commit allows the unit tests
to run on both, pytest 6.x (nose test layout) and the new
pytest 7.x (xunit test layout). This Fixes #2072 in a
much nicer way. Thanks much to @smarlowucf
2022-02-26 20:26:18 +01:00
Marcus Schäfer
1f869e7ca8
Revert "Unit test adaptions to pytest v7"
This reverts commit 0dc2e803e0.
The pytest interface from version v6 to v7 has received
changes which requires the tests to be adapted to work for
either the old or the new interface. As there are still many
distributions which uses v6 as the standard we decided to
revert back the adaptions done to support v7 and create
a version requirement to v6 in .virtualenv.dev-requirements.txt
This Fixes #2072
2022-02-26 20:19:42 +01:00
Marcus Schäfer
0dc2e803e0
Fixed unit tests
The pytest interface setup() method call has changed
in a way that an additional parameter is passed to
the method which leads to a python error at invocation
time if the setup method does not define it.
2022-02-07 21:27:39 +01:00
Marcus Schäfer
cabeec54c3
Fixed unit test race condition 2022-01-24 15:57:36 +01:00
Marcus Schäfer
4a4a4033d1
Added partition sizes to disk size math
Make sure partition sizes are used for the calculation
of the entire disk size to fit the size constraints of
the image disk
2021-11-03 13:31:17 +01:00
Marcus Schäfer
94de1336d8
Support custom partitions
In addition to the volume volume management settings also
allow to setup low level table entries like in the following
example:

<partitions>
    <partition name="var" size="100" mountpoint="/var" filesystem="ext3"/>
</partitions>
2021-11-03 13:31:17 +01:00
Marcus Schäfer
21d757dafe
Merge pull request #1848 from OSInside/delete_obsolete_ddb_adapter_hack
Delete obsolete ddb.adapterType patching
2021-09-07 18:01:57 +02:00
Marcus Schäfer
fc2446dfea
Moving temp data handling to its own namespace
Moving use of mkdtemp, NamedTemporaryFile and TemporaryDirectory
into its own class called Temporary: By default all temporary
data is created below /var/tmp but can be changed via the
global commandline option --temp-dir. This Fixes #1870
2021-07-22 13:31:44 +02:00
Marcus Schäfer
b65bcd8274
Fixed LUKS keyfile permission bits
LUKS keyfile should use 0600 file permission flags
2021-07-06 14:42:19 +02:00
Marcus Schäfer
fb3dc5744d
Allow creation of LUKS system with empty key
To support cloud platforms better we should allow the
creation of an initial(insecure) LUKS encrypted image
with an empty passphrase/keyfile. This Fixes
bsc#1187461 and bsc#1187460
2021-06-17 16:57:40 +02:00
Marcus Schäfer
687a2decf9
Delete obsolete ddb.adapterType patching
When building a vmdk image with pvscsi as adapter type, kiwi
implicitly changed the adapter_type from pvscsi to lsilogic
because qemu only knows lsilogic. At the end kiwi patched
the adapter type in the descriptor of the vmdk header back
to pvscsi. That patching seems to be wrong according to
information from users and VMware support. This commit
deletes the descriptor patching and only leaves the pvscsi
setting in the guest configuration(vmx).
This Fixes bsc#1180539 and Fixes #1847
2021-06-15 10:16:28 +02:00
Marcus Schäfer
c694a2eb5f
Fixed platform setup for vagrant unit tests 2021-04-15 11:05:24 +02:00
Marcus Schäfer
ce9b1ccc08
Added option to set the image target architecture
The option --target-arch allows to set the architecture
used to build the image. By default this is the host
architecture. Please note, if the specified architecture
name does not match the host architecture and is therefore
requesting a cross architecture image build, it's important
to understand that for this process to work a preparatory
step to support the image architecture and binary format
on the building host is required and is not considered a
responsibility of kiwi. There will be a followup effort
on providing a plugin for kiwi which should be used to
manage the needed binfmt settings for cross arch image
builds
2021-04-14 12:53:28 +02:00
Marcus Schäfer
81bb72cf69
Complete strong typing for API methods
Added required code changes to let mypy pass when running
from the toplevel kiwi namespace. This now finally
Fixes #1644
2021-04-10 20:04:39 +02:00
Marcus Schäfer
408506b5ae
Merge pull request #1740 from OSInside/strong-typing
Add strong typing for the following API methods
2021-02-26 09:15:17 +01:00
Marcus Schäfer
4e62aebd39
Fixed code smells reported from codacy
In addition cleanup unused instance variable self.custom_args
from DiskFormatBase class
2021-02-25 09:31:17 +01:00
Jesus Bermudez Velazquez
3fbcbfc450
Add strong typing for the following API methods
kiwi/storage/raid_device
kiwi/storage/setup
kiwi/storage/subformat/base
kiwi/storage/subformat/gce
kiwi/storage/subformat/ova
kiwi/storage/subformat/qcow2

This references issue #1644
2021-02-23 13:01:53 +00:00
Marcus Schäfer
2fe9e1e89c
Added strong typing for the following API methods
* storage/subformat/vagrant_base.py
* storage/subformat/vagrant_libvirt.py
* storage/subformat/vagrant_virtualbox.py
* storage/subformat/vdi.py
* storage/subformat/vhd.py
* storage/subformat/vhdfixed.py
* storage/subformat/vhdx.py
* storage/subformat/vmdk.py

This references Issue #1644
2021-02-23 11:29:12 +01:00
Jesus Bermudez Velazquez
77a62e1c81
Add strong typing for the following API methods
kiwi/storage/device_provider
kiwi/storage/disk
kiwi/storage/loop_device
kiwi/storage/luks_device
kiwi/storage/mapped_device

This references issue #1644
2021-02-12 11:49:58 +00:00
Marcus Schäfer
7a5ab282b6
Refactor RuntimeConfig class
The former implementation read the runtime config file every
time a new RuntimeConfig instance was created. The runtime
config is however static during the runtime of an image build
process and not supposed to change. Therefore the file should
be read in once and any new instance of RuntimConfig should
just use what has been read in at the first invocation. This
commit refactors the RuntimeConfig class to hold an application
global RUNTIME_CONFIG variable and allows to reread the
config on explicit request.
2021-02-08 12:41:20 +01:00
Marcus Schäfer
7b727414ce
Refactor Partitioner
This commit refactors the Partitioner class and turns it into a
proper factory class and also includes type hints to facilitate
it's use from an API POV. Related to #1498
2020-11-25 17:02:12 +01:00
Marcus Schäfer
80d1a1b49e
No bootpartition for XFS by default
Selecting the xfs filesystem made kiwi to create an extra
boot partition. This is from times when grub was not able
to read from XFS. As grub doesn't have this limitation since
quite some time the bootpartition default in kiwi for XFS
should be changed. This is realted to #1611
2020-11-13 10:02:34 +01:00
Marcus Schäfer
7b479cbd9c
Refactor DiskFormat
This commit refactors DiskFormat to turn it into a proper
factory class and to also include type hints to facilitate it's
use from an API POV. Related to #1498
2020-11-02 14:53:36 +01:00
Marcus Schäfer
a124d82173
Allow custom root volume name setup
In addition to the custom size of the root volume it's now
also possible to setup the name of the root volume as follows:

    <volume name="@root=rootlv"/>

If no name for the root volume is specified the default
name: LVRoot applies as before. This Fixes #1530
2020-10-27 16:17:47 +01:00