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] 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