Skip to content

Commit 3aa33a7

Browse files
Merge pull request #13 from ancorgs/storage-new-api-ags7
Provide information in the storage signals
2 parents 3854894 + 0f10897 commit 3aa33a7

File tree

2 files changed

+130
-14
lines changed

2 files changed

+130
-14
lines changed

service/lib/agama/dbus/storage/manager.rb

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,8 @@ def initialize(backend, logger: nil)
7878
dbus_method(:SolveConfigModel, "in model:s, out result:s") { |m| solve_config_model(m) }
7979
dbus_method(:GetProposal, "out proposal:s") { recover_proposal }
8080
dbus_method(:GetIssues, "out issues:s") { recover_issues }
81-
dbus_signal(:SystemChanged)
82-
dbus_signal(:ProposalChanged)
83-
dbus_signal(:IssuesChanged)
81+
dbus_signal(:SystemChanged, "system:s")
82+
dbus_signal(:ProposalChanged, "proposal:s")
8483
dbus_signal(:ProgressChanged, "progress:s")
8584
dbus_signal(:ProgressFinished)
8685
end
@@ -93,7 +92,7 @@ def activate
9392

9493
next_progress_step(PROBING_STEP)
9594
backend.probe
96-
self.SystemChanged
95+
emit_system_changed
9796

9897
next_progress_step(CONFIGURING_STEP)
9998
configure_with_current
@@ -108,7 +107,7 @@ def probe
108107

109108
next_progress_step(PROBING_STEP)
110109
backend.probe
111-
self.SystemChanged
110+
emit_system_changed
112111

113112
next_progress_step(CONFIGURING_STEP)
114113
configure_with_current
@@ -126,12 +125,11 @@ def configure_product(id)
126125
next_progress_step(PROBING_STEP)
127126
if !backend.probed?
128127
backend.probe
129-
self.SystemChanged
128+
emit_system_changed
130129
end
131130

132131
next_progress_step(CONFIGURING_STEP)
133-
backend.configure
134-
self.ProposalChanged
132+
calculate_proposal
135133

136134
finish_progress
137135
end
@@ -208,8 +206,7 @@ def configure(serialized_config)
208206
start_progress(1, CONFIGURING_STEP)
209207

210208
config_json = JSON.parse(serialized_config, symbolize_names: true)
211-
backend.configure(config_json)
212-
self.ProposalChanged
209+
calculate_proposal(config_json)
213210

214211
finish_progress
215212
end
@@ -227,8 +224,7 @@ def configure_with_model(serialized_model)
227224
storage_system: proposal.storage_system
228225
).convert
229226
config_json = { storage: Agama::Storage::ConfigConversions::ToJSON.new(config).convert }
230-
backend.configure(config_json)
231-
self.ProposalChanged
227+
calculate_proposal(config_json)
232228

233229
finish_progress
234230
end
@@ -400,7 +396,15 @@ def configure_with_current
400396
return unless config_json
401397

402398
configure(config_json)
403-
self.ProposalChanged
399+
end
400+
401+
# @see #configure
402+
# @see #configure_with_model
403+
#
404+
# @param config_json [Hash, nil] see Agama::Storage::Manager#configure
405+
def calculate_proposal(config_json = nil)
406+
backend.configure(config_json)
407+
self.ProposalChanged(recover_proposal)
404408
end
405409

406410
# JSON representation of the given devicegraph from StorageManager
@@ -510,6 +514,11 @@ def volume_templates
510514
end
511515
end
512516

517+
# Emits the SystemChanged signal
518+
def emit_system_changed
519+
self.SystemChanged(recover_system)
520+
end
521+
513522
def add_s390_interfaces
514523
require "agama/dbus/storage/interfaces/dasd_manager"
515524
require "agama/dbus/storage/interfaces/zfcp_manager"

service/test/agama/dbus/storage/manager_test.rb

Lines changed: 108 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,11 @@ def parse(string)
7070
end
7171

7272
before do
73-
# Speed up tests by avoding real check of TPM presence.
73+
# Speed up tests by avoiding real check of TPM presence.
7474
allow(Y2Storage::EncryptionMethod::TPM_FDE).to receive(:possible?).and_return(true)
75+
# Speed up tests by avoiding looking up by name in the system
76+
allow(Y2Storage::BlkDevice).to receive(:find_by_any_name)
77+
7578
allow(Yast::Arch).to receive(:s390).and_return false
7679
allow(backend).to receive(:on_configure)
7780
allow(backend).to receive(:on_issues_change)
@@ -786,6 +789,110 @@ def parse(string)
786789
end
787790
end
788791

792+
describe "#probe" do
793+
before do
794+
allow(subject).to receive(:SystemChanged)
795+
allow(subject).to receive(:ProgressChanged)
796+
allow(subject).to receive(:ProgressFinished)
797+
798+
allow(backend).to receive(:activated?).and_return activated
799+
allow(backend).to receive(:probe)
800+
end
801+
802+
let(:activated) { true }
803+
804+
it "triggers a new probing" do
805+
expect(backend).to receive(:probe)
806+
subject.probe
807+
end
808+
809+
context "when storage devices are already activated" do
810+
it "does not activate devices" do
811+
expect(backend).to_not receive(:activate)
812+
subject.probe
813+
end
814+
end
815+
816+
context "when storage devices are not yet activated" do
817+
let(:activated) { false }
818+
819+
it "activates the devices" do
820+
expect(backend).to receive(:activate)
821+
subject.probe
822+
end
823+
end
824+
825+
context "when no storage configuration has been set" do
826+
it "does not calculate a new proposal" do
827+
expect(backend).to_not receive(:configure)
828+
subject.probe
829+
end
830+
831+
it "does not emit a ProposalChanged signal" do
832+
expect(subject).to_not receive(:ProposalChanged)
833+
subject.probe
834+
end
835+
836+
it "emits signals for SystemChanged, ProgressChanged and ProgressFinished" do
837+
expect(subject).to receive(:SystemChanged) do |system_str|
838+
system = parse(system_str)
839+
device = system[:devices].first
840+
expect(device[:name]).to eq "/dev/sda"
841+
expect(system[:availableDrives]).to eq [device[:sid]]
842+
end
843+
expect(subject).to receive(:ProgressChanged).with(/storage configuration/i)
844+
expect(subject).to receive(:ProgressFinished)
845+
846+
subject.probe
847+
end
848+
end
849+
850+
context "when a storage configuration was previously set" do
851+
before do
852+
allow(proposal).to receive(:storage_json).and_return config_json.to_json
853+
allow(subject).to receive(:ProposalChanged)
854+
end
855+
856+
let(:config_json) do
857+
{
858+
storage: {
859+
drives: [
860+
{
861+
partitions: [
862+
{ search: "*", delete: true },
863+
{ filesystem: { path: "/" }, size: { min: "5 GiB" } }
864+
]
865+
}
866+
]
867+
}
868+
}
869+
end
870+
871+
it "re-calculates the proposal" do
872+
expect(backend).to receive(:configure).with(config_json)
873+
subject.probe
874+
end
875+
876+
it "emits signals for ProposalChanged, SystemChanged, ProgressChanged and ProgressFinished" do
877+
expect(subject).to receive(:SystemChanged) do |system_str|
878+
system = parse(system_str)
879+
device = system[:devices].first
880+
expect(device[:name]).to eq "/dev/sda"
881+
expect(system[:availableDrives]).to eq [device[:sid]]
882+
end
883+
expect(subject).to receive(:ProposalChanged) do |proposal_str|
884+
proposal = parse(proposal_str)
885+
expect(proposal[:devices]).to be_a Array
886+
expect(proposal[:actions]).to be_a Array
887+
end
888+
expect(subject).to receive(:ProgressChanged).with(/storage configuration/i)
889+
expect(subject).to receive(:ProgressFinished)
890+
891+
subject.probe
892+
end
893+
end
894+
end
895+
789896
describe "#recover_issues" do
790897
context "if no proposal has been calculated" do
791898
it "returns an empty array" do

0 commit comments

Comments
 (0)