Skip to content

Commit

Permalink
Use new service widget
Browse files Browse the repository at this point in the history
  • Loading branch information
joseivanlopez committed Aug 10, 2018
1 parent 776030d commit 7016920
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 33 deletions.
40 changes: 11 additions & 29 deletions src/include/slp-server/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
# Authors: Zugec Michal <mzugec@suse.cz>
#
# $Id$

require "cwm/service_widget"

module Yast
module SlpServerDialogsInclude
def initialize_slp_server_dialogs(include_target)
Expand All @@ -16,7 +19,6 @@ def initialize_slp_server_dialogs(include_target)
Yast.import "SlpServer"
Yast.import "CWMTab"
Yast.import "CWM"
Yast.import "CWMServiceStart"
Yast.import "CWMFirewallInterfaces"
Yast.import "TablePopup"
Yast.import "LogView"
Expand All @@ -34,34 +36,7 @@ def initialize_slp_server_dialogs(include_target)


@widgets = {
# service status widget
"auto_start_up" => CWMServiceStart.CreateAutoStartWidget(
{
"get_service_auto_start" => fun_ref(
SlpServer.method(:GetStartService),
"boolean ()"
),
"set_service_auto_start" => fun_ref(
SlpServer.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")
)
}
),
"auto_start_up" => service_widget.cwm_definition,
# firewall widget
"firewall" => CWMFirewallInterfaces.CreateOpenFirewallWidget(
# bnc#825505 - fixed not working checkbox due to unknown firewall service
Expand Down Expand Up @@ -307,6 +282,13 @@ def initialize_slp_server_dialogs(include_target)
}
end

# Widget to define state and start mode of the service
#
# @return [::CWM::ServiceWidget]
def service_widget
@service ||= ::CWM::ServiceWidget.new(SlpServer.service)
end

def initExpert(key)
TablePopup.TableInit(CWM.GetProcessedWidget, key)

Expand Down
37 changes: 33 additions & 4 deletions src/modules/SlpServer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
# Representation of the configuration of slp-server.
# Input and output routines.
require "yast"
require "yast2/system_service"

module Yast
class SlpServerClass < Module
Expand All @@ -25,6 +26,7 @@ def main
Yast.import "Package"
Yast.import "Popup"
Yast.import "Confirm"
Yast.import "Mode"
Yast.import "Map"
Yast.import "NetworkService"

Expand Down Expand Up @@ -73,6 +75,13 @@ def main
@reg_files = []
end

# Service to configure
#
# @return [Yast2::SystemService]
def service
@service ||= Yast2::SystemService.find("slpd")
end

# Abort function
# @return [Boolean] return true if abort
def Abort
Expand Down Expand Up @@ -235,7 +244,6 @@ def Read
return false if !Confirm.MustBeRoot
return false if !NetworkService.RunningNetworkPopup
Progress.NextStage
return false if false
Builtins.sleep(sl)

Progress.set(false)
Expand Down Expand Up @@ -309,15 +317,15 @@ def Write
Progress.set(true)

Progress.NextStage

# Error message
Report.Error(_("Cannot write settings.")) if !WriteGlobalConfig()
Report.Error(_("Cannot write settings.")) unless save_settings

Builtins.sleep(sl)

# run SuSEconfig
return false if Abort()
Progress.NextStage
# Error message
return false if false
Builtins.sleep(sl)

return false if Abort()
Expand All @@ -330,6 +338,25 @@ def Write
true
end

# Saves service settings
#
# @return [Boolean] true if settings were correctly saved; false otherwise
def save_settings
WriteGlobalConfig() && save_status
end

# Saves service status (start mode and starts/stops the service)
#
# @note For AutoYaST and for command line actions, it does not save the service,
# due to the {#service} is not used in that cases.
#
# @return [Boolean]
def save_status
return true if Mode.auto || Mode.commandline

service.save
end

# Get all slp-server settings from the first parameter
# (For use by autoinstallation.)
# @param [Hash] settings The YCP structure to be imported.
Expand Down Expand Up @@ -400,12 +427,14 @@ def AutoPackages
{ "install" => [], "remove" => [] }
end

# @deprecated
def GetStartService
@serviceStatus = Service.Enabled("slpd")
Builtins.y2milestone("Status of slpd service %1", @serviceStatus)
@serviceStatus
end

# @deprecated
def SetStartService(status)
Builtins.y2milestone("Set service status %1", status)
if status == true
Expand Down
72 changes: 72 additions & 0 deletions test/slp_server_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,76 @@
end
end
end

describe "#Write" do
subject(:slp_server) { Yast::SlpServerClass.new }

before do
allow(Yast::Progress).to receive(:New)
allow(Yast::Progress).to receive(:NextStage)
allow(Yast::Progress).to receive(:set)

allow(Yast::Builtins).to receive(:sleep)

allow(Yast::SuSEFirewall).to receive(:Write)

allow(Yast2::SystemService).to receive(:find).with("slpd").and_return(service)

allow(Yast::Mode).to receive(:auto) { auto }
allow(Yast::Mode).to receive(:commandline) { commandline }

slp_server.main
end

let(:service) { instance_double(Yast2::SystemService, save: true) }

let(:auto) { false }
let(:commandline) { false }

shared_examples "old behavior" do
it "does not save the system service" do
allow(slp_server).to receive(:WriteGlobalConfig).and_return(true)

expect(service).to_not receive(:save)

slp_server.Write
end

it "calls to :WriteGlobalConfig" do
expect(slp_server).to receive(:WriteGlobalConfig).and_return(true)

slp_server.Write
end
end

context "when running in command line" do
let(:commandline) { true }

include_examples "old behavior"
end

context "when running in AutoYaST mode" do
let(:auto) { true }

include_examples "old behavior"
end

context "when running in normal mode" do
before do
allow(slp_server).to receive(:WriteGlobalConfig).and_return(true)
end

it "calls to :WriteGlobalConfig" do
expect(slp_server).to receive(:WriteGlobalConfig)

slp_server.Write
end

it "saves the system service" do
expect(service).to receive(:save)

slp_server.Write
end
end
end
end

0 comments on commit 7016920

Please sign in to comment.