Skip to content

Commit

Permalink
Merge 0396ebc into 09ffd50
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 13, 2018
2 parents 09ffd50 + 0396ebc commit aff3aed
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 193 deletions.
13 changes: 13 additions & 0 deletions package/yast2-dhcp-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
-------------------------------------------------------------------
Tue Aug 13 12:00:22 UTC 2018 - dgonzalez@suse.com

- Use CWM::ServiceWidget to manage the service status
(part of fate#319428).
- 4.1.0

-------------------------------------------------------------------
Mon Aug 13 10:32:56 UTC 2018 - igonzalezsosa@suse.com

- Fix package building with yast2 4.0.84 (bsc#1104644).
- 4.0.3

-------------------------------------------------------------------
Fri Aug 3 09:39:35 UTC 2018 - igonzalezsosa@suse.com

Expand Down
10 changes: 5 additions & 5 deletions package/yast2-dhcp-server.spec
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@


Name: yast2-dhcp-server
Version: 4.0.2
Version: 4.1.0
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand All @@ -27,12 +27,12 @@ Group: System/YaST
License: GPL-2.0
BuildRequires: perl-Digest-SHA1 perl-X500-DN perl-XML-Writer docbook-xsl-stylesheets doxygen libxslt perl-XML-Writer popt-devel sgml-skel update-desktop-files yast2-perl-bindings yast2-testsuite yast2-dns-server
BuildRequires: yast2-devtools >= 3.1.10
# UI::ServiceStatus
BuildRequires: yast2 >= 3.1.161
# Yast2::ServiceWidget
BuildRequires: yast2 >= 4.1.0

Requires: perl-gettext yast2-perl-bindings bind-utils perl-X500-DN yast2-ldap perl-Digest-SHA1 perl-Parse-RecDescent
# UI::ServiceStatus
Requires: yast2 >= 3.1.161
# Yast2::ServiceWidget
Requires: yast2 >= 4.1.0
# DnsServerAPI::IsServiceConfigurableExternally
Requires: yast2-dns-server >= 2.13.16

Expand Down
82 changes: 55 additions & 27 deletions src/include/dhcp-server/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@
#
# Representation of the configuration of dhcp-server.
# Input and output routines.

require "yast2/popup"

module Yast
module DhcpServerDialogsInclude
include Yast::Logger

def initialize_dhcp_server_dialogs(include_target)
textdomain "dhcp-server"

Expand All @@ -23,6 +28,7 @@ def initialize_dhcp_server_dialogs(include_target)
Yast.import "Popup"
Yast.import "Label"
Yast.import "Confirm"
Yast.import "Mode"

@functions = { :abort => fun_ref(method(:confirmAbort), "boolean ()") }
end
Expand All @@ -47,44 +53,66 @@ def ReadDialog
end

# Write settings dialog
# @return `abort if aborted and `next otherwise
#
# @return [Symbol] :next whether configuration is saved successfully
# :back if user decided go back to change settings
# :abort otherwise
def WriteDialog
Builtins.y2milestone("Running write dialog")
Wizard.RestoreHelp(Ops.get(@HELPS, "write", ""))
ret = DhcpServer.Write
if ret && restart_after_writing?
# Restart only if it's already running
DhcpServerUI.service.try_restart
end
# yes-no popup
if !ret &&
Popup.YesNo(
_("Saving the configuration failed. Change the settings?")
)
return :back
end
ret ? :next : :abort
help_text = @HELPS.fetch("write") { "" }
Wizard.RestoreHelp(help_text)

return :next if write_settings
return :back if back_to_change_setting?
:abort
end

# Write settings without quitting
def SaveAndRestart(event)
return nil unless CWM.validate_current_widgets(event)
CWM.save_current_widgets(event)
return nil unless validate_and_save_widgets(event)

help_text = @HELPS.fetch("write") { "" }

Wizard.CreateDialog
Wizard.RestoreHelp(Ops.get(@HELPS, "write", ""))
ret = DhcpServer.Write
if ret
# Restart only if it's already running
DhcpServerUI.service.try_restart if restart_after_writing?
else
Report.Error(_("Saving the configuration failed"))
end
UI.CloseDialog
Wizard.RestoreHelp(help_text)
Report.Error(_("Saving the configuration failed")) unless write_settings
Wizard.CloseDialog

service_widget.refresh

nil
end

# Write DHCP server settings and save the service
#
# @note currently, the DhpcServer is a Perl module, reason why the write of
# settings is being performed in two separate steps.
#
# @return [Boolean] true if settings are saved successfully; false otherwise
def write_settings
DhcpServer.Write && dhcp_service.save(keep_state: Mode.auto)
end

# Shows a popup asking to user if wants to change settings
#
# @return [Boolean] true if user decides to go back to change settings; false otherwise
def back_to_change_setting?
change_settings_message = _("Saving the configuration failed. Change the settings?")
Yast2::Popup.show(change_settings_message, headline: :warning, buttons: :yes_no) == :yes
end

# Validates and saves CWM widgets
#
# @param [Hash] event map that triggered saving
#
# @return [Boolean] true when widgets pass the validaton; false otherwise
def validate_and_save_widgets(event)
return false unless CWM.validate_current_widgets(event)

CWM.save_current_widgets(event)

true
end

# Run main dialog
# @return [Symbol] for wizard sequencer
def OldMainDialog
Expand Down
38 changes: 3 additions & 35 deletions src/include/dhcp-server/dialogs2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def initialize_dhcp_server_dialogs2(include_target)
@tabs = {
"start_up" => {
"contents" => VBox(
"service_status",
"service_widget",
VSpacing(),
"use_ldap",
VSpacing(),
Expand All @@ -97,7 +97,7 @@ def initialize_dhcp_server_dialogs2(include_target)
# tree item
"tree_item_label" => _("Start-Up"),
"widget_names" => [
"service_status",
"service_widget",
"use_ldap",
"expert_settings",
"other_options",
Expand Down Expand Up @@ -192,29 +192,7 @@ def initialize_dhcp_server_dialogs2(include_target)
Builtins.union(
@widgets,
{
"auto_start_up" => CWMServiceStart.CreateAutoStartWidget(
{
"get_service_auto_start" => fun_ref(
method(:GetStartService),
"boolean ()"
),
"set_service_auto_start" => fun_ref(
method(:SetStartService),
"void (boolean)"
),
# radio button
"start_auto_button" => _("When &Booting"),
# radio button
"start_manual_button" => _("&Manually"),
"help" => Builtins.sformat(
CWMServiceStart.AutoStartHelpTemplate,
# part of help text - radio button label, NO SHORTCUT!!!
_("When Booting"),
# part of help text - radio button label, NO SHORTCUT!!!
_("Manually")
)
}
),
"auto_start_up" => service_widget.cwm_definition,
"use_ldap" => CWMServiceStart.CreateLdapWidget(
{
"get_use_ldap" => fun_ref(
Expand Down Expand Up @@ -2133,16 +2111,6 @@ def OtherOptionsStore(key, event)
nil
end

def GetStartService
DhcpServer.GetStartService
end

def SetStartService(start)
DhcpServer.SetStartService(start)

nil
end

# Common Config Dialog
# @return [Symbol] for the wizard sequencer
def CommonConfigDialog
Expand Down
79 changes: 20 additions & 59 deletions src/include/dhcp-server/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
# Authors: Jiri Srain <jsrain@suse.cz>

require "yast"
require "ui/service_status"
require "yast2/system_service"
require "cwm"
require "cwm/service_widget"

# Representation of the configuration of dhcp-server.
# Input and output routines.
Expand All @@ -27,22 +29,20 @@ 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
# Returns the service for DHCP
#
# @return [::UI::ServiceStatus] nil if the service is not found (dhcp server
# not installed)
def status_widget
return @status_widget unless @status_widget.nil?

service = DhcpServerUI.service
if service
@status_widget = ::UI::ServiceStatus.new(service, reload_flag_label: :restart)
else
nil
end
# @return [Yast2::SystemService] status service
def dhcp_service
@dhcp_service ||= Yast2::SystemService.find(DhcpServer.ServiceName)
end

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

# Function for deleting entry from section
Expand Down Expand Up @@ -855,47 +855,15 @@ def AllSettingsButtonHandle(key, event)

# Handle function for the 'Apply' button
def handle_apply(_key, event)
event_id = event["ID"]
if event_id == "apply"
SaveAndRestart(event)
end
nil
end

def init_service_status(_key)
# If UI::ServiceStatus is used, do not let DnsServer manage the service
# status, let the user decide
DhcpServer.SetWriteOnly(true)
nil
end
SaveAndRestart(event) if event["ID"] == "apply"

# 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
DhcpServer.SetModified
end
nil
end

# Store settings of the widget
# @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?)
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
# DhcpServer module
def InitWidgets
options = [
"option subnet-mask",
Expand Down Expand Up @@ -1326,16 +1294,9 @@ def InitWidgets
# it needs the "dhcp-server" package already installed in the system
# otherwise it crashes
def InitServiceWidget
return if @widgets["service_status"]

@widgets["service_status"] = {
"widget" => :custom,
"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)")
}
return if @widgets["service_widget"]

@widgets["service_widget"] = service_widget.cwm_definition
end
end
end
27 changes: 0 additions & 27 deletions src/modules/DhcpServer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1745,33 +1745,6 @@ sub Write {
SCR->Write (".sysconfig.dhcpd.DHCPD_INTERFACE", $ifaces_list);
SCR->Write (".sysconfig.dhcpd.DHCPD_OTHER_ARGS", $other_options);
SCR->Write (".sysconfig.dhcpd", undef);


if ($start_service)
{
y2milestone ("Enabling the DHCP service");
my $ret = 1;
if (! $write_only)
{
$ret = Service->Restart ($SERVICE);
}
Service->Enable ($SERVICE);
if (!$ret)
{
# error report
Report->Error (__("Error occurred while restarting the DHCP daemon."));
$ok = 0;
}
}
else
{
y2milestone ("Disabling the DHCP service");
if (! $write_only)
{
Service->Stop ($SERVICE);
}
Service->Disable ($SERVICE);
}

Progress->NextStage ();

Expand Down

0 comments on commit aff3aed

Please sign in to comment.