Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create provider discovery feature. #61

Merged
merged 6 commits into from
Jul 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 27 additions & 9 deletions app/models/manageiq/providers/lenovo/manager_mixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,47 @@ def raw_connect(username, password, host, port, verify_ssl)
# Factory method to create EmsLenovo with instances
# or images for the given authentication. Created EmsLenovo instances
# will automatically have EmsRefreshes queued up.
def discover(username, password, host, port, verify_ssl = 0)
new_emses = []
def discover(ip_address, port)
require 'xclarity_client'

if XClarityClient::Discover.responds?(ip_address, port)
new_ems = create!(
:name => "Discovered Provider ##{count + 1}",
:hostname => URI('https://' + ip_address),
:zone => Zone.default_zone
)

raw_connect(username, password, host, port, verify_ssl)
# Set empty authentications
create_default_authentications(new_ems)

EmsRefresh.queue_refresh(new_emses) unless new_emses.blank?
_log.info("Reached Lenovo XClarity Appliance with endpoint: #{ip_address}")
_log.info("Created EMS: #{new_ems.name} with id: #{new_ems.id}")
end

new_emses
EmsRefresh.queue_refresh(new_ems) unless new_ems.blank?
end

def discover_queue(username, password, zone = nil)
def discover_queue(ip_address, port, zone = nil)
MiqQueue.put(
:class_name => name,
:method_name => "discover_from_queue",
:args => [username, MiqPassword.encrypt(password)],
:args => [ip_address, port],
:zone => zone
)
end

private

def discover_from_queue(username, password)
discover(username, MiqPassword.decrypt(password))
def discover_from_queue(ip_address, port)
discover(ip_address, port)
end

def create_default_authentications(ems)
auth = Authentication.new
auth.userid = ''
auth.password = ''
auth.resource_id = ems.id
auth.save!
end
end
end
2 changes: 2 additions & 0 deletions manageiq-providers-lenovo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,7 @@ Gem::Specification.new do |s|

s.add_dependency "xclarity_client", "~> 0.5.2"
s.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
s.add_development_dependency "webmock", "~> 2.1.0"
s.add_development_dependency "simplecov"
s.add_dependency "faker", "~>1.8.3"
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'xclarity_client'
require 'faker'

describe ManageIQ::Providers::Lenovo::PhysicalInfraManager do
before :all do
Expand Down Expand Up @@ -125,11 +126,6 @@
end
end

it 'will execute discover successfully' do
result = described_class.new.class.discover(@auth[:user], @auth[:pass], @auth[:host], @auth[:port])
expect(result).to eq([])
end

it 'will execute discover_queue successfully' do
result = described_class.new.class.discover_queue(@auth[:user], @auth[:pass])
expect(result).to_not eq(nil)
Expand All @@ -152,4 +148,28 @@
client = described_class.new.connect(@auth)
expect(client).to be_a(XClarityClient::Client)
end

context 'valid discover' do
before :each do
EvmSpecHelper.local_miq_server(:zone => Zone.seed)
@port = Random.rand(10_000).to_s
@address = URI('https://' + Faker::Internet.ip_v4_address + ':' + @port)
WebMock.allow_net_connect!
stub_request(:get, File.join(@address.to_s, '/aicc')).to_return(:status => [200, 'OK'])
end

it 'should create a new instance' do
expect { described_class.discover(@address.host, @port) }.to change { described_class.count }.by 1
end
end

context 'invalid discover' do
before :each do
@port = Random.rand(10_000).to_s
@address = URI('https://' + Faker::Internet.ip_v4_address + ':' + @port)
end
it 'should not create a new instance' do
expect { described_class.discover(@address.host, @port) }.to change { described_class.count }.by 0
end
end
end