recognize "--key /dev/mapper/VG-LV🔑password"; fix %check phase

(1) Backport the upstream patches for recognizing the command line option

      --key /dev/mapper/VG-LV🔑password

    Similarly to the backports for guestfs-tools BZ#2209280 and libguestfs
    BZ#2209279, here we need to update the common submodule (thankfully we
    need not excise any hunks -- we had to do that for libguestfs).

    Unlike those "single-step" submodule updates however, for virt-v2v we
    bridge the same submodule commit range 70c10a079a30..b636c3f20a1b in
    two steps, stopping at commit 38e6988c1864 in the middle. We do that
    simply because that's how upstream virt-v2v moved; i.e., there are two
    upstream patches to cherry-pick for advancing our submodule reference.

(2) In dist-git commit ef9a918d7e, there was a typo: the "test" command
    was left out. Therefore even our simple test conversion has not been
    invoked -- see e.g.
    <https://download.eng.bos.redhat.com/brewroot/vol/rhel-9/packages/virt-v2v/2.3.4/2.el9/data/logs/x86_64/build.log>:

> + -s test-data/phony-guests/windows.img
> /var/tmp/rpm-tmp.UMecKA: line 48: -s: command not found

    Unfortunately, incorrectly (not) invoking "test -s" has had results
    identical to invoking "test -s" correctly and "test -s" failing;
    therefore we've been just silently skipping our simple conversion,
    assuming "no non-empty guest disk images".

    Fix this typo...

(3) ... and then run the sole "test-v2v-fedora-luks-on-lvm-conversion.sh"
    test from the test suite, for verifying the backport in the build
    environment. (The idea for the future is that we'd run such individual
    tests whenever backporting patches.) For this, we also start depending
    (at build time) on the sqlite3 command.

resolves: rhbz#2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
This commit is contained in:
Laszlo Ersek 2023-06-19 15:50:15 +02:00
parent 0aadbb4e02
commit 552929e8d3
6 changed files with 414 additions and 2 deletions

View File

@ -0,0 +1,60 @@
From 6dea82d823c344af0277bb35de789828cfd3e413 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Sat, 22 Apr 2023 09:06:01 +0100
Subject: [PATCH] Update common submodule
Richard W.M. Jones (1):
mlcustomize/SELinux_relabel.ml: Use Array.mem
Roman Kagan (1):
mlcustomize: skip SELinux relabeling if it's disabled
(cherry picked from commit e83de8abe6c5388585885cef28d7a198b7bfc90c)
---
common | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Submodule common 70c10a07..38e6988c:
diff --git a/common/mlcustomize/SELinux_relabel.ml b/common/mlcustomize/SELinux_relabel.ml
index 5ecf7bd7..2f3a09bf 100644
--- a/common/mlcustomize/SELinux_relabel.ml
+++ b/common/mlcustomize/SELinux_relabel.ml
@@ -24,10 +24,6 @@ open Printf
module G = Guestfs
-(* Simple reimplementation of Array.mem, available only with OCaml >= 4.03. *)
-let array_find a l =
- List.mem a (Array.to_list l)
-
let rec relabel (g : G.guestfs) =
(* Is the guest using SELinux? (Otherwise this is a no-op). *)
if is_selinux_guest g then (
@@ -59,14 +55,24 @@ and use_setfiles g =
g#aug_load ();
debug_augeas_errors g;
+ let config_path = "/files/etc/selinux/config" in
+ let config_keys = g#aug_ls config_path in
+ (* SELinux may be disabled via a setting in config file *)
+ let selinux_disabled =
+ let selinuxmode_path = config_path ^ "/SELINUX" in
+ if Array.mem selinuxmode_path config_keys then
+ g#aug_get selinuxmode_path = "disabled"
+ else
+ false in
+ if selinux_disabled then
+ failwith "selinux disabled";
+
(* Get the SELinux policy name, eg. "targeted", "minimum".
* Use "targeted" if not specified, just like libselinux does.
*)
let policy =
- let config_path = "/files/etc/selinux/config" in
let selinuxtype_path = config_path ^ "/SELINUXTYPE" in
- let keys = g#aug_ls config_path in
- if array_find selinuxtype_path keys then
+ if Array.mem selinuxtype_path config_keys then
g#aug_get selinuxtype_path
else
"targeted" in

View File

@ -0,0 +1,152 @@
From 1d69132b7b7209dbf231a4668b3a6531a6f9cdf3 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Fri, 19 May 2023 11:34:18 +0200
Subject: [PATCH] update common submodule
Laszlo Ersek (2):
options/keys: key_store_import_key(): un-constify "key" parameter
options/keys: introduce unescape_device_mapper_lvm()
https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
(cherry picked from commit b0dbe7c7728579d6c2128c733491755eee1a91b5)
---
common | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
Submodule common 38e6988c..b636c3f2:
diff --git a/common/options/options.h b/common/options/options.h
index 94573ee0..94e8b9ee 100644
--- a/common/options/options.h
+++ b/common/options/options.h
@@ -169,7 +169,8 @@ extern struct matching_key *get_keys (struct key_store *ks, const char *device,
const char *uuid, size_t *nr_matches);
extern void free_keys (struct matching_key *keys, size_t nr_matches);
extern struct key_store *key_store_add_from_selector (struct key_store *ks, const char *selector);
-extern struct key_store *key_store_import_key (struct key_store *ks, const struct key_store_key *key);
+extern struct key_store *key_store_import_key (struct key_store *ks,
+ struct key_store_key *key);
extern bool key_store_requires_network (const struct key_store *ks);
extern void free_key_store (struct key_store *ks);
diff --git a/common/options/keys.c b/common/options/keys.c
index 48f1bc7c..52b27369 100644
--- a/common/options/keys.c
+++ b/common/options/keys.c
@@ -260,8 +260,107 @@ key_store_add_from_selector (struct key_store *ks, const char *selector)
return key_store_import_key (ks, &key);
}
+/* Turn /dev/mapper/VG-LV into /dev/VG/LV, in-place. */
+static void
+unescape_device_mapper_lvm (char *id)
+{
+ static const char dev[] = "/dev/", dev_mapper[] = "/dev/mapper/";
+ const char *input_start;
+ char *output;
+ enum { M_SCAN, M_FILL, M_DONE } mode;
+
+ if (!STRPREFIX (id, dev_mapper))
+ return;
+
+ /* Start parsing "VG-LV" from "id" after "/dev/mapper/". */
+ input_start = id + (sizeof dev_mapper - 1);
+
+ /* Start writing the unescaped "VG/LV" output after "/dev/". */
+ output = id + (sizeof dev - 1);
+
+ for (mode = M_SCAN; mode < M_DONE; ++mode) {
+ char c;
+ const char *input = input_start;
+ const char *hyphen_buffered = NULL;
+ bool single_hyphen_seen = false;
+
+ do {
+ c = *input;
+
+ switch (c) {
+ case '-':
+ if (hyphen_buffered == NULL)
+ /* This hyphen may start an escaped hyphen, or it could be the
+ * separator in VG-LV.
+ */
+ hyphen_buffered = input;
+ else {
+ /* This hyphen completes an escaped hyphen; unescape it. */
+ if (mode == M_FILL)
+ *output++ = '-';
+ hyphen_buffered = NULL;
+ }
+ break;
+
+ case '/':
+ /* Slash characters are forbidden in VG-LV anywhere. If there's any,
+ * we'll find it in the first (i.e., scanning) phase, before we output
+ * anything back to "id".
+ */
+ assert (mode == M_SCAN);
+ return;
+
+ default:
+ /* Encountered a non-slash, non-hyphen character -- which also may be
+ * the terminating NUL.
+ */
+ if (hyphen_buffered != NULL) {
+ /* The non-hyphen character comes after a buffered hyphen, so the
+ * buffered hyphen is supposed to be the single hyphen that separates
+ * VG from LV in VG-LV. There are three requirements for this
+ * separator: (a) it must be unique (we must not have seen another
+ * such separator earlier), (b) it must not be at the start of VG-LV
+ * (because VG would be empty that way), (c) it must not be at the end
+ * of VG-LV (because LV would be empty that way). Should any of these
+ * be violated, we'll catch that during the first (i.e., scanning)
+ * phase, before modifying "id".
+ */
+ if (single_hyphen_seen || hyphen_buffered == input_start ||
+ c == '\0') {
+ assert (mode == M_SCAN);
+ return;
+ }
+
+ /* Translate the separator hyphen to a slash character. */
+ if (mode == M_FILL)
+ *output++ = '/';
+ hyphen_buffered = NULL;
+ single_hyphen_seen = true;
+ }
+
+ /* Output the non-hyphen character (including the terminating NUL)
+ * regardless of whether there was a buffered hyphen separator (which,
+ * by now, we'll have attempted to translate and flush).
+ */
+ if (mode == M_FILL)
+ *output++ = c;
+ }
+
+ ++input;
+ } while (c != '\0');
+
+ /* We must have seen the VG-LV separator. If that's not the case, we'll
+ * catch it before modifying "id".
+ */
+ if (!single_hyphen_seen) {
+ assert (mode == M_SCAN);
+ return;
+ }
+ }
+}
+
struct key_store *
-key_store_import_key (struct key_store *ks, const struct key_store_key *key)
+key_store_import_key (struct key_store *ks, struct key_store_key *key)
{
struct key_store_key *new_keys;
@@ -278,6 +377,7 @@ key_store_import_key (struct key_store *ks, const struct key_store_key *key)
error (EXIT_FAILURE, errno, "realloc");
ks->keys = new_keys;
+ unescape_device_mapper_lvm (key->id);
ks->keys[ks->nr_keys] = *key;
++ks->nr_keys;

View File

@ -0,0 +1,81 @@
From 2558084d081c3dd9b0d681f3cf6789b48485cb62 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Mon, 15 May 2023 19:55:28 +0200
Subject: [PATCH] LUKS-on-LVM conversion test: rename VGs and LVs
In preparation for a subsequent patch, rename "VG" to "Volume-Group", and
"LV<n>" to "Logical-Volume-<n>", in the LUKS-on-LVM conversion test.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230515175529.290724-2-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 0ecbe09c09cace1fe0d03cad3ac53000bfeb3cb6)
---
test-data/phony-guests/make-fedora-img.pl | 30 +++++++++++--------
.../test-v2v-fedora-luks-on-lvm-conversion.sh | 8 ++---
2 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/test-data/phony-guests/make-fedora-img.pl b/test-data/phony-guests/make-fedora-img.pl
index c30c0b53..830accfc 100755
--- a/test-data/phony-guests/make-fedora-img.pl
+++ b/test-data/phony-guests/make-fedora-img.pl
@@ -224,23 +224,27 @@ EOF
# Create the Volume Group on /dev/sda2.
$g->pvcreate ('/dev/sda2');
- $g->vgcreate ('VG', ['/dev/sda2']);
- $g->lvcreate ('Root', 'VG', 256);
- $g->lvcreate ('LV1', 'VG', 32);
- $g->lvcreate ('LV2', 'VG', 32);
- $g->lvcreate ('LV3', 'VG', 64);
+ $g->vgcreate ('Volume-Group', ['/dev/sda2']);
+ $g->lvcreate ('Root', 'Volume-Group', 256);
+ $g->lvcreate ('Logical-Volume-1', 'Volume-Group', 32);
+ $g->lvcreate ('Logical-Volume-2', 'Volume-Group', 32);
+ $g->lvcreate ('Logical-Volume-3', 'Volume-Group', 64);
# Format each Logical Group as a LUKS device, with a different password.
- $g->luks_format ('/dev/VG/Root', 'FEDORA-Root', 0);
- $g->luks_format ('/dev/VG/LV1', 'FEDORA-LV1', 0);
- $g->luks_format ('/dev/VG/LV2', 'FEDORA-LV2', 0);
- $g->luks_format ('/dev/VG/LV3', 'FEDORA-LV3', 0);
+ $g->luks_format ('/dev/Volume-Group/Root', 'FEDORA-Root', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-1', 'FEDORA-LV1', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-2', 'FEDORA-LV2', 0);
+ $g->luks_format ('/dev/Volume-Group/Logical-Volume-3', 'FEDORA-LV3', 0);
# Open the LUKS devices. This creates nodes like /dev/mapper/*-luks.
- $g->cryptsetup_open ('/dev/VG/Root', 'FEDORA-Root', 'Root-luks');
- $g->cryptsetup_open ('/dev/VG/LV1', 'FEDORA-LV1', 'LV1-luks');
- $g->cryptsetup_open ('/dev/VG/LV2', 'FEDORA-LV2', 'LV2-luks');
- $g->cryptsetup_open ('/dev/VG/LV3', 'FEDORA-LV3', 'LV3-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Root',
+ 'FEDORA-Root', 'Root-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-1',
+ 'FEDORA-LV1', 'LV1-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-2',
+ 'FEDORA-LV2', 'LV2-luks');
+ $g->cryptsetup_open ('/dev/Volume-Group/Logical-Volume-3',
+ 'FEDORA-LV3', 'LV3-luks');
# Phony root filesystem.
$g->mkfs ('ext2', '/dev/mapper/Root-luks', blocksize => 4096, label => 'ROOT');
diff --git a/tests/test-v2v-fedora-luks-on-lvm-conversion.sh b/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
index 1a4068cf..7ad17e0d 100755
--- a/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
+++ b/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
@@ -28,9 +28,9 @@ skip_if_skipped
f=../test-data/phony-guests/fedora-luks-on-lvm.img
requires test -f $f
-keys=(--key /dev/VG/Root:key:FEDORA-Root
- --key /dev/VG/LV1:key:FEDORA-LV1
- --key /dev/VG/LV2:key:FEDORA-LV2
- --key /dev/VG/LV3:key:FEDORA-LV3)
+keys=(--key /dev/Volume-Group/Root:key:FEDORA-Root
+ --key /dev/Volume-Group/Logical-Volume-1:key:FEDORA-LV1
+ --key /dev/Volume-Group/Logical-Volume-2:key:FEDORA-LV2
+ --key /dev/Volume-Group/Logical-Volume-3:key:FEDORA-LV3)
$VG virt-v2v --debug-gc -i disk $f -o null "${keys[@]}"

View File

@ -0,0 +1,34 @@
From c8902c551014bc0163122d9fd2005d97d3cb38a5 Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Mon, 15 May 2023 19:55:29 +0200
Subject: [PATCH] LUKS-on-LVM conversion test: test /dev/mapper/VG-LV
translation
In the LUKS-on-LVM conversion test, repeat the null conversion with such
"--key" options that exercise the recent "/dev/mapper/VG-LV" ->
"/dev/VG/LV" translation (unescaping) from libguestfs-common.
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230515175529.290724-3-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 3060af01e87fbffe1cb413938c3c5431f2242bd4)
---
tests/test-v2v-fedora-luks-on-lvm-conversion.sh | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/tests/test-v2v-fedora-luks-on-lvm-conversion.sh b/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
index 7ad17e0d..605b19fb 100755
--- a/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
+++ b/tests/test-v2v-fedora-luks-on-lvm-conversion.sh
@@ -34,3 +34,10 @@ keys=(--key /dev/Volume-Group/Root:key:FEDORA-Root
--key /dev/Volume-Group/Logical-Volume-3:key:FEDORA-LV3)
$VG virt-v2v --debug-gc -i disk $f -o null "${keys[@]}"
+
+keys=(--key /dev/mapper/Volume--Group-Root:key:FEDORA-Root
+ --key /dev/mapper/Volume--Group-Logical--Volume--1:key:FEDORA-LV1
+ --key /dev/mapper/Volume--Group-Logical--Volume--2:key:FEDORA-LV2
+ --key /dev/mapper/Volume--Group-Logical--Volume--3:key:FEDORA-LV3)
+
+$VG virt-v2v --debug-gc -i disk $f -o null "${keys[@]}"

View File

@ -0,0 +1,63 @@
From 10192f8ee3a7900e76d5c9a0fb330eb5ff1fe22c Mon Sep 17 00:00:00 2001
From: Laszlo Ersek <lersek@redhat.com>
Date: Mon, 19 Jun 2023 18:27:29 +0200
Subject: [PATCH] test-data/phony-guests: fix prerequisite list of
"fedora-luks-on-lvm.img"
In the virt-v2v repo, commit 1e75569aa074 ("test-data/phony-guests: Allow
virt-v2v to work against phony Fedora") is an ancestor of commit
e4efe4b7d240 ("tests: add LUKS-on-LVM test"). The latter created a state
where "fedora-static-bin" and LUKS on LVM testing would coexist (i.e.,
where "fedora-static-bin" would be uploaded to the LUKS-on-LVM disk image
as well), but the commit didn't spell out the dependency in
"test-data/phony-guests/Makefile.am".
Do that now.
The problem can be triggered with:
> autoreconf -i
> ./configure
> make
> make -C test-data/phony-guests fedora-luks-on-lvm.img
where the last command fails with
> make: Entering directory '.../test-data/phony-guests'
> SRCDIR=. LAYOUT=luks-on-lvm ../../run --test ./make-fedora-img.pl
> open: fedora-static-bin: No such file or directory at
> .../test-data/phony-guests/make-fedora-img.pl line 373.
(In the guestfs-tools repo, the relative order (the descendancy) between
both commits is the opposite. There, commit 27da4b0c4991 ("inspector: add
LUKS-on-LVM test") came first, and commit eb0ff1859eb6
("test-data/phony-guests: Allow virt-v2v to work against phony Fedora"),
came second. The latter commit, in fact being a port of virt-v2v commit
1e75569aa074, brought together "fedora-static-bin" with "LUKS on LVM"
testing, and it correctly added "fedora-static-bin" as a pre-requisite
for building "fedora-luks-on-lvm.img".)
Fixes: e4efe4b7d240b66b1d53fbe5a127f4f5966f6903
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2168506
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Message-Id: <20230619162729.153334-1-lersek@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 13a6f4b9686e3fc385663bffc31c08d2c2bb7959)
---
test-data/phony-guests/Makefile.am | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/test-data/phony-guests/Makefile.am b/test-data/phony-guests/Makefile.am
index 29dbd4d0..10c0241b 100644
--- a/test-data/phony-guests/Makefile.am
+++ b/test-data/phony-guests/Makefile.am
@@ -103,7 +103,8 @@ fedora-btrfs.img: make-fedora-img.pl \
# Make a (dummy) Fedora image with LUKS-on-LVM.
fedora-luks-on-lvm.img: make-fedora-img.pl \
fedora-journal.tar.xz \
- fedora.db
+ fedora.db \
+ fedora-static-bin
SRCDIR=$(srcdir) LAYOUT=luks-on-lvm $(top_builddir)/run --test ./$<
# Make a (dummy) Fedora image with LVM-on-LUKS.

View File

@ -16,7 +16,7 @@
Name: virt-v2v
Epoch: 1
Version: 2.3.4
Release: 2%{?dist}
Release: 3%{?dist}
Summary: Convert a virtual machine to run on KVM
License: GPLv2+
@ -48,6 +48,11 @@ Patch0009: 0009-RHEL-Remove-the-in-place-option.patch
Patch0010: 0010-RHEL-9-oo-compressed-Remove-nbdcopy-version-check-an.patch
Patch0011: 0011-RHEL-9-tests-Remove-btrfs-test.patch
Patch0012: 0012-RHEL-9-Remove-block-driver-option.patch
Patch0013: 0013-Update-common-submodule.patch
Patch0014: 0014-update-common-submodule.patch
Patch0015: 0015-LUKS-on-LVM-conversion-test-rename-VGs-and-LVs.patch
Patch0016: 0016-LUKS-on-LVM-conversion-test-test-dev-mapper-VG-LV-tr.patch
Patch0017: 0017-test-data-phony-guests-fix-prerequisite-list-of-fedo.patch
%if !0%{?rhel}
# libguestfs hasn't been built on i686 for a while since there is no
@ -112,6 +117,7 @@ BuildRequires: nbdkit-python-plugin
BuildRequires: nbdkit-cow-filter >= 1.28.3-1.el9
%ifarch x86_64
BuildRequires: glibc-static
BuildRequires: sqlite
%endif
%if 0%{verify_tarball_signature}
@ -287,10 +293,21 @@ export LIBGUESTFS_TRACE=1
# working.
for f in windows.img fedora.img; do
make -C test-data/phony-guests $f
if -s test-data/phony-guests/$f; then
if test -s test-data/phony-guests/$f; then
./run virt-v2v -v -x -i disk test-data/phony-guests/$f -o null
fi
done
# Individual tests we do want to run for checking backports.
# The "windows.img" target below is harmless; it is already made by the
# loop above (even if only with zero size, due to RHEL9 lacking NTFS
# support). Repeat it here effectively for documentation purposes, as
# the upstream test suite depends on "windows.img", for formatting
# "windows.vmdk", regardless of the TESTS we want to run. The real
# target we need to make here is "fedora-luks-on-lvm.img".
make -C test-data/phony-guests windows.img fedora-luks-on-lvm.img
make -C tests TESTS=test-v2v-fedora-luks-on-lvm-conversion.sh check
%endif
@ -336,6 +353,11 @@ done
%changelog
* Tue Jun 20 2023 Laszlo Ersek <lersek@redhat.com> - 1:2.3.4-3
- recognize "--key /dev/mapper/VG-LV:key:password"
- enable the %%check tests for real
resolves: rhbz#2168506
* Fri Apr 28 2023 Richard W.M. Jones <rjones@redhat.com> - 1:2.3.4-2
- Rebase to virt-v2v 2.3.4
resolves: rhbz#2187961, rhbz#2175703, rhbz#2172075, rhbz#2168082,