-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use the new ServiceWidget #26
Conversation
src/include/dhcp-server/dialogs.rb
Outdated
# @return [Boolean] true if settings are saved successfully; false otherwise | ||
def write_settings | ||
if DhcpServer.Write | ||
dhcp_service.save |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks wrong for me. It should be part of DhcpServer. So this service belongs to backend and not UI. Ideally DhcpServer holds service and see below.
src/include/dhcp-server/widgets.rb
Outdated
# | ||
# @return [Yast2::SystemService] status service | ||
def dhcp_service | ||
@service ||= Yast2::SystemService.find(DhcpServer.ServiceName) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here I would like to ideally see just Yast::DhcpServer.service
src/include/dhcp-server/widgets.rb
Outdated
else | ||
nil | ||
end | ||
@status_widget ||= dhcp_service ? Yast2::ServiceWidget.new(dhcp_service) : nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should not silently ignore that service is missing and simply report error. As having DHCP server without service is useless.
src/include/dhcp-server/widgets.rb
Outdated
def restart_after_writing? | ||
# If ServiceStatus is used, DhcpServer must be set to write-only | ||
DhcpServer.GetWriteOnly() && status_widget && status_widget.reload_flag? | ||
nil | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
those methods is no longer needed.
src/include/dhcp-server/widgets.rb
Outdated
"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)") | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is wrong. Here it is CWM and old hash based one. So ideally you should here just do:
service_widget = CWM::ServiceWidget.new(dhcp_service)
@widgets[service_widget.widget_id] = service_widget.cwm_definitions
same as you can see in example for old hash based CWM.
b7f35d8
to
2134df1
Compare
@@ -7,7 +7,9 @@ | |||
# Authors: Jiri Srain <jsrain@suse.cz> | |||
|
|||
require "yast" | |||
require "ui/service_status" | |||
require "yast2/system_service" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a dependency to the RPM spec file on the yast2.rpm version that provides these new APIs
c44c308
to
548f7e0
Compare
src/include/dhcp-server/dialogs.rb
Outdated
Wizard.RestoreHelp(help_text) | ||
|
||
return :next if write_settings | ||
return :back if Popup.YesNo(_("Saving the configuration failed. Change the settings?")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only for your information: we have a new Yast2::Popup class. Maybe a good opportunity to use it here. You can see an example in storage-ng
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good to know, thank you 👍
src/include/dhcp-server/dialogs.rb
Outdated
|
||
nil | ||
end | ||
|
||
# Write DHCP server settings and save the service | ||
# | ||
# NOTE: currently, the DhpcServer is a Perl module, reason why the write of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: please, use @note
instead of NOTE:
to tell to YARD that this is a note. YARD will render it with a different style.
|
||
# Validates and saves CWM widgets | ||
# | ||
# @param [Hash] event map that triggered saving |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NP: please, document return value.
4a091b5
to
5429ff4
Compare
src/include/dhcp-server/dialogs.rb
Outdated
# @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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful. This Yast2::Popup
returns a Symbol (:yes, :no), so you have to check it:
Yast2::Popup.show(change_settings_message, headline: :warning, buttons: :yes_no) == :yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ooops! Thank you.
# UI::ServiceStatus | ||
BuildRequires: yast2 >= 3.1.161 | ||
# Yast2::ServiceWidget | ||
BuildRequires: yast2 >= 4.1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only BuildRequres ? I guess it also needs it as Requires.
src/modules/DhcpServer.pm
Outdated
Service->Stop ($SERVICE); | ||
} | ||
Service->Disable ($SERVICE); | ||
if (Mode->auto() || Mode->config()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would add a # TODO here with something similar to you have explained in the commit.
68017b4
to
4bd94a0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, update version and add changelog entry.
85af08d
to
489def5
Compare
Adapt old test suite to new services management (2)
Despite services will be managed by Yast2::SystemService from now on, it is necessary to keep the related Perl code for `auto` and `config` modes until them will be also managed from Ruby.
fff997c
to
7655ad6
Compare
Using the `keep_state` option of Yast2::SystemService#save method. See commit 7acbe06.
74fd537
to
34fa445
Compare
34fa445
to
0396ebc
Compare
src/include/dhcp-server/dialogs.rb
Outdated
# @return `abort if aborted and `next otherwise | ||
# | ||
# @return [Symbol] :next whether configuration is saved successfully | ||
# :back if user decided go back to change settings |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
decided to go
src/include/dhcp-server/dialogs.rb
Outdated
return :back | ||
end | ||
ret ? :next : :abort | ||
help_text = @HELPS.fetch("write") { "" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What about @HELPS.fetch("write", "")
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it is more simple and readable.
I usually use the block notation because performance: in this case the empty string only will be created if Hash has no the write
key. However, I must admit that in this case the difference it will be not significant. So, I will to change it :)
src/include/dhcp-server/dialogs.rb
Outdated
CWM.save_current_widgets(event) | ||
return nil unless validate_and_save_widgets(event) | ||
|
||
help_text = @HELPS.fetch("write") { "" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same than above. You do not need to use a block here.
test/dialog_test.rb
Outdated
let(:service) { instance_double(Yast2::SystemService, save: true, currently_active?: true) } | ||
|
||
before do | ||
allow_any_instance_of(TestDialog).to receive(:fun_ref) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of allow_any_instance_of
. Actually, its usage is discouraged. What about setting this expectation in the subject (if possible) or just adding the method to the TestDialog
class? Anyway, we are working with legacy code, so it is not that bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did not know that. Thank you.
I will to update/improve it
test/dialog_test.rb
Outdated
dialog.WriteDialog | ||
end | ||
|
||
it "aks for changing the current settings" do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typo: asks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🙈
More info: https://trello.com/c/uAe4i9Ru/107-5-fate319428-allow-socket-activation-widget