Skip to content

Commit

Permalink
Merge 959cbfc into 62e07ed
Browse files Browse the repository at this point in the history
  • Loading branch information
dgdavid committed Aug 24, 2018
2 parents 62e07ed + 959cbfc commit 0e7ce60
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 11 deletions.
7 changes: 7 additions & 0 deletions package/yast2-dhcp-server.changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
-------------------------------------------------------------------
Fri Aug 24 14:21:19 UTC 2018 - dgonzalez@suse.com

- Do not crah when dhcpd service is not installed
(related to fate#319428)
- 4.1.2

-------------------------------------------------------------------
Thu Aug 23 09:38:55 UTC 2018 - dgonzalez@suse.com

Expand Down
2 changes: 1 addition & 1 deletion 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.1.1
Version: 4.1.2
Release: 0

BuildRoot: %{_tmppath}/%{name}-%{version}-build
Expand Down
7 changes: 5 additions & 2 deletions src/include/dhcp-server/dialogs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def SaveAndRestart(event)
Report.Error(_("Saving the configuration failed")) unless write_settings
Wizard.CloseDialog

service_widget.refresh
service_widget.refresh if service

nil
end
Expand All @@ -89,7 +89,10 @@ def SaveAndRestart(event)
#
# @return [Boolean] true if settings are saved successfully; false otherwise
def write_settings
DhcpServer.Write && dhcp_service.save(keep_state: Mode.auto)
return false unless DhcpServer.Write
return true unless service

service.save(keep_state: Mode.auto)
end

# Shows a popup asking to user if wants to change settings
Expand Down
29 changes: 25 additions & 4 deletions src/include/dhcp-server/widgets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ def initialize_dhcp_server_widgets(include_target)
# Returns the service for DHCP
#
# @return [Yast2::SystemService] status service
def dhcp_service
@dhcp_service ||= Yast2::SystemService.find(DhcpServer.ServiceName)
def service
@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)
@service_widget ||= ::CWM::ServiceWidget.new(service)
end

# Function for deleting entry from section
Expand Down Expand Up @@ -1296,7 +1296,28 @@ def InitWidgets
def InitServiceWidget
return if @widgets["service_widget"]

@widgets["service_widget"] = service_widget.cwm_definition
@widgets["service_widget"] = service_widget_content
end

private

# Returns the content to be displayed in the start up section
#
# Depending on whether the `dhcpd` is installed or not, it will return a
#
# * ServiceWidget definition (when installed)
# * Label with an information message (when not)
#
# @return [Hash]
def service_widget_content
if service
service_widget.cwm_definition
else
{
"widget" => :custom,
"custom_widget" => Left(Label(_("Service dhcpd is not installed")))
}
end
end
end
end
40 changes: 36 additions & 4 deletions test/dialog_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,39 @@ def fun_ref(*args)
before do
allow(::CWM::ServiceWidget).to receive(:new).and_return(widget)
allow(Yast2::SystemService).to receive(:find).with("dhcpd").and_return(service)
allow(Yast::DhcpServer).to receive(:Write).and_return(dhcp_configuration_written)
end

describe "#WriteDialog" do
let(:dhcp_configuration_written) { true }
let(:dhcp_configuration_written) { true }

describe "#SaveAndRestart" do
before do
allow(Yast::DhcpServer).to receive(:Write).and_return(dhcp_configuration_written)
allow(dialog).to receive(:validate_and_save_widgets).and_return(true)
allow(dialog).to receive(:write_settings).and_return(true)
end

let(:event) { { "ID": ":next"} }

context "when service is installed" do
it "refreshes the service widget" do
expect(widget).to receive(:refresh)

dialog.SaveAndRestart(event)
end
end

context "when service is not installed" do
let(:service) { nil }

it "does not refresh the service widget" do
expect(widget).to_not receive(:refresh)

dialog.SaveAndRestart(event)
end
end
end

describe "#WriteDialog" do
it "writes needed configuration" do
expect(Yast::DhcpServer).to receive(:Write)

Expand All @@ -76,7 +100,7 @@ def fun_ref(*args)
end

context "and is in `auto` Mode" do
before do
before do
allow(Yast::Mode).to receive(:auto).and_return(true)
end

Expand All @@ -86,6 +110,14 @@ def fun_ref(*args)
dialog.WriteDialog
end
end

context "and service is not installed" do
let(:service) { nil }

it "does not try to save the service" do
expect(service).to_not receive(:save)
end
end
end

context "when the configuration is not written" do
Expand Down

0 comments on commit 0e7ce60

Please sign in to comment.