Skip to content

Commit

Permalink
storage: fix btrfs config
Browse files Browse the repository at this point in the history
- Do not pre-assign default values, otherwise it is impossible to
  know whether such values have to be solved.
  • Loading branch information
joseivanlopez committed Oct 17, 2024
1 parent 12fb25d commit 259b652
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
6 changes: 0 additions & 6 deletions service/lib/agama/storage/configs/btrfs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class Btrfs
# @return [String, nil]
attr_accessor :default_subvolume

# Constructor
def initialize
@snapshots = false
@read_only = false
end

# @return [Boolean]
def snapshots?
!!snapshots
Expand Down
34 changes: 32 additions & 2 deletions service/test/agama/storage/config_solver_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"mount_path" => "/", "filesystem" => "btrfs",
"size" => { "auto" => true, "min" => "5 GiB", "max" => "10 GiB" },
"btrfs" => {
"snapshots" => true, "default_subvolume" => "@",
"snapshots" => true, "default_subvolume" => "@", "read_only" => true,
"subvolumes" => ["home", "opt", "root", "srv"]
},
"outline" => {
Expand Down Expand Up @@ -188,12 +188,42 @@
expect(filesystem.type.fs_type).to eq(Y2Storage::Filesystems::Type::BTRFS)
expect(filesystem.type.btrfs).to be_a(Agama::Storage::Configs::Btrfs)
expect(filesystem.type.btrfs.snapshots?).to eq(true)
expect(filesystem.type.btrfs.read_only?).to eq(false)
expect(filesystem.type.btrfs.read_only?).to eq(true)
expect(filesystem.type.btrfs.default_subvolume).to eq("@")
expect(filesystem.type.btrfs.subvolumes).to all(be_a(Y2Storage::SubvolSpecification))
end
end

context "if a config does not specify all the btrfs properties" do
let(:config_json) do
{
drives: [
{
filesystem: {
path: "/",
type: {
btrfs: {
snapshots: false
}
}
}
}
]
}
end

it "completes the btrfs config according to the product info" do
subject.solve(config)

drive = config.drives.first
btrfs = drive.filesystem.type.btrfs
expect(btrfs.snapshots?).to eq(false)
expect(btrfs.read_only?).to eq(true)
expect(btrfs.default_subvolume).to eq("@")
expect(btrfs.subvolumes).to all(be_a(Y2Storage::SubvolSpecification))
end
end

partition_proc = proc { |c| c.drives.first.partitions.first }

context "if a config does not specify size" do
Expand Down

0 comments on commit 259b652

Please sign in to comment.