-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathcloud_manager_spec.rb
121 lines (100 loc) · 3.71 KB
/
cloud_manager_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
describe ManageIQ::Providers::Google::CloudManager do
context ".raw_connect" do
let(:config) do
{
:provider => "Google",
:google_project => "project",
:google_json_key_string => "encrypted",
:app_name => Vmdb::Appliance.PRODUCT_NAME,
:app_version => Vmdb::Appliance.VERSION,
:google_client_options => {
:proxy => "proxy_uri"
}
}
end
before do
require 'fog/google'
end
it "decrypts json keys" do
expect(::Fog::Compute).to receive(:new).with(config)
described_class.raw_connect("project", MiqPassword.encrypt("encrypted"), {:service => "compute"}, "proxy_uri")
end
it "works with unencrypted keys" do
expect(::Fog::Compute).to receive(:new).with(config)
described_class.raw_connect("project", "encrypted", {:service => "compute"}, "proxy_uri")
end
end
it ".ems_type" do
expect(described_class.ems_type).to eq('gce')
end
it ".description" do
expect(described_class.description).to eq('Google Compute Engine')
end
it "does not create orphaned network_manager" do
ems = FactoryGirl.create(:ems_google)
same_ems = ExtManagementSystem.find(ems.id)
ems.destroy
expect(ExtManagementSystem.count).to eq(0)
same_ems.save!
expect(ExtManagementSystem.count).to eq(0)
end
it "moves the network_manager to the same zone and provider region as the cloud_manager" do
zone1 = FactoryGirl.create(:zone)
zone2 = FactoryGirl.create(:zone)
ems = FactoryGirl.create(:ems_google, :zone => zone1, :provider_region => "us-east1")
expect(ems.network_manager.zone).to eq zone1
expect(ems.network_manager.zone_id).to eq zone1.id
expect(ems.network_manager.provider_region).to eq "us-east1"
ems.zone = zone2
ems.provider_region = "us-central1"
ems.save!
ems.reload
expect(ems.network_manager.zone).to eq zone2
expect(ems.network_manager.zone_id).to eq zone2.id
expect(ems.network_manager.provider_region).to eq "us-central1"
end
context "#connectivity" do
before do
@google_project = "yourprojectid"
@google_json_key = "{\r\n\"type\": \"service_account\",\r\n\"private_key_id\": \"abcdefg\"}"
@e = FactoryGirl.create(:ems_google)
@e.authentications << FactoryGirl.create(:authentication, :userid => "_", :auth_key => @google_json_key)
@e.project = @google_project
end
context "#connect " do
it "defaults" do
expect(described_class).to receive(:raw_connect) do |project, auth_key|
expect(project).to eq(@google_project)
expect(auth_key).to eq(@google_json_key)
end
@e.connect
end
it "sends proxy uri when set to fog-google" do
Settings.http_proxy.gce = {
:host => "192.168.24.99",
:port => "1234",
:user => "my_user",
:password => "my_password"
}
require 'fog/google'
expect(Fog::Compute::Google).to receive(:new) do |options|
expect(options.fetch_path(:google_client_options, :proxy).to_s)
.to eq("http://my_user:[email protected]:1234")
end
@e.connect
end
end
context "#validation" do
it "handles incorrect password" do
allow(ManageIQ::Providers::Google::CloudManager).to receive(:connect).and_raise(StandardError)
expect { @e.verify_credentials }.to raise_error(MiqException::MiqInvalidCredentialsError, /Invalid Google JSON*/)
end
end
end
context 'catalog types' do
let(:ems) { FactoryGirl.create(:ems_google) }
it "#supported_google_types" do
expect(ems.supported_catalog_types).to eq(%w(google))
end
end
end