Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Mar 8, 2024
1 parent bf0fa83 commit 464a0a2
Show file tree
Hide file tree
Showing 9 changed files with 210 additions and 18 deletions.
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/storage/interfaces/device/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion service/lib/agama/dbus/storage/interfaces/device/device.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
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_relative "../../../../../test_helper"
require "y2storage/filesystem_label"

shared_examples "Filesystem interface" do
describe "Filesystem D-Bus interface" do
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 464a0a2

Please sign in to comment.