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

API session not up when getting monitoring system ID #9400

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
37 changes: 11 additions & 26 deletions testsuite/features/support/api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
require_relative 'namespaces/user'
require_relative 'xmlrpc_client'
require_relative 'http_client'
require 'date'

# Abstract parent class describing an API test
class ApiTest
Expand Down Expand Up @@ -61,39 +60,25 @@ def call(name, *params)
Thread.new do
@semaphore.synchronize do
begin
manage_api_lock(name)
response = make_api_call(name, *params)
@token =
if name.include?('user.')
@connection.call('auth.login', login: 'admin', password: 'admin')
else
@connection.call('auth.login', login: $current_user, password: $current_password)
end
params[0][:sessionKey] = @token
response = @connection.call(name, *params)
rescue SystemCallError => e
raise "API call failed: #{e.message}"
ensure
@connection.call('auth.logout', sessionKey: @token) if @token
api_unlock if name.include?('user.')
@token = nil
end
response
end
end
thread.value
end

private

# Handles API lock management
def manage_api_lock(name)
if name.include?('user.')
repeat_until_timeout(timeout: DEFAULT_TIMEOUT, message: 'We couldn\'t get access to the API') do
break unless api_lock?

sleep 1
end
@token = @connection.call('auth.login', login: 'admin', password: 'admin')
else
@token = @connection.call('auth.login', login: $current_user, password: $current_password)
end
end

# Makes the actual API call
def make_api_call(name, *params)
params[0][:sessionKey] = @token
@connection.call(name, *params)
end
end

# Derived class for an XML-RPC test
Expand Down
Loading