From 4b3a142a5a00ff4413f96e8395201937d80cdb82 Mon Sep 17 00:00:00 2001 From: Ancor Gonzalez Sosa Date: Mon, 1 Apr 2024 15:20:23 +0100 Subject: [PATCH] WIP: [service] More robust transport and bus checks --- .../dbus/storage/interfaces/device/drive.rb | 8 +++---- .../interfaces/device/drive_examples.rb | 22 ++++++++++++++++--- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/service/lib/agama/dbus/storage/interfaces/device/drive.rb b/service/lib/agama/dbus/storage/interfaces/device/drive.rb index bbe8223055..51c2f0d7c0 100644 --- a/service/lib/agama/dbus/storage/interfaces/device/drive.rb +++ b/service/lib/agama/dbus/storage/interfaces/device/drive.rb @@ -85,10 +85,10 @@ def drive_model # # @return [String] def drive_bus - # FIXME: not sure how robust this is (is the value always in English?) - return "" if storage_device.bus.casecmp?("none") + # FIXME: not sure whether checking for "none" is robust enough + return "" if storage_device.bus.nil? || storage_device.bus.casecmp?("none") - storage_device.bus || "" + storage_device.bus end # Bus Id for DASD @@ -114,7 +114,7 @@ def drive_transport return "" unless storage_device.respond_to?(:transport) transport = storage_device.transport - return "" if transport.is?(:unknown) + return "" if transport.nil? || transport.is?(:unknown) # FIXME: transport does not have proper i18n support at yast2-storage-ng, so we are # just duplicating some logic from yast2-storage-ng here diff --git a/service/test/agama/dbus/storage/interfaces/device/drive_examples.rb b/service/test/agama/dbus/storage/interfaces/device/drive_examples.rb index 62595298c4..42d9c082e3 100644 --- a/service/test/agama/dbus/storage/interfaces/device/drive_examples.rb +++ b/service/test/agama/dbus/storage/interfaces/device/drive_examples.rb @@ -192,13 +192,29 @@ allow(device).to receive(:transport).and_return(transport) end - let(:transport) { instance_double(Y2Storage::DataTransport, to_s: "usb") } + let(:transport) { Y2Storage::DataTransport::FCOE } it "returns the transport" do - expect(subject.drive_transport).to eq("usb") + expect(subject.drive_transport).to eq("fcoe") end - context "if transport is unknown" do + context "if transport is Unknown" do + let(:transport) { Y2Storage::DataTransport::UNKNOWN } + + it "returns an empty string" do + expect(subject.drive_transport).to eq("") + end + end + + context "if transport is USB" do + let(:transport) { Y2Storage::DataTransport::USB } + + it "returns the corresponding string" do + expect(subject.drive_transport).to eq("USB") + end + end + + context "if transport is missing" do let(:transport) { nil } it "returns an empty string" do