Skip to content

Commit 1a020de

Browse files
authored
Merge pull request #809 from kbrock/host_states
Move vmware Host power_state logic to vmware
2 parents 295d175 + 2064b7d commit 1a020de

File tree

2 files changed

+93
-40
lines changed
  • app/models/manageiq/providers/vmware/infra_manager
  • spec/models/manageiq/providers/vmware/infra_manager

2 files changed

+93
-40
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,29 @@ class ManageIQ::Providers::Vmware::InfraManager::Host < ::Host
22
include ManageIQ::Providers::Vmware::InfraManager::VimConnectMixin
33
include ManageIQ::Providers::Vmware::InfraManager::EmsRefObjMixin
44

5+
# overrides base start to support "standby" powerstate
6+
supports :start do
7+
if !supports?(:ipmi)
8+
unsupported_reason_add(:start, unsupported_reason(:ipmi))
9+
elsif %w[off standby].exclude?(power_state)
10+
unsupported_reason_add(:start, _("The Host is not in power state off or standby"))
11+
end
12+
end
13+
514
def connect(options = {})
615
vim_connect(options)
716
end
817

18+
def start
19+
if verbose_supports?(:start)
20+
if power_state == 'standby'
21+
check_policy_prevent("request_host_start", "vim_power_up_from_standby")
22+
else
23+
super
24+
end
25+
end
26+
end
27+
928
def provider_object(connection)
1029
api_type = connection.about["apiType"]
1130
mor =

spec/models/manageiq/providers/vmware/infra_manager/host_spec.rb

Lines changed: 74 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,90 +1,124 @@
11
describe ManageIQ::Providers::Vmware::InfraManager::Host do
2-
before(:each) do
3-
@host = FactoryBot.create(:host_vmware)
2+
include Spec::Support::SupportsHelper
3+
4+
let(:ems) { FactoryBot.create(:ems_vmware) }
5+
let(:host) { FactoryBot.create(:host_vmware, :ext_management_system => ems) }
6+
7+
describe "supports :start" do
8+
let(:host) { FactoryBot.create(:host_vmware, :ext_management_system => ems, :power_state => power_state) }
9+
10+
before { EvmSpecHelper.local_miq_server }
11+
12+
context "when it does not support ipmi" do
13+
before do
14+
stub_supports_all_others(Host)
15+
stub_supports_not(Host, :ipmi)
16+
end
17+
18+
let(:power_state) { "off" }
19+
it { expect(host.supports?(:start)).to be_falsey }
20+
end
21+
22+
context "when it supports ipmi" do
23+
before do
24+
stub_supports_all_others(Host)
25+
stub_supports(Host, :ipmi)
26+
end
27+
28+
context "when off" do
29+
let(:power_state) { "off" }
30+
it { expect(host.supports?(:start)).to be_truthy }
31+
end
32+
33+
context "when on" do
34+
let(:power_state) { "on" }
35+
it { expect(host.supports?(:start)).to be_falsey }
36+
end
37+
38+
# new in this provider
39+
context "when standby" do
40+
let(:power_state) { "standby" }
41+
it { expect(host.supports?(:start)).to be_truthy }
42+
end
43+
end
444
end
545

646
context "#reserve_next_available_vnc_port" do
747
context "without EMS defaults set" do
8-
before(:each) do
9-
@ems = FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => nil, :host_default_vnc_port_end => nil)
10-
@host.ext_management_system = @ems
11-
end
48+
let(:ems) { FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => nil, :host_default_vnc_port_end => nil) }
1249

1350
it "normal case" do
14-
@host.update(:next_available_vnc_port => 5901)
51+
host.update(:next_available_vnc_port => 5901)
1552

16-
expect(@host.reserve_next_available_vnc_port).to eq(5901)
17-
expect(@host.next_available_vnc_port).to eq(5902)
53+
expect(host.reserve_next_available_vnc_port).to eq(5901)
54+
expect(host.next_available_vnc_port).to eq(5902)
1855
end
1956

2057
it "with last value of nil" do
21-
@host.update(:next_available_vnc_port => nil)
58+
host.update(:next_available_vnc_port => nil)
2259

23-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
24-
expect(@host.next_available_vnc_port).to eq(5901)
60+
expect(host.reserve_next_available_vnc_port).to eq(5900)
61+
expect(host.next_available_vnc_port).to eq(5901)
2562
end
2663

2764
it "with last value at end of range" do
28-
@host.update(:next_available_vnc_port => 5999)
65+
host.update(:next_available_vnc_port => 5999)
2966

30-
expect(@host.reserve_next_available_vnc_port).to eq(5999)
31-
expect(@host.next_available_vnc_port).to eq(5900)
67+
expect(host.reserve_next_available_vnc_port).to eq(5999)
68+
expect(host.next_available_vnc_port).to eq(5900)
3269
end
3370

3471
it "with last value before start of range" do
35-
@host.update(:next_available_vnc_port => 5899)
72+
host.update(:next_available_vnc_port => 5899)
3673

37-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
38-
expect(@host.next_available_vnc_port).to eq(5901)
74+
expect(host.reserve_next_available_vnc_port).to eq(5900)
75+
expect(host.next_available_vnc_port).to eq(5901)
3976
end
4077

4178
it "with last value after end of range" do
42-
@host.update(:next_available_vnc_port => 6000)
79+
host.update(:next_available_vnc_port => 6000)
4380

44-
expect(@host.reserve_next_available_vnc_port).to eq(5900)
45-
expect(@host.next_available_vnc_port).to eq(5901)
81+
expect(host.reserve_next_available_vnc_port).to eq(5900)
82+
expect(host.next_available_vnc_port).to eq(5901)
4683
end
4784
end
4885

4986
context "with EMS defaults set" do
50-
before(:each) do
51-
@ems = FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => 5925, :host_default_vnc_port_end => 5930)
52-
@host.ext_management_system = @ems
53-
end
87+
let(:ems) { FactoryBot.create(:ems_vmware, :host_default_vnc_port_start => 5925, :host_default_vnc_port_end => 5930) }
5488

5589
it "normal case" do
56-
@host.update(:next_available_vnc_port => 5926)
90+
host.update(:next_available_vnc_port => 5926)
5791

58-
expect(@host.reserve_next_available_vnc_port).to eq(5926)
59-
expect(@host.next_available_vnc_port).to eq(5927)
92+
expect(host.reserve_next_available_vnc_port).to eq(5926)
93+
expect(host.next_available_vnc_port).to eq(5927)
6094
end
6195

6296
it "with last value of nil" do
63-
@host.update(:next_available_vnc_port => nil)
97+
host.update(:next_available_vnc_port => nil)
6498

65-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
66-
expect(@host.next_available_vnc_port).to eq(5926)
99+
expect(host.reserve_next_available_vnc_port).to eq(5925)
100+
expect(host.next_available_vnc_port).to eq(5926)
67101
end
68102

69103
it "with last value at end of range" do
70-
@host.update(:next_available_vnc_port => 5930)
104+
host.update(:next_available_vnc_port => 5930)
71105

72-
expect(@host.reserve_next_available_vnc_port).to eq(5930)
73-
expect(@host.next_available_vnc_port).to eq(5925)
106+
expect(host.reserve_next_available_vnc_port).to eq(5930)
107+
expect(host.next_available_vnc_port).to eq(5925)
74108
end
75109

76110
it "with last value before start of range" do
77-
@host.update(:next_available_vnc_port => 5924)
111+
host.update(:next_available_vnc_port => 5924)
78112

79-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
80-
expect(@host.next_available_vnc_port).to eq(5926)
113+
expect(host.reserve_next_available_vnc_port).to eq(5925)
114+
expect(host.next_available_vnc_port).to eq(5926)
81115
end
82116

83117
it "with last value after end of range" do
84-
@host.update(:next_available_vnc_port => 5931)
118+
host.update(:next_available_vnc_port => 5931)
85119

86-
expect(@host.reserve_next_available_vnc_port).to eq(5925)
87-
expect(@host.next_available_vnc_port).to eq(5926)
120+
expect(host.reserve_next_available_vnc_port).to eq(5925)
121+
expect(host.next_available_vnc_port).to eq(5926)
88122
end
89123
end
90124
end

0 commit comments

Comments
 (0)