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

drop unsupported_reason_add #901

Merged
merged 1 commit into from
Feb 28, 2024
Merged

Conversation

kbrock
Copy link
Member

@kbrock kbrock commented Feb 24, 2024

part of:

Deprecating unsupported_reason_add. Returning the string instead

Note, these are all the same:

unsupported_reason_add(:feature, unsupported_reason(:feature2)) unless supports_feature2?
unsupported_reason_add(:feature, unsupported_reason(:feature2)) unless supports?(:feature2)
unsupported_reason(:feature2) unless supports?(:feature2)
unsupported_reason(:feature2)

@kbrock
Copy link
Member Author

kbrock commented Feb 24, 2024

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

@agrare agrare Feb 26, 2024

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)

Suggested change
'Cannot resize disks of a VM with snapshots' unless snapshots.empty?
_("Cannot resize disks of a VM with snapshots") unless snapshots.empty?

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 am unsure if we want to add gettext to all of these.
(also feel like we may want to go towards default values here)

Comment on lines 8 to 9
unsupported_reason(:control) ||
("The VM is powered on" if vm_powered_on?)
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

Comment on lines 10 to 11
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))
Copy link
Member

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

Comment on lines 32 to 33
unsupported_reason(:control) ||
(_("The VM is not powered on") unless current_state == "on")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
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

@kbrock kbrock force-pushed the unsupported_supports branch from ffab99e to cf716a5 Compare February 28, 2024 00:04
@miq-bot
Copy link
Member

miq-bot commented Feb 28, 2024

Checked commit kbrock@cf716a5 with ruby 2.7.8, rubocop 1.56.3, haml-lint 0.51.0, and yamllint
10 files checked, 1 offense detected

app/models/manageiq/providers/vmware/infra_manager/host_esx.rb

@kbrock
Copy link
Member Author

kbrock commented Feb 28, 2024

update:

  • localization x 4 (_())
  • control(:feature) => if else

@agrare agrare merged commit c4c086f into ManageIQ:master Feb 28, 2024
4 checks passed
@kbrock kbrock deleted the unsupported_supports branch February 29, 2024 14:01
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
Copy link
Member

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

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

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

Choose a reason for hiding this comment

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

same

kbrock added a commit to kbrock/manageiq-providers-vmware that referenced this pull request Jul 1, 2024
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
kbrock added a commit to kbrock/manageiq-providers-vmware that referenced this pull request Jul 1, 2024
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?'
kbrock added a commit to kbrock/manageiq-providers-vmware that referenced this pull request Jul 1, 2024
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?'
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants