Skip to content

Commit

Permalink
Don't init ServiceStatus if service is not there (bsc#959730)
Browse files Browse the repository at this point in the history
  • Loading branch information
ancorgs committed Jan 7, 2016
1 parent 24f1658 commit ca35372
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
16 changes: 4 additions & 12 deletions src/include/dhcp-server/dialogs.rb
Expand Up @@ -17,6 +17,7 @@ def initialize_dhcp_server_dialogs(include_target)

Yast.import "Wizard"
Yast.import "DhcpServer"
Yast.import "DhcpServerUI"
Yast.import "CWM"

Yast.import "Popup"
Expand Down Expand Up @@ -46,9 +47,9 @@ def WriteDialog
Builtins.y2milestone("Running write dialog")
Wizard.RestoreHelp(Ops.get(@HELPS, "write", ""))
ret = DhcpServer.Write
if ret && restart?
if ret && restart_after_writing?
# Restart only if it's already running
@service.try_restart
DhcpServerUI.service.try_restart
end
# yes-no popup
if !ret &&
Expand All @@ -70,7 +71,7 @@ def SaveAndRestart(event)
ret = DhcpServer.Write
if ret
# Restart only if it's already running
@service.try_restart if restart?
DhcpServerUI.service.try_restart if restart_after_writing?
else
Report.Error(_("Saving the configuration failed"))
end
Expand Down Expand Up @@ -644,14 +645,5 @@ def ConfigTypeSwitch
return :expert if Mode.config
DhcpServer.IsConfigurationSimple ? :simple : :expert
end

private

# Checks if the service must be restarted after saving
# @return [Boolean]
def restart?
# If ServiceStatus is used, DhcpServer must be set to write-only
DhcpServer.GetWriteOnly() && @status_widget && @status_widget.reload_flag?
end
end
end
33 changes: 26 additions & 7 deletions src/include/dhcp-server/widgets.rb
Expand Up @@ -27,10 +27,22 @@ def initialize_dhcp_server_widgets(include_target)
Yast.import "TablePopup"
Yast.import "SuSEFirewall"
Yast.import "Mode"
Yast.import "DhcpServerUI"
end

# Widget to handle the status of the service
#
# @return [::UI::ServiceStatus] nil if the service is not found (dhcp server
# not installed)
def status_widget
return @status_widget unless @status_widget.nil?

# Init ServiceStatus widget
@service = SystemdService.find(DhcpServer.ServiceName())
@status_widget = ::UI::ServiceStatus.new(@service, reload_flag_label: :restart)
service = DhcpServerUI.service
if service
@status_widget = ::UI::ServiceStatus.new(service, reload_flag_label: :restart)
else
nil
end
end

# Function for deleting entry from section
Expand Down Expand Up @@ -858,7 +870,7 @@ def init_service_status(_key)
# Handle function for the ServiceStatus widget
def handle_service_status(_key, event)
event_id = event["ID"]
if @status_widget.handle_input(event_id) == :enabled_flag
if status_widget.handle_input(event_id) == :enabled_flag
DhcpServer.SetModified
end
nil
Expand All @@ -868,10 +880,17 @@ def handle_service_status(_key, event)
# @param [String] id string widget id
# @param [Hash] event map event that caused storing process
def store_service_status(_key, _event)
DhcpServer.SetStartService(@status_widget.enabled_flag?)
DhcpServer.SetStartService(status_widget.enabled_flag?)
nil
end

# Checks if the service must be restarted after saving
# @return [Boolean]
def restart_after_writing?
# If ServiceStatus is used, DhcpServer must be set to write-only
DhcpServer.GetWriteOnly() && status_widget && status_widget.reload_flag?
end

# Initialize widgets
# Create description map and copy it into appropriate variable of the
# DhcpServer module
Expand Down Expand Up @@ -1012,8 +1031,8 @@ def InitWidgets
},
"service_status" => {
"widget" => :custom,
"custom_widget" => @status_widget.widget,
"help" => @status_widget.help,
"custom_widget" => status_widget.widget,
"help" => status_widget.help,
"init" => fun_ref(method(:init_service_status), "void (string)"),
"handle" => fun_ref(method(:handle_service_status), "symbol (string, map)"),
"store" => fun_ref(method(:store_service_status), "void (string, map)")
Expand Down
8 changes: 8 additions & 0 deletions src/modules/DhcpServerUI.rb
Expand Up @@ -24,6 +24,7 @@ def main
Yast.import "Report"
Yast.import "Service"
Yast.import "SuSEFirewall"
Yast.import "SystemdService"

@current_entry_type = ""
@current_entry_id = ""
Expand Down Expand Up @@ -81,6 +82,13 @@ def DhcpServerUI
nil
end

# Object representing the DHCP service for its usage in the UI code
#
# @return [Yast::SystemdServiceClass::Service]
def service
@service ||= SystemdService.find(DhcpServer.ServiceName())
end

publish :variable => :current_entry_type, :type => "string"
publish :variable => :current_entry_id, :type => "string"
publish :variable => :current_entry_options, :type => "list <map <string, string>>"
Expand Down

0 comments on commit ca35372

Please sign in to comment.