Skip to content

add test that generated json from autoyast xml is valid#1946

Closed
jreidinger wants to merge 6 commits intomasterfrom
ci_autoinst_schema
Closed

add test that generated json from autoyast xml is valid#1946
jreidinger wants to merge 6 commits intomasterfrom
ci_autoinst_schema

Conversation

@jreidinger
Copy link
Contributor

@jreidinger jreidinger commented Jan 24, 2025

Problem

autoinst.xml profile conversion can lead to non valid profile.json

#1960
#1907
#1903

Solution

Add ci test to validate cloned autoyast profile. Fix issue with localization. Fix other autoyast conversion related issues.

Note: sadly I need to add python3-jsonschema to install as rubygem-json-schema does not support anything newer then draft5 json schema and we use newer.

Testing

  • Added a new unit test

Output

before pretty generate

{"localization":{"timezone":"America/New_York"},"product":{"id":"SLES"},"root":{"password":"$6$sxZ921ci.szwhCIw$9lrLQTtanJcpPeJkqv9pU0LsKQLO3RcPhBPBDMfc1uGUDCfgiyEyGPNr/ZKXAgqZsL61DANvr4uAYYDkif/Ma0","hashedPassword":true},"software":{"patterns":["apparmor","base","basic_desktop","enhanced_base","minimal_base","x11","x11_yast","yast2_basis"]},"legacyAutoyastStorage":[{"device":"/dev/system","enable_snapshots":true,"partitions":[{"create":true,"filesystem":"xfs","format":false,"lv_name":"home","mount":"/home","mountby":"device","pool":false,"resize":false,"size":"5792333824","stripes":1,"stripesize":0},{"create":true,"create_subvolumes":true,"filesystem":"btrfs","format":false,"lv_name":"root","mount":"/","mountby":"device","pool":false,"quotas":true,"resize":false,"size":"13522436096","stripes":1,"stripesize":0,"subvolumes":[{"copy_on_write":false,"path":"var"},{"copy_on_write":true,"path":"usr/local"},{"copy_on_write":true,"path":"tmp"},{"copy_on_write":true,"path":"srv"},{"copy_on_write":true,"path":"root"},{"copy_on_write":true,"path":"opt"},{"copy_on_write":true,"path":"boot/grub2/x86_64-efi"},{"copy_on_write":true,"path":"boot/grub2/i386-pc"}],"subvolumes_prefix":"@"},{"create":true,"filesystem":"swap","format":false,"lv_name":"swap","mount":"swap","mountby":"device","pool":false,"resize":false,"size":"2147483648","stripes":1,"stripesize":0}],"pesize":"4194304","type":"CT_LVM"},{"device":"/dev/sda","disklabel":"gpt","partitions":[{"create":true,"format":false,"partition_id":263,"partition_nr":1,"resize":false,"size":"8388608"},{"create":true,"format":false,"lvm_group":"system","partition_id":142,"partition_nr":2,"resize":false,"size":"21465382400"}],"type":"CT_DISK","use":"all"}],"user":{"userName":"tux","fullName":"tux","password":"$6$epM6.b193j7ZvUaw$/oMPS9pQR9X9i1MAJag20ZFy0XSI4985uVQDGLugwoCbDJVoXKCWLMFM.WncHr/bpkjecwb.LLaJeheYatq8f.","hashedPassword":true}}

after pretty generate

{
  "localization": {
    "timezone": "America/New_York"
  },
  "product": {
    "id": "SLES"
  },
  "root": {
    "password": "$6$sxZ921ci.szwhCIw$9lrLQTtanJcpPeJkqv9pU0LsKQLO3RcPhBPBDMfc1uGUDCfgiyEyGPNr/ZKXAgqZsL61DANvr4uAYYDkif/Ma0",
    "hashedPassword": true
  },
  "software": {
    "patterns": [
      "apparmor",
      "base",
      "basic_desktop",
      "enhanced_base",
      "minimal_base",
      "x11",
      "x11_yast",
      "yast2_basis"
    ]
  },
  "legacyAutoyastStorage": [
    {
      "device": "/dev/system",
      "enable_snapshots": true,
      "partitions": [
        {
          "create": true,
          "filesystem": "xfs",
          "format": false,
          "lv_name": "home",
          "mount": "/home",
          "mountby": "device",
          "pool": false,
          "resize": false,
          "size": "5792333824",
          "stripes": 1,
          "stripesize": 0
        },
        {
          "create": true,
          "create_subvolumes": true,
          "filesystem": "btrfs",
          "format": false,
          "lv_name": "root",
          "mount": "/",
          "mountby": "device",
          "pool": false,
          "quotas": true,
          "resize": false,
          "size": "13522436096",
          "stripes": 1,
          "stripesize": 0,
          "subvolumes": [
            {
              "copy_on_write": false,
              "path": "var"
            },
            {
              "copy_on_write": true,
              "path": "usr/local"
            },
            {
              "copy_on_write": true,
              "path": "tmp"
            },
            {
              "copy_on_write": true,
              "path": "srv"
            },
            {
              "copy_on_write": true,
              "path": "root"
            },
            {
              "copy_on_write": true,
              "path": "opt"
            },
            {
              "copy_on_write": true,
              "path": "boot/grub2/x86_64-efi"
            },
            {
              "copy_on_write": true,
              "path": "boot/grub2/i386-pc"
            }
          ],
          "subvolumes_prefix": "@"
        },
        {
          "create": true,
          "filesystem": "swap",
          "format": false,
          "lv_name": "swap",
          "mount": "swap",
          "mountby": "device",
          "pool": false,
          "resize": false,
          "size": "2147483648",
          "stripes": 1,
          "stripesize": 0
        }
      ],
      "pesize": "4194304",
      "type": "CT_LVM"
    },
    {
      "device": "/dev/sda",
      "disklabel": "gpt",
      "partitions": [
        {
          "create": true,
          "format": false,
          "partition_id": 263,
          "partition_nr": 1,
          "resize": false,
          "size": "8388608"
        },
        {
          "create": true,
          "format": false,
          "lvm_group": "system",
          "partition_id": 142,
          "partition_nr": 2,
          "resize": false,
          "size": "21465382400"
        }
      ],
      "type": "CT_DISK",
      "use": "all"
    }
  ],
  "user": {
    "userName": "tux",
    "fullName": "tux",
    "password": "$6$epM6.b193j7ZvUaw$/oMPS9pQR9X9i1MAJag20ZFy0XSI4985uVQDGLugwoCbDJVoXKCWLMFM.WncHr/bpkjecwb.LLaJeheYatq8f.",
    "hashedPassword": true
  }
}

Copy link
Contributor

@imobachgs imobachgs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some minor comments. Otherwise, LGTM.

def read_script(section)
script = {
"name" => section["file_name"]
"name" => section["filename"] || "annonymous#{@anonymous_counter += 1}"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: it should be anonymous but, to be honest, I do not like that prefix that much. I would prefer script-, or unnamed- or something else.

context "for cloned profile" do
let(:profile_name) { "cloned.xml" }

it "generate json according to schema" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
it "generate json according to schema" do
it "generate JSON according to schema" do

end
end

context "for cloned profile" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is just an AutoYaST profile, right? No matter whether it is cloned or written from scratch.

@imobachgs
Copy link
Contributor

We refactored the converters when working on #1976, so this PR cannot be applied anymore. I have opened #1995 including your fixes (and some minor improvements). We could rework this one to add only the tests.

imobachgs added a commit that referenced this pull request Feb 14, 2025
## Problem

The conversion of the localization and scripts sections has several
problems:

- #1903
- #1907
- #1960

This PR include some changes from #1951 and #1946.

## Solution

- Fix the handling of the scripts file name and location.
- Fix the name of the localization setting ("localization" instead of
"l10n").

Additionally, use "pretty" JSON when exporting the converted profile.

## Testing

- _Added a new unit test_
@jreidinger jreidinger closed this Feb 19, 2025
@jreidinger jreidinger deleted the ci_autoinst_schema branch February 19, 2025 09:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants