From 464a0a2dde30e4ec36dbbfc087fa75426061f867 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:05:21 +0000 Subject: [PATCH] WIP --- .../dbus/storage/interfaces/device/block.rb | 2 +- .../dbus/storage/interfaces/device/device.rb | 2 +- .../storage/interfaces/device/partition.rb | 2 +- .../test/agama/dbus/storage/device_test.rb | 68 +++++++++++++++++++ .../interfaces/device/block_examples.rb | 6 -- .../interfaces/device/device_examples.rb | 59 ++++++++++++++++ .../interfaces/device/filesystem_examples.rb | 35 +++++++++- .../interfaces/device/lvm_vg_examples.rb | 6 -- .../interfaces/device/partition_examples.rb | 48 +++++++++++++ 9 files changed, 210 insertions(+), 18 deletions(-) create mode 100644 service/test/agama/dbus/storage/interfaces/device/device_examples.rb create mode 100644 service/test/agama/dbus/storage/interfaces/device/partition_examples.rb diff --git a/service/lib/agama/dbus/storage/interfaces/device/block.rb b/service/lib/agama/dbus/storage/interfaces/device/block.rb index f9f79c3553..def101b5de 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/block.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/block.rb @@ -105,7 +105,7 @@ def block_systems def self.included(base) base.class_eval do - dbus_interface BLOCK_INTERFACE do + 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 index 7a1848bb93..ef60e633f8 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/device.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/device.rb @@ -67,7 +67,7 @@ def device_description def self.included(base) base.class_eval do - dbus_interface DEVICE_INTERFACE 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" diff --git a/service/lib/agama/dbus/storage/interfaces/device/partition.rb b/service/lib/agama/dbus/storage/interfaces/device/partition.rb index 39d3696bb7..050d836663 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/partition.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/partition.rb @@ -60,7 +60,7 @@ def partition_efi def self.included(base) base.class_eval do - dbus_interface PARTITION_INTERFACE do + dbus_interface PARTITION_INTERFACE do dbus_reader :partition_device, "o", dbus_name: "Device" dbus_reader :partition_efi, "b", dbus_name: "EFI" end diff --git a/service/test/agama/dbus/storage/device_test.rb b/service/test/agama/dbus/storage/device_test.rb index f67ecaaa8a..afa44307ff 100644 --- a/service/test/agama/dbus/storage/device_test.rb +++ b/service/test/agama/dbus/storage/device_test.rb @@ -23,11 +23,13 @@ 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" 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" @@ -66,6 +68,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 +86,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 +108,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,11 +130,41 @@ 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 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" } @@ -141,8 +185,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" @@ -155,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/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/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 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) 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