Skip to content

Commit

Permalink
Merge pull request #118 from tzumainn/openstack-validation
Browse files Browse the repository at this point in the history
update raw connect method to accomodate OpenStack complexity
  • Loading branch information
mansam authored Oct 17, 2017
2 parents 315fdb3 + 775d7bb commit 413554b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 17 deletions.
23 changes: 15 additions & 8 deletions app/models/manageiq/providers/openstack/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,21 @@ module ManageIQ::Providers::Openstack::ManagerMixin
# OpenStack interactions
#
module ClassMethods
def raw_connect(username, password, auth_url, service = "Compute")
require 'manageiq/providers/openstack/legacy/openstack_handle'
OpenstackHandle::Handle.raw_connect(username, MiqPassword.try_decrypt(password), auth_url, service)
end

def auth_url(address, port = nil)
require 'manageiq/providers/openstack/legacy/openstack_handle'
OpenstackHandle::Handle.auth_url(address, port)
def raw_connect(password, params, service = "Compute")
ems = new
ems.name = params[:name].strip
ems.provider_region = params[:provider_region]
ems.api_version = params[:api_version].strip
ems.security_protocol = params[:default_security_protocol].strip
ems.keystone_v3_domain_id = params[:keystone_v3_domain_id]

user, hostname, port = params[:default_userid], params[:default_hostname].strip, params[:default_api_port].strip

endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol}
authentication = {:userid => user, :password => MiqPassword.try_decrypt(password), :save => false, :role => 'default', :authtype => 'default'}
ems.connection_configurations = [{:endpoint => endpoint,
:authentication => authentication}]
ems.connect(:service => service)
end
end

Expand Down
38 changes: 29 additions & 9 deletions spec/models/manageiq/providers/openstack/cloud_manager_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
describe ManageIQ::Providers::Openstack::CloudManager do
context "Class Methods" do
it("from mixin") { expect(described_class.methods).to include(:auth_url, :raw_connect) }
it("from mixin") { expect(described_class.methods).to include(:raw_connect) }
end

it ".ems_type" do
Expand Down Expand Up @@ -59,25 +59,45 @@
end

it "accepts and decrypts encrypted passwords" do
params = {
:name => 'dummy',
:provider_region => '',
:api_version => 'v2.0',
:default_security_protocol => 'non-ssl',
:default_userid => 'admin',
:default_hostname => 'address',
:default_api_port => '5000'
}
expect(OpenstackHandle::Handle).to receive(:raw_connect).with(
"admin",
"dummy",
"dummy",
"http://address:5000/v2.0/tokens",
"Compute"
"http://address:5000",
"Compute",
instance_of(Hash)
)

described_class.raw_connect("dummy", MiqPassword.encrypt("dummy"), "http://address:5000/v2.0/tokens", "Compute")
described_class.raw_connect(MiqPassword.encrypt("dummy"), params, "Compute")
end

it "works with unencrypted passwords" do
params = {
:name => 'dummy',
:provider_region => '',
:api_version => 'v2.0',
:default_security_protocol => 'non-ssl',
:default_userid => 'admin',
:default_hostname => 'address',
:default_api_port => '5000'
}
expect(OpenstackHandle::Handle).to receive(:raw_connect).with(
"admin",
"dummy",
"dummy",
"http://address:5000/v2.0/tokens",
"Compute"
"http://address:5000",
"Compute",
instance_of(Hash)
)

described_class.raw_connect("dummy", "dummy", "http://address:5000/v2.0/tokens", "Compute")
described_class.raw_connect("dummy", params, "Compute")
end
end

Expand Down

0 comments on commit 413554b

Please sign in to comment.