Skip to content
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

Merged
merged 13 commits into from
Aug 14, 2018
Merged

Use the new ServiceWidget #26

merged 13 commits into from
Aug 14, 2018

Conversation

dgdavid
Copy link
Member

@dgdavid dgdavid commented Jul 27, 2018

# @return [Boolean] true if settings are saved successfully; false otherwise
def write_settings
if DhcpServer.Write
dhcp_service.save
Copy link
Member

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.

#
# @return [Yast2::SystemService] status service
def dhcp_service
@service ||= Yast2::SystemService.find(DhcpServer.ServiceName)
Copy link
Member

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

else
nil
end
@status_widget ||= dhcp_service ? Yast2::ServiceWidget.new(dhcp_service) : nil
Copy link
Member

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.

@coveralls
Copy link

coveralls commented Jul 27, 2018

Coverage Status

Coverage increased (+0.4%) to 16.345% when pulling 0620039 on feature/service-widget into 09ffd50 on master.

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
Copy link
Member

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.

"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)")
}
Copy link
Member

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.

@dgdavid dgdavid force-pushed the feature/service-widget branch 2 times, most recently from b7f35d8 to 2134df1 Compare July 31, 2018 08:09
@dgdavid dgdavid changed the title WIP: replacing ServiceStatus widget by ServiceWidget Use the new ServiceWidget Jul 31, 2018
@@ -7,7 +7,9 @@
# Authors: Jiri Srain <jsrain@suse.cz>

require "yast"
require "ui/service_status"
require "yast2/system_service"
Copy link
Member

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

@dgdavid dgdavid force-pushed the feature/service-widget branch 3 times, most recently from c44c308 to 548f7e0 Compare July 31, 2018 13:54
Wizard.RestoreHelp(help_text)

return :next if write_settings
return :back if Popup.YesNo(_("Saving the configuration failed. Change the settings?"))

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

Copy link
Member Author

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 👍


nil
end

# Write DHCP server settings and save the service
#
# NOTE: currently, the DhpcServer is a Perl module, reason why the write of

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

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.

# @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)

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

Copy link
Member Author

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

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.

Service->Stop ($SERVICE);
}
Service->Disable ($SERVICE);
if (Mode->auto() || Mode->config())

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.

@dgdavid dgdavid force-pushed the feature/service-widget branch 2 times, most recently from 68017b4 to 4bd94a0 Compare August 7, 2018 10:23
Copy link

@joseivanlopez joseivanlopez left a 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.

@dgdavid dgdavid force-pushed the feature/service-widget branch 4 times, most recently from 85af08d to 489def5 Compare August 10, 2018 12:01
imobachgs and others added 7 commits August 13, 2018 11:30
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.
@dgdavid dgdavid force-pushed the feature/service-widget branch 4 times, most recently from 74fd537 to 34fa445 Compare August 13, 2018 14:23
# @return `abort if aborted and `next otherwise
#
# @return [Symbol] :next whether configuration is saved successfully
# :back if user decided go back to change settings
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

decided to go

return :back
end
ret ? :next : :abort
help_text = @HELPS.fetch("write") { "" }
Copy link
Contributor

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", "") ?

Copy link
Member Author

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 :)

CWM.save_current_widgets(event)
return nil unless validate_and_save_widgets(event)

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

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.

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

before do
allow_any_instance_of(TestDialog).to receive(:fun_ref)
Copy link
Contributor

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.

Copy link
Member Author

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

dialog.WriteDialog
end

it "aks for changing the current settings" do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: asks

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙈

@dgdavid dgdavid merged commit 6cf1c69 into master Aug 14, 2018
@dgdavid dgdavid deleted the feature/service-widget branch August 14, 2018 07:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants