Skip to content

Commit

Permalink
service: Export staging devices
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Mar 6, 2024
1 parent 36ff75a commit fa1ace3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 46 deletions.
12 changes: 11 additions & 1 deletion service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

# Copyright (c) [2022-2023] SUSE LLC
# Copyright (c) [2022-2024] SUSE LLC
#
# All Rights Reserved.
#
Expand Down Expand Up @@ -289,6 +289,7 @@ def register_proposal_callbacks
proposal.on_calculate do
export_proposal
proposal_properties_changed
refresh_staging_devices
end
end

Expand Down Expand Up @@ -332,6 +333,11 @@ def refresh_system_devices
system_devices_tree.update(devicegraph)
end

def refresh_staging_devices
devicegraph = Y2Storage::StorageManager.instance.staging
staging_devices_tree.update(devicegraph)
end

def refresh_iscsi_nodes
nodes = backend.iscsi.nodes
iscsi_nodes_tree.update(nodes)
Expand All @@ -348,6 +354,10 @@ def system_devices_tree
@system_devices_tree ||= DevicesTree.new(@service, tree_path("system"), logger: logger)
end

def staging_devices_tree
@staging_devices_tree ||= DevicesTree.new(@service, tree_path("staging"), logger: logger)
end

def tree_path(tree_root)
File.join(PATH, tree_root)
end
Expand Down
82 changes: 37 additions & 45 deletions service/test/agama/dbus/storage/devices_tree_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
require_relative "../../../test_helper"
require_relative "../../storage/storage_helpers"
require "agama/dbus/storage/devices_tree"
require "y2storage"
require "dbus"
require "y2storage"

describe Agama::DBus::Storage::DevicesTree do
include Agama::RSpec::StorageHelpers
Expand Down Expand Up @@ -87,7 +87,8 @@
mock_storage(devicegraph: scenario)

allow(service).to receive(:get_node).with(root_path, anything).and_return(root_node)
allow(root_node).to receive(:descendant_objects).and_return(dbus_objects)
# Returning an empty list for the second call to mock the effect of calling to #clear.
allow(root_node).to receive(:descendant_objects).and_return(dbus_objects, [])

allow(service).to receive(:export)
allow(service).to receive(:unexport)
Expand All @@ -102,57 +103,48 @@

let(:devicegraph) { Y2Storage::StorageManager.instance.probed }

context "if a device is not exported yet" do
let(:dbus_objects) { [] }
let(:dbus_objects) { [dbus_object1, dbus_object2] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sda, subject.path_for(sda), subject) }
let(:dbus_object2) { Agama::DBus::Storage::Device.new(sdb, subject.path_for(sdb), subject) }
let(:sda) { devicegraph.find_by_name("/dev/sda") }
let(:sdb) { devicegraph.find_by_name("/dev/sdb") }

it "exports a D-Bus object" do
sda = devicegraph.find_by_name("/dev/sda")
sdb = devicegraph.find_by_name("/dev/sdb")
md0 = devicegraph.find_by_name("/dev/md0")
sda1 = devicegraph.find_by_name("/dev/sda1")
sda2 = devicegraph.find_by_name("/dev/sda2")
md0p1 = devicegraph.find_by_name("/dev/md0p1")

expect(service).to export_object("#{root_path}/#{sda.sid}")
expect(service).to export_object("#{root_path}/#{sdb.sid}")
expect(service).to export_object("#{root_path}/#{md0.sid}")
expect(service).to export_object("#{root_path}/#{sda1.sid}")
expect(service).to export_object("#{root_path}/#{sda2.sid}")
expect(service).to export_object("#{root_path}/#{md0p1.sid}")
expect(service).to_not receive(:export)
it "unexports the current D-Bus objects" do
expect(service).to unexport_object("#{root_path}/#{sda.sid}")
expect(service).to unexport_object("#{root_path}/#{sdb.sid}")

subject.update(devicegraph)
end
subject.update(devicegraph)
end

context "if a device is already exported" do
let(:dbus_objects) { [dbus_object1] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sda, subject.path_for(sda), subject) }
let(:sda) { devicegraph.find_by_name("/dev/sda") }

it "does not export a D-Bus object" do
expect(service).to_not export_object("#{root_path}/#{sda.sid}")

subject.update(devicegraph)
end

it "updates the D-Bus object" do
expect(dbus_object1.storage_device).to equal(sda)
it "exports disk devices and partitions" do
md0 = devicegraph.find_by_name("/dev/md0")
sda1 = devicegraph.find_by_name("/dev/sda1")
sda2 = devicegraph.find_by_name("/dev/sda2")
md0p1 = devicegraph.find_by_name("/dev/md0p1")

expect(service).to export_object("#{root_path}/#{sda.sid}")
expect(service).to export_object("#{root_path}/#{sdb.sid}")
expect(service).to export_object("#{root_path}/#{md0.sid}")
expect(service).to export_object("#{root_path}/#{sda1.sid}")
expect(service).to export_object("#{root_path}/#{sda2.sid}")
expect(service).to export_object("#{root_path}/#{md0p1.sid}")
expect(service).to_not receive(:export)

subject.update(devicegraph)
end

subject.update(devicegraph)
context "if there are LVM volume groups" do
let(:scenario) { "trivial_lvm.yml" }

expect(dbus_object1.storage_device).to_not equal(sda)
expect(dbus_object1.storage_device.sid).to equal(sda.sid)
end
end
let(:dbus_objects) { [] }

context "if an exported D-Bus object does not represent any of the current devices" do
let(:dbus_objects) { [dbus_object1] }
let(:dbus_object1) { Agama::DBus::Storage::Device.new(sdd, subject.path_for(sdd), subject) }
let(:sdd) { instance_double(Y2Storage::Disk, sid: 1, is?: false, filesystem: false) }
it "exports the LVM volume groups and the logical volumes" do
vg0 = devicegraph.find_by_name("/dev/vg0")
lv1 = devicegraph.find_by_name("/dev/vg0/lv1")

it "unexports the D-Bus object" do
expect(service).to unexport_object("#{root_path}/1")
expect(service).to receive(:export)
expect(service).to export_object("#{root_path}/#{vg0.sid}")
expect(service).to export_object("#{root_path}/#{lv1.sid}")

subject.update(devicegraph)
end
Expand Down

0 comments on commit fa1ace3

Please sign in to comment.