From 1ba7c2be636cf3fde2c674caeb5ef66a74fe1dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 12:09:36 +0000 Subject: [PATCH 1/6] service: Add Device interface --- .../agama/dbus/storage/interfaces/device.rb | 1 + .../dbus/storage/interfaces/device/block.rb | 10 +-- .../dbus/storage/interfaces/device/device.rb | 82 +++++++++++++++++++ .../dbus/storage/interfaces/device/lvm_vg.rb | 8 -- .../test/agama/dbus/storage/device_test.rb | 43 ++++++++++ .../interfaces/device/block_examples.rb | 6 -- .../interfaces/device/device_examples.rb | 59 +++++++++++++ .../interfaces/device/lvm_vg_examples.rb | 6 -- 8 files changed, 186 insertions(+), 29 deletions(-) create mode 100644 service/lib/agama/dbus/storage/interfaces/device/device.rb create mode 100644 service/test/agama/dbus/storage/interfaces/device/device_examples.rb diff --git a/service/lib/agama/dbus/storage/interfaces/device.rb b/service/lib/agama/dbus/storage/interfaces/device.rb index f721da72ef..478b141bd0 100644 --- a/service/lib/agama/dbus/storage/interfaces/device.rb +++ b/service/lib/agama/dbus/storage/interfaces/device.rb @@ -33,6 +33,7 @@ module Device require "agama/dbus/storage/interfaces/device/block" require "agama/dbus/storage/interfaces/device/component" +require "agama/dbus/storage/interfaces/device/device" require "agama/dbus/storage/interfaces/device/drive" require "agama/dbus/storage/interfaces/device/filesystem" require "agama/dbus/storage/interfaces/device/lvm_vg" diff --git a/service/lib/agama/dbus/storage/interfaces/device/block.rb b/service/lib/agama/dbus/storage/interfaces/device/block.rb index fa7c3e301b..def101b5de 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/block.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/block.rb @@ -44,13 +44,6 @@ def self.apply?(storage_device) BLOCK_INTERFACE = "org.opensuse.Agama.Storage1.Block" private_constant :BLOCK_INTERFACE - # Name of the block device - # - # @return [String] e.g., "/dev/sda" - def block_name - storage_device.name - end - # Position of the first block of the region. # # @return [Integer] @@ -112,8 +105,7 @@ def block_systems def self.included(base) base.class_eval do - dbus_interface BLOCK_INTERFACE do - dbus_reader :block_name, "s", dbus_name: "Name" + dbus_interface BLOCK_INTERFACE do dbus_reader :block_start, "t", dbus_name: "Start" dbus_reader :block_active, "b", dbus_name: "Active" dbus_reader :block_encrypted, "b", dbus_name: "Encrypted" diff --git a/service/lib/agama/dbus/storage/interfaces/device/device.rb b/service/lib/agama/dbus/storage/interfaces/device/device.rb new file mode 100644 index 0000000000..f10b8a1829 --- /dev/null +++ b/service/lib/agama/dbus/storage/interfaces/device/device.rb @@ -0,0 +1,82 @@ +# 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 "dbus" +require "y2storage/device_description" + +module Agama + module DBus + module Storage + module Interfaces + module Device + # Interface for a device. + # + # @note This interface is intended to be included by {Agama::DBus::Storage::Device}. + module Device + # Whether this interface should be implemented for the given device. + # + # @note All devices implement this interface. + # + # @param _storage_device [Y2Storage::Device] + # @return [Boolean] + def self.apply?(_storage_device) + true + end + + DEVICE_INTERFACE = "org.opensuse.Agama.Storage1.Device" + private_constant :DEVICE_INTERFACE + + # sid of the device. + # + # @return [Integer] + def device_sid + storage_device.sid + end + + # Name of the device. + # + # @return [String] e.g., "/dev/sda". + def device_name + storage_device.name + end + + # Description of the device. + # + # @return [String] e.g., "EXT4 Partition". + def device_description + Y2Storage::DeviceDescription.new(storage_device).to_s + end + + def self.included(base) + base.class_eval do + dbus_interface DEVICE_INTERFACE do + dbus_reader :device_sid, "u", dbus_name: "SID" + dbus_reader :device_name, "s", dbus_name: "Name" + dbus_reader :device_description, "s", dbus_name: "Description" + end + end + end + end + end + end + end + end +end diff --git a/service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb b/service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb index b69b84a5f5..8d219fc6dd 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb @@ -44,13 +44,6 @@ def self.apply?(storage_device) VOLUME_GROUP_INTERFACE = "org.opensuse.Agama.Storage1.LVM.VolumeGroup" private_constant :VOLUME_GROUP_INTERFACE - # Name of the volume group - # - # @return [String] e.g., "/dev/mapper/vg0" - def lvm_vg_name - storage_device.name - end - # Size of the volume group in bytes # # @return [Integer] @@ -75,7 +68,6 @@ def lvm_vg_lvs def self.included(base) base.class_eval 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" dbus_reader :lvm_vg_lvs, "ao", dbus_name: "LogicalVolumes" diff --git a/service/test/agama/dbus/storage/device_test.rb b/service/test/agama/dbus/storage/device_test.rb index f67ecaaa8a..b7a8f42df6 100644 --- a/service/test/agama/dbus/storage/device_test.rb +++ b/service/test/agama/dbus/storage/device_test.rb @@ -23,6 +23,7 @@ require_relative "../../storage/storage_helpers" require_relative "./interfaces/device/block_examples" require_relative "./interfaces/device/component_examples" +require_relative "./interfaces/device/device_examples" require_relative "./interfaces/device/drive_examples" require_relative "./interfaces/device/filesystem_examples" require_relative "./interfaces/device/lvm_vg_examples" @@ -66,6 +67,10 @@ let(:device) { devicegraph.find_by_name("/dev/sda") } + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + it "defines the Drive interface" do expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Drive") end @@ -80,6 +85,10 @@ let(:device) { devicegraph.dm_raids.first } + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + it "defines the Drive interface" do expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Drive") end @@ -98,6 +107,10 @@ let(:device) { devicegraph.md_raids.first } + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + it "does not define the Drive interface" do expect(subject).to_not include_dbus_interface("org.opensuse.Agama.Storage1.Drive") end @@ -116,6 +129,14 @@ let(:device) { devicegraph.find_by_name("/dev/vg0") } + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + + it "does not define the Drive interface" do + expect(subject).to_not include_dbus_interface("org.opensuse.Agama.Storage1.Drive") + end + it "defines the LVM.VolumeGroup interface" do expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.LVM.VolumeGroup") end @@ -141,8 +162,30 @@ .to_not include_dbus_interface("org.opensuse.Agama.Storage1.PartitionTable") end end + + context "when the device is formatted" do + let(:scenario) { "multipath-formatted.xml" } + + let(:device) { devicegraph.find_by_name("/dev/mapper/0QEMU_QEMU_HARDDISK_mpath1") } + + it "defines the Filesystem interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Filesystem") + end + end + + context "when the device is no formatted" do + let(:scenario) { "partitioned_md.yml" } + + let(:device) { devicegraph.find_by_name("/dev/sda") } + + it "does not define the Filesystem interface" do + expect(subject).to_not include_dbus_interface("org.opensuse.Agama.Storage1.Filesystem") + end + end end + include_examples "Device interface" + include_examples "Drive interface" include_examples "RAID interface" diff --git a/service/test/agama/dbus/storage/interfaces/device/block_examples.rb b/service/test/agama/dbus/storage/interfaces/device/block_examples.rb index 6211a2d913..ba3ec052a9 100644 --- a/service/test/agama/dbus/storage/interfaces/device/block_examples.rb +++ b/service/test/agama/dbus/storage/interfaces/device/block_examples.rb @@ -27,12 +27,6 @@ let(:device) { devicegraph.find_by_name("/dev/sda") } - describe "#block_name" do - it "returns the name of the device" do - expect(subject.block_name).to eq("/dev/sda") - end - end - describe "#block_start" do before do allow(device).to receive(:start).and_return(345) diff --git a/service/test/agama/dbus/storage/interfaces/device/device_examples.rb b/service/test/agama/dbus/storage/interfaces/device/device_examples.rb new file mode 100644 index 0000000000..2afc123152 --- /dev/null +++ b/service/test/agama/dbus/storage/interfaces/device/device_examples.rb @@ -0,0 +1,59 @@ +# 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" +require "y2storage/device_description" + +shared_examples "Device interface" do + describe "Device D-Bus interface" do + let(:scenario) { "partitioned_md.yml" } + + let(:device) { devicegraph.find_by_name("/dev/sda") } + + describe "#device_sid" do + before do + allow(device).to receive(:sid).and_return(123) + end + + it "returns the SID of the device" do + expect(subject.device_sid).to eq(123) + end + end + + describe "#device_name" do + it "returns the name of the device" do + expect(subject.device_name).to eq("/dev/sda") + end + end + + describe "#device_description" do + before do + allow(Y2Storage::DeviceDescription).to receive(:new).with(device).and_return(description) + end + + let(:description) { instance_double(Y2Storage::DeviceDescription, to_s: "test") } + + it "returns the description of the device" do + expect(subject.device_description).to eq("test") + end + end + end +end diff --git a/service/test/agama/dbus/storage/interfaces/device/lvm_vg_examples.rb b/service/test/agama/dbus/storage/interfaces/device/lvm_vg_examples.rb index ad646ca618..2e716acde5 100644 --- a/service/test/agama/dbus/storage/interfaces/device/lvm_vg_examples.rb +++ b/service/test/agama/dbus/storage/interfaces/device/lvm_vg_examples.rb @@ -27,12 +27,6 @@ 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) From f94680dd17b64a9e546b582e56167b2df64c4c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 12:12:32 +0000 Subject: [PATCH 2/6] service: Add Partition interface --- .../agama/dbus/storage/interfaces/device.rb | 1 + .../storage/interfaces/device/partition.rb | 74 +++++++++++++++++++ .../test/agama/dbus/storage/device_test.rb | 25 +++++++ .../interfaces/device/partition_examples.rb | 48 ++++++++++++ 4 files changed, 148 insertions(+) create mode 100644 service/lib/agama/dbus/storage/interfaces/device/partition.rb create mode 100644 service/test/agama/dbus/storage/interfaces/device/partition_examples.rb diff --git a/service/lib/agama/dbus/storage/interfaces/device.rb b/service/lib/agama/dbus/storage/interfaces/device.rb index 478b141bd0..374c0b6188 100644 --- a/service/lib/agama/dbus/storage/interfaces/device.rb +++ b/service/lib/agama/dbus/storage/interfaces/device.rb @@ -39,5 +39,6 @@ module Device require "agama/dbus/storage/interfaces/device/lvm_vg" require "agama/dbus/storage/interfaces/device/md" require "agama/dbus/storage/interfaces/device/multipath" +require "agama/dbus/storage/interfaces/device/partition" require "agama/dbus/storage/interfaces/device/partition_table" require "agama/dbus/storage/interfaces/device/raid" diff --git a/service/lib/agama/dbus/storage/interfaces/device/partition.rb b/service/lib/agama/dbus/storage/interfaces/device/partition.rb new file mode 100644 index 0000000000..050d836663 --- /dev/null +++ b/service/lib/agama/dbus/storage/interfaces/device/partition.rb @@ -0,0 +1,74 @@ +# 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 "dbus" + +module Agama + module DBus + module Storage + module Interfaces + module Device + # Interface for partition. + # + # @note This interface is intended to be included by {Agama::DBus::Storage::Device} if + # needed. + module Partition + # Whether this interface should be implemented for the given device. + # + # @note Partitions implement this interface. + # + # @param storage_device [Y2Storage::Device] + # @return [Boolean] + def self.apply?(storage_device) + storage_device.is?(:partition) + end + + PARTITION_INTERFACE = "org.opensuse.Agama.Storage1.Partition" + private_constant :PARTITION_INTERFACE + + # Device hosting the partition table of this partition. + # + # @return [Array<::DBus::ObjectPath>] + def partition_device + tree.path_for(storage_device.partitionable) + end + + # Whether it is a (valid) EFI System partition + # + # @return [Boolean] + def partition_efi + storage_device.efi_system? + end + + def self.included(base) + base.class_eval do + dbus_interface PARTITION_INTERFACE do + dbus_reader :partition_device, "o", dbus_name: "Device" + dbus_reader :partition_efi, "b", dbus_name: "EFI" + end + end + end + end + end + end + end + end +end diff --git a/service/test/agama/dbus/storage/device_test.rb b/service/test/agama/dbus/storage/device_test.rb index b7a8f42df6..afa44307ff 100644 --- a/service/test/agama/dbus/storage/device_test.rb +++ b/service/test/agama/dbus/storage/device_test.rb @@ -29,6 +29,7 @@ require_relative "./interfaces/device/lvm_vg_examples" require_relative "./interfaces/device/md_examples" require_relative "./interfaces/device/multipath_examples" +require_relative "./interfaces/device/partition_examples" require_relative "./interfaces/device/partition_table_examples" require_relative "./interfaces/device/raid_examples" require "agama/dbus/storage/device" @@ -142,6 +143,28 @@ end end + context "when the given device is a partition" do + let(:scenario) { "partitioned_md.yml" } + + let(:device) { devicegraph.find_by_name("/dev/sda1") } + + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + + it "defines the Block interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Block") + end + + it "does not define the Drive interface" do + expect(subject).to_not include_dbus_interface("org.opensuse.Agama.Storage1.Drive") + end + + it "defines the Partition interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Partition") + end + end + context "when the given device has a partition table" do let(:scenario) { "partitioned_md.yml" } @@ -198,6 +221,8 @@ include_examples "LVM.VolumeGroup interface" + include_examples "Partition interface" + include_examples "PartitionTable interface" include_examples "Filesystem interface" diff --git a/service/test/agama/dbus/storage/interfaces/device/partition_examples.rb b/service/test/agama/dbus/storage/interfaces/device/partition_examples.rb new file mode 100644 index 0000000000..f99b71d523 --- /dev/null +++ b/service/test/agama/dbus/storage/interfaces/device/partition_examples.rb @@ -0,0 +1,48 @@ +# 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 "Partition interface" do + describe "Partition D-Bus interface" do + let(:scenario) { "partitioned_md.yml" } + + let(:device) { devicegraph.find_by_name("/dev/sda1") } + + describe "#partition_device" do + it "returns the path of the host device" do + sda = devicegraph.find_by_name("/dev/sda") + + expect(subject.partition_device).to eq(tree.path_for(sda)) + end + end + + describe "#partition_efi" do + before do + allow(device).to receive(:efi_system?).and_return(true) + end + + it "returns whether it is an EFI partition" do + expect(subject.partition_efi).to eq(true) + end + end + end +end From d2ce25e03b69a76e95e656d1363dd7863fba80cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 12:13:19 +0000 Subject: [PATCH 3/6] service: Adapt Filesystem interface --- .../storage/interfaces/device/filesystem.rb | 19 +++++++--- .../interfaces/device/filesystem_examples.rb | 35 +++++++++++++++++-- 2 files changed, 46 insertions(+), 8 deletions(-) diff --git a/service/lib/agama/dbus/storage/interfaces/device/filesystem.rb b/service/lib/agama/dbus/storage/interfaces/device/filesystem.rb index 36ee17c2ea..ad066f2022 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/filesystem.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/filesystem.rb @@ -20,6 +20,7 @@ # find current contact information at www.suse.com. require "dbus" +require "y2storage/filesystem_label" module Agama module DBus @@ -51,18 +52,26 @@ def filesystem_type storage_device.filesystem.type.to_s end - # Whether the filesystem contains the directory layout of an ESP partition. + # Mount path of the file system. # - # @return [Boolean] - def filesystem_efi? - storage_device.filesystem.efi? + # @return [String] Empty if not mounted. + def filesystem_mount_path + storage_device.filesystem.mount_path || "" + end + + # Label of the file system. + # + # @return [String] Empty if it has no label. + def filesystem_label + Y2Storage::FilesystemLabel.new(storage_device).to_s end def self.included(base) base.class_eval do dbus_interface FILESYSTEM_INTERFACE do dbus_reader :filesystem_type, "s", dbus_name: "Type" - dbus_reader :filesystem_efi?, "b", dbus_name: "EFI" + dbus_reader :filesystem_mount_path, "s", dbus_name: "MountPath" + dbus_reader :filesystem_label, "s", dbus_name: "Label" end end end diff --git a/service/test/agama/dbus/storage/interfaces/device/filesystem_examples.rb b/service/test/agama/dbus/storage/interfaces/device/filesystem_examples.rb index c581bd7668..84b8da4a10 100644 --- a/service/test/agama/dbus/storage/interfaces/device/filesystem_examples.rb +++ b/service/test/agama/dbus/storage/interfaces/device/filesystem_examples.rb @@ -20,6 +20,7 @@ # find current contact information at www.suse.com. require_relative "../../../../../test_helper" +require "y2storage/filesystem_label" shared_examples "Filesystem interface" do describe "Filesystem D-Bus interface" do @@ -33,9 +34,37 @@ end end - describe "#filesystem_efi?" do - it "returns whether the file system is an EFI" do - expect(subject.filesystem_efi?).to eq(false) + describe "#filesystem_mount_path" do + context "if the file system is mounted" do + before do + device.filesystem.mount_path = "/test" + end + + it "returns the mount path" do + expect(subject.filesystem_mount_path).to eq("/test") + end + end + + context "if the file system is not mounted" do + before do + device.filesystem.mount_path = "" + end + + it "returns empty string" do + expect(subject.filesystem_mount_path).to eq("") + end + end + end + + describe "#filesystem_label" do + before do + allow(Y2Storage::FilesystemLabel).to receive(:new).with(device).and_return(label) + end + + let(:label) { instance_double(Y2Storage::FilesystemLabel, to_s: "photos") } + + it "returns the label of the file system" do + expect(subject.filesystem_label).to eq("photos") end end end From 19f769a45a203fc76704ac8552e0949a64ac00ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 12:13:45 +0000 Subject: [PATCH 4/6] service: Update dependency --- service/package/gem2rpm.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/service/package/gem2rpm.yml b/service/package/gem2rpm.yml index fef1bc79db..9a886072bd 100644 --- a/service/package/gem2rpm.yml +++ b/service/package/gem2rpm.yml @@ -38,8 +38,7 @@ Requires: yast2-iscsi-client >= 4.5.7 Requires: yast2-network Requires: yast2-proxy - # ProposalSettings#swap_reuse - Requires: yast2-storage-ng >= 5.0.3 + Requires: yast2-storage-ng >= 5.0.8 Requires: yast2-users %ifarch s390 s390x Requires: yast2-s390 >= 4.6.4 From ba9304366cb2c822ad7277bcd983868b32916cfb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 15:55:06 +0000 Subject: [PATCH 5/6] service: Use display_name --- service/lib/agama/dbus/storage/interfaces/device/device.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/service/lib/agama/dbus/storage/interfaces/device/device.rb b/service/lib/agama/dbus/storage/interfaces/device/device.rb index f10b8a1829..6aef6084b7 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/device.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/device.rb @@ -51,11 +51,11 @@ def device_sid storage_device.sid end - # Name of the device. + # Name to represent the device. # # @return [String] e.g., "/dev/sda". def device_name - storage_device.name + storage_device.display_name || "" end # Description of the device. From aa1e7a3ec813a1a4b563a0524477fa6d35a795fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Iv=C3=A1n=20L=C3=B3pez=20Gonz=C3=A1lez?= Date: Fri, 8 Mar 2024 15:55:57 +0000 Subject: [PATCH 6/6] service: Add LogicalVolume interface --- .../agama/dbus/storage/interfaces/device.rb | 1 + .../dbus/storage/interfaces/device/lvm_lv.rb | 66 +++++++++++++++++++ .../test/agama/dbus/storage/device_test.rb | 21 ++++++ .../interfaces/device/lvm_lv_examples.rb | 38 +++++++++++ 4 files changed, 126 insertions(+) create mode 100644 service/lib/agama/dbus/storage/interfaces/device/lvm_lv.rb create mode 100644 service/test/agama/dbus/storage/interfaces/device/lvm_lv_examples.rb diff --git a/service/lib/agama/dbus/storage/interfaces/device.rb b/service/lib/agama/dbus/storage/interfaces/device.rb index 374c0b6188..6376f6a0c4 100644 --- a/service/lib/agama/dbus/storage/interfaces/device.rb +++ b/service/lib/agama/dbus/storage/interfaces/device.rb @@ -36,6 +36,7 @@ module Device require "agama/dbus/storage/interfaces/device/device" require "agama/dbus/storage/interfaces/device/drive" require "agama/dbus/storage/interfaces/device/filesystem" +require "agama/dbus/storage/interfaces/device/lvm_lv" require "agama/dbus/storage/interfaces/device/lvm_vg" require "agama/dbus/storage/interfaces/device/md" require "agama/dbus/storage/interfaces/device/multipath" diff --git a/service/lib/agama/dbus/storage/interfaces/device/lvm_lv.rb b/service/lib/agama/dbus/storage/interfaces/device/lvm_lv.rb new file mode 100644 index 0000000000..93757ffdfc --- /dev/null +++ b/service/lib/agama/dbus/storage/interfaces/device/lvm_lv.rb @@ -0,0 +1,66 @@ +# 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 "dbus" + +module Agama + module DBus + module Storage + module Interfaces + module Device + # Interface for LVM logical volume. + # + # @note This interface is intended to be included by {Agama::DBus::Storage::Device} if + # needed. + module LvmLv + # Whether this interface should be implemented for the given device. + # + # @note LVM logical volumes implement this interface. + # + # @param storage_device [Y2Storage::Device] + # @return [Boolean] + def self.apply?(storage_device) + storage_device.is?(:lvm_lv) + end + + LOGICAL_VOLUME_INTERFACE = "org.opensuse.Agama.Storage1.LVM.LogicalVolume" + private_constant :LOGICAL_VOLUME_INTERFACE + + # LVM volume group hosting the this logical volume. + # + # @return [Array<::DBus::ObjectPath>] + def lvm_lv_vg + tree.path_for(storage_device.lvm_vg) + end + + def self.included(base) + base.class_eval do + dbus_interface LOGICAL_VOLUME_INTERFACE do + dbus_reader :lvm_lv_vg, "o", dbus_name: "VolumeGroup" + end + end + end + end + end + end + end + end +end diff --git a/service/test/agama/dbus/storage/device_test.rb b/service/test/agama/dbus/storage/device_test.rb index afa44307ff..efb5ffe720 100644 --- a/service/test/agama/dbus/storage/device_test.rb +++ b/service/test/agama/dbus/storage/device_test.rb @@ -26,6 +26,7 @@ require_relative "./interfaces/device/device_examples" require_relative "./interfaces/device/drive_examples" require_relative "./interfaces/device/filesystem_examples" +require_relative "./interfaces/device/lvm_lv_examples" require_relative "./interfaces/device/lvm_vg_examples" require_relative "./interfaces/device/md_examples" require_relative "./interfaces/device/multipath_examples" @@ -143,6 +144,24 @@ end end + context "when the given device is a LVM logical volume" do + let(:scenario) { "trivial_lvm.yml" } + + let(:device) { devicegraph.find_by_name("/dev/vg0/lv1") } + + it "defines the Device interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.Device") + end + + it "does not define the Drive interface" do + expect(subject).to_not include_dbus_interface("org.opensuse.Agama.Storage1.Drive") + end + + it "defines the LVM.LogicalVolume interface" do + expect(subject).to include_dbus_interface("org.opensuse.Agama.Storage1.LVM.LogicalVolume") + end + end + context "when the given device is a partition" do let(:scenario) { "partitioned_md.yml" } @@ -221,6 +240,8 @@ include_examples "LVM.VolumeGroup interface" + include_examples "LVM.LogicalVolume interface" + include_examples "Partition interface" include_examples "PartitionTable interface" diff --git a/service/test/agama/dbus/storage/interfaces/device/lvm_lv_examples.rb b/service/test/agama/dbus/storage/interfaces/device/lvm_lv_examples.rb new file mode 100644 index 0000000000..9f96a71ecb --- /dev/null +++ b/service/test/agama/dbus/storage/interfaces/device/lvm_lv_examples.rb @@ -0,0 +1,38 @@ +# 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.LogicalVolume interface" do + describe "LVM.LogicalVolume D-Bus interface" do + let(:scenario) { "trivial_lvm.yml" } + + let(:device) { devicegraph.find_by_name("/dev/vg0/lv1") } + + describe "#lvm_lv_vg" do + it "returns the path of the host volume group" do + vg0 = devicegraph.find_by_name("/dev/vg0") + + expect(subject.lvm_lv_vg).to eq(tree.path_for(vg0)) + end + end + end +end