Skip to content

Commit

Permalink
Use CWM::ServiceWidget instead of the former CWM auto start
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 2, 2018
1 parent 94a72a5 commit 1e8e307
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 28 deletions.
40 changes: 12 additions & 28 deletions src/include/iscsi-client/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
# $Id$
#
# Main file for iscsi-client configuration. Uses all other files.

require "cwm/service_widget"

module Yast
module IscsiClientDialogsInclude
def initialize_iscsi_client_dialogs(include_target)
Expand All @@ -50,34 +53,8 @@ def initialize_iscsi_client_dialogs(include_target)
Yast.include include_target, "iscsi-client/widgets.rb"

@widgets = {
"auto_start_up" => CWMServiceStart.CreateAutoStartWidget(
{
"get_service_auto_start" => fun_ref(
IscsiClientLib.method(:GetStartService),
"boolean ()"
),
"set_service_auto_start" => fun_ref(
IscsiClientLib.method(:SetStartService),
"void (boolean)"
),
# radio button (starting SLP service - option 1)
"start_auto_button" => _(
"When &Booting"
),
# radio button (starting SLP service - option 2)
"start_manual_button" => _(
"&Manually"
),
"help" => Builtins.sformat(
CWMServiceStart.AutoStartHelpTemplate,
# part of help text, used to describe radiobuttons (matching starting SLP service but without "&")
_("When Booting"),
# part of help text, used to describe radiobuttons (matching starting SLP service but without "&")
_("Manually")
)
}
),
"isns" => {
"auto_start_up" => service_widget.cwm_definition,
"isns" => {
"widget" => :custom,
"custom_widget" => HBox(
MinWidth(
Expand Down Expand Up @@ -543,5 +520,12 @@ def ConnAuthDialog(return_to)
)
deep_copy(ret)
end

# Returns the status widget for service
#
# @return [::CWM::ServiceWidget] service status widget
def service_widget
@service_widget ||= ::CWM::ServiceWidget.new(IscsiClient.services)
end
end
end
14 changes: 14 additions & 0 deletions src/modules/IscsiClient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@
#
# Representation of the configuration of iscsi-client.
# Input and output routines.

require "yast"
require "yast2/system_service"
require "yast2/compound_service"

module Yast
class IscsiClientClass < Module
Expand Down Expand Up @@ -69,6 +72,17 @@ def main
@AbortFunction = fun_ref(method(:Modified), "boolean ()")
end

# Returns a related iSCSI services
#
# @return [Yast2::CompundService]
def services
@services ||= Yast2::CompoundService.new(
Yast2::SystemService.find("iscsi"),
Yast2::SystemService.find("iscsid"),
Yast2::SystemService.find("iscsiuio")
)
end

# Abort function
# @return [Boolean] return true if abort
def Abort
Expand Down
29 changes: 29 additions & 0 deletions test/iscsi_client_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env rspec

require_relative "./test_helper"

Yast.import "IscsiClient"

describe Yast::IscsiClient do
subject { described_class }

let(:service) { double("Yast2::SystemService", is_a?: true).as_null_object }

describe "#services" do
before do
allow(Yast2::SystemService).to receive(:find).with(anything).and_return(service)
end

it "includes iscsi, iscsid, and iscsiuio" do
expect(Yast2::SystemService).to receive(:find).with("iscsi")
expect(Yast2::SystemService).to receive(:find).with("iscsid")
expect(Yast2::SystemService).to receive(:find).with("iscsiuio")

described_class.services
end

it "returns a compound service" do
expect(subject.services).to be_a(Yast2::CompoundService)
end
end
end
26 changes: 26 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
srcdir = File.expand_path("../../src", __FILE__)
y2dirs = ENV.fetch("Y2DIR", "").split(":")
ENV["Y2DIR"] = y2dirs.unshift(srcdir).join(":")

if ENV["COVERAGE"]
require "simplecov"
SimpleCov.start do
add_filter "/test/"
end

src_location = File.expand_path("../../src", __FILE__)
# track all ruby files under src
SimpleCov.track_files("#{src_location}/**/*.rb")

# use coveralls for on-line code coverage reporting at Travis CI
if ENV["TRAVIS"]
require "coveralls"
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
SimpleCov::Formatter::HTMLFormatter,
Coveralls::SimpleCov::Formatter
]
end
end

require "rspec"
require "yast"

0 comments on commit 1e8e307

Please sign in to comment.