Skip to content

Commit

Permalink
service: Convert autoyast partitioning section (#1285)
Browse files Browse the repository at this point in the history
The list of drives in the "partitioning" section of an AutoYaST profile
is directly converted to json as "legacyAutoyastStorage" key.

See:

* #1279
* #1284

~~~
$ ./service/bin/agama-autoyast file:///path/to/profile.xml /tmp
$ cat /tmp/autoinst.json | jq

{
  "legacyAutoyastStorage": [
    {
      "device": "/dev/sda",
      "disklabel": "gpt",
      "enable_snapshots": true,
      "initialize": true,
      "partitions": [
        {
          "create": true,
          "partition_id": 263,
          "partition_nr": 1,
          "resize": false,
          "size": "8225280"
        }
      ],
      "type": "CT_DISK",
      "use": "all"
  ]
}
~~~

Note: Agama CLI complains when using `file://`:

~~~
$ agama profile autoyast file:///path/to/profile.xml
No such file or directory (os error 2)
~~~
  • Loading branch information
joseivanlopez committed Jun 5, 2024
2 parents e2c7a5a + bb64818 commit f7bf531
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 17 deletions.
14 changes: 3 additions & 11 deletions service/lib/agama/autoyast/storage_reader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,12 @@ def initialize(profile)
@profile = profile
end

# @return [Hash] Agama "storage" section
# @return [Hash] Agama "legacyAutoyastStorage" section
def read
drives = profile.fetch_as_array("partitioning")
return {} if drives.nil?
return {} if drives.empty?

# TODO: rely on AutoinstProfile classes
devices = drives.each_with_object([]) do |d, all|
next unless d["device"]

all << d["device"]
end
return {} if devices.empty?

{ "storage" => { "bootDevice" => devices.first } }
{ "legacyAutoyastStorage" => drives }
end
end
end
Expand Down
6 changes: 6 additions & 0 deletions service/package/rubygem-agama-yast.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
-------------------------------------------------------------------
Tue Jun 4 14:16:02 UTC 2024 - José Iván López González <jlopez@suse.com>

- Convert AutoYaST partitioning section to JSON
(gh#openSUSE/agama#1285).

-------------------------------------------------------------------
Mon May 27 12:43:49 UTC 2024 - José Iván López González <jlopez@suse.com>

Expand Down
9 changes: 6 additions & 3 deletions service/test/agama/autoyast/converter_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,13 @@
end
end

context "when a storage device is selected" do
it "exports the device" do
context "when partitioning is defined" do
it "exports the drives information" do
subject.to_agama(workdir)
expect(result["storage"]).to include("bootDevice" => "/dev/vda")
expect(result["legacyAutoyastStorage"]).to include({
"device" => "/dev/vda",
"use" => "all"
})
end
end

Expand Down
13 changes: 10 additions & 3 deletions service/test/agama/autoyast/storage_reader_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,17 @@
end
end

context "when there are no drives" do
let(:profile) { { "partitioning" => [] } }

it "returns an empty hash" do
expect(subject.read).to be_empty
end
end

context "when there is a list of drives" do
it "uses the first 'device' key as 'bootDevice'" do
boot_device = subject.read.dig("storage", "bootDevice")
expect(boot_device).to eq("/dev/vda")
it "returns the list as 'legacyAutoyastStorage'" do
expect(subject.read["legacyAutoyastStorage"]).to eq(profile["partitioning"])
end
end
end
Expand Down

0 comments on commit f7bf531

Please sign in to comment.