Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Mar 6, 2024
1 parent ee1e6fc commit 14cfa68
Show file tree
Hide file tree
Showing 8 changed files with 198 additions and 57 deletions.
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def lvm_vg_lvs

def self.included(base)
base.class_eval do
dbus_interface VOLUME_GROUP_INTERFACE do
dbus_interface VOLUME_GROUP_INTERFACE do
dbus_reader :lvm_vg_name, "s", dbus_name: "Name"
dbus_reader :lvm_vg_size, "t", dbus_name: "Size"
dbus_reader :lvm_vg_pvs, "ao", dbus_name: "PhysicalVolumes"
Expand Down
25 changes: 16 additions & 9 deletions service/test/agama/dbus/storage/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,20 @@
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require "agama/dbus/storage/device"
require "agama/dbus/storage/devices_tree"
require "dbus"
require_relative "../../../test_helper"
require_relative "../../storage/storage_helpers"
require_relative "./interfaces/device/block_examples"
require_relative "./interfaces/device/component_examples"
require_relative "./interfaces/device/drive_examples"
require_relative "./interfaces/device/filesystem_examples"
require_relative "./interfaces/device/lvm_vg_examples"
require_relative "./interfaces/device/md_examples"
require_relative "./interfaces/device/multipath_examples"
require_relative "./interfaces/device/partition_table_examples"
require_relative "./interfaces/device/raid_examples"
require "agama/dbus/storage/device"
require "agama/dbus/storage/devices_tree"
require "dbus"

describe Agama::DBus::Storage::Device do
include Agama::RSpec::StorageHelpers
Expand Down Expand Up @@ -110,6 +111,16 @@
end
end

context "when the given device is a LVM volume group" do
let(:scenario) { "trivial_lvm.yml" }

let(:device) { devicegraph.find_by_name("/dev/vg0") }

it "defines the LVM.VolumeGroup interface" do
expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.LVM.VolumeGroup")
end
end

context "when the given device has a partition table" do
let(:scenario) { "partitioned_md.yml" }

Expand Down Expand Up @@ -142,6 +153,8 @@

include_examples "Block interface"

include_examples "LVM.VolumeGroup interface"

include_examples "PartitionTable interface"

include_examples "Filesystem interface"
Expand All @@ -168,12 +181,6 @@
context "if the given device has the same sid" do
let(:new_device) { devicegraph.find_by_name("/dev/sda") }

it "sets the new device" do
subject.storage_device = new_device

expect(subject.storage_device).to equal(new_device)
end

it "emits a properties changed signal for each interface" do
subject.interfaces_and_properties.each_key do |interface|
expect(subject).to receive(:dbus_properties_changed).with(interface, anything, anything)
Expand Down
82 changes: 37 additions & 45 deletions service/test/agama/dbus/storage/devices_tree_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
require_relative "../../../test_helper"
require_relative "../../storage/storage_helpers"
require "agama/dbus/storage/devices_tree"
require "y2storage"
require "dbus"
require "y2storage"

describe Agama::DBus::Storage::DevicesTree do
include Agama::RSpec::StorageHelpers
Expand Down Expand Up @@ -87,7 +87,8 @@
mock_storage(devicegraph: scenario)

allow(service).to receive(:get_node).with(root_path, anything).and_return(root_node)
allow(root_node).to receive(:descendant_objects).and_return(dbus_objects)
# Returning an empty list for the second call to mock the effect of calling to #clear.
allow(root_node).to receive(:descendant_objects).and_return(dbus_objects, [])

allow(service).to receive(:export)
allow(service).to receive(:unexport)
Expand All @@ -102,57 +103,48 @@

let(:devicegraph) { Y2Storage::StorageManager.instance.probed }

context "if a device is not exported yet" do
let(:dbus_objects) { [] }
let(:dbus_objects) { [dbus_object1, dbus_object2] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sda, subject.path_for(sda), subject) }
let(:dbus_object2) { Agama::DBus::Storage::Device.new(sdb, subject.path_for(sdb), subject) }
let(:sda) { devicegraph.find_by_name("/dev/sda") }
let(:sdb) { devicegraph.find_by_name("/dev/sdb") }

it "exports a D-Bus object" do
sda = devicegraph.find_by_name("/dev/sda")
sdb = devicegraph.find_by_name("/dev/sdb")
md0 = devicegraph.find_by_name("/dev/md0")
sda1 = devicegraph.find_by_name("/dev/sda1")
sda2 = devicegraph.find_by_name("/dev/sda2")
md0p1 = devicegraph.find_by_name("/dev/md0p1")

expect(service).to export_object("#{root_path}/#{sda.sid}")
expect(service).to export_object("#{root_path}/#{sdb.sid}")
expect(service).to export_object("#{root_path}/#{md0.sid}")
expect(service).to export_object("#{root_path}/#{sda1.sid}")
expect(service).to export_object("#{root_path}/#{sda2.sid}")
expect(service).to export_object("#{root_path}/#{md0p1.sid}")
expect(service).to_not receive(:export)
it "unexports the current D-Bus objects" do
expect(service).to unexport_object("#{root_path}/#{sda.sid}")
expect(service).to unexport_object("#{root_path}/#{sdb.sid}")

subject.update(devicegraph)
end
subject.update(devicegraph)
end

context "if a device is already exported" do
let(:dbus_objects) { [dbus_object1] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sda, subject.path_for(sda), subject) }
let(:sda) { devicegraph.find_by_name("/dev/sda") }

it "does not export a D-Bus object" do
expect(service).to_not export_object("#{root_path}/#{sda.sid}")

subject.update(devicegraph)
end

it "updates the D-Bus object" do
expect(dbus_object1.storage_device).to equal(sda)
it "exports disk devices and partitions" do
md0 = devicegraph.find_by_name("/dev/md0")
sda1 = devicegraph.find_by_name("/dev/sda1")
sda2 = devicegraph.find_by_name("/dev/sda2")
md0p1 = devicegraph.find_by_name("/dev/md0p1")

expect(service).to export_object("#{root_path}/#{sda.sid}")
expect(service).to export_object("#{root_path}/#{sdb.sid}")
expect(service).to export_object("#{root_path}/#{md0.sid}")
expect(service).to export_object("#{root_path}/#{sda1.sid}")
expect(service).to export_object("#{root_path}/#{sda2.sid}")
expect(service).to export_object("#{root_path}/#{md0p1.sid}")
expect(service).to_not receive(:export)

subject.update(devicegraph)
end

subject.update(devicegraph)
context "if there are LVM volume groups" do
let(:scenario) { "trivial_lvm.yml" }

expect(dbus_object1.storage_device).to_not equal(sda)
expect(dbus_object1.storage_device.sid).to equal(sda.sid)
end
end
let(:dbus_objects) { [] }

context "if an exported D-Bus object does not represent any of the current devices" do
let(:dbus_objects) { [dbus_object1] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sdd, subject.path_for(sdd), subject) }
let(:sdd) { instance_double(Y2Storage::Disk, sid: 1, is?: false, filesystem: false) }
it "exports the LVM volume groups and the logical volumes" do
vg0 = devicegraph.find_by_name("/dev/vg0")
lv1 = devicegraph.find_by_name("/dev/vg0/lv1")

it "unexports the D-Bus object" do
expect(service).to unexport_object("#{root_path}/1")
expect(service).to receive(:export)
expect(service).to export_object("#{root_path}/#{vg0.sid}")
expect(service).to export_object("#{root_path}/#{lv1.sid}")

subject.update(devicegraph)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@
end
end

describe "#block_start" do
before do
allow(device).to receive(:start).and_return(345)
end

it "returns the first block of the region" do
expect(subject.block_start).to eq(345)
end
end

describe "#block_active" do
before do
allow(device).to receive(:active?).and_return(true)
Expand All @@ -43,6 +53,12 @@
end
end

describe "#block_encrypted" do
it "returns whether the device is encrypted" do
expect(subject.block_encrypted).to eq(false)
end
end

describe "#block_udev_ids" do
before do
allow(device).to receive(:udev_ids).and_return(udev_ids)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# frozen_string_literal: true

# Copyright (c) [2024] SUSE LLC
#
# All Rights Reserved.
#
# This program is free software; you can redistribute it and/or modify it
# under the terms of version 2 of the GNU General Public License as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, contact SUSE LLC.
#
# To contact SUSE LLC about this file by physical or electronic mail, you may
# find current contact information at www.suse.com.

require_relative "../../../../../test_helper"

shared_examples "LVM.VolumeGroup interface" do
describe "LVM.VolumeGroup D-Bus interface" do
let(:scenario) { "trivial_lvm.yml" }

let(:device) { devicegraph.find_by_name("/dev/vg0") }

describe "#lvm_vg_name" do
it "returns the name of the volume group" do
expect(subject.lvm_vg_name).to eq("/dev/vg0")
end
end

describe "#lvm_vg_size" do
before do
allow(device).to receive(:size).and_return(size)
end

let(:size) { Y2Storage::DiskSize.new(1024) }

it "returns the size in bytes" do
expect(subject.lvm_vg_size).to eq(1024)
end
end

describe "#lvm_vg_pvs" do
it "returns the D-Bus path of the physical volumes" do
sda1 = devicegraph.find_by_name("/dev/sda1")

expect(subject.lvm_vg_pvs).to contain_exactly(tree.path_for(sda1))
end
end

describe "#lvm_vg_lvs" do
it "returns the D-Bus path of the logical volumes" do
lv1 = devicegraph.find_by_name("/dev/vg0/lv1")

expect(subject.lvm_vg_lvs).to contain_exactly(tree.path_for(lv1))
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
# find current contact information at www.suse.com.

require_relative "../../../../../test_helper"
require "y2storage/disk_size"
require "y2storage/partition_tables/partition_slot"
require "y2storage/region"

shared_examples "PartitionTable interface" do
describe "PartitionTable D-Bus interface" do
Expand All @@ -39,5 +42,34 @@
expect(subject.partition_table_partitions).to contain_exactly(tree.path_for(md0p1))
end
end

describe "#partition_table_unused_slots" do
before do
allow(device).to receive(:partition_table).and_return(partition_table)
allow(partition_table).to receive(:unused_partition_slots).and_return(unused_slots)
end

let(:partition_table) { device.partition_table }

let(:unused_slots) do
[
instance_double(Y2Storage::PartitionTables::PartitionSlot, region: region1),
instance_double(Y2Storage::PartitionTables::PartitionSlot, region: region2)
]
end

let(:region1) do
instance_double(Y2Storage::Region, start: 234, size: Y2Storage::DiskSize.new(1024))
end

let(:region2) do
instance_double(Y2Storage::Region, start: 987, size: Y2Storage::DiskSize.new(2048))
end

it "returns the information about the unused slots" do
md0p1 = devicegraph.find_by_name("/dev/md0p1")
expect(subject.partition_table_unused_slots).to contain_exactly([234, 1024], [987, 2048])
end
end
end
end
10 changes: 8 additions & 2 deletions service/test/agama/dbus/storage/proposal_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,27 +257,33 @@

let(:action1) do
instance_double(Y2Storage::CompoundAction,
sentence: "test1", device_is?: false, delete?: false)
sentence: "test1", target_device: device1, device_is?: false, delete?: false)
end

let(:action2) do
instance_double(Y2Storage::CompoundAction,
sentence: "test2", device_is?: true, delete?: true)
sentence: "test2", target_device: device2, device_is?: true, delete?: true)
end

let(:device1) { instance_double(Y2Storage::Device, sid: 1) }

let(:device2) { instance_double(Y2Storage::Device, sid: 2) }

it "returns a list with a hash for each action" do
expect(subject.actions.size).to eq(2)
expect(subject.actions).to all(be_a(Hash))

action1, action2 = subject.actions

expect(action1).to eq({
"Device" => 1,
"Text" => "test1",
"Subvol" => false,
"Delete" => false
})

expect(action2).to eq({
"Device" => 2,
"Text" => "test2",
"Subvol" => true,
"Delete" => true
Expand Down
24 changes: 24 additions & 0 deletions service/test/fixtures/trivial_lvm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
---
- disk:
name: /dev/sda
size: 200 GiB
partition_table: gpt
partitions:

- partition:
size: unlimited
name: /dev/sda1
id: lvm

- lvm_vg:
vg_name: vg0
lvm_pvs:
- lvm_pv:
blk_device: /dev/sda1

lvm_lvs:
- lvm_lv:
size: unlimited
lv_name: lv1
file_system: btrfs
mount_point: /

0 comments on commit 14cfa68

Please sign in to comment.