-
Notifications
You must be signed in to change notification settings - Fork 69
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
drop unsupported_reason_add #901
Conversation
I put the redundant return because it was more consistent |
@@ -10,7 +10,7 @@ class ManageIQ::Providers::Vmware::CloudManager::Vm < ManageIQ::Providers::Cloud | |||
supports :revert_to_snapshot | |||
supports :reconfigure_disks | |||
supports :reconfigure_disksize do | |||
unsupported_reason_add(:reconfigure_disksize, 'Cannot resize disks of a VM with snapshots') unless snapshots.empty? | |||
'Cannot resize disks of a VM with snapshots' unless snapshots.empty? |
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.
Should this have gettext wrappers? (We can probably do this in a follow-up since there are a number of these across multiple providers)
'Cannot resize disks of a VM with snapshots' unless snapshots.empty? | |
_("Cannot resize disks of a VM with snapshots") unless snapshots.empty? |
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 unsure if we want to add gettext to all of these.
(also feel like we may want to go towards default values here)
unsupported_reason(:control) || | ||
("The VM is powered on" if vm_powered_on?) |
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.
unsupported_reason(:control) || | |
("The VM is powered on" if vm_powered_on?) | |
if vm_powered_on? | |
"The VM is powered on" | |
else | |
unsupported_reason(:control) | |
end |
if !supports?(:ipmi) | ||
unsupported_reason_add(:start, unsupported_reason(:ipmi)) | ||
elsif %w[off standby].exclude?(power_state) | ||
unsupported_reason_add(:start, _("The Host is not in power state off or standby")) | ||
end | ||
unsupported_reason(:ipmi) || | ||
(_("The Host is not in power state off or standby") if %w[off standby].exclude?(power_state)) |
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.
if %w[off standby].exclude?(power_state))
_("The Host is not in power state off or standby")
else
unsupported_reason(:ipmi)
end
unsupported_reason(:control) || | ||
(_("The VM is not powered on") unless current_state == "on") |
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.
unsupported_reason(:control) || | |
(_("The VM is not powered on") unless current_state == "on") | |
if current_state == "on" | |
unsupported_reason(:control) | |
else | |
_("The VM is not powered on") | |
end |
ffab99e
to
cf716a5
Compare
Checked commit kbrock@cf716a5 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint app/models/manageiq/providers/vmware/infra_manager/host_esx.rb
|
update:
|
end | ||
end | ||
|
||
supports :shutdown_guest do | ||
unsupported_reason_add(:shutdown_guest, unsupported_reason(:control)) unless supports?(:control) | ||
reason = unsupported_reason(:control) | ||
return reason if reason |
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.
@kbrock I'm running some tests with rails 7... probably unrelated... I'm seeing a local jump error here because we're returning from within a block.
[----] E, [2024-07-01T16:07:26.262770#61590:7288] ERROR -- evm: [LocalJumpError]: unexpected return Method:[block (2 levels) in <class:LogProxy>]
[----] E, [2024-07-01T16:07:26.262895#61590:7288] ERROR -- evm: /Users/joerafaniello/.gem/ruby/3.1.5/bundler/gems/manageiq-providers-vmware-5c67447bd206/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb:20:in `block (2 levels) in <module:Guest>'
/Users/joerafaniello/Code/manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `instance_eval'
/Users/joerafaniello/Code/manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `check_supports'
/Users/joerafaniello/Code/manageiq/app/models/mixins/supports_feature_mixin.rb:71:in `supports?'
/Users/joerafaniello/Code/manageiq-ui-classic/app/helpers/application_helper/button/generic_feature_button_with_disable.rb:5:in `disabled?'
/Users/joerafaniello/Code/manageiq-ui-classic/app/helpers/application_helper/button/basic.rb:54:in `calculate_properties'
I guess we want a structure like
if reason
...
elsif current_state == "on"
else
...
end
Can you take a look?
unsupported_reason_add(:reboot, _("The Host is not connected to an active Provider")) unless has_active_ems? | ||
unsupported_reason_add(:reboot, _("The host is not in standby")) unless power_state == "standby" | ||
return _("The Host is not connected to an active Provider") unless has_active_ems? | ||
return _("The host is not in standby") unless power_state == "standby" |
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.
ah, same problem as below... return from within block
unsupported_reason_add(:exit_maint_mode, _("The Host is not connected to an active Provider")) unless has_active_ems? | ||
unsupported_reason_add(:exit_maint_mode, _("The host is not in maintenance mode")) unless power_state == "maintenance" | ||
return _("The Host is not connected to an active Provider") unless has_active_ems? | ||
return _("The host is not in maintenance mode") unless power_state == "maintenance" |
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.
These are all the same
@@ -3,37 +3,45 @@ module ManageIQ::Providers::Vmware::InfraManager::Vm::Operations::Guest | |||
|
|||
included do | |||
supports :reboot_guest do | |||
unsupported_reason_add(:reboot_guest, unsupported_reason(:control)) unless supports?(:control) | |||
reason = unsupported_reason(:control) | |||
return reason if reason |
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
return from a block behaves in strange ways. What we wanted is to return that value from the block (aka, acted like it is a proc) solution is to not use return Introduced by ManageIQ#901 Solution is to use the pattern used throughout the file
Introduced by ManageIQ#901 Return from a block behaves in strange ways. What we wanted is to return that value from the block (aka, acted like it is a proc) Solution is to change the order of the if block so we can avoid supports? and avoid setting a variable. (and obviously, avoiding the bad return) Error ----- ERROR -- evm: [LocalJumpError]: unexpected return Method:[block (2 levels) in <class:LogProxy>] ERROR -- evm: manageiq-providers-vmware/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb:20:in `block (2 levels) in <module:Guest>' manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `instance_eval' manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `check_supports' manageiq/app/models/mixins/supports_feature_mixin.rb:71:in `supports?'
Introduced by ManageIQ#901 Return from a block behaves in strange ways. What we wanted is to return that value from the block (aka, acted like it is a proc) Solution is to change the order of the if block so we can avoid supports? and avoid setting a variable. (and obviously, avoiding the bad return) Error ----- ``` ERROR -- evm: [LocalJumpError]: unexpected return Method:[block (2 levels) in <class:LogProxy>] ERROR -- evm: manageiq-providers-vmware/app/models/manageiq/providers/vmware/infra_manager/vm/operations/guest.rb:20: in `block (2 levels) in <module:Guest>' manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `instance_eval' manageiq/app/models/mixins/supports_feature_mixin.rb:113:in `check_supports' manageiq/app/models/mixins/supports_feature_mixin.rb:71:in `supports?' ```
part of:
Deprecating
unsupported_reason_add
. Returning the string insteadNote, these are all the same: