Skip to content

Commit

Permalink
helpers: remove empty customization fields
Browse files Browse the repository at this point in the history
Customizations that contain empty arrays or objects instead of being
undefined cause failed image builds even with a valid blueprint.

The clean function recursively removes this empty fields from the
blueprint object and fixes the edge image build failures.
  • Loading branch information
jkozol committed Jun 2, 2024
1 parent a92e18f commit 4630e41
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
23 changes: 21 additions & 2 deletions src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,23 @@ export const formTimestampLabel = (ts) => {
return tsDisplay;
};

export const cleanEmptyFields = (obj) => {
const cleaned = Object.entries(obj).reduce((fields, [key, value]) => {
if (value === undefined || value === null || value === "") {
return fields;
}
if (typeof value === "object") {
const cleanedValue = cleanEmptyFields(value);
if (Object.keys(cleanedValue).length === 0) {
return fields;
}
return { ...fields, [key]: cleanedValue };
}
return { ...fields, [key]: value };
}, {});
return cleaned;
};

export const blueprintToFormState = (blueprint) => {
if (!blueprint) return {};
const formState = {
Expand Down Expand Up @@ -83,7 +100,7 @@ const formStateToCustomizations = (customizations) => {
};
const filesystem = customizations.filesystem
? customizations.filesystem.map(parseFilesystem)
: [];
: undefined;

let openscap;
if (
Expand Down Expand Up @@ -125,9 +142,11 @@ export const formStateToBlueprint = (formValues) => {
? formStateToCustomizations(formValues?.customizations)
: undefined;

const cleanEmptyCustomizations = cleanEmptyFields(customizations);

const blueprint = {
...formValues.blueprint,
customizations,
customizations: cleanEmptyCustomizations,
packages,
};
return blueprint;
Expand Down
16 changes: 16 additions & 0 deletions test/verify/check-imageWizard
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,22 @@ class TestImageWizard(composerlib.ComposerCase):
# Cancel upload
b.click("footer button:contains('Cancel')")

@unittest.skipIf(os.environ.get("TEST_OS").split('-')[0] != "rhel", "Skipping test for non RHEL")
def testEdgeImageFields(self):
b = self.browser

self.login_and_go("/composer", superuser=True)
b.wait_visible("#main")

# Select create image from created blueprint
b.click("tr[data-testid=httpd-server] button[aria-label='Create image']")
b.wait_in_text(".pf-c-wizard__main", "httpd-server")
time.sleep(1)
# Edge image type
b.select_PF4("#image-output-select-toggle", "RHEL for Edge Installer (.iso)")
b.click("button:contains('Next')")

b.click("footer button:contains('Create')")

if __name__ == '__main__':
testlib.test_main()

0 comments on commit 4630e41

Please sign in to comment.