Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend storage D-Bus API #1082

Merged
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions service/lib/agama/dbus/storage/interfaces/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,12 @@ 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"
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"
10 changes: 1 addition & 9 deletions service/lib/agama/dbus/storage/interfaces/device/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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"
Expand Down
82 changes: 82 additions & 0 deletions service/lib/agama/dbus/storage/interfaces/device/device.rb
Original file line number Diff line number Diff line change
@@ -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
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved
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
19 changes: 14 additions & 5 deletions service/lib/agama/dbus/storage/interfaces/device/filesystem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# find current contact information at www.suse.com.

require "dbus"
require "y2storage/filesystem_label"

module Agama
module DBus
Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions service/lib/agama/dbus/storage/interfaces/device/lvm_vg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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"
joseivanlopez marked this conversation as resolved.
Show resolved Hide resolved
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"
Expand Down
74 changes: 74 additions & 0 deletions service/lib/agama/dbus/storage/interfaces/device/partition.rb
Original file line number Diff line number Diff line change
@@ -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
3 changes: 1 addition & 2 deletions service/package/gem2rpm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
68 changes: 68 additions & 0 deletions service/test/agama/dbus/storage/device_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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" }

Expand All @@ -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"
Expand All @@ -155,6 +221,8 @@

include_examples "LVM.VolumeGroup interface"

include_examples "Partition interface"

include_examples "PartitionTable interface"

include_examples "Filesystem interface"
Expand Down
Loading
Loading