Skip to content

Commit

Permalink
Replacing validate_reset by supports_reset?
Browse files Browse the repository at this point in the history
  • Loading branch information
Gaurav Aradhye committed Oct 28, 2016
1 parent ff9564d commit 816cf6f
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 32 deletions.
2 changes: 1 addition & 1 deletion app/helpers/application_helper/button/instance_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ class ApplicationHelper::Button::InstanceReset < ApplicationHelper::Button::Basi

def visible?
return true if @display == "instances"
@record.is_available?(:reset)
@record.supports_reset?
end
end
17 changes: 10 additions & 7 deletions app/models/host.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,14 @@ class Host < ApplicationRecord
before_create :make_smart
after_save :process_events

supports :reset do
unsupported_reason_add(:reset, _("The Host is not configured for IPMI")) if ipmi_address.blank?
unsupported_reason_add(:reset, _("The Host has no IPMI credentials")) if authentication_type(:ipmi).nil?
if authentication_userid(:ipmi).blank? || authentication_password(:ipmi).blank?
unsupported_reason_add(:reset, _("The Host has invalid IPMI credentials"))
end
end

def self.include_descendant_classes_in_expressions?
true
end
Expand Down Expand Up @@ -256,10 +264,6 @@ def validate_stop
validate_ipmi('on')
end

def validate_reset
validate_ipmi
end

def validate_ipmi(pstate = nil)
return {:available => false, :message => "The Host is not configured for IPMI"} if ipmi_address.blank?
return {:available => false, :message => "The Host has no IPMI credentials"} if authentication_type(:ipmi).nil?
Expand Down Expand Up @@ -361,11 +365,10 @@ def ipmi_power_reset
end

def reset
msg = validate_reset
if msg[:available]
if supports_reset?
check_policy_prevent("request_host_reset", "ipmi_power_reset")
else
_log.warn("Cannot stop because <#{msg[:message]}>")
_log.warn("Cannot stop because <#{unsupported_reason(:reset)}>")
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@ module ManageIQ::Providers::Openstack::CloudManager::Vm::Operations::Guest
unsupported_reason_add(:reboot_guest, unsupported_reason(:control)) unless supports_control?
unsupported_reason_add(:reboot_guest, _("The VM is not powered on")) unless current_state == "on"
end
end

def validate_reset
validate_vm_control_powered_on
supports :reset do
unsupported_reason_add(:reset, unsupported_reason(:control)) unless supports_control?
unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on"
end
end

def raw_reboot_guest
Expand Down
4 changes: 0 additions & 4 deletions app/models/manageiq/providers/openstack/infra_manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,4 @@ def register_and_configure_nodes(nodes_json)
def validate_shutdown
{:available => false, :message => nil}
end

def validate_reset
{:available => false, :message => nil}
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ module ManageIQ::Providers::Vmware::InfraManager::Vm::Operations::Guest
end
end
end
end

def validate_standby_guest
validate_vm_control_powered_on
supports :reset do
unsupported_reason_add(:reset, unsupported_reason(:control)) unless supports_control?
unsupported_reason_add(:reset, _("The VM is not powered on")) unless current_state == "on"
end
end

def validate_reset
def validate_standby_guest
validate_vm_control_powered_on
end
end
4 changes: 0 additions & 4 deletions app/models/miq_template/operations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def validate_standby_guest
validate_invalid_for_template(_("Standby Guest Operation"))
end

def validate_reset
validate_invalid_for_template(_("Reset Operation"))
end

private

def validate_invalid_for_template(message_prefix)
Expand Down
1 change: 1 addition & 0 deletions app/models/mixins/supports_feature_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ module SupportsFeatureMixin
:refresh_new_target => 'Refresh non-existing record',
:regions => 'Regions of a Provider',
:remove_host => 'Remove Host',
:reset => 'Reset',
:resize => 'Resizing',
:retire => 'Retirement',
:smartstate_analysis => 'Smartstate Analaysis',
Expand Down
4 changes: 0 additions & 4 deletions app/models/vm/operations/guest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ def validate_standby_guest
validate_unsupported("Standby Guest Operation")
end

def validate_reset
validate_unsupported("Reset Guest Operation")
end

def raw_shutdown_guest
unless has_active_ems?
raise _("VM has no %{table}, unable to shutdown guest OS") %
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
context "when record is resetable" do
before do
@record = FactoryGirl.create(:vm_openstack)
allow(@record).to receive(:is_available?).with(:reset).and_return(true)
allow(@record).to receive(:supports_reset?).and_return(true)
end

it_behaves_like "will not be skipped for this record"
Expand All @@ -12,7 +12,7 @@
context "when record is not resetable" do
before do
@record = FactoryGirl.create(:vm_openstack)
allow(@record).to receive(:is_available?).with(:reset).and_return(false)
allow(@record).to receive(:supports_reset?).and_return(false)
end

it_behaves_like "will be skipped for this record"
Expand Down
6 changes: 3 additions & 3 deletions spec/models/host_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,9 +594,9 @@ def assert_remote_credentials_validated
end
end

describe "#validate_reset" do
it "returns available true" do
expect(host_with_ipmi.validate_reset).to eq(:available => true, :message => nil)
describe "#supports_reset" do
it "returns true for supports_reset?" do
expect(host_with_ipmi.supports_reset?).to be_truthy
end
end
end
Expand Down

0 comments on commit 816cf6f

Please sign in to comment.