Skip to content

Commit

Permalink
service: Update storage properties on software change
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed May 20, 2024
1 parent 75f70d8 commit 0761a25
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
39 changes: 31 additions & 8 deletions service/lib/agama/dbus/storage/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,15 @@ class Manager < BaseObject
def initialize(backend, logger)
super(PATH, logger: logger)
@backend = backend
@product_mount_points = read_product_mount_points
@encryption_methods = read_encryption_methods

register_storage_callbacks
register_proposal_callbacks
register_progress_callbacks
register_service_status_callbacks
register_iscsi_callbacks
register_software_callbacks

add_s390_interfaces if Yast::Arch.s390
end
Expand Down Expand Up @@ -118,18 +122,23 @@ def available_devices
proposal.available_devices.map { |d| system_devices_tree.path_for(d) }
end

# List of meaningful mount points for the current product.
# Reads the list of meaningful mount points for the current product.
#
# @return [Array<String>]
def product_mount_points
volume_templates_builder.all.map(&:mount_path).reject(&:empty?)
def read_product_mount_points
volume_templates_builder
.all
.map(&:mount_path)
.reject(&:empty?)
end

# List of possible encryption methods for the current system and product
# Reads the list of possible encryption methods for the current system and product.
#
# @return [Array<String>]
def encryption_methods
Agama::Storage::EncryptionSettings.available_methods.map { |m| m.id.to_s }
def read_encryption_methods
Agama::Storage::EncryptionSettings
.available_methods
.map { |m| m.id.to_s }
end

# Path of the D-Bus object containing the calculated proposal
Expand Down Expand Up @@ -169,9 +178,11 @@ def calculate_proposal(dbus_settings)
dbus_interface PROPOSAL_CALCULATOR_INTERFACE do
dbus_reader :available_devices, "ao"

dbus_reader :product_mount_points, "as"
# PropertiesChanged signal if the product changes, see {#register_software_callbacks}.
dbus_reader_attr_accessor :product_mount_points, "as"

dbus_reader :encryption_methods, "as"
# PropertiesChanged signal if software is probed, see {#register_software_callbacks}.
dbus_reader_attr_accessor :encryption_methods, "as"

dbus_reader :result, "o"

Expand Down Expand Up @@ -310,6 +321,18 @@ def register_iscsi_callbacks
end
end

def register_software_callbacks
backend.software.on_product_selected do
# A PropertiesChanged signal is emitted (see ::DBus::Object.dbus_reader_attr_accessor).
self.product_mount_points = read_product_mount_points
end

backend.software.on_probe_finished do
# A PropertiesChanged signal is emitted (see ::DBus::Object.dbus_reader_attr_accessor).
self.encryption_methods = read_encryption_methods
end
end

def storage_properties_changed
properties = interfaces_and_properties[STORAGE_INTERFACE]
dbus_properties_changed(STORAGE_INTERFACE, properties, [])
Expand Down
3 changes: 2 additions & 1 deletion service/test/agama/dbus/software/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@
end

describe "#probe" do
it "runs the probing, setting the service as busy meanwhile" do
it "runs the probing, setting the service as busy meanwhile, and emits a signal" do
expect(subject.service_status).to receive(:busy)
expect(backend).to receive(:probe)
expect(subject.service_status).to receive(:idle)
expect(subject).to receive(:ProbeFinished)

subject.probe
end
Expand Down
6 changes: 5 additions & 1 deletion service/test/agama/dbus/storage/manager_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,11 @@
on_sessions_change: nil)
end

let(:software) { instance_double(Agama::DBus::Clients::Software, on_product_selected: nil) }
let(:software) do
instance_double(Agama::DBus::Clients::Software,
on_product_selected: nil,
on_probe_finished: nil)
end

before do
allow(Yast::Arch).to receive(:s390).and_return false
Expand Down

0 comments on commit 0761a25

Please sign in to comment.