From 5657313a861f67ae27bcc591fe5c87a42b698652 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 13 Oct 2017 16:28:57 +0200 Subject: [PATCH 1/5] update raw connect method to accomodate OpenStack complexity --- .../providers/openstack/manager_mixin.rb | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index 31108a9eb..3a2232661 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -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 = self.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 => password, :save => false, :role => 'default', :authtype => 'default'} + ems.connection_configurations = [{:endpoint => endpoint, + :authentication => authentication}] + ems.connect(:service => service) end end From 9f2bd70a03d1757ac1ff72008086b5863c6ee3a2 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 13 Oct 2017 16:55:55 +0200 Subject: [PATCH 2/5] correct stylistic issues --- app/models/manageiq/providers/openstack/manager_mixin.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index 3a2232661..be804944d 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -12,7 +12,7 @@ module ManageIQ::Providers::Openstack::ManagerMixin # module ClassMethods def raw_connect(password, params, service = "Compute") - ems = self.new + ems = new ems.name = params[:name].strip ems.provider_region = params[:provider_region] ems.api_version = params[:api_version].strip @@ -24,7 +24,7 @@ def raw_connect(password, params, service = "Compute") endpoint = {:role => :default, :hostname => hostname, :port => port, :security_protocol => ems.security_protocol} authentication = {:userid => user, :password => password, :save => false, :role => 'default', :authtype => 'default'} ems.connection_configurations = [{:endpoint => endpoint, - :authentication => authentication}] + :authentication => authentication}] ems.connect(:service => service) end end From 2fac5fc254e9315e230f38dbd05091cc16cfc984 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 13 Oct 2017 17:14:42 +0200 Subject: [PATCH 3/5] decrypt password --- app/models/manageiq/providers/openstack/manager_mixin.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index be804944d..57f5007c5 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -22,7 +22,7 @@ def raw_connect(password, params, service = "Compute") 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 => password, :save => false, :role => 'default', :authtype => 'default'} + authentication = {:userid => user, :password => MiqPassword.decrypt(password), :save => false, :role => 'default', :authtype => 'default'} ems.connection_configurations = [{:endpoint => endpoint, :authentication => authentication}] ems.connect(:service => service) From edb4e6a139c04e56b0a4eed867c9534620c8d87b Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 13 Oct 2017 18:07:33 +0200 Subject: [PATCH 4/5] fix tests --- .../providers/openstack/manager_mixin.rb | 2 +- .../providers/openstack/cloud_manager_spec.rb | 38 ++++++++++++++----- 2 files changed, 30 insertions(+), 10 deletions(-) diff --git a/app/models/manageiq/providers/openstack/manager_mixin.rb b/app/models/manageiq/providers/openstack/manager_mixin.rb index 57f5007c5..2042faae4 100644 --- a/app/models/manageiq/providers/openstack/manager_mixin.rb +++ b/app/models/manageiq/providers/openstack/manager_mixin.rb @@ -22,7 +22,7 @@ def raw_connect(password, params, service = "Compute") 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.decrypt(password), :save => false, :role => 'default', :authtype => 'default'} + 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) diff --git a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb index c6497729a..f367397e7 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb @@ -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 @@ -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 From 775d7bbc3035d44120515508a276327006bd7fb6 Mon Sep 17 00:00:00 2001 From: Tzu-Mainn Chen Date: Fri, 13 Oct 2017 18:19:03 +0200 Subject: [PATCH 5/5] stylistic fixes --- .../providers/openstack/cloud_manager_spec.rb | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb index f367397e7..007cd884a 100644 --- a/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb +++ b/spec/models/manageiq/providers/openstack/cloud_manager_spec.rb @@ -60,13 +60,13 @@ it "accepts and decrypts encrypted passwords" do params = { - :name => 'dummy', - :provider_region => '', - :api_version => 'v2.0', + :name => 'dummy', + :provider_region => '', + :api_version => 'v2.0', :default_security_protocol => 'non-ssl', - :default_userid => 'admin', - :default_hostname => 'address', - :default_api_port => '5000' + :default_userid => 'admin', + :default_hostname => 'address', + :default_api_port => '5000' } expect(OpenstackHandle::Handle).to receive(:raw_connect).with( "admin", @@ -81,13 +81,13 @@ it "works with unencrypted passwords" do params = { - :name => 'dummy', - :provider_region => '', - :api_version => 'v2.0', + :name => 'dummy', + :provider_region => '', + :api_version => 'v2.0', :default_security_protocol => 'non-ssl', - :default_userid => 'admin', - :default_hostname => 'address', - :default_api_port => '5000' + :default_userid => 'admin', + :default_hostname => 'address', + :default_api_port => '5000' } expect(OpenstackHandle::Handle).to receive(:raw_connect).with( "admin",