Apply upstream fixes for unit tests

Add patches needed for the unit tests to pass on RHEL-8
 - https://github.com/osbuild/osbuild/pull/1316
 - https://github.com/osbuild/osbuild/pull/1317

Related: rhbz#2174845

Signed-off-by: Tomáš Hozza <thozza@redhat.com>
This commit is contained in:
Tomáš Hozza 2023-05-25 16:29:22 +02:00
parent 997ba9631d
commit eba57a46bf
No known key found for this signature in database
GPG Key ID: C5887AD51D9F3C2D
3 changed files with 1444 additions and 2 deletions

169
PR1316.patch Normal file
View File

@ -0,0 +1,169 @@
From 3e780762cb92f3cbb1c80c78669f1768613f163e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Hozza?= <thozza@redhat.com>
Date: Thu, 25 May 2023 13:12:08 +0200
Subject: [PATCH] stages/sgdisk: option to not quote partition names passed to
sgdisk
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The partition name in the sgdisk stage was previously quoted when
passed to sgdisk as an argument. I think that this was done because
the sgdisk man page states that:
```
If you want to set a name that includes a space, enclose it in
quotation marks, as in sgdisk -c 1:"Sample Name" /dev/sdb.
```
However, this should apply only when sgdisk is run in a shell, so that
the argument is not split by shell into multiple arguments and passes
as a single string.
The stage is executing sgdisk using Python `subprocess` module, which
does not need strings with spaces to be quoted, because they are passed
to the command as separate items which are not split in any way.
The previous behavior of the stage was that these quotes became part of
the actual partition name in the partition table.
After a discussion within the team, we determined that this is a bug.
However, fixing it would result in osbuild producing a different
artifact for the same manifest, compared to osbuild version without such
fix. This is undesired.
For backward compatibility, a new `quote_partition_name` property is
added to the stage options, which can be used to make the stage not
quote the partition name when passed to `sgdisk`. As a result, the
partition name won't be quoted in the partition table.
The default stage behavior us kept.
Modify unit tests to use this option by default.
Signed-off-by: Tomáš Hozza <thozza@redhat.com>
---
stages/org.osbuild.sgdisk | 13 ++++++++++---
test/data/stages/sgdisk/disk.img.json | 8 ++++----
test/data/stages/sgdisk/sgdisk.json | 1 +
test/data/stages/sgdisk/sgdisk.mpp.json | 1 +
4 files changed, 16 insertions(+), 7 deletions(-)
diff --git a/stages/org.osbuild.sgdisk b/stages/org.osbuild.sgdisk
index c90d4e6..13d9696 100755
--- a/stages/org.osbuild.sgdisk
+++ b/stages/org.osbuild.sgdisk
@@ -30,6 +30,11 @@ SCHEMA_2 = r"""
"description": "UUID for the disk image's partition table",
"type": "string"
},
+ "quote_partition_name": {
+ "description": "Quote partition names passed to sgdisk, so that they end up quoted in the partition table. This is old behavior kept for backward compatibility.",
+ "type": "boolean",
+ "default": true
+ },
"partitions": {
"description": "Partition layout ",
"type": "array",
@@ -109,7 +114,7 @@ class PartitionTable:
def __getitem__(self, key) -> Partition:
return self.partitions[key]
- def write_to(self, target):
+ def write_to(self, target, quote_partition_name):
"""Write the partition table to disk"""
# generate the command for sfdisk to create the table
@@ -138,8 +143,9 @@ class PartitionTable:
]
if part.name:
+ part_name = f'"{part.name}"' if quote_partition_name else part.name
cmd += [
- "-c", f'{idx}:"{part.name}"'
+ "-c", f"{idx}:{part_name}"
]
if part.uuid:
@@ -180,12 +186,13 @@ def main(devices, options):
device = devices["device"]["path"]
ptuuid = options["uuid"]
+ quote_partition_name = options.get("quote_partition_name", True)
partitions = options.get("partitions")
parts = [partition_from_json(p) for p in partitions]
pt = PartitionTable(ptuuid, parts)
- pt.write_to(device)
+ pt.write_to(device, quote_partition_name)
subprocess.run(["sgdisk", "-p", device],
encoding='utf8',
diff --git a/test/data/stages/sgdisk/disk.img.json b/test/data/stages/sgdisk/disk.img.json
index 18c048d..89a5199 100644
--- a/test/data/stages/sgdisk/disk.img.json
+++ b/test/data/stages/sgdisk/disk.img.json
@@ -13,7 +13,7 @@
"size": 1024000,
"type": "C12A7328-F81F-11D2-BA4B-00A0C93EC93B",
"uuid": "80B68AE7-3531-478C-A5FF-9B80F1CB07E9",
- "name": "\"EFI System Partition\"",
+ "name": "EFI System Partition",
"attrs": "LegacyBIOSBootable"
},
{
@@ -22,7 +22,7 @@
"size": 1024000,
"type": "BC13C2FF-59E6-4262-A352-B275FD6F7172",
"uuid": "CFE2BEB6-0BB8-4FB6-9075-2E79413AB707",
- "name": "\"boot\"",
+ "name": "boot",
"attrs": "LegacyBIOSBootable"
},
{
@@ -31,7 +31,7 @@
"size": 4096,
"type": "FAC7F1FB-3E8D-4137-A512-961DE09A5549",
"uuid": "6E2E131D-14C4-4278-876A-5067C40EAECD",
- "name": "\"BIOS boot\""
+ "name": "BIOS boot"
},
{
"node": "disk.img4",
@@ -39,7 +39,7 @@
"size": 18917343,
"type": "E6D6D379-F507-44C2-A23C-238F2A3DF928",
"uuid": "646E1B09-9358-4A9C-B630-E3C0C296F7C6",
- "name": "\"LVM\""
+ "name": "LVM"
}
]
}
diff --git a/test/data/stages/sgdisk/sgdisk.json b/test/data/stages/sgdisk/sgdisk.json
index 05d8dcf..29725ec 100644
--- a/test/data/stages/sgdisk/sgdisk.json
+++ b/test/data/stages/sgdisk/sgdisk.json
@@ -375,6 +375,7 @@
},
"options": {
"uuid": "68ad7ade-3fa7-4844-8b2f-1c4cd30bef70",
+ "quote_partition_name": false,
"partitions": [
{
"uuid": "80b68ae7-3531-478c-a5ff-9b80f1cb07e9",
diff --git a/test/data/stages/sgdisk/sgdisk.mpp.json b/test/data/stages/sgdisk/sgdisk.mpp.json
index f4024e1..11b57c1 100644
--- a/test/data/stages/sgdisk/sgdisk.mpp.json
+++ b/test/data/stages/sgdisk/sgdisk.mpp.json
@@ -31,6 +31,7 @@
},
"options": {
"uuid": "68ad7ade-3fa7-4844-8b2f-1c4cd30bef70",
+ "quote_partition_name": false,
"partitions": [
{
"uuid": "80b68ae7-3531-478c-a5ff-9b80f1cb07e9",
--
2.40.1

1263
PR1317.patch Normal file

File diff suppressed because it is too large Load Diff

View File

@ -9,12 +9,19 @@ Version: 85
%global pkgdir %{_prefix}/lib/%{pypi_name}
Name: %{pypi_name}
Release: 1%{?dist}
Release: 2%{?dist}
License: Apache-2.0
URL: %{forgeurl}
Source0: %{forgesource}
# Add patches needed for the unit tests to pass on RHEL-8
# https://github.com/osbuild/osbuild/pull/1316
Patch0: PR1316.patch
# https://github.com/osbuild/osbuild/pull/1317
Patch1: PR1317.patch
BuildArch: noarch
Summary: A build system for OS images
@ -121,7 +128,7 @@ Contains additional tools and utilities for development of
manifests and osbuild.
%prep
%forgesetup
%forgeautosetup -p1
%build
%py3_build
@ -252,6 +259,9 @@ fi
%changelog
* Tue May 30 2023 Tomáš Hozza <thozza@redhat.com> - 85-2
- Backport upstream fixes for unit tests on RHEL-8 (PR#1316, PR#1317)
* Thu May 11 2023 imagebuilder-bot <imagebuilder-bots+imagebuilder-bot@redhat.com> - 85-1
- New upstream release