|
1 | 1 | 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 |
4 | 44 | end |
5 | 45 |
|
6 | 46 | context "#reserve_next_available_vnc_port" do |
7 | 47 | 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) } |
12 | 49 |
|
13 | 50 | it "normal case" do |
14 | | - @host.update(:next_available_vnc_port => 5901) |
| 51 | + host.update(:next_available_vnc_port => 5901) |
15 | 52 |
|
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) |
18 | 55 | end |
19 | 56 |
|
20 | 57 | it "with last value of nil" do |
21 | | - @host.update(:next_available_vnc_port => nil) |
| 58 | + host.update(:next_available_vnc_port => nil) |
22 | 59 |
|
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) |
25 | 62 | end |
26 | 63 |
|
27 | 64 | 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) |
29 | 66 |
|
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) |
32 | 69 | end |
33 | 70 |
|
34 | 71 | 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) |
36 | 73 |
|
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) |
39 | 76 | end |
40 | 77 |
|
41 | 78 | 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) |
43 | 80 |
|
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) |
46 | 83 | end |
47 | 84 | end |
48 | 85 |
|
49 | 86 | 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) } |
54 | 88 |
|
55 | 89 | it "normal case" do |
56 | | - @host.update(:next_available_vnc_port => 5926) |
| 90 | + host.update(:next_available_vnc_port => 5926) |
57 | 91 |
|
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) |
60 | 94 | end |
61 | 95 |
|
62 | 96 | it "with last value of nil" do |
63 | | - @host.update(:next_available_vnc_port => nil) |
| 97 | + host.update(:next_available_vnc_port => nil) |
64 | 98 |
|
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) |
67 | 101 | end |
68 | 102 |
|
69 | 103 | 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) |
71 | 105 |
|
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) |
74 | 108 | end |
75 | 109 |
|
76 | 110 | 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) |
78 | 112 |
|
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) |
81 | 115 | end |
82 | 116 |
|
83 | 117 | 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) |
85 | 119 |
|
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) |
88 | 122 | end |
89 | 123 | end |
90 | 124 | end |
|
0 commit comments